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().