vtkWarpVector seems to be stripping off my arrays?

I have a thermomechanical FEM dataset that includes “deformation” vectors. The data comes to me in a giant collection NumPy arrays. The data may have cell connectivity, wherever it is created - but I never see it, and have to create my own:

# Read in location, skin the surface:
pd = vtkPolyData()
pts = vtkPoints()
for loc in locations:
    pts.InsertNextPoint(loc)
pd.SetPoints(pts)
d2 = vtkDelaunay2D()
d2.SetInputData(pd)
d2.Update()

# Read temperature and deformation data:
displacement = numpy_to_vtk(displacement_data)
displacement.SetName("Displacement")
d2.GetOutputDataObject(0).GetPointData().AddArray(displacement)
d2.GetOutputDataObject(0).GetPointData().SetActiveVectors("Displacement")

temperature = numpy_to_vtk(temperature_data)
temperature.SetName("Temperature")
d2.GetOutputDataObject(0).GetPointData().AddArray(temperature)
d2.GetOutputDataObject(0).GetPointData().SetActiveScalars("Temperature")

Ok, that’s roughly how I set it up, if I stop in a debugger, the arrays are there (after all, I just added them). Once I run them through vtkWarpVector … they’re gone. I can get this done in ParaView … but I need a script …

wv = vtkWarpVector()
wv.SetInputConnection(d2.GetOutputPort())
wv.Update()
print(wv.GetOutputDataObject(0).GetPointData())
# ^^ arrays are gone :(

vtkWarpVector is not stripping the arrays. You are adding them to the output of a filter, and if that filter re-executes, it will recreate the output data object, effectively “stripping” your arrays out.

Make a shallow copy of d2’s output instead and work with that.

d3 = vtkPolyData()
d3.ShallowCopy(d2.GetOutputDataObject(0))

then add your arrays to d3 and pass that as the input to vtkWarpVector.

wv.SetInputData(d3)
1 Like

Ok - I feel silly! Thanks!

You are welcome. It’s something that isn’t obvious with the pipeline execution model.