<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10px"><font size="2">Dear ITK Users,</font><div id="yui_3_16_0_ym19_1_1507462341160_16020"><font size="2"><br id="yui_3_16_0_ym19_1_1507462341160_16021"></font></div><div id="yui_3_16_0_ym19_1_1507462341160_16022" dir="ltr"><font id="yui_3_16_0_ym19_1_1507462341160_16370" size="2">According the mail <a id="yui_3_16_0_ym19_1_1507462341160_16023" rel="nofollow" target="_blank" href="https://public.kitware.com/pipermail/insight-users/2007-November/024272.html">https://public.kitware.com/pipermail/insight-users/2007-November/024272.html</a>
, I have converted my vtkUnstructuredGrid, wich I extracted from a
vtkPolyData and contains TRIANGLE_CELL's to the itkMesh and than from
itkMesh to itk::Fem::Object to deform my mesh:</font></div><div id="yui_3_16_0_ym19_1_1507462341160_16024" dir="ltr"><font id="yui_3_16_0_ym19_1_1507462341160_16369" size="2">My problem is: If I call "m_FemSolver->Update();" ,I get a segmentation fault, which I really not understand. <br id="yui_3_16_0_ym19_1_1507462341160_16025"></font></div><div id="yui_3_16_0_ym19_1_1507462341160_16026" dir="ltr"><font size="2"><br id="yui_3_16_0_ym19_1_1507462341160_16027"></font></div><div id="yui_3_16_0_ym19_1_1507462341160_16028" dir="ltr"><font id="yui_3_16_0_ym19_1_1507462341160_16368" size="2">Program received signal SIGSEGV, Segmentation fault.<br id="yui_3_16_0_ym19_1_1507462341160_16029">0x00007fffb1086dd5 in itk::fem::FEMObject<2u>::DeepCopy (this=0x4cc5ee0, <br id="yui_3_16_0_ym19_1_1507462341160_16030"> Copy=0x4cc1780)<br id="yui_3_16_0_ym19_1_1507462341160_16031"> at /home/toolkits/itk-4.7.2/Modules/Numerics/FEM/include/itkFEMObject.hxx:157<br id="yui_3_16_0_ym19_1_1507462341160_16032">157 a->UnRegister();<br id="yui_3_16_0_ym19_1_1507462341160_16033"></font></div><div id="yui_3_16_0_ym19_1_1507462341160_16034" dir="ltr"><font size="2"><br id="yui_3_16_0_ym19_1_1507462341160_16035"></font></div><div id="yui_3_16_0_ym19_1_1507462341160_16036" dir="ltr"><font size="2"><br id="yui_3_16_0_ym19_1_1507462341160_16037"></font></div><div id="yui_3_16_0_ym19_1_1507462341160_16038" dir="ltr"><font id="yui_3_16_0_ym19_1_1507462341160_16366" size="2">void itkMeshToFemMesh::updateItkMeshSlot(itk::Mesh<double, 3, MeshTraitsType> *itkMesh)<br id="yui_3_16_0_ym19_1_1507462341160_16039">{<br id="yui_3_16_0_ym19_1_1507462341160_16040"> typedef itk::fem::FEMObject<3> FemObjectType;<br id="yui_3_16_0_ym19_1_1507462341160_16041"> FemObjectType::Pointer m_FemObject= FemObjectType::New();<br id="yui_3_16_0_ym19_1_1507462341160_16042"><br id="yui_3_16_0_ym19_1_1507462341160_16043"> typedef itk::fem::Solver<3> SolverType;<br id="yui_3_16_0_ym19_1_1507462341160_16044"> typedef SolverType::Pointer SolverPointerType;<br id="yui_3_16_0_ym19_1_1507462341160_16045"> SolverPointerType m_FemSolver= SolverType::New();<br id="yui_3_16_0_ym19_1_1507462341160_16046"><br id="yui_3_16_0_ym19_1_1507462341160_16047"> // Define the Element Material properties<br id="yui_3_16_0_ym19_1_1507462341160_16048"> typedef itk::fem::MaterialLinearElasticity MaterialType;<br id="yui_3_16_0_ym19_1_1507462341160_16049"> MaterialType::Pointer material= MaterialType::New();<br id="yui_3_16_0_ym19_1_1507462341160_16050"> material->SetGlobalNumber(0);<br id="yui_3_16_0_ym19_1_1507462341160_16051"> material->SetYoungsModulus(200E6);<br id="yui_3_16_0_ym19_1_1507462341160_16052"> material->SetCrossSectionalArea(1.0);<br id="yui_3_16_0_ym19_1_1507462341160_16053"> material->SetThickness(1.0);<br id="yui_3_16_0_ym19_1_1507462341160_16054"> material->SetMomentOfInertia(1.0);<br id="yui_3_16_0_ym19_1_1507462341160_16055"> material->SetPoissonsRatio(0.2);<br id="yui_3_16_0_ym19_1_1507462341160_16056"> material->SetDensityHeatProduct(1.0);<br id="yui_3_16_0_ym19_1_1507462341160_16057"> m_FemObject->AddNextMaterial(material);<br id="yui_3_16_0_ym19_1_1507462341160_16058"><br id="yui_3_16_0_ym19_1_1507462341160_16059"> // Define the element type<br id="yui_3_16_0_ym19_1_1507462341160_16060"> typedef itk::fem::Element2DC0LinearTriangularStrain TriangularElementType;<br id="yui_3_16_0_ym19_1_1507462341160_16061"> TriangularElementType::Pointer triangularElement= TriangularElementType::New();<br id="yui_3_16_0_ym19_1_1507462341160_16062"> triangularElement->SetMaterial(material.GetPointer());<br id="yui_3_16_0_ym19_1_1507462341160_16063"><br id="yui_3_16_0_ym19_1_1507462341160_16064"> // Convert mesh points into nodes<br id="yui_3_16_0_ym19_1_1507462341160_16065"> VectorType point(3);<br id="yui_3_16_0_ym19_1_1507462341160_16066"> PointType*ptr;<br id="yui_3_16_0_ym19_1_1507462341160_16067"> PointType pt;<br id="yui_3_16_0_ym19_1_1507462341160_16068"> ptr= &pt;<br id="yui_3_16_0_ym19_1_1507462341160_16069"><br id="yui_3_16_0_ym19_1_1507462341160_16070"> int numOfPoints= itkMesh->GetNumberOfPoints();<br id="yui_3_16_0_ym19_1_1507462341160_16071"> cout<<"itkMesh numOfPoints: "<<numOfPoints<<endl;<br id="yui_3_16_0_ym19_1_1507462341160_16072"><br id="yui_3_16_0_ym19_1_1507462341160_16073"> int numberOfCells= itkMesh->GetNumberOfCells();<br id="yui_3_16_0_ym19_1_1507462341160_16074"> cout<<"itkMesh numberOfCells: "<<numberOfCells<<endl;<br id="yui_3_16_0_ym19_1_1507462341160_16075"><br id="yui_3_16_0_ym19_1_1507462341160_16076"> CellsContainerPointer cellIterator= itkMesh->GetCells();<br id="yui_3_16_0_ym19_1_1507462341160_16077"> CellIterator cells= cellIterator->Begin();<br id="yui_3_16_0_ym19_1_1507462341160_16078"><br id="yui_3_16_0_ym19_1_1507462341160_16079"> bool flag= true;<br id="yui_3_16_0_ym19_1_1507462341160_16080"><br id="yui_3_16_0_ym19_1_1507462341160_16081"> for(int k=0; k< numberOfCells; k++)<br id="yui_3_16_0_ym19_1_1507462341160_16082"> {<br id="yui_3_16_0_ym19_1_1507462341160_16083"> CellType *cellPtr= cells.Value();<br id="yui_3_16_0_ym19_1_1507462341160_16084"> cout<<"Cell Value: "<< cells.Value() << " Cell Type= " << cellPtr->GetType()<<endl;<br id="yui_3_16_0_ym19_1_1507462341160_16085"><br id="yui_3_16_0_ym19_1_1507462341160_16086"> switch(cellPtr->GetType())<br id="yui_3_16_0_ym19_1_1507462341160_16087"> {<br id="yui_3_16_0_ym19_1_1507462341160_16088"> case CellType::TRIANGLE_CELL:<br id="yui_3_16_0_ym19_1_1507462341160_16089"> {<br id="yui_3_16_0_ym19_1_1507462341160_16090"> if(flag== true) // To make sure that the nodes are created just once<br id="yui_3_16_0_ym19_1_1507462341160_16091"> {<br id="yui_3_16_0_ym19_1_1507462341160_16092"> for(int j= 0; j< numOfPoints; j++)<br id="yui_3_16_0_ym19_1_1507462341160_16093"> {<br id="yui_3_16_0_ym19_1_1507462341160_16094"> itkMesh->GetPoint(j, ptr);<br id="yui_3_16_0_ym19_1_1507462341160_16095"><br id="yui_3_16_0_ym19_1_1507462341160_16096"> typedef TriangularElementType::Node TriangularNodeType;<br id="yui_3_16_0_ym19_1_1507462341160_16097"> TriangularNodeType::Pointer triangularNode= TriangularNodeType::New();<br id="yui_3_16_0_ym19_1_1507462341160_16098"> point[0]= -1.0;<br id="yui_3_16_0_ym19_1_1507462341160_16099"> point[1]= 2.0;<br id="yui_3_16_0_ym19_1_1507462341160_16100"> point[2]= 3.0;<br id="yui_3_16_0_ym19_1_1507462341160_16101"> triangularNode->SetCoordinates(point);<br id="yui_3_16_0_ym19_1_1507462341160_16102"> triangularNode->SetGlobalNumber(j);<br id="yui_3_16_0_ym19_1_1507462341160_16103"> m_FemObject->AddNextNode(triangularNode.GetPointer());<br id="yui_3_16_0_ym19_1_1507462341160_16104"> }<br id="yui_3_16_0_ym19_1_1507462341160_16105"> flag= false;<br id="yui_3_16_0_ym19_1_1507462341160_16106"> }<br id="yui_3_16_0_ym19_1_1507462341160_16107"> PointIdIterator pointIt= cellPtr->PointIdsBegin();<br id="yui_3_16_0_ym19_1_1507462341160_16108"> int i= 0;<br id="yui_3_16_0_ym19_1_1507462341160_16109"><br id="yui_3_16_0_ym19_1_1507462341160_16110"> while(pointIt!= cellPtr->PointIdsEnd())<br id="yui_3_16_0_ym19_1_1507462341160_16111"> {<br id="yui_3_16_0_ym19_1_1507462341160_16112"> triangularElement->SetNode(i, m_FemObject->GetNode(*pointIt));<br id="yui_3_16_0_ym19_1_1507462341160_16113"> pointIt++;<br id="yui_3_16_0_ym19_1_1507462341160_16114"> i++;<br id="yui_3_16_0_ym19_1_1507462341160_16115"> }<br id="yui_3_16_0_ym19_1_1507462341160_16116"> cells++;<br id="yui_3_16_0_ym19_1_1507462341160_16117"> triangularElement->SetGlobalNumber(k);<br id="yui_3_16_0_ym19_1_1507462341160_16118"> m_FemObject->AddNextElement(triangularElement.GetPointer());<br id="yui_3_16_0_ym19_1_1507462341160_16119"> break;<br id="yui_3_16_0_ym19_1_1507462341160_16120"> }<br id="yui_3_16_0_ym19_1_1507462341160_16121"> }<br id="yui_3_16_0_ym19_1_1507462341160_16122"> }<br id="yui_3_16_0_ym19_1_1507462341160_16123"></font></div><div id="yui_3_16_0_ym19_1_1507462341160_16124" dir="ltr"><font size="2"><br id="yui_3_16_0_ym19_1_1507462341160_16125"></font></div><div id="yui_3_16_0_ym19_1_1507462341160_16126" dir="ltr"><font size="2"> // Define some Load<br id="yui_3_16_0_ym19_1_1507462341160_16127"> LoadNodePointerType loadNode =LoadNodeType::New();<br id="yui_3_16_0_ym19_1_1507462341160_16128"> loadNode->SetElement(triangularElement);<br id="yui_3_16_0_ym19_1_1507462341160_16129"> loadNode->SetGlobalNumber(3);<br id="yui_3_16_0_ym19_1_1507462341160_16130"> loadNode->SetNode(1);<br id="yui_3_16_0_ym19_1_1507462341160_16131"><br id="yui_3_16_0_ym19_1_1507462341160_16132"> vnl_vector<double> force(2);<br id="yui_3_16_0_ym19_1_1507462341160_16133"> force[0]= 20.0;<br id="yui_3_16_0_ym19_1_1507462341160_16134"> force[1]= -20.0;</font></div><div id="yui_3_16_0_ym19_1_1507462341160_16135" dir="ltr"><font id="yui_3_16_0_ym19_1_1507462341160_16343" size="2"> force[2]= 10.0;<br id="yui_3_16_0_ym19_1_1507462341160_16136"> loadNode->SetForce(force);<br id="yui_3_16_0_ym19_1_1507462341160_16137"> m_FemObject->AddNextLoad(loadNode);<br id="yui_3_16_0_ym19_1_1507462341160_16138"><br id="yui_3_16_0_ym19_1_1507462341160_16139"> //Solve for displacements.<br id="yui_3_16_0_ym19_1_1507462341160_16140"> m_FemObject->FinalizeMesh();<br id="yui_3_16_0_ym19_1_1507462341160_16141"> m_FemSolver->SetInput(m_FemObject);<br id="yui_3_16_0_ym19_1_1507462341160_16142"> m_FemSolver->Update(); // SEGMENTATION FAULT<br id="yui_3_16_0_ym19_1_1507462341160_16143"><br id="yui_3_16_0_ym19_1_1507462341160_16144"> cout<< "Fem Solver Output: "<< m_FemSolver->GetOutput()<<endl;<br id="yui_3_16_0_ym19_1_1507462341160_16145"><br id="yui_3_16_0_ym19_1_1507462341160_16146"> const unsigned int invalidId= itk::fem::Element::InvalidDegreeOfFreedomID;<br id="yui_3_16_0_ym19_1_1507462341160_16147"> int numberOfNodes= m_FemSolver->GetInput()->GetNumberOfNodes();<br id="yui_3_16_0_ym19_1_1507462341160_16148"><br id="yui_3_16_0_ym19_1_1507462341160_16149"> for(int i= 0; i< numberOfNodes; i++)<br id="yui_3_16_0_ym19_1_1507462341160_16150"> {<br id="yui_3_16_0_ym19_1_1507462341160_16151"> itk::fem::Element::Node::Pointer node= m_FemSolver->GetInput()->GetNode(i);<br id="yui_3_16_0_ym19_1_1507462341160_16152"> cout<<"Fem Node : "<< node->GetGlobalNumber()<<endl;<br id="yui_3_16_0_ym19_1_1507462341160_16153"><br id="yui_3_16_0_ym19_1_1507462341160_16154"> for(unsigned int j= 0, dof; (dof= node->GetDegreeOfFreedom(j))!= invalidId; j++)<br id="yui_3_16_0_ym19_1_1507462341160_16155"> {<br id="yui_3_16_0_ym19_1_1507462341160_16156"> cout <<"Solver GetSolution: "<< m_FemSolver->GetSolution(dof)<<endl;<br id="yui_3_16_0_ym19_1_1507462341160_16157"> }<br id="yui_3_16_0_ym19_1_1507462341160_16158"> }<br id="yui_3_16_0_ym19_1_1507462341160_16159"><br id="yui_3_16_0_ym19_1_1507462341160_16160"> // Write the deformed mesh<br id="yui_3_16_0_ym19_1_1507462341160_16161"> typedef itk::FEMObjectSpatialObject<3> FemObjectSpatialObjectType;<br id="yui_3_16_0_ym19_1_1507462341160_16162"> FemObjectSpatialObjectType::Pointer m_FemSpatialObject= FemObjectSpatialObjectType::New();<br id="yui_3_16_0_ym19_1_1507462341160_16163"> m_FemSpatialObject->SetFEMObject(m_FemSolver->GetOutput());<br id="yui_3_16_0_ym19_1_1507462341160_16164"><br id="yui_3_16_0_ym19_1_1507462341160_16165"> typedef itk::FEMSpatialObjectWriter<3> FemSpatialObjectWriterType;<br id="yui_3_16_0_ym19_1_1507462341160_16166"> FemSpatialObjectWriterType::Pointer femSpatialWriter= FemSpatialObjectWriterType::New();<br id="yui_3_16_0_ym19_1_1507462341160_16167"> femSpatialWriter->SetInput(m_FemSpatialObject);<br id="yui_3_16_0_ym19_1_1507462341160_16168"> femSpatialWriter->SetFileName("deformedMesh.meta");<br id="yui_3_16_0_ym19_1_1507462341160_16169"> femSpatialWriter->Update();<br id="yui_3_16_0_ym19_1_1507462341160_16170">}<br id="yui_3_16_0_ym19_1_1507462341160_16171"></font></div><div id="yui_3_16_0_ym19_1_1507462341160_16172" dir="ltr"><font size="2"><br id="yui_3_16_0_ym19_1_1507462341160_16173"></font></div><font id="yui_3_16_0_ym19_1_1507462341160_16344" size="2">Thank you for any help!</font></div></body></html>