<div dir="ltr"><div><div><div><div><div><div>Hello Yusuf,<br><br></div>I am not sure what the problem is, but here are some ideas you can try to understand it or try to solve it:<br></div>1) Use ITK smart pointers instead of raw pointers. The crash seem to indicate that the program was trying to unregister a smart pointer, but your mesh is declared as a raw pointer. The issue could come from this.<br></div>2) Have you tried to look at your data, once converted, to make sure that it was converted correctly? Maybe there is a problem during your conversion which leads to an empty mesh or something worst.<br><br></div>Hope this helps,<br></div>Francois<br><br></div>PS: As a side note, you may want to join the ITK discourse forum to ask your question or help others. The mailing list is still active but more people seem to be using the discourse forum now that it is available (<a href="http://discourse.itk.org/">http://discourse.itk.org/</a>)<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 9, 2017 at 8:08 AM, Yusuf OEZBEK via Insight-users <span dir="ltr"><<a href="mailto:insight-users@itk.org" target="_blank">insight-users@itk.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear ITK Users,<br>
<br>
According the mail <a href="https://public.kitware.com/pipermail/insight-users/2007-November/024272.html" rel="noreferrer" target="_blank">https://public.kitware.com/<wbr>pipermail/insight-users/2007-<wbr>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:<br>
My problem is: If I call "m_FemSolver->Update();" ,I get a segmentation fault, which I really not understand.<br>
<br>
Program received signal SIGSEGV, Segmentation fault.<br>
0x00007fffb1086dd5 in itk::fem::FEMObject<2u>::<wbr>DeepCopy (this=0x4cc5ee0,<br>
Copy=0x4cc1780)<br>
at /home/toolkits/itk-4.7.2/<wbr>Modules/Numerics/FEM/include/<wbr>itkFEMObject.hxx:157<br>
157 a->UnRegister();<br>
<br>
<br>
void itkMeshToFemMesh::<wbr>updateItkMeshSlot(itk::Mesh<<wbr>double, 3, MeshTraitsType> *itkMesh)<br>
{<br>
typedef itk::fem::FEMObject<3> FemObjectType;<br>
FemObjectType::Pointer m_FemObject= FemObjectType::New();<br>
<br>
typedef itk::fem::Solver<3> SolverType;<br>
typedef SolverType::Pointer SolverPointerType;<br>
SolverPointerType m_FemSolver= SolverType::New();<br>
<br>
// Define the Element Material properties<br>
typedef itk::fem::<wbr>MaterialLinearElasticity MaterialType;<br>
MaterialType::Pointer material= MaterialType::New();<br>
material->SetGlobalNumber(0);<br>
material->SetYoungsModulus(<wbr>200E6);<br>
material-><wbr>SetCrossSectionalArea(1.0);<br>
material->SetThickness(1.0);<br>
material->SetMomentOfInertia(<wbr>1.0);<br>
material->SetPoissonsRatio(0.<wbr>2);<br>
material-><wbr>SetDensityHeatProduct(1.0);<br>
m_FemObject->AddNextMaterial(<wbr>material);<br>
<br>
// Define the element type<br>
typedef itk::fem::<wbr>Element2DC0LinearTriangularStr<wbr>ain TriangularElementType;<br>
TriangularElementType::Pointer triangularElement= TriangularElementType::New();<br>
triangularElement-><wbr>SetMaterial(material.<wbr>GetPointer());<br>
<br>
// Convert mesh points into nodes<br>
VectorType point(3);<br>
PointType*ptr;<br>
PointType pt;<br>
ptr= &pt;<br>
<br>
int numOfPoints= itkMesh->GetNumberOfPoints();<br>
cout<<"itkMesh numOfPoints: "<<numOfPoints<<endl;<br>
<br>
int numberOfCells= itkMesh->GetNumberOfCells();<br>
cout<<"itkMesh numberOfCells: "<<numberOfCells<<endl;<br>
<br>
CellsContainerPointer cellIterator= itkMesh->GetCells();<br>
CellIterator cells= cellIterator->Begin();<br>
<br>
bool flag= true;<br>
<br>
for(int k=0; k< numberOfCells; k++)<br>
{<br>
CellType *cellPtr= cells.Value();<br>
cout<<"Cell Value: "<< cells.Value() << " Cell Type= " << cellPtr->GetType()<<endl;<br>
<br>
switch(cellPtr->GetType())<br>
{<br>
case CellType::TRIANGLE_CELL:<br>
{<br>
if(flag== true) // To make sure that the nodes are created just once<br>
{<br>
for(int j= 0; j< numOfPoints; j++)<br>
{<br>
itkMesh->GetPoint(j, ptr);<br>
<br>
typedef TriangularElementType::Node TriangularNodeType;<br>
TriangularNodeType::Pointer triangularNode= TriangularNodeType::New();<br>
point[0]= -1.0;<br>
point[1]= 2.0;<br>
point[2]= 3.0;<br>
triangularNode-><wbr>SetCoordinates(point);<br>
triangularNode-><wbr>SetGlobalNumber(j);<br>
m_FemObject->AddNextNode(<wbr>triangularNode.GetPointer());<br>
}<br>
flag= false;<br>
}<br>
PointIdIterator pointIt= cellPtr->PointIdsBegin();<br>
int i= 0;<br>
<br>
while(pointIt!= cellPtr->PointIdsEnd())<br>
{<br>
triangularElement->SetNode(i, m_FemObject->GetNode(*pointIt)<wbr>);<br>
pointIt++;<br>
i++;<br>
}<br>
cells++;<br>
triangularElement-><wbr>SetGlobalNumber(k);<br>
m_FemObject->AddNextElement(<wbr>triangularElement.GetPointer()<wbr>);<br>
break;<br>
}<br>
}<br>
}<br>
<br>
// Define some Load<br>
LoadNodePointerType loadNode =LoadNodeType::New();<br>
loadNode->SetElement(<wbr>triangularElement);<br>
loadNode->SetGlobalNumber(3);<br>
loadNode->SetNode(1);<br>
<br>
vnl_vector<double> force(2);<br>
force[0]= 20.0;<br>
force[1]= -20.0;<br>
force[2]= 10.0;<br>
loadNode->SetForce(force);<br>
m_FemObject->AddNextLoad(<wbr>loadNode);<br>
<br>
//Solve for displacements.<br>
m_FemObject->FinalizeMesh();<br>
m_FemSolver->SetInput(m_<wbr>FemObject);<br>
m_FemSolver->Update(); // SEGMENTATION FAULT<br>
<br>
cout<< "Fem Solver Output: "<< m_FemSolver->GetOutput()<<<wbr>endl;<br>
<br>
const unsigned int invalidId= itk::fem::Element::<wbr>InvalidDegreeOfFreedomID;<br>
int numberOfNodes= m_FemSolver->GetInput()-><wbr>GetNumberOfNodes();<br>
<br>
for(int i= 0; i< numberOfNodes; i++)<br>
{<br>
itk::fem::Element::Node::<wbr>Pointer node= m_FemSolver->GetInput()-><wbr>GetNode(i);<br>
cout<<"Fem Node : "<< node->GetGlobalNumber()<<endl;<br>
<br>
for(unsigned int j= 0, dof; (dof= node->GetDegreeOfFreedom(j))!= invalidId; j++)<br>
{<br>
cout <<"Solver GetSolution: "<< m_FemSolver->GetSolution(dof)<<wbr><endl;<br>
}<br>
}<br>
<br>
// Write the deformed mesh<br>
typedef itk::FEMObjectSpatialObject<3> FemObjectSpatialObjectType;<br>
FemObjectSpatialObjectType::<wbr>Pointer m_FemSpatialObject= FemObjectSpatialObjectType::<wbr>New();<br>
m_FemSpatialObject-><wbr>SetFEMObject(m_FemSolver-><wbr>GetOutput());<br>
<br>
typedef itk::FEMSpatialObjectWriter<3> FemSpatialObjectWriterType;<br>
FemSpatialObjectWriterType::<wbr>Pointer femSpatialWriter= FemSpatialObjectWriterType::<wbr>New();<br>
femSpatialWriter->SetInput(m_<wbr>FemSpatialObject);<br>
femSpatialWriter->SetFileName(<wbr>"deformedMesh.meta");<br>
femSpatialWriter->Update();<br>
}<br>
<br>
Thank you for any help!<br>
The ITK community is transitioning from this mailing list to <a href="http://discourse.itk.org" rel="noreferrer" target="_blank">discourse.itk.org</a>. Please join us there!<br>
______________________________<wbr>__<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_<wbr>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/insight-users</a><br>
</blockquote></div><br></div>