apply filter multiple times

Dear all:

I am having some issue setting up a rather complex pipeline involving, but not exclusively, vtk objects and filters. I think basically the issue boils down to this: I create an unstructured grid with some vector field, warp it, modify the vector field (outside vtk), warp it again, etc. Pretty basic, right? Of course I do not want to reallocate an unstructured grid for the warped mesh each time I run the warp filter, but rather modify the one that is allocated the first time I run the warp filter. Makes sense? I have done this many times, for pipelines that only involve vtk stuff. However, I am not sure how to do this for pipelines involving non-vtk operations. Here is a minimal example: I create a sphere, warp it along the normals, scale the normals, warp it again using the already existing warp filter (here the scaling is not taken into account for some reason), and warp it using a new warp filter (here it works, but I guess it creates a new object instead of modifying the existing one, right?).

#coding=utf8

import vtk
import vtk.numpy_interface.dataset_adapter as dsa
import vtk.numpy_interface.algorithms as algs

sphere_source = vtk.vtkSphereSource()
sphere_source.Update()
sphere = sphere_source.GetOutput()
sphere.GetPointData().SetActiveVectors("Normals")

print (sphere.GetBounds()[4:6])

pdata_writer = vtk.vtkPolyDataWriter()
pdata_writer.SetInputData(sphere)
pdata_writer.SetFileName("test_vtk_sphere.vtk")
pdata_writer.Write()

warp = vtk.vtkWarpVector()
# warp.SetInputConnection(sphere_source.GetOutputPort())
warp.SetInputDataObject(sphere)
# warp.SetInputData(sphere)
warp.Update()
warp_sphere = warp.GetOutput()

print (warp_sphere.GetBounds()[4:6])

pdata_writer.SetInputData(warp_sphere)
pdata_writer.SetFileName("test_vtk_warp_sphere1.vtk")
pdata_writer.Write()

sphere_np = dsa.WrapDataObject(sphere)
sphere_np.GetPointData()["Normals"][:] = 2*sphere_np.GetPointData()["Normals"][:]

warp.Update()

print (warp_sphere.GetBounds()[4:6]) # does not take scaling of normals into account…

pdata_writer.SetInputData(warp_sphere)
pdata_writer.SetFileName("test_vtk_warp_sphere2.vtk")
pdata_writer.Write()

warp = vtk.vtkWarpVector()
# warp.SetInputConnection(sphere_source.GetOutputPort())
warp.SetInputDataObject(sphere)
# warp.SetInputData(sphere)
warp.Update()
warp_sphere = warp.GetOutput()

print (warp_sphere.GetBounds()[4:6]) # this one works

pdata_writer.SetInputData(warp_sphere)
pdata_writer.SetFileName("test_vtk_warp_sphere3.vtk")
pdata_writer.Write()

This seem like a trivial issue, but I cannot seem to figure it out. Can someone help me? Thank you so much.

Martin