How to read points and radius info of .vtk file into ITK program

Hi all,

My goal is to register 2d/3d vessel networks. The first step I’ve done is to use the VMTK module in slicer to segment out and calculate the radii of each centerline point. This saves as a .vtk file. However, while trying to use VTKPolyDataReader, I receive an error because the .vtk file is made up of binary data instead of ASCII which is one of the caveats.
I downloaded paraview and used it to save my .vtk data as ASCII. However, I’m still unable to view my points as I now see that I’m violating the primary caveat of only reading .vtk files that contain triangle meshes.
Is there some way I can read this data in such as saving the .vtk as a .stl or .obj file?

Hi @Henco,

Try the MeshFileReader instead of the VTKPolyDataReader, since it supports both binary and ASCII .vtk polydata files. It also supports .obj. STL support is available with the ITKIOMeshSTL module.

Hi Matt,

Thanks for the reply. I’m using this MeshReader Example to test the reader. It doesn’t seem to be working. I fed it the IDs of two points and did not receive the EuclideanDistance between the two.
I also added these lines of code at the end of the program, right before return EXIT_SUCCESS, to it to see how many points are read (I checked in paraview, should be 11836)

MeshType::Pointer mesh = reader->GetOutput();
std::cout << mesh->GetNumberOfPoints() << std::endl;

However, when I run this program, I receive no cout. I’m not sure if this is because of the program itself or because I’m dealing with a 3D collection of points in the .vtk file

@Henco To print properties of the mesh and learn more about what was read, add:


Unfortunately I still do not receive any output to the command line even after adding that line.
I believe the problem lies within my data, as removing the reader->Update command causes the mesh->Print(std::cout) line to trigger and print to the command line, albeit only with the templated information.

If the file is opened with a text editor, does the header contain DATASET POLYDATA? .vtk files can contain different data types – polydata is what is supported by these readers.

Yes it does say DATASET POLYDATA

For those following, I was able to get ITK to read in the centerlines as a mesh. I accomplished this by saving the VMTK Centerline Model as a .obj file. This allowed the itk::MeshFileReader to recognize it and read it in as a mesh.
However, this method unfortunately does not retain the radius information of each point.

@Henco thanks for the update.

I am wondering if this is a locale issue, as discussed here?

CC @dzenanz