<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10px"><div id="yui_3_16_0_ym19_1_1507461188624_4339">Dear ITK Users,</div><div id="yui_3_16_0_ym19_1_1507461188624_4338"><br></div><div id="yui_3_16_0_ym19_1_1507461188624_4358" dir="ltr">According the mail <a class="" id="yui_3_16_0_ym19_1_1507461188624_4357" 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:</div><div id="yui_3_16_0_ym19_1_1507461188624_6644" dir="ltr">My problem is: If I call "m_FemSolver->Update();" ,I get a segmentation fault, which I really not understand. <br></div><div id="yui_3_16_0_ym19_1_1507461188624_6761" dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1507461188624_6735" dir="ltr">Program received signal SIGSEGV, Segmentation fault.<br id="yui_3_16_0_ym19_1_1507461188624_6730">0x00007fffb1086dd5 in itk::fem::FEMObject<2u>::DeepCopy (this=0x4cc5ee0, <br id="yui_3_16_0_ym19_1_1507461188624_6731"> Copy=0x4cc1780)<br id="yui_3_16_0_ym19_1_1507461188624_6732"> at /home/toolkits/itk-4.7.2/Modules/Numerics/FEM/include/itkFEMObject.hxx:157<br id="yui_3_16_0_ym19_1_1507461188624_6733">157 a->UnRegister();<br id="yui_3_16_0_ym19_1_1507461188624_6734"></div><div id="yui_3_16_0_ym19_1_1507461188624_6736" dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1507461188624_6760" dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1507461188624_6247" dir="ltr">void itkMeshToFemMesh::updateItkMeshSlot(itk::Mesh<double, 3, MeshTraitsType> *itkMesh)<br id="yui_3_16_0_ym19_1_1507461188624_6506">{<br id="yui_3_16_0_ym19_1_1507461188624_6507"> typedef itk::fem::FEMObject<3> FemObjectType;<br id="yui_3_16_0_ym19_1_1507461188624_6508"> FemObjectType::Pointer m_FemObject= FemObjectType::New();<br id="yui_3_16_0_ym19_1_1507461188624_6509"><br id="yui_3_16_0_ym19_1_1507461188624_6510"> typedef itk::fem::Solver<3> SolverType;<br id="yui_3_16_0_ym19_1_1507461188624_6511"> typedef SolverType::Pointer SolverPointerType;<br id="yui_3_16_0_ym19_1_1507461188624_6512"> SolverPointerType m_FemSolver= SolverType::New();<br id="yui_3_16_0_ym19_1_1507461188624_6513"><br id="yui_3_16_0_ym19_1_1507461188624_6514"> // Define the Element Material properties<br id="yui_3_16_0_ym19_1_1507461188624_6515"> typedef itk::fem::MaterialLinearElasticity MaterialType;<br id="yui_3_16_0_ym19_1_1507461188624_6516"> MaterialType::Pointer material= MaterialType::New();<br id="yui_3_16_0_ym19_1_1507461188624_6517"> material->SetGlobalNumber(0);<br id="yui_3_16_0_ym19_1_1507461188624_6518"> material->SetYoungsModulus(200E6);<br id="yui_3_16_0_ym19_1_1507461188624_6519"> material->SetCrossSectionalArea(1.0);<br id="yui_3_16_0_ym19_1_1507461188624_6520"> material->SetThickness(1.0);<br id="yui_3_16_0_ym19_1_1507461188624_6521"> material->SetMomentOfInertia(1.0);<br id="yui_3_16_0_ym19_1_1507461188624_6522"> material->SetPoissonsRatio(0.2);<br id="yui_3_16_0_ym19_1_1507461188624_6523"> material->SetDensityHeatProduct(1.0);<br id="yui_3_16_0_ym19_1_1507461188624_6524"> m_FemObject->AddNextMaterial(material);<br id="yui_3_16_0_ym19_1_1507461188624_6525"><br id="yui_3_16_0_ym19_1_1507461188624_6526"> // Define the element type<br id="yui_3_16_0_ym19_1_1507461188624_6527"> typedef itk::fem::Element2DC0LinearTriangularStrain TriangularElementType;<br id="yui_3_16_0_ym19_1_1507461188624_6528"> TriangularElementType::Pointer triangularElement= TriangularElementType::New();<br id="yui_3_16_0_ym19_1_1507461188624_6529"> triangularElement->SetMaterial(material.GetPointer());<br id="yui_3_16_0_ym19_1_1507461188624_6530"><br id="yui_3_16_0_ym19_1_1507461188624_6531"> // Convert mesh points into nodes<br id="yui_3_16_0_ym19_1_1507461188624_6532"> VectorType point(3);<br id="yui_3_16_0_ym19_1_1507461188624_6533"> PointType*ptr;<br id="yui_3_16_0_ym19_1_1507461188624_6534"> PointType pt;<br id="yui_3_16_0_ym19_1_1507461188624_6535"> ptr= &pt;<br id="yui_3_16_0_ym19_1_1507461188624_6536"><br id="yui_3_16_0_ym19_1_1507461188624_6537"> int numOfPoints= itkMesh->GetNumberOfPoints();<br id="yui_3_16_0_ym19_1_1507461188624_6538"> cout<<"itkMesh numOfPoints: "<<numOfPoints<<endl;<br id="yui_3_16_0_ym19_1_1507461188624_6539"><br id="yui_3_16_0_ym19_1_1507461188624_6540"> int numberOfCells= itkMesh->GetNumberOfCells();<br id="yui_3_16_0_ym19_1_1507461188624_6541"> cout<<"itkMesh numberOfCells: "<<numberOfCells<<endl;<br id="yui_3_16_0_ym19_1_1507461188624_6542"><br id="yui_3_16_0_ym19_1_1507461188624_6543"> CellsContainerPointer cellIterator= itkMesh->GetCells();<br id="yui_3_16_0_ym19_1_1507461188624_6544"> CellIterator cells= cellIterator->Begin();<br id="yui_3_16_0_ym19_1_1507461188624_6545"><br id="yui_3_16_0_ym19_1_1507461188624_6546"> bool flag= true;<br id="yui_3_16_0_ym19_1_1507461188624_6547"><br id="yui_3_16_0_ym19_1_1507461188624_6548"> for(int k=0; k< numberOfCells; k++)<br id="yui_3_16_0_ym19_1_1507461188624_6549"> {<br id="yui_3_16_0_ym19_1_1507461188624_6550"> CellType *cellPtr= cells.Value();<br id="yui_3_16_0_ym19_1_1507461188624_6551"> cout<<"Cell Value: "<< cells.Value() << " Cell Type= " << cellPtr->GetType()<<endl;<br id="yui_3_16_0_ym19_1_1507461188624_6552"><br id="yui_3_16_0_ym19_1_1507461188624_6553"> switch(cellPtr->GetType())<br id="yui_3_16_0_ym19_1_1507461188624_6554"> {<br id="yui_3_16_0_ym19_1_1507461188624_6555"> case CellType::TRIANGLE_CELL:<br id="yui_3_16_0_ym19_1_1507461188624_6556"> {<br id="yui_3_16_0_ym19_1_1507461188624_6557"> if(flag== true) // To make sure that the nodes are created just once<br id="yui_3_16_0_ym19_1_1507461188624_6558"> {<br id="yui_3_16_0_ym19_1_1507461188624_6559"> for(int j= 0; j< numOfPoints; j++)<br id="yui_3_16_0_ym19_1_1507461188624_6560"> {<br id="yui_3_16_0_ym19_1_1507461188624_6561"> itkMesh->GetPoint(j, ptr);<br id="yui_3_16_0_ym19_1_1507461188624_6562"><br id="yui_3_16_0_ym19_1_1507461188624_6563"> typedef TriangularElementType::Node TriangularNodeType;<br id="yui_3_16_0_ym19_1_1507461188624_6564"> TriangularNodeType::Pointer triangularNode= TriangularNodeType::New();<br id="yui_3_16_0_ym19_1_1507461188624_6565"> point[0]= -1.0;<br id="yui_3_16_0_ym19_1_1507461188624_6566"> point[1]= 2.0;<br id="yui_3_16_0_ym19_1_1507461188624_6567"> point[2]= 3.0;<br id="yui_3_16_0_ym19_1_1507461188624_6568"> triangularNode->SetCoordinates(point);<br id="yui_3_16_0_ym19_1_1507461188624_6569"> triangularNode->SetGlobalNumber(j);<br id="yui_3_16_0_ym19_1_1507461188624_6570"> m_FemObject->AddNextNode(triangularNode.GetPointer());<br id="yui_3_16_0_ym19_1_1507461188624_6571"> }<br id="yui_3_16_0_ym19_1_1507461188624_6572"> flag= false;<br id="yui_3_16_0_ym19_1_1507461188624_6573"> }<br id="yui_3_16_0_ym19_1_1507461188624_6574"> PointIdIterator pointIt= cellPtr->PointIdsBegin();<br id="yui_3_16_0_ym19_1_1507461188624_6575"> int i= 0;<br id="yui_3_16_0_ym19_1_1507461188624_6576"><br id="yui_3_16_0_ym19_1_1507461188624_6577"> while(pointIt!= cellPtr->PointIdsEnd())<br id="yui_3_16_0_ym19_1_1507461188624_6578"> {<br id="yui_3_16_0_ym19_1_1507461188624_6579"> triangularElement->SetNode(i, m_FemObject->GetNode(*pointIt));<br id="yui_3_16_0_ym19_1_1507461188624_6580"> pointIt++;<br id="yui_3_16_0_ym19_1_1507461188624_6581"> i++;<br id="yui_3_16_0_ym19_1_1507461188624_6582"> }<br id="yui_3_16_0_ym19_1_1507461188624_6583"> cells++;<br id="yui_3_16_0_ym19_1_1507461188624_6585"> triangularElement->SetGlobalNumber(k);<br id="yui_3_16_0_ym19_1_1507461188624_6586"> m_FemObject->AddNextElement(triangularElement.GetPointer());<br id="yui_3_16_0_ym19_1_1507461188624_6587"> break;<br id="yui_3_16_0_ym19_1_1507461188624_6588"> }<br id="yui_3_16_0_ym19_1_1507461188624_6589"> }<br id="yui_3_16_0_ym19_1_1507461188624_6590"> }<br id="yui_3_16_0_ym19_1_1507461188624_6591"></div><div id="yui_3_16_0_ym19_1_1507461188624_6808" dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1507461188624_6807" dir="ltr"> // Define some Load<br id="yui_3_16_0_ym19_1_1507461188624_6592"> LoadNodePointerType loadNode =LoadNodeType::New();<br id="yui_3_16_0_ym19_1_1507461188624_6593"> loadNode->SetElement(triangularElement);<br id="yui_3_16_0_ym19_1_1507461188624_6594"> loadNode->SetGlobalNumber(3);<br id="yui_3_16_0_ym19_1_1507461188624_6595"> loadNode->SetNode(1);<br id="yui_3_16_0_ym19_1_1507461188624_6596"><br id="yui_3_16_0_ym19_1_1507461188624_6597"> vnl_vector<double> force(2);<br id="yui_3_16_0_ym19_1_1507461188624_6598"> force[0]= 20.0;<br id="yui_3_16_0_ym19_1_1507461188624_6599"> force[1]= -20.0;</div><div id="yui_3_16_0_ym19_1_1507461188624_6673" dir="ltr"> force[2]= 10.0;<br id="yui_3_16_0_ym19_1_1507461188624_6600"> loadNode->SetForce(force);<br id="yui_3_16_0_ym19_1_1507461188624_6601"> m_FemObject->AddNextLoad(loadNode);<br id="yui_3_16_0_ym19_1_1507461188624_6602"><br id="yui_3_16_0_ym19_1_1507461188624_6603"> //Solve for displacements.<br id="yui_3_16_0_ym19_1_1507461188624_6604"> m_FemObject->FinalizeMesh();<br id="yui_3_16_0_ym19_1_1507461188624_6605"> m_FemSolver->SetInput(m_FemObject);<br id="yui_3_16_0_ym19_1_1507461188624_6606"> m_FemSolver->Update(); // SEGMENTATION FAULT<br id="yui_3_16_0_ym19_1_1507461188624_6607"><br id="yui_3_16_0_ym19_1_1507461188624_6608"> cout<< "Fem Solver Output: "<< m_FemSolver->GetOutput()<<endl;<br id="yui_3_16_0_ym19_1_1507461188624_6609"><br id="yui_3_16_0_ym19_1_1507461188624_6610"> const unsigned int invalidId= itk::fem::Element::InvalidDegreeOfFreedomID;<br id="yui_3_16_0_ym19_1_1507461188624_6611"> int numberOfNodes= m_FemSolver->GetInput()->GetNumberOfNodes();<br id="yui_3_16_0_ym19_1_1507461188624_6612"><br id="yui_3_16_0_ym19_1_1507461188624_6613"> for(int i= 0; i< numberOfNodes; i++)<br id="yui_3_16_0_ym19_1_1507461188624_6614"> {<br id="yui_3_16_0_ym19_1_1507461188624_6615"> itk::fem::Element::Node::Pointer node= m_FemSolver->GetInput()->GetNode(i);<br id="yui_3_16_0_ym19_1_1507461188624_6616"> cout<<"Fem Node : "<< node->GetGlobalNumber()<<endl;<br id="yui_3_16_0_ym19_1_1507461188624_6617"><br id="yui_3_16_0_ym19_1_1507461188624_6618"> for(unsigned int j= 0, dof; (dof= node->GetDegreeOfFreedom(j))!= invalidId; j++)<br id="yui_3_16_0_ym19_1_1507461188624_6619"> {<br id="yui_3_16_0_ym19_1_1507461188624_6620"> cout <<"Solver GetSolution: "<< m_FemSolver->GetSolution(dof)<<endl;<br id="yui_3_16_0_ym19_1_1507461188624_6621"> }<br id="yui_3_16_0_ym19_1_1507461188624_6622"> }<br id="yui_3_16_0_ym19_1_1507461188624_6623"><br id="yui_3_16_0_ym19_1_1507461188624_6624"> // Write the deformed mesh<br id="yui_3_16_0_ym19_1_1507461188624_6625"> typedef itk::FEMObjectSpatialObject<3> FemObjectSpatialObjectType;<br id="yui_3_16_0_ym19_1_1507461188624_6626"> FemObjectSpatialObjectType::Pointer m_FemSpatialObject= FemObjectSpatialObjectType::New();<br id="yui_3_16_0_ym19_1_1507461188624_6627"> m_FemSpatialObject->SetFEMObject(m_FemSolver->GetOutput());<br id="yui_3_16_0_ym19_1_1507461188624_6628"><br id="yui_3_16_0_ym19_1_1507461188624_6629"> typedef itk::FEMSpatialObjectWriter<3> FemSpatialObjectWriterType;<br id="yui_3_16_0_ym19_1_1507461188624_6630"> FemSpatialObjectWriterType::Pointer femSpatialWriter= FemSpatialObjectWriterType::New();<br id="yui_3_16_0_ym19_1_1507461188624_6631"> femSpatialWriter->SetInput(m_FemSpatialObject);<br id="yui_3_16_0_ym19_1_1507461188624_6632"> femSpatialWriter->SetFileName("deformedMesh.meta");<br id="yui_3_16_0_ym19_1_1507461188624_6633"> femSpatialWriter->Update();<br id="yui_3_16_0_ym19_1_1507461188624_6634">}<br></div><div id="yui_3_16_0_ym19_1_1507461188624_7083" dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1507461188624_7085" dir="ltr">Thank you for any help!<br></div><div dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1507461188624_4432"><br></div><div id="yui_3_16_0_ym19_1_1507461188624_4407"><br></div></div></body></html>