NaNs produce invalid values in vtkCellDataToPointData
When computing point data from cell data, NaN values don't seem to be handled correctly in VTK 8.0.1, as opposed to earlier versions. A sample code below shows that invalid values are produced with VTK 8.0.1, whereas NaNs are output with VTK 6.3.0.
This leads for my application to spurious contours when displaying an isosurface of 3D volumetric data. When reverting to VTK 6.3.0, NaNs are present as expected in the resulting PointData, which will not be contoured.
Example render with VTK 6.3.0 (surface added to show boundary of non-NaN values
Example render with VTK 8.0.1:
Simple test code
import vtk
import numpy as np
# Create a 3D array with increasing values, set one plane to NaN
dimensions = (2,2,2)
y = np.r_[:np.prod(dimensions)].reshape(dimensions).astype('f4')
y[:,0,:] = np.NaN
# Convert to VTK array
array = vtk.vtkFloatArray()
array.SetNumberOfComponents(1)
array.SetNumberOfValues(y.size)
for i in range(y.size):
array.SetValue(i, y.flat[i])
# Create ImageData and set cell values
im = vtk.vtkImageData()
im.SetDimensions(dimensions[0]+1, dimensions[1]+1, dimensions[2]+1)
im.GetCellData().SetScalars(array)
# Compute point values
cell2point = vtk.vtkCellDataToPointData()
cell2point.SetInputData(im)
cell2point.Update()
# Print out results
pointScalars = cell2point.GetOutput().GetPointData().GetScalars()
for i in xrange(np.prod((dimensions[0]+1, dimensions[1]+1, dimensions[2]+1))):
print pointScalars.GetValue(i)
Output with VTK 8.0.1:
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
2.0
2.5
3.0
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
4.0
4.5
5.0
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
-9.99999968029e+37
6.0
6.5
7.0
Output with VTK 6.3.0:
nan
nan
nan
nan
nan
nan
2.0
2.5
3.0
nan
nan
nan
nan
nan
nan
4.0
4.5
5.0
nan
nan
nan
nan
nan
nan
6.0
6.5
7.0