My user is trying to clip an object, such as the can, and then animate the clip
plane to remain in the middle of the dataset over time. He then wants to be
able to follow data. Finally, he wants this in a script, so he can run many
datasets through this process. Here is a thread on how it is done. The trick
is to insert a python track in the animation view that keeps the clip centered,
and then add a camera track using follow data. The trace recorder is missing
this magic - I will write up a bug.
Alan
<<Start reply from Utkarsh>>
Alan,
Attached is the corrected trace. Yes, it's indeed a bug. We'll need to extend
the tracing to trace Python Animation Cue, which it's currently missing.
Utkarsh
On Mon, Jul 11, 2016 at 7:21 PM, Scott, W Alan <[email protected]> wrote:
> Utkarsh,
>
> You sent us a bit of Python to use in the Animation View a few weeks ago.
> It keeps a clip centered on the screen. This is exactly what we
> wanted, thanks. What my users actually want (users are cc’d) is this
> snippet inserted into a Python script, so that they can batch larger
> jobs. So, Richard and I tried creating a trace with the trace
> recorder. Did the
> following:
>
> · Trace recorder on.
>
> · Can.exo. All vars on. Apply.
>
> · Clip. Z normal. Apply.
>
> · Animation View/ Python / Cut and pasted in your magic Python.
>
> · Animation View/ Camera/ Follow Data.
>
> · Trace recorder off.
>
> · Play.
>
>
>
> Worked perfectly! Excellent!
>
>
>
> But, the trace missed the insertion of your magic Python. How should
> we modify a Python trace to include your magic Python?
>
>
>
> Here is what you gave us:
>
>
>
>
>
> def start_cue(self): pass
>
>
>
> def tick(self):
>
> ts = self.GetClockTime()
>
> from paraview import simple as pvs
>
> clip = pvs.FindSource("Clip1")
>
> ip = clip.Input
>
> ip.UpdatePipeline(ts)
>
> bds = ip.GetDataInformation().GetBounds()
>
> center = [ (bds[0] + bds[1]) / 2.0,
>
> (bds[2] + bds[3]) / 2.0,
>
> (bds[4] + bds[5]) / 2.0 ]
>
> clip.ClipType.Origin = center
>
>
>
> def end_cue(self): pass
>
>
>
>
>
> And, attached is the (bad) trace from the steps above.
>
>
>
> Thanks,
>
>
>
> Alan
>
>
#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
##----------------------------------------------------------------------------------------
def AddPythonAnimationCue(scene, script):
"""New function to add a Python animation cue to the scene with a specific script."""
cue = PythonAnimationCue(Script=script)
scene.Cues.append(cue)
return cue
##----------------------------------------------------------------------------------------
# create a new 'ExodusIIReader'
canex2 = ExodusIIReader(FileName=['D:\\alan\\demos\\training-2016\\can.ex2'])
canex2.ElementVariables = []
canex2.PointVariables = []
canex2.GlobalVariables = []
canex2.NodeSetArrayStatus = []
canex2.SideSetArrayStatus = []
# get animation scene
animationScene1 = GetAnimationScene()
# update animation scene based on data timesteps
animationScene1.UpdateAnimationUsingDataTimeSteps()
# Properties modified on canex2
canex2.ElementVariables = ['EQPS']
canex2.PointVariables = ['DISPL', 'VEL', 'ACCL']
canex2.GlobalVariables = ['KE', 'XMOM', 'YMOM', 'ZMOM', 'NSTEPS', 'TMSTEP']
canex2.ElementBlocks = ['Unnamed block ID: 1 Type: HEX', 'Unnamed block ID: 2 Type: HEX']
# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
# uncomment following to set a specific view size
# renderView1.ViewSize = [1347, 620]
# show data in view
canex2Display = Show(canex2, renderView1)
# trace defaults for the display properties.
canex2Display.ColorArrayName = [None, '']
canex2Display.OSPRayScaleArray = 'ACCL'
canex2Display.OSPRayScaleFunction = 'PiecewiseFunction'
canex2Display.GlyphType = 'Arrow'
canex2Display.ScalarOpacityUnitDistance = 1.3901072164734267
canex2Display.SetScaleArray = ['POINTS', 'GlobalNodeId']
canex2Display.ScaleTransferFunction = 'PiecewiseFunction'
canex2Display.OpacityArray = ['POINTS', 'GlobalNodeId']
canex2Display.OpacityTransferFunction = 'PiecewiseFunction'
# reset view to fit data
renderView1.ResetCamera()
# set scalar coloring
ColorBy(canex2Display, ('FIELD', 'vtkBlockColors'))
# show color bar/color legend
canex2Display.SetScalarBarVisibility(renderView1, True)
# get color transfer function/color map for 'vtkBlockColors'
vtkBlockColorsLUT = GetColorTransferFunction('vtkBlockColors')
vtkBlockColorsLUT.InterpretValuesAsCategories = 1
vtkBlockColorsLUT.Annotations = ['0', '0', '1', '1', '2', '2', '3', '3', '4', '4', '5', '5', '6', '6', '7', '7', '8', '8', '9', '9', '10', '10', '11', '11']
vtkBlockColorsLUT.ActiveAnnotatedValues = ['0', '1']
vtkBlockColorsLUT.IndexedColors = [1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.63, 0.63, 1.0, 0.67, 0.5, 0.33, 1.0, 0.5, 0.75, 0.53, 0.35, 0.7, 1.0, 0.75, 0.5]
# get opacity transfer function/opacity map for 'vtkBlockColors'
vtkBlockColorsPWF = GetOpacityTransferFunction('vtkBlockColors')
# reset view to fit data
renderView1.ResetCamera()
# reset view to fit data
renderView1.ResetCamera()
# create a new 'Clip'
clip1 = Clip(Input=canex2)
clip1.ClipType = 'Plane'
clip1.Scalars = ['POINTS', 'GlobalNodeId']
clip1.Value = 5044.5
# init the 'Plane' selected for 'ClipType'
clip1.ClipType.Origin = [0.21706008911132812, 4.0, -5.110947132110596]
# Properties modified on clip1.ClipType
clip1.ClipType.Origin = [0.217060089111328, 4.0, -5.1109471321106]
clip1.ClipType.Normal = [0.0, 0.0, 1.0]
# Properties modified on clip1.ClipType
clip1.ClipType.Origin = [0.217060089111328, 4.0, -5.1109471321106]
clip1.ClipType.Normal = [0.0, 0.0, 1.0]
# show data in view
clip1Display = Show(clip1, renderView1)
# trace defaults for the display properties.
clip1Display.ColorArrayName = [None, '']
clip1Display.OSPRayScaleArray = 'ACCL'
clip1Display.OSPRayScaleFunction = 'PiecewiseFunction'
clip1Display.GlyphType = 'Arrow'
clip1Display.ScalarOpacityUnitDistance = 1.2936407495554014
clip1Display.SetScaleArray = [None, '']
clip1Display.ScaleTransferFunction = 'PiecewiseFunction'
clip1Display.OpacityArray = [None, '']
clip1Display.OpacityTransferFunction = 'PiecewiseFunction'
# hide data in view
Hide(canex2, renderView1)
# set scalar coloring
ColorBy(clip1Display, ('FIELD', 'vtkBlockColors'))
# show color bar/color legend
clip1Display.SetScalarBarVisibility(renderView1, True)
# toggle 3D widget visibility (only when running from the GUI)
Hide3DWidgets(proxy=clip1.ClipType)
# reset view to fit data
renderView1.ResetCamera()
# get camera animation track for the view
cameraAnimationCue1 = GetCameraTrack(view=renderView1)
# create keyframes for this animation track
# create a key frame
keyFrame6216 = CameraKeyFrame()
keyFrame6216.Position = [0.21706008911132812, -35.77659794632151, -0.16642117500305176]
keyFrame6216.FocalPoint = [0.21706008911132812, 4.0, -0.16642117500305176]
keyFrame6216.ViewUp = [0.0, 0.0, 1.0]
keyFrame6216.ParallelScale = 10.29494109789382
keyFrame6216.PositionPathPoints = [0.21706008911132812, -36.477609634399414, -0.16642117500305176, 24.009202080263023, -28.747074085904224, -0.16642117500305176, 38.71355449595837, -8.508269268704522, -0.16642117500305176, 38.71355449595837, 16.508269268704513, -0.16642117500305176, 24.009202080263023, 36.74707408590422, -0.16642117500305176, 0.21706008911133168, 44.47760963439939, -0.16642117500305176, -23.575081902040353, 36.74707408590421, -0.16642117500305176, -38.27943431773569, 16.508269268704517, -0.16642117500305176, -38.27943431773569, -8.508269268704503, -0.16642117500305176, -23.575081902040356, -28.747074085904188, -0.16642117500305176]
keyFrame6216.FocalPathPoints = [0.21706008911132812, 4.0, -0.16642117500305176]
keyFrame6216.ClosedPositionPath = 1
# create a key frame
keyFrame6217 = CameraKeyFrame()
keyFrame6217.KeyTime = 1.0
keyFrame6217.Position = [0.21706008911132812, -35.77659794632151, -0.16642117500305176]
keyFrame6217.FocalPoint = [0.21706008911132812, 4.0, -0.16642117500305176]
keyFrame6217.ViewUp = [0.0, 0.0, 1.0]
keyFrame6217.ParallelScale = 10.29494109789382
# initialize the animation track
cameraAnimationCue1.Mode = 'Follow-data'
cameraAnimationCue1.KeyFrames = [keyFrame6216, keyFrame6217]
cameraAnimationCue1.DataSource = clip1
##----------------------------------------------------------------------------------------
AddPythonAnimationCue(animationScene1,
"""
def start_cue(self): pass
def tick(self):
ts = self.GetClockTime()
from paraview import simple as pvs
clip = pvs.FindSource("Clip1")
ip = clip.Input
ip.UpdatePipeline(ts)
bds = ip.GetDataInformation().GetBounds()
center = [ (bds[0] + bds[1]) / 2.0,
(bds[2] + bds[3]) / 2.0,
(bds[4] + bds[5]) / 2.0 ]
clip.ClipType.Origin = center
def end_cue(self): pass
""")
##----------------------------------------------------------------------------------------
#### saving camera placements for all active views
# current camera placement for renderView1
renderView1.CameraPosition = [0.21706008911132812, -35.77659794632151, -0.16642117500305176]
renderView1.CameraFocalPoint = [0.21706008911132812, 4.0, -0.16642117500305176]
renderView1.CameraViewUp = [0.0, 0.0, 1.0]
renderView1.CameraParallelScale = 10.29494109789382
#### uncomment the following to render all views
# RenderAllViews()
# alternatively, if you want to write images, you can use SaveScreenshot(...).
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the ParaView Wiki at:
http://paraview.org/Wiki/ParaView
Search the list archives at: http://markmail.org/search/?q=ParaView
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview