Visualizing complex vibration modes - ParaView Support - ParaView
The above thread suggested how to animate a complex field (harmonic vibration).
I wrote a bit of code to dump a Python script to animate the motion.
Unfortunately, I am getting an error: ValueError: 'Step' is not a valid value for Interpolation!
I do want a Step interpolation, and I can get it through the dialogue in the animation view.
But the code doesn’t work.
Any idea what is wrong with the setup of the key frames?
from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()
renderView1 = GetActiveViewOrCreate('RenderView')
# find source: pick up the name from the Julia source
shape_source = FindSource('shape_2.97094e+02.vtu')
# create a new 'Programmable Filter'
programmableFilter1 = ProgrammableFilter(Input=shape_source)
programmableFilter1.Script = ''
programmableFilter1.RequestInformationScript = ''
programmableFilter1.RequestUpdateExtentScript = ''
programmableFilter1.PythonPath = ''
# Properties modified on programmableFilter1
programmableFilter1.Script = ''
programmableFilter1.RequestInformationScript = ''
programmableFilter1.RequestUpdateExtentScript = ''
programmableFilter1.PythonPath = ''
# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
# uncomment following to set a specific view size
# renderView1.ViewSize = [1492, 589]
# get layout
layout1 = GetLayout()
# show data in view
programmableFilter1Display = Show(programmableFilter1, renderView1, 'UnstructuredGridRepresentation')
# trace defaults for the display properties.
programmableFilter1Display.Representation = 'Surface'
programmableFilter1Display.ColorArrayName = [None, '']
programmableFilter1Display.OSPRayScaleFunction = 'PiecewiseFunction'
programmableFilter1Display.SelectOrientationVectors = 'None'
programmableFilter1Display.ScaleFactor = 0.1273491016886233
programmableFilter1Display.SelectScaleArray = 'None'
programmableFilter1Display.GlyphType = 'Arrow'
programmableFilter1Display.GlyphTableIndexArray = 'None'
programmableFilter1Display.GaussianRadius = 0.0063674550844311645
programmableFilter1Display.SetScaleArray = [None, '']
programmableFilter1Display.ScaleTransferFunction = 'PiecewiseFunction'
programmableFilter1Display.OpacityArray = [None, '']
programmableFilter1Display.OpacityTransferFunction = 'PiecewiseFunction'
programmableFilter1Display.DataAxesGrid = 'GridAxesRepresentation'
programmableFilter1Display.PolarAxes = 'PolarAxesRepresentation'
programmableFilter1Display.ScalarOpacityUnitDistance = 0.054253560164564396
# hide data in view
Hide(shape_source, renderView1)
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on programmableFilter1
programmableFilter1.Script = """
U_real = inputs[0].PointData['U_real']
U_imag = inputs[0].PointData['U_imag']
executive = self.GetExecutive()
time_value = executive.GetOutputInformation(0).Get(executive.UPDATE_TIME_STEP())
U = (U_real * cos(2*pi*time_value) - U_imag * sin(2*pi*time_value))
output.PointData.append(U, 'U')
"""
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on programmableFilter1
programmableFilter1.RequestInformationScript = """
executive = self.GetExecutive()
outInfo = executive.GetOutputInformation(0)
outInfo.Remove(executive.TIME_STEPS())
for i in range(0, 400+1):
outInfo.Append(executive.TIME_STEPS(), i/100)
outInfo.Remove(executive.TIME_RANGE())
outInfo.Append(executive.TIME_RANGE(), 0)
outInfo.Append(executive.TIME_RANGE(), 1)
"""
# get animation scene
animationScene1 = GetAnimationScene()
# get the time-keeper
timeKeeper1 = GetTimeKeeper()
# update animation scene based on data timesteps
animationScene1.UpdateAnimationUsingDataTimeSteps()
# create a new 'Warp By Vector'
warpByVector1 = WarpByVector(Input=programmableFilter1)
warpByVector1.Vectors = ['POINTS', 'U']
# show data in view
warpByVector1Display = Show(warpByVector1, renderView1, 'UnstructuredGridRepresentation')
# trace defaults for the display properties.
warpByVector1Display.Representation = 'Surface'
warpByVector1Display.ColorArrayName = [None, '']
warpByVector1Display.OSPRayScaleArray = 'U'
warpByVector1Display.OSPRayScaleFunction = 'PiecewiseFunction'
warpByVector1Display.SelectOrientationVectors = 'None'
warpByVector1Display.ScaleFactor = 0.12734916553420975
warpByVector1Display.SelectScaleArray = 'None'
warpByVector1Display.GlyphType = 'Arrow'
warpByVector1Display.GlyphTableIndexArray = 'None'
warpByVector1Display.GaussianRadius = 0.006367458276710487
warpByVector1Display.SetScaleArray = ['POINTS', 'U']
warpByVector1Display.ScaleTransferFunction = 'PiecewiseFunction'
warpByVector1Display.OpacityArray = ['POINTS', 'U']
warpByVector1Display.OpacityTransferFunction = 'PiecewiseFunction'
warpByVector1Display.DataAxesGrid = 'GridAxesRepresentation'
warpByVector1Display.PolarAxes = 'PolarAxesRepresentation'
warpByVector1Display.ScalarOpacityUnitDistance = 0.054253582666424625
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
warpByVector1Display.ScaleTransferFunction.Points = [-4.840145009488761e-06, 0.0, 0.5, 0.0, 3.06785751639229e-06, 1.0, 0.5, 0.0]
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
warpByVector1Display.OpacityTransferFunction.Points = [-4.840145009488761e-06, 0.0, 0.5, 0.0, 3.06785751639229e-06, 1.0, 0.5, 0.0]
# hide data in view
Hide(programmableFilter1, renderView1)
# update the view to ensure updated data information
renderView1.Update()
# Properties modified on warpByVector1
warpByVector1.ScaleFactor = 1.0
# update the view to ensure updated data information
renderView1.Update()
# get animation track
warpByVector1ScaleFactorTrack = GetAnimationTrack('ScaleFactor', index=0, proxy=warpByVector1)
# create keyframes for this animation track
# create a key frame
keyFrame9511 = CompositeKeyFrame()
keyFrame9511.KeyTime = 0.0
keyFrame9511.KeyValues = [1.33756e+03]
keyFrame9511.Interpolation = 'Step'
keyFrame9511.Base = 2.0
keyFrame9511.StartPower = 0.0
keyFrame9511.EndPower = 1.0
keyFrame9511.Phase = 0.0
keyFrame9511.Frequency = 1.0
keyFrame9511.Offset = 0.0
# create a key frame
keyFrame9512 = CompositeKeyFrame()
keyFrame9512.KeyTime = 1.0
keyFrame9512.KeyValues = [1.33756e+03]
keyFrame9512.Interpolation = 'Step'
keyFrame9512.Base = 2.0
keyFrame9512.StartPower = 0.0
keyFrame9512.EndPower = 1.0
keyFrame9512.Phase = 0.0
keyFrame9512.Frequency = 1.0
keyFrame9512.Offset = 0.0
# initialize the animation track
warpByVector1ScaleFactorTrack.KeyFrames = [keyFrame9511, keyFrame9512]
animationScene1.Play()
animationScene1.Play()
#### saving camera placements for all active views
# current camera placement for renderView1
renderView1.CameraPosition = [0.9397382619147922, -0.8500997386424357, -1.8495294823857338]
renderView1.CameraFocalPoint = [0.46404687523764426, 0.43327050958540075, 0.6787765407842903]
renderView1.CameraViewUp = [-0.1576136295811123, -0.8922072135678301, 0.42323070756715725]
renderView1.CameraParallelScale = 0.744106007631631
#### uncomment the following to render all views
# RenderAllViews()
# alternatively, if you want to write images, you can use SaveScreenshot(...).