[ITK-users] Problems with mesh I/O and conversions in ITK
Carlos Henrique Villa Pinto
chvillap at gmail.com
Thu Apr 17 07:39:15 EDT 2014
Hi Matt and everyone,
So it seems the best thing to do is to convert the triangle strips to
another representation (supported by ITK) and then use
MeshFileReader/Writer normally, right?
I used VTK to do that, changing everything to polygons, and so
MeshFileReader/Writer were finally able to read and write the models
without data losses. Thank you very much for your help with that!
But there are still a problem: when I try to convert the resulting mesh to
a simplex mesh (using TriangleMeshToSimplexMeshFilter), my program seems to
enter an infinite loop. Trying to perform the same conversion in another
mesh (that one from the ITK example I mentioned earlier, which already uses
the polygon representation), everything works fine and my program executes
in just a few seconds. So perhaps there's something wrong in my triangle
strips -> polygons conversion.
Below is the source code for such conversion. I used VTK, so maybe this is
not the right place to ask, but any help would be greatly appreciated.
===========================================================================================================================
// Read the input VTK polydata.
vtkSmartPointer<vtkPolyDataReader> reader =
vtkSmartPointer<vtkPolyDataReader>::New();
reader->SetFileName(inputFileName.c_str());
reader->Update();
std::cout << "PolyData read ok\n";
// Convert the triangle strips to polygons.
vtkSmartPointer<vtkPolyData> originalPoly = reader->GetOutput();
vtkIdType npts = 0;
vtkIdType *pts = NULL;
vtkCellArray *strips = originalPoly->GetStrips();
vtkCellArray *triangles = vtkCellArray::New();
for (strips->InitTraversal(); strips->GetNextCell(npts, pts); )
vtkTriangleStrip::DecomposeStrip(npts, pts, triangles);
vtkSmartPointer<vtkPolyData> newPoly = vtkPolyData::New();
newPoly->SetPoints(originalPoly->GetPoints());
newPoly->SetPolys(triangles);
newPoly->BuildLinks();
triangles->Delete();
std::cout << "TRIANGLE_STRIPS to POLYGONS conversion ok\n";
// Write the output polydata.
vtkSmartPointer<vtkPolyDataWriter> writer =
vtkSmartPointer<vtkPolyDataWriter>::New();
writer->SetFileName(outputFileName.c_str());
writer->SetInputData(newPoly);
writer->Update();
std::cout << "PolyData write ok\n";
===========================================================================================================================
Thanks,
[]s
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20140417/5073aa89/attachment.html>
More information about the Insight-users
mailing list