Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double-check limitations of vtk file support #698

Closed
N-Dekker opened this issue Aug 1, 2022 · 10 comments
Closed

Double-check limitations of vtk file support #698

N-Dekker opened this issue Aug 1, 2022 · 10 comments
Assignees

Comments

@N-Dekker
Copy link
Member

N-Dekker commented Aug 1, 2022

According to the manual https://elastix.lumc.nl/download/elastix-5.0.1-manual.pdf

The support for .vtk files is still a bit limited. Currently, only ASCII files are supported, with triangular meshes.

It seems to me that non-triangular point lists are also supported, right?

I did encounter another limitation though: it appears that VTK only supports 3-D points. Should we adjust the manual accordingly?

@stefanklein
Copy link
Member

stefanklein commented Aug 1, 2022 via email

@N-Dekker
Copy link
Member Author

N-Dekker commented Aug 1, 2022

we use this implementation: https://itk.org/Doxygen/html/classitk_1_1VTKPolyDataReader.html

Thanks @stefanklein, I see now, it says:

Caveat1: itkVTKPolyDataReader can only read triangle meshes. Use vtkTriangleFilter to convert your mesh to a triangle mesh. Caviet2: itkVTKPolyDataReader can only read vtk legacy files. Caveat3: itkVTKPolyDataReader cannot read binary vtk files.

Interestingly, it also says about VTKPolyDataReader:

This class may be deprecated in the future. The MeshFileReader is preferred

Only elxStatisticalShapePenalty still uses VTKPolyDataReader: https://github.com/SuperElastix/elastix/blob/4.9.0/Components/Metrics/StatisticalShapePenalty/elxStatisticalShapePenalty.hxx#L380

Other metrics components already use itk::MeshFileReader. elastix::TransformBase was upgraded from itk::VTKPolyDataReader to itk::MeshFileReader with ebcb511 ("ENH: switching elastix to ITK4 !", Marius, 13 Jan 2012.) Hopefully, itk::MeshFileReader has dropped the triangle-only limitation...


Update: I just double-checked: itk::MeshFileReader does not require triangles. So this limitation is indeed out-dated. (Especially when elxStatisticalShapePenalty also stops using VTKPolyDataReader.)

N-Dekker added a commit that referenced this issue Aug 1, 2022
The documentation of `itk::VTKPolyDataReader` says:

> This class may be deprecated in the future. The MeshFileReader is preferred.

https://github.com/InsightSoftwareConsortium/ITK/blob/v5.3rc03/Modules/Core/Mesh/include/itkVTKPolyDataReader.h#L37-L38

Moreover:

> itkVTKPolyDataReader can only read triangle meshes

While `itk::MeshFileReader` does not have this limitation.

Related to issue #698 "Double-check limitations of vtk file support"
N-Dekker added a commit that referenced this issue Aug 1, 2022
The documentation of `itk::VTKPolyDataReader` says:

> This class may be deprecated in the future. The MeshFileReader is preferred.

https://github.com/InsightSoftwareConsortium/ITK/blob/v5.3rc03/Modules/Core/Mesh/include/itkVTKPolyDataReader.h#L37-L38

Moreover:

> itkVTKPolyDataReader can only read triangle meshes

While `itk::MeshFileReader` does not have this limitation.

Related to issue #698 "Double-check limitations of vtk file support"
@stefanklein
Copy link
Member

stefanklein commented Aug 2, 2022 via email

@N-Dekker
Copy link
Member Author

N-Dekker commented Aug 2, 2022

perhaps you can check the code of that class. Any easy way of testing the triangle limitation.
Probably would be good to also use this implementation in the statisticalshapepenalty. In any case, this is the recommended way to read/write vtk meshes.

@stefanklein I double-checked: it is specifically the itkVTKPolyDataReader that requires POLYGONS in the vtk file. Otherwise it will throw an exception: https://github.com/InsightSoftwareConsortium/ITK/blob/v5.3rc04/Modules/Core/Mesh/include/itkVTKPolyDataReader.hxx#L177

On the other hand, itk::MeshFileReader does accept vtk files without POLYGONS Which should be fine, as https://vtk.org/wp-content/uploads/2015/04/file-formats.pdf says:

None of the keywords VERTICES, LINES, POLYGONS, or TRIANGLE_STRIPS is required.

So a vtk file may just contain a list of points, without triangles or other connections between them.

So yes, I replaced itkVTKPolyDataReader with itk::MeshFileReader in elxStatisticalShapePenalty, pull request #699

N-Dekker added a commit to SuperElastix/manual that referenced this issue Aug 2, 2022
Related to issue SuperElastix/elastix#698 "Double-check limitations of vtk file support"
@stefanklein
Copy link
Member

stefanklein commented Aug 2, 2022 via email

@N-Dekker
Copy link
Member Author

N-Dekker commented Aug 3, 2022

Excellent, thanks!

You're welcome. BTW, it appears to me now that itk::MeshFileReader<MeshType> and itk::MeshFileWriter<MeshType> do support both 2D and 3D points. I mean, I tested with either a 2D or a 3D MeshType, and they both just appear to work fine. It's just the ITK/Python itk.meshread that assumes 3D (producing seemingly arbitrary values for the 3rd coordinate of each read point).

https://github.com/InsightSoftwareConsortium/ITK/blob/585b8f991d7c8fb2d84b51571c3c91f7ae79706e/Modules/IO/MeshVTK/src/itkVTKPolyDataMeshIO.cxx#L287 says:

  this->m_PointDimension = 3; // vtk only support 3 dimensional points

But I guess it isn't so strict! 😃 With MeshFileReader and MeshFileWriter, 2D just works, using vtk files.

I think it's good to know, because otherwise our own specific elastix/transformix input and output point file formats would have been the only file formats for 2D points, supported by elastix/transformix.

@stefanklein
Copy link
Member

stefanklein commented Aug 3, 2022 via email

@N-Dekker
Copy link
Member Author

N-Dekker commented Aug 4, 2022

OK great, maybe bring that to the attention of the ITK-guys

Good idea @stefanklein, it appears that there was an issue already, "Add 2D mesh support", I just added my comment: slicersalt/ITKShape#8 (comment)

@stefanklein
Copy link
Member

stefanklein commented Aug 5, 2022 via email

@N-Dekker
Copy link
Member Author

OK, so the vtk file format may not be perfect, but for now, at least for backward compatibility of elastix and transformix, it's good enough. Significant progress was made to improve vtk file support:

Time to close this issue for now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants