Dear all,
I have an STL file that I would like to transform it via a series of 4x4 matrices, and make an animation at each time point. I was able to put together the following as a Programmable Filter script, but it does not work: it only translate the whole mesh to a distance at time = 1 and then stops. Could anyone please help me?
# Code for 'Script'
import vtk
import numpy as np
def GetUpdateTimestep(algorithm):
executive = algorithm.GetExecutive()
outInfo = executive.GetOutputInformation(0)
return outInfo.Get(executive.UPDATE_TIME_STEP()) \
if outInfo.Has(executive.UPDATE_TIME_STEP()) else None
reqTime = GetUpdateTimestep(self)
src = self.GetInputDataObject(0, 0)
tfm_arr = np.array([[1, 0, 0, reqTime],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]])
transform = vtk.vtkTransform()
transform.SetMatrix(tfm_arr.flatten())
transformFilter=vtk.vtkTransformPolyDataFilter()
transformFilter.SetTransform(transform)
transformFilter.SetInputData(src)
transformFilter.Update()
output.ShallowCopy(transformFilter.GetOutput())
output.GetInformation().Set(output.DATA_TIME_STEP(), reqTime)
# Code for ’RequestInformation Script’.
import numpy as np
def setOutputTimesteps(algorithm ,timesteps):
executive = algorithm.GetExecutive()
outInfo = executive.GetOutputInformation(0)
# First remove existing time steps
outInfo.Remove(executive.TIME_STEPS())
for timestep in timesteps :
outInfo.Append(executive.TIME_STEPS(), timestep)
outInfo.Remove(executive.TIME_RANGE())
outInfo.Append(executive.TIME_RANGE(), timesteps[0])
outInfo.Append(executive.TIME_RANGE(), timesteps[-1])
timesteps = np.arange(10)
setOutputTimesteps(self, timesteps)
# Code for 'RequestUpdateExtent Script'
executive = self.GetExecutive()
outInfo = executive.GetOutputInformation(0)
outTimeSteps = outInfo.Get(executive.TIME_STEPS())
currentTimeStep = outInfo.Get(executive.UPDATE_TIME_STEP())
currentTimeStepIndex = outTimeSteps.index(currentTimeStep)
requestedTimeStepIndex = currentTimeStepIndex + 1
requestedTimeStep = outTimeSteps[requestedTimeStepIndex]
if requestedTimeStepIndex <= len(outTimeSteps):
outInfo.Set(executive.UPDATE_TIME_STEP(), requestedTimeStep)