Is there NaN support for legacy vtkPolyDataReader

I would just like to double check something or perhaps request a pointer to documentation on this.

ParaView is clearly prepared for handling NaN values. There’s even a special color field in Color Map Editor. But when I open a legacy polydata file which (for good reasons!) contains some NaNs I get:

Generic Warning: In /home/buildslave/dashboards/buildbot/paraview-pvbinsdash-linux-shared-release_superbuild/build/superbuild/paraview/src/VTK/IO/Legacy/vtkDataReader.cxx, line 1436
Error reading ascii data. Possible mismatch of datasize with declaration.

ERROR: In /home/buildslave/dashboards/buildbot/paraview-pvbinsdash-linux-shared-release_superbuild/build/superbuild/paraview/src/VTK/IO/Legacy/vtkDataReader.cxx, line 770
vtkPolyDataReader (0x862b6f0): Unsupported cell attribute type: nan for file: /home/rsa/projects/sem/codes/drops/tools/dropmark/build/a.vtk

ERROR: In /home/buildslave/dashboards/buildbot/paraview-pvbinsdash-linux-shared-release_superbuild/build/superbuild/paraview/src/VTK/Common/DataModel/vtkDataSet.cxx, line 468
vtkPolyData (0x1cf8fad0): Cell array nan with 1 components, has only 0 tuples but there are 1528 cells

ERROR: In /home/buildslave/dashboards/buildbot/paraview-pvbinsdash-linux-shared-release_superbuild/build/superbuild/paraview/src/VTK/IO/Parallel/vtkPDataSetReader.cxx, line 736
vtkPDataSetReader (0xcc0e970): Attribute Mismatch.

I have now moved on to vtp format and without any modification NaNs are handled correctly.

So my question is there a way to handle NaNs in legacy format?

Legacy .vtk file do handle correctly NaN values.
Attached is a .vtk file that contains NaN values and can be opened and
visualized without issues in ParaView.

datasetWithNan.vtk (117.6 KB)

Thanks for a quick reply. Yes, so we actually noticed that some of our datasets work fine too, but some don’t. I am attaching a file that we created with VTK forcing vtkMath::NaN(). Just to give you some minimal background, the VTK program makes a size estimate of contours, but in some cases estimates are invalid.This does not open in ParaView if I save it as legacy .vtk, but is fine with XML .vtp.

oneDropHasNaNs.vtk (10.5 KB)

We could also use vtkPolyDataReader directory from VTK to read these files.

Indeed, it seems like nan values are only supported in binary mode, not in ascii mode. this is a limitation of the legact vtkDataReader. This is definitely fixable tough.

In the meantime, you could use binary format instead.

Seems I have hit this particularity as well now when writing meshes from ITK-5 and converting them with VTK-8 from vkt to vtp format

Generic Warning: In /opt/compilation/VTK-git/IO/Legacy/vtkDataReader.cxx, line 1436
Error reading ascii data. Possible mismatch of datasize with declaration.

ERROR: In /opt/compilation/VTK-git/IO/Legacy/vtkPolyDataReader.cxx, line 303
vtkPolyDataReader (0x55ea5ce79dd0): Unrecognized keyword: nan

and it seems the itk::VTKPolyDataWriter does not have the option to write binary (or did I miss something in the docs @thewtex?).

itk::VTKPolyDataWriter is deprecated in favor of itk::MeshFileWriter where SetFileTypeAsBINARY() can be set.

1 Like

itk::VTKPolyDataWriter is deprecated in favor of itk::MeshFileWriter where SetFileTypeAsBINARY() can be set.

Many thanks @thewtex for that hint. Works great now, seems though the default is SetFileTypeAsASCII().

I did not want to create a new thread and it fits here nicely, so sorry for digging this up.

Due to some legacy software I’m forced to use VTK ASCII format. I found out that NaN seems to be not working when opening those files in paraview:

Generic Warning: In vtkDataReader.cxx, line 1526
Error reading ascii data. Possible mismatch of datasize with declaration.

ERROR: In vtkDataReader.cxx, line 854
vtkUnstructuredGridReader (000001A629CD1350): Unsupported cell attribute type: nan for file: C:/Users/reox/Downloads/demo.vtk

demo.vtk (298 Bytes)

However, when I looked into the actual VTK code, there are functions that should handle inf and nan: VTK/IO/Legacy/vtkDataReader.cxx at 5e26033e83257007465f0108408f3663da3188e2 · Kitware/VTK · GitHub
Or is this actually not the function that is used in the reader?

I confirm there is as issue with reading NaN data from ASCII files in the legacy format.

Here is a binary file that can be opened fine:
binary.vtk (468 Bytes)

Same in ASCII fails to open:
ascii.vtk (461 Bytes)

Please open an issue @reox : https://gitlab.kitware.com/vtk/vtk/-/work_items

thanks, alright, I created an issue: https://gitlab.kitware.com/vtk/vtk/-/work_items/20026