/usr/include/ITK-4.5/itkMetaFEMObjectConverter.hxx is in libinsighttoolkit4-dev 4.5.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef __itkMetaFEMObjectConverter_hxx
#define __itkMetaFEMObjectConverter_hxx
#include "itkMetaFEMObjectConverter.h"
#include "itkFEMElementBase.h"
#include "itkFEMLightObject.h"
#include "itkFEMMaterialLinearElasticity.h"
#include "itkFEMLoadEdge.h"
#include "itkFEMLoadGrav.h"
#include "itkObjectFactoryBase.h"
namespace itk
{
/** Constructor */
template <unsigned int NDimensions>
MetaFEMObjectConverter<NDimensions>
::MetaFEMObjectConverter()
{
}
template< unsigned int NDimensions >
typename MetaFEMObjectConverter< NDimensions >::MetaObjectType *
MetaFEMObjectConverter< NDimensions>
::CreateMetaObject()
{
return dynamic_cast<MetaObjectType *>(new FEMObjectMetaObjectType);
}
/** Convert a metaFEMObject into an FEMObject SpatialObject */
template <unsigned int NDimensions>
typename MetaFEMObjectConverter<NDimensions>::SpatialObjectPointer
MetaFEMObjectConverter<NDimensions>
::MetaObjectToSpatialObject(const MetaObjectType * mo)
{
const MetaFEMObject *FEMmo = dynamic_cast<const MetaFEMObject *>(mo);
if(FEMmo == 0)
{
itkExceptionMacro(<< "Can't convert MetaObject to MetaFEMObject");
}
FEMObjectSpatialObjectPointer FEMSO = FEMObjectSpatialObjectType::New();
typedef fem::FEMObject<NDimensions> FEMObjectType;
typedef typename FEMObjectType::Pointer FEMObjectPointer;
FEMObjectPointer myFEMObject = FEMObjectType::New();
// copy all the node information
typedef typename MetaFEMObject::NodeListType NodeListType;
const NodeListType nodelist = FEMmo->GetNodeList();
typename NodeListType::const_iterator it_nodes = nodelist.begin();
while(it_nodes != nodelist.end())
{
FEMObjectNode *node = (*it_nodes);
// create a new object of the correct class
//a = FEMOF::Create(clID);
fem::Element::Node::Pointer o1 = fem::Element::Node::New();
o1->SetGlobalNumber(node->m_GN);
fem::Element::VectorType pt(node->m_Dim);
for (unsigned int i=0; i<node->m_Dim; i++)
{
pt[i] = node->m_X[i];
}
o1->SetCoordinates(pt);
myFEMObject->AddNextNode(o1);
it_nodes++;
}
// copy all the material information
// as of now linear elastic material property is the only
// material property type. other types could be added in the
// future.
typedef typename MetaFEMObject::MaterialListType MaterialListType;
const MaterialListType materiallist = FEMmo->GetMaterialList();
typename MaterialListType::const_iterator it_material = materiallist.begin();
while(it_material != materiallist.end())
{
FEMObjectMaterial *material = (*it_material);
fem::MaterialLinearElasticity::Pointer o1 =
fem::MaterialLinearElasticity::New();
o1->SetGlobalNumber(material->m_GN);
o1->SetYoungsModulus(material->E); /* Young modulus */
o1->SetPoissonsRatio(material->nu);
o1->SetCrossSectionalArea(material->A); /* Crossection area */
o1->SetMomentOfInertia(material->I); /* Moment of inertia */
o1->SetThickness(material->h);
o1->SetDensityHeatProduct(material->RhoC);
myFEMObject->AddNextMaterial(o1);
it_material++;
}
// copy all the Element information
typedef typename MetaFEMObject::ElementListType ElementListType;
const ElementListType elementlist = FEMmo->GetElementList();
typename ElementListType::const_iterator it_elements = elementlist.begin();
while(it_elements != elementlist.end())
{
FEMObjectElement *element = (*it_elements);
itk::LightObject::Pointer a =
ObjectFactoryBase::CreateInstance ( element->m_ElementName );
a->UnRegister();
fem::Element::Pointer o1 = dynamic_cast<fem::Element *>(a.GetPointer());
o1->SetGlobalNumber(element->m_GN);
int numNodes = element->m_NumNodes;
for (int i=0; i<numNodes; i++)
{
o1->SetNode(i, myFEMObject->GetNodeWithGlobalNumber(element->m_NodesId[i]));
}
o1->SetMaterial( myFEMObject->GetMaterialWithGlobalNumber(element->m_MaterialGN).GetPointer() );
myFEMObject->AddNextElement( o1 );
it_elements++;
}
// copy all the load and boundary condition information
typedef typename MetaFEMObject::LoadListType LoadListType;
const LoadListType loadlist = FEMmo->GetLoadList();
typename LoadListType::const_iterator it_load = loadlist.begin();
while(it_load != loadlist.end())
{
FEMObjectLoad *load = (*it_load);
std::string loadname = std::string(load->m_LoadName);
if(loadname == "LoadNode")
{
fem::LoadNode::Pointer o1 =
fem::LoadNode::New();
o1->SetGlobalNumber(load->m_GN);
o1->SetElement(myFEMObject->GetElementWithGlobalNumber(load->m_ElementGN));
o1->SetNode(load->m_NodeNumber);
int dim = load->m_Dim;
vnl_vector< double > F(dim);
for (int i=0; i<dim; i++)
{
F[i] = load->m_ForceVector[i];
}
o1->SetForce(F);
myFEMObject->AddNextLoad( o1 );
}
else if(loadname == "LoadBC")
{
fem::LoadBC::Pointer o1 =
fem::LoadBC::New();
o1->SetGlobalNumber(load->m_GN);
o1->SetDegreeOfFreedom(load->m_DOF);
o1->SetElement(myFEMObject->GetElementWithGlobalNumber(load->m_ElementGN));
int numRHS = load->m_NumRHS;
vnl_vector< double > F(numRHS);
for (int i=0; i<numRHS; i++)
{
F[i] = load->m_RHS[i];
}
o1->SetValue(F);
myFEMObject->AddNextLoad( o1 );
}
else if(loadname == "LoadBCMFC")
{
fem::LoadBCMFC::Pointer o1 =
fem::LoadBCMFC::New();
o1->SetGlobalNumber(load->m_GN);
int NumLHS;
int elementGN;
int DOF;
float Value;
NumLHS = load->m_NumLHS;
for ( int i = 0; i < NumLHS; i++ )
{
FEMObjectMFCTerm *mfcTerm =
dynamic_cast< FEMObjectMFCTerm * > (load->m_LHS[i]);
elementGN = mfcTerm->m_ElementGN;
DOF = mfcTerm->m_DOF;
Value = mfcTerm->m_Value;
o1->GetLeftHandSideArray().push_back(fem::LoadBCMFC::MFCTerm(myFEMObject->GetElementWithGlobalNumber(elementGN).GetPointer(), DOF, Value) );
}
int NumRHS = load->m_NumRHS;
for (int i=0; i<NumRHS; i++)
{
o1->GetRightHandSideArray().set_size(o1->GetRightHandSideArray().size() + 1);
o1->GetRightHandSideArray().put(o1->GetRightHandSideArray().size() - 1, load->m_RHS[i]);
}
myFEMObject->AddNextLoad( o1 );
}
else if(loadname == "LoadEdge")
{
fem::LoadEdge::Pointer o1 =
fem::LoadEdge::New();
o1->SetGlobalNumber(load->m_GN);
int numRows;
o1->AddNextElement(myFEMObject->GetElementWithGlobalNumber(load->m_ElementGN));
o1->SetGlobalNumber(load->m_GN);
o1->SetEdge(load->m_EdgeNumber);
METAIO_STL::vector< METAIO_STL::vector<float> > force = load->m_ForceMatrix;
numRows = force.size();
if(numRows)
{
METAIO_STL::vector<float> forcevector = force[0];
int numCols = forcevector.size();
o1->GetForce().set_size(numRows, numCols);
for ( int i = 0; i < numRows; i++ )
{
forcevector = force[i];
for ( int j = 0; j < numCols; j++ )
{
o1->GetForce()[i][j] = forcevector[j];
}
}
myFEMObject->AddNextLoad( o1 );
}
}
else if(loadname == "LoadGravConst")
{
fem::LoadGravConst::Pointer o1 =
fem::LoadGravConst::New();
o1->SetGlobalNumber(load->m_GN);
for (int i=0; i<load->m_NumElements; i++)
{
o1->GetElementArray().push_back(myFEMObject->GetElementWithGlobalNumber(load->m_Elements[i]).GetPointer());
}
o1->GetForce().set_size(load->m_Dim);
for(int i=0; i<load->m_Dim; i++)
{
o1->GetForce()[i] = load->m_ForceVector[i];
}
myFEMObject->AddNextLoad( o1 );
}
else if(loadname == "LoadLandmark")
{
fem::LoadLandmark::Pointer o1 =
fem::LoadLandmark::New();
o1->SetGlobalNumber(load->m_GN);
o1->SetEta(load->m_Variance);
o1->GetElementArray().resize(1);
int dim = load->m_Undeformed.size();
vnl_vector<double> source;
vnl_vector<double> target;
vnl_vector<double> point;
vnl_vector<double> force;
source.set_size(dim);
target.set_size(dim);
point.set_size(dim);
force.set_size(dim);
for (int i=0; i<dim; i++)
{
source[i] = load->m_Deformed[i];
target[i] = load->m_Undeformed[i];
point[i] = load->m_Deformed[i];
force[i] = load->m_Undeformed[i] - load->m_Deformed[i];
}
//FIXME - Check Source and Target
o1->SetSource( source );
o1->SetTarget( target );
o1->SetPoint( point );
o1->SetForce( force );
/*
o1->GetSource().set_size(dim);
o1->GetPoint().set_size(dim);
o1->GetTarget().set_size(dim);
o1->GetForce().set_size(dim);
for (int i=0; i<dim; i++)
{
o1->GetSource()[i] = load->m_Deformed[i];
o1->GetPoint()[i] = load->m_Deformed[i];
o1->GetTarget()[i] = load->m_Undeformed[i];
o1->GetForce()[i] = load->m_Undeformed[i] - load->m_Deformed[i];
}
*/
myFEMObject->AddNextLoad( o1 );
}
it_load++;
}
FEMSO->SetFEMObject(myFEMObject);
return FEMSO.GetPointer();
}
/** Convert an FEMObject SpatialObject into a metaFEMObject */
template <unsigned int NDimensions>
typename MetaFEMObjectConverter<NDimensions>::MetaObjectType *
MetaFEMObjectConverter<NDimensions>
::SpatialObjectToMetaObject(const SpatialObjectType * so)
{
FEMObjectSpatialObjectConstPointer FEMSO =
dynamic_cast<const FEMObjectSpatialObjectType *>(so);
if(FEMSO.IsNull())
{
itkExceptionMacro(<< "Can't downcast SpatialObject to FEMObjectSpatialObject");
}
typedef fem::FEMObject<NDimensions> FEMObjectType;
typedef typename FEMObjectType::ConstPointer FEMObjectConstPointer;
FEMObjectConstPointer curFEMObject = FEMSO->GetFEMObject();
FEMObjectMetaObjectType * FEMmo = new MetaFEMObject(NDimensions);
// copy the relevant info from spatial object to femobject
// copy node info.
const int numSONodes = curFEMObject->GetNumberOfNodes();
for (int i=0; i<numSONodes; i++)
{
FEMObjectNode *Node = new FEMObjectNode(NDimensions);
fem::Element::Node::ConstPointer SONode = curFEMObject->GetNode(i);
fem::Element::VectorType pt = SONode->GetCoordinates();
Node->m_GN = SONode->GetGlobalNumber();
for (unsigned int j=0; j<NDimensions; j++)
{
Node->m_X[j] = pt[j];
}
FEMmo->GetNodeList().push_back(Node);
}
// copy material info.
int numMaterial = curFEMObject->GetNumberOfMaterials();
for (int i=0; i<numMaterial; i++)
{
fem::Material::ConstPointer SOMaterial = curFEMObject->GetMaterial(i);
FEMObjectMaterial *Material = new FEMObjectMaterial;
// check for the material type
std::string mat_name = SOMaterial->GetNameOfClass();
if(mat_name == "MaterialLinearElasticity")
{
strcpy(Material->m_MaterialName, mat_name.c_str());
fem::MaterialLinearElasticity::ConstPointer SOMaterialCast =
dynamic_cast<const fem::MaterialLinearElasticity * >( SOMaterial.GetPointer() );
Material->m_GN = SOMaterialCast->GetGlobalNumber();
Material->E = SOMaterialCast->GetYoungsModulus();
Material->A = SOMaterialCast->GetCrossSectionalArea();
Material->I = SOMaterialCast->GetMomentOfInertia();
Material->nu = SOMaterialCast->GetPoissonsRatio();
Material->h = SOMaterialCast->GetThickness();
Material->RhoC = SOMaterialCast->GetDensityHeatProduct();
FEMmo->GetMaterialList().push_back(Material);
}
}
// copy element info.
const int numElements = curFEMObject->GetNumberOfElements();
for (int i=0; i<numElements; i++)
{
fem::Element::ConstPointer SOElement = curFEMObject->GetElement(i);
const int numNodes = SOElement->GetNumberOfNodes();
FEMObjectElement *Element = new FEMObjectElement(numNodes);
Element->m_GN = SOElement->GetGlobalNumber();
Element->m_Dim = NDimensions;
Element->m_NumNodes = numNodes;
std::string element_name = SOElement->GetNameOfClass();
strcpy(Element->m_ElementName, element_name.c_str());
Element->m_MaterialGN = SOElement->GetMaterial()->GetGlobalNumber();
for (int j=0; j<numNodes; j++)
{
Element->m_NodesId[j] = SOElement->GetNode(j)->GetGlobalNumber();
}
FEMmo->GetElementList().push_back(Element);
}
// copy load/bc info.
int numLoads = curFEMObject->GetNumberOfLoads();
for (int ll=0; ll<numLoads; ++ll)
{
fem::Load::ConstPointer SOLoad = curFEMObject->GetLoad(ll);
FEMObjectLoad *Load = new FEMObjectLoad;
// check for the load/bc type
std::string load_name = SOLoad->GetNameOfClass();
strcpy(Load->m_LoadName, load_name.c_str());
if(load_name == "LoadNode")
{
fem::LoadNode::ConstPointer SOLoadCast =
dynamic_cast<const fem::LoadNode * >( SOLoad.GetPointer() );
Load->m_GN = SOLoadCast->GetGlobalNumber();
Load->m_ElementGN = SOLoadCast->GetElement()->GetGlobalNumber();
Load->m_NodeNumber = SOLoadCast->GetNode();
int dim = SOLoadCast->GetForce().size();
Load->m_ForceVector.resize(dim);
Load->m_Dim = dim;
for (int j=0; j<dim; j++)
{
Load->m_ForceVector[j] = SOLoadCast->GetForce()[j];
}
FEMmo->GetLoadList().push_back(Load);
}
else if(load_name == "LoadBC")
{
fem::LoadBC::ConstPointer SOLoadCast =
dynamic_cast<const fem::LoadBC * >( SOLoad.GetPointer() );
Load->m_GN = SOLoadCast->GetGlobalNumber();
Load->m_DOF = SOLoadCast->GetDegreeOfFreedom();
Load->m_ElementGN = SOLoadCast->GetElement()->GetGlobalNumber();
int numRHS = SOLoadCast->GetValue().size();
Load->m_RHS.resize(numRHS);
Load->m_NumRHS = numRHS;
for (int j=0; j<numRHS; j++)
{
Load->m_RHS[j] = SOLoadCast->GetValue()[j];
}
FEMmo->GetLoadList().push_back(Load);
}
else if(load_name == "LoadBCMFC")
{
int elementGN;
int DOF;
float Value;
fem::LoadBCMFC::ConstPointer SOLoadCast =
dynamic_cast<const fem::LoadBCMFC * >( SOLoad.GetPointer() );
Load->m_GN = SOLoadCast->GetGlobalNumber();
Load->m_NumLHS = SOLoadCast->GetNumberOfLeftHandSideTerms();
for ( int i = 0; i < Load->m_NumLHS; i++ )
{
/** set the global number of element that we're applying the load to */
elementGN = SOLoadCast->GetLeftHandSideTerm(i).m_element->GetGlobalNumber();
/** set the dof within that element */
DOF = SOLoadCast->GetLeftHandSideTerm(i).dof;
/** set weight */
Value = SOLoadCast->GetLeftHandSideTerm(i).value;
/** add a new MFCTerm to the lhs */
FEMObjectMFCTerm *mfcTerm = new FEMObjectMFCTerm(elementGN, DOF, Value);
Load->m_LHS.push_back(mfcTerm);
}
/** set the rhs */
Load->m_NumRHS = SOLoadCast->GetNumberOfRightHandSideTerms();
Load->m_RHS.resize(Load->m_NumRHS);
for (int i=0; i<Load->m_NumRHS; i++)
{
Load->m_RHS[i] = SOLoadCast->GetRightHandSideTerm(i);
}
FEMmo->GetLoadList().push_back(Load);
}
else if(load_name == "LoadEdge")
{
fem::LoadEdge::ConstPointer SOLoadCast =
dynamic_cast<const fem::LoadEdge * >( SOLoad.GetPointer() );
Load->m_GN = SOLoadCast->GetGlobalNumber();
Load->m_ElementGN = SOLoadCast->GetElementArray()[0]->GetGlobalNumber();
Load->m_EdgeNumber = SOLoadCast->GetEdge();
vnl_matrix< fem::Element::Float > force = SOLoadCast->GetForce();
const int numRows = force.rows();
const int numCols = force.columns();
for ( int i = 0; i < numRows; i++ )
{
METAIO_STL::vector<float> F(numCols);
for ( int j = 0; j < numCols; j++ )
{
F[j] = force[i][j];
}
Load->m_ForceMatrix.push_back(F);
}
FEMmo->GetLoadList().push_back(Load);
}
else if(load_name == "LoadGravConst")
{
fem::LoadGravConst::ConstPointer SOLoadCast =
dynamic_cast<const fem::LoadGravConst * >( SOLoad.GetPointer() );
Load->m_GN = SOLoadCast->GetGlobalNumber();
const int numLoadElements = SOLoadCast->GetElementArray().size();
Load->m_NumElements = numLoadElements;
for (int i=0; i<numLoadElements; i++)
{
const int elementGN = SOLoadCast->GetElementArray()[i]->GetGlobalNumber();
Load->m_Elements.push_back(elementGN);
}
Load->m_Dim = SOLoadCast->GetForce().size();
for (int i=0; i<Load->m_Dim; i++)
{
Load->m_ForceVector.push_back(SOLoadCast->GetForce()[i]);
}
FEMmo->GetLoadList().push_back(Load);
}
else if(load_name == "LoadLandmark")
{
fem::LoadLandmark::ConstPointer SOLoadCast =
dynamic_cast<const fem::LoadLandmark * >( SOLoad.GetPointer() );
Load->m_GN = SOLoadCast->GetGlobalNumber();
Load->m_Variance = SOLoadCast->GetEta();
const int dim = SOLoadCast->GetSource().size();
Load->m_Undeformed.resize(dim);
Load->m_Deformed.resize(dim);
for (int i=0; i<dim; i++)
{
Load->m_Deformed[i] = SOLoadCast->GetSource()[i];
Load->m_Undeformed[i] = SOLoadCast->GetTarget()[i];
}
FEMmo->GetLoadList().push_back(Load);
}
}
return FEMmo;
}
} // end namespace itk
#endif
|