<div dir="ltr"><div>Hi Matt,</div><div><br></div><div>As far as I could see, every model from the brain database has information about points, triangle strips and normals in their .vtk files. So using visualization tools like Paraview and Slicer, I can see the (original) models surfaces entirely, not just their points.</div>
<div><br></div><div>However, the outputs provided by the MeshFileWriter class keep only the points' data, even though my program performs only a simple read-write.</div>
<div><br></div><div>At first I thought this problem could be due to some incompatibility of file format versions, since the original models are VTK DataFiles v3.0 and ITK saves the outputs as v2.0. But for that other model taken from the ITK example, everything works fine despite this discrepancy.</div>
<div><br></div><div>Thanks,</div><div>[]s</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-14 13:41 GMT-03:00 Matt McCormick <span dir="ltr"><<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Carlos,<br>
<br>
When using MeshFileReader/MeshFileWriter, which cell data is being<br>
lost? Examining a few of the files in the link provided at<br>
nac-brain-atlas-1.0/models/ I am only seeing points.<br>
<br>
Thanks,<br>
Matt<br>
<div><div class="h5"><br>
On Mon, Apr 14, 2014 at 8:54 AM, Carlos Henrique Villa Pinto<br>
<<a href="mailto:chvillap@gmail.com">chvillap@gmail.com</a>> wrote:<br>
> Hi everyone!<br>
> I'm having some problems working with meshes in ITK.<br>
><br>
> What I'm trying to do (by now) is just a brief test in which I read a .vtk<br>
> mesh file from this database:<br>
> <a href="http://www.spl.harvard.edu/publications/item/view/2037" target="_blank">http://www.spl.harvard.edu/publications/item/view/2037</a>, write it again to<br>
> the disk and see if everything is ok. Very simple.<br>
><br>
> The problem is: if I try to do that using the itk::MeshReader and<br>
> itk::MeshWriter classes, the program doesn't work as expected since the<br>
> written mesh apparently loses all information about the original mesh's<br>
> cells (I'm using Paraview and Slicer for visualization). The same thing<br>
> happens if I use the itk::VTKPolyDataReader and itk::VTKPolyDataWriter<br>
> classes for the mesh I/O. However, if I do the same test reading the .vtk<br>
> mesh file provided by this example:<br>
> <a href="http://itk.org/ITKExamples/src/IO/Mesh/ReadMesh/Documentation.html" target="_blank">http://itk.org/ITKExamples/src/IO/Mesh/ReadMesh/Documentation.html</a>,<br>
> everything works fine in both cases. So I guess it could be a file format<br>
> issue.<br>
><br>
> I also tried to use VTK instead of ITK for the mesh I/O (the<br>
> vtkPolyDataReader and vtkPolyDataWriter classes). And with that, the program<br>
> works fine even with the meshes from the brain database. But as I intend to<br>
> work with deformable models algorithms in ITK, that approach requires me to<br>
> convert the read vtkPolyData into a ITK simplex mesh, but such conversion<br>
> makes my program crash (either an exception is thrown because of an invalid<br>
> point or the program enters in an infinite loop). I'm using the<br>
> vtkPolyDataToitkMesh class (from InsightApplications) to convert the VTK<br>
> polydata to a ITK triangle mesh, and the<br>
> itk::TriangleMeshToSimplexMeshFilter class to convert the latter to a<br>
> simplex mesh.<br>
><br>
> Last, but not least: if I just do the following conversions: VTK polydata -><br>
> ITK triangle mesh -> VTK polydata and try to write the resulting polydata<br>
> (using vtkPolyDataWriter), I get a segmentation fault. No clue about what<br>
> causes it.<br>
><br>
> The more recent and complete version of my code (VTK + ITK) is below. If<br>
> anyone could help me with any of these issues, I would be very grateful.<br>
><br>
> =============================================================================================<br>
><br>
> // Set the ITK type definitions.<br>
><br>
> const int Dimension = 3;<br>
> typedef double PixelType;<br>
><br>
> typedef vtkPolyDataToitkMesh::TriangleMeshType<br>
> TriangleMeshType;<br>
> typedef itk::DefaultDynamicMeshTraits<PixelType, Dimension, Dimension,<br>
> double, double> SimplexMeshTraits;<br>
> typedef itk::SimplexMesh<PixelType, Dimension, SimplexMeshTraits><br>
> SimplexMeshType;<br>
><br>
> typedef itk::TriangleMeshToSimplexMeshFilter<TriangleMeshType,<br>
> SimplexMeshType> TriangleToSimplexFilterType;<br>
> typedef itk::SimplexMeshToTriangleMeshFilter<SimplexMeshType,<br>
> TriangleMeshType> SimplexToTriangleFilterType;<br>
><br>
> typedef itk::SimplexMeshVolumeCalculator<SimplexMeshType><br>
> VolumeCalculatorType;<br>
><br>
> typedef itk::VTKPolyDataWriter<TriangleMeshType> WriterType;<br>
><br>
> // Read the input VTK polydata.<br>
><br>
> vtkSmartPointer<vtkPolyDataReader> reader =<br>
> vtkSmartPointer<vtkPolyDataReader>::New();<br>
> reader->SetFileName(inputFileName.c_str());<br>
> reader->Update();<br>
><br>
> std::cout << "Polydata read ok\n";<br>
><br>
> // Convert the VTK polydata to a ITK mesh.<br>
><br>
> vtkPolyDataToitkMesh polyDataToMesh;<br>
> polyDataToMesh.SetInput(reader->GetOutput());<br>
> polyDataToMesh.ConvertvtkToitk();<br>
><br>
> std::cout << "Conversion to triangle mesh ok\n";<br>
><br>
> // Convert the triangle mesh to a simplex mesh.<br>
><br>
> TriangleToSimplexFilterType::Pointer triangleToSimplexFilter =<br>
> TriangleToSimplexFilterType::New();<br>
> triangleToSimplexFilter->SetInput(polyDataToMesh.GetOutput());<br>
> triangleToSimplexFilter->Update();<br>
><br>
> std::cout << "Conversion to simplex mesh ok\n";<br>
><br>
> // Compute the simplex mesh volume.<br>
><br>
> VolumeCalculatorType::Pointer volumeCalculator =<br>
> VolumeCalculatorType::New();<br>
> volumeCalculator->SetSimplexMesh(triangleToSimplexFilter->GetOutput());<br>
> volumeCalculator->Compute();<br>
><br>
> std::cout << "Volume calculation ok (value = " <<<br>
> volumeCalculator->GetVolume() << ")\n";<br>
><br>
> // Convert the simplex mesh to triangle mesh.<br>
><br>
> SimplexToTriangleFilterType::Pointer simplexToTriangleFilter =<br>
> SimplexToTriangleFilterType::New();<br>
> simplexToTriangleFilter->SetInput(triangleToSimplexFilter->GetOutput());<br>
> simplexToTriangleFilter->Update();<br>
><br>
> std::cout << "Conversion to triangle mesh ok\n";<br>
><br>
> // Convert the ITK mesh to VTK polydata.<br>
><br>
> itkMeshTovtkPolyData meshToPolyData;<br>
> meshToPolyData.SetInput(simplexToTriangleFilter->GetOutput());<br>
> meshToPolyData.ConvertitkTovtk();<br>
><br>
> std::cout << "Conversion to polydata ok\n";<br>
><br>
> // Write the output polydata.<br>
><br>
> vtkSmartPointer<vtkPolyDataWriter> writer =<br>
> vtkSmartPointer<vtkPolyDataWriter>::New();<br>
> writer->SetFileName(outputFileName.c_str());<br>
> writer->SetInputData(meshToPolyData.GetOutput());<br>
> writer->Update();<br>
><br>
> std::cout << "Polydata write ok\n";<br>
><br>
> =============================================================================================<br>
><br>
> Thanks in advance.<br>
> []s<br>
><br>
> --<br>
> Carlos Henrique Villa Pinto<br>
> Graduate Student in Computer Science<br>
> Federal University of São Carlos - Brazil<br>
> XCS<br>
><br>
</div></div>> _____________________________________<br>
> Powered by <a href="http://www.kitware.com" 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" target="_blank">http://www.kitware.com/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" target="_blank">http://www.kitware.com/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" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Carlos Henrique Villa Pinto<div>Graduate Student in Computer Science</div><div>Federal University of São Carlos - Brazil</div><div>XCS</div></div>
</div>