# Is there NaN support for legacy vtkPolyDataReader

**URL:** https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389
**Category:** ParaView Support
**Created:** [March 4, 2019, 10:34pm UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389 "2019-03-04T22:34:30Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![robertsawko](https://discourse.paraview.org/user_avatar/discourse.paraview.org/robertsawko/32/6283_2.png) [@robertsawko](https://discourse.paraview.org/u/robertsawko)
#### Post date: [March 4, 2019, 10:34pm UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389/1 "2019-03-04T22:34:30Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [March 5, 2019, 9:26am UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389/2 "2019-03-05T09:26:36Z")

</div>

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](https://discourse.paraview.org/uploads/default/original/2X/c/cb806a1eb3c5210df1040ff3a59ed76770ef4065.vtk) (117.6 KB)

---

<div class="post-metadata">

### Author: ![robertsawko](https://discourse.paraview.org/user_avatar/discourse.paraview.org/robertsawko/32/6283_2.png) [@robertsawko](https://discourse.paraview.org/u/robertsawko)
#### Post date: [March 5, 2019, 11:21am UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389/3 "2019-03-05T11:21:23Z")

</div>

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](https://discourse.paraview.org/uploads/default/original/2X/9/940092dfc1fb1b175de710cd74032ca61ad9119e.vtk) (10.5 KB)

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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [March 5, 2019, 12:26pm UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389/4 "2019-03-05T12:26:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![romangrothausmann](https://discourse.paraview.org/user_avatar/discourse.paraview.org/romangrothausmann/32/1021_2.png) [@romangrothausmann](https://discourse.paraview.org/u/romangrothausmann)
#### Post date: [March 24, 2020, 12:09pm UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389/5 "2020-03-24T12:09:21Z")

</div>

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

```auto
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](https://itk.org/Doxygen/html/classitk_1_1VTKPolyDataWriter-members.html) does not have the option to write binary (or did I miss something in the docs @thewtex?).

---

<div class="post-metadata">

### Author: ![thewtex](https://discourse.paraview.org/user_avatar/discourse.paraview.org/thewtex/32/854_2.png) [@thewtex](https://discourse.paraview.org/u/thewtex)
#### Post date: [March 24, 2020, 11:33pm UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389/6 "2020-03-24T23:33:45Z")

</div>

> [@romangrothausmann](#):
>
> it seems the [itk::VTKPolyDataWriter](https://itk.org/Doxygen/html/classitk_1_1VTKPolyDataWriter-members.html) 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](https://itk.org/Doxygen/html/classitk_1_1MeshFileWriter.html) where [SetFileTypeAsBINARY()](https://itk.org/Doxygen/html/classitk_1_1MeshFileWriter.html#a7bbd2c67ddb93022e2a213a6bea45cf4) can be set.

---

<div class="post-metadata">

### Author: ![romangrothausmann](https://discourse.paraview.org/user_avatar/discourse.paraview.org/romangrothausmann/32/1021_2.png) [@romangrothausmann](https://discourse.paraview.org/u/romangrothausmann)
#### Post date: [March 25, 2020, 11:51am UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389/7 "2020-03-25T11:51:37Z")

</div>

> `itk::VTKPolyDataWriter` is deprecated in favor of [itk::MeshFileWriter](https://itk.org/Doxygen/html/classitk_1_1MeshFileWriter.html) where [SetFileTypeAsBINARY()](https://itk.org/Doxygen/html/classitk_1_1MeshFileWriter.html#a7bbd2c67ddb93022e2a213a6bea45cf4) can be set.

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

---

<div class="post-metadata">

### Author: ![reox](https://discourse.paraview.org/user_avatar/discourse.paraview.org/reox/32/16237_2.png) [@reox](https://discourse.paraview.org/u/reox)
#### Post date: [April 10, 2026, 7:36am UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389/8 "2026-04-10T07:36:59Z")

</div>

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:

```auto
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](https://discourse.paraview.org/uploads/short-url/qxxENeloCFenY8dHoREZqQnVVL9.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](https://github.com/Kitware/VTK/blob/5e26033e83257007465f0108408f3663da3188e2/IO/Legacy/vtkDataReader.cxx#L74)  
Or is this actually not the function that is used in the reader?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [April 10, 2026, 9:32am UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389/9 "2026-04-10T09:32:15Z")

</div>

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](https://discourse.paraview.org/uploads/short-url/oN6y9vpq7NQ258eqi51qWVGXXoS.vtk) (468 Bytes)

Same in ASCII fails to open:  
[ascii.vtk](https://discourse.paraview.org/uploads/short-url/gGDSvg4W90uMyN8T8rezttuENnz.vtk) (461 Bytes)

Please open an issue @reox : [https://gitlab.kitware.com/vtk/vtk/-/work\_items](https://gitlab.kitware.com/vtk/vtk/-/work_items)

---

<div class="post-metadata">

### Author: ![reox](https://discourse.paraview.org/user_avatar/discourse.paraview.org/reox/32/16237_2.png) [@reox](https://discourse.paraview.org/u/reox)
#### Post date: [April 10, 2026, 9:42am UTC](https://discourse.paraview.org/t/is-there-nan-support-for-legacy-vtkpolydatareader/1389/10 "2026-04-10T09:42:12Z")

</div>

thanks, alright, I created an issue: [https://gitlab.kitware.com/vtk/vtk/-/work\_items/20026](https://gitlab.kitware.com/vtk/vtk/-/work_items/20026)
