GetBounds() fails on VTK9 with NaN points
I originally posted this issue here: https://discourse.vtk.org/t/getbounds-fails-with-nan-points-in-vtk9/4351
Check out this surface mesh which has a scalar array that contains NaNs: surface.vtp
If I apply a warp by scalar filter, the resulting mesh will have NaN points. This is fine and expected and works wonderfully on VTK<9, but on VTK==9, it does not work.
I noticed this issue while trying to plot this warped mesh with PyVista and ParaView with VTK9 which does not work because the rendering routines rely on GetBounds returning the non-NaN bounds. i.e. ParaView cannot display a mesh that contains NaN points.
Here are some details with VTK-Python
import vtk
reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName("surface.vtp")
reader.Update()
surface = reader.GetOutputDataObject(0)
alg = vtk.vtkWarpScalar()
alg.SetInputDataObject(surface)
# args: (idx, port, connection, field, name)
alg.SetInputArrayToProcess(0, 0, 0, 0, "my data")
alg.SetScaleFactor(1.0)
alg.Update()
output = alg.GetOutputDataObject(0)
print(output.GetBounds())
Output:
VTK 8.x | VTK 9.x |
---|---|
(639926.0, 728426.0, 5669105.0, 5818551.0, 218.24110412597656, 1170.1644287109375 ) |
(nan, nan, nan, nan, nan, nan) |
To add to the oddness, (in VTK9) GetBounds()
on the vtkPolyData
object returns Nan while GetBounds()
on the vtkPoints
returns the correct bounds
>>> output.GetBounds()
(nan, nan, nan, nan, nan, nan)
>>> output.GetPoints().GetBounds()
(639926.0, 728426.0, 5669105.0, 5818551.0, 218.24110412597656, 1170.1644287109375)
@lassoan, did the leg work of figuring out what is going on in that discourse issue. It seems like this would be low hanging fruit for a new VTK developer. See their fix here: https://github.com/lassoan/VTK/commit/92b1ee09385c271a88dc4d38d8ce4e4dc5940d9f