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

BUG: VTKPolyDataMeshIO should not hang on inf and NaN in ASCII .vtk file #3542

Conversation

N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Aug 10, 2022

MeshFileReader/VTKPolyDataMeshIO did hang forever when trying to read an
ASCII .vtk file that contained non-numeric chars in "POINTS" section, for
example "Infinity" or "NaN".

With this commit, "inf" and "Infinity" will be interpreted as the floating point
value infinity, while "nan" and "NaN" will be interpreted as Not-A-Number. Other
strings of non-numeric characters in the list of point components (coordinates)
will cause the reader to throw an appropriate itk::ExceptionObject.

Addresses issue #3539
"MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS"
section (including "Infinity" and "NaN")"

@github-actions github-actions bot added area:IO Issues affecting the IO module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances labels Aug 10, 2022
@Leengit
Copy link
Contributor

Leengit commented Aug 10, 2022

Is it worth it to go completely case insensitive to catch "Inf", "Nan", etc.?

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Aug 10, 2022

Is it worth it to go completely case insensitive to catch "Inf", "Nan", etc.?

@Leengit Good question! "Infinity" and "NaN" are essential because those are the strings produced by ITK's MeshFileWriter, using itk::VTKPolyDataMeshIO (which internally uses https://github.com/google/double-conversion). However, it appears that VTK prints infinity and Not-A-Number via printf-style "%g" formatting. Which yields "inf" and "nan" (both entirely lowercase).

I'm not aware of any other string representation of infinity and Not-A-Number that is actually being used in .vtk files.


FYI, This is where our (ITK) "Infinity" and "NaN" strings come from: https://github.com/google/double-conversion/blob/af09fd65fcf24eee95dc62813ba9123414635428/double-conversion/double-to-string.cc#L44-L49 While here is where I see VTK using "%g" to output floating points: https://gitlab.kitware.com/vtk/vtk/-/blob/54a30648db36cab3b91d140a30b14176f97c254a/IO/Legacy/vtkDataWriter.cxx#L1299

Just double-checked: VTK's vtkPolyDataWriter does indeed write "inf" and "nan" for infinity and NaN values respectively, as I just tried, after building the latest version of VTK, from https://gitlab.kitware.com/vtk/vtk/-/tree/54a30648db36cab3b91d140a30b14176f97c254a/ using VS2019.

@N-Dekker N-Dekker marked this pull request as ready for review August 10, 2022 21:14
@N-Dekker N-Dekker marked this pull request as draft August 11, 2022 09:26
`MeshFileReader`/`VTKPolyDataMeshIO` did hang forever when trying to read an
ASCII .vtk file that contained non-numeric chars in "POINTS" section, for
example "Infinity" or "NaN".

With this commit, "inf" and "Infinity" will be interpreted as the floating point
value infinity, while "nan" and "NaN" will be interpreted as Not-A-Number. Other
strings of non-numeric characters in the list of point components (coordinates)
will cause the reader to throw an appropriate `itk::ExceptionObject`.

Addresses issue InsightSoftwareConsortium#3539
"MeshFileReader/VTKPolyDataMeshIO hangs forever on non-numeric chars in "POINTS"
section (including "Infinity" and "NaN")"
@N-Dekker N-Dekker force-pushed the MeshFileRead-ASCII-vtk-Infinity-NaN branch from 5b0969d to b04d2e3 Compare August 11, 2022 09:54
@N-Dekker N-Dekker marked this pull request as ready for review August 11, 2022 13:26
Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔢 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:IO Issues affecting the IO module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
5 participants