wiki:Examples/ParaviewAnimating

Version 7 (modified by Herwig Zilken, 6 years ago) ( diff )

--

Animating Data with ParaView Python Scripting

Some information on how to write Python scripts to animate your data with ParaView can be found here:
https://www.paraview.org/Wiki/ParaView/Python_Scripting
https://www.paraview.org/ParaView3/Doc/Nightly/www/py-doc/paraview.servermanager_proxies.html

On this page, we would like to share our own experience with you. DISCLAIMER: our knowlegde about all this is not complete and maybe incorrect. So believe everything found on this page on your own risk.

ParaView Gui: Animation View

As usual, when you want to write a Python script for ParaView from scratch, and have no idea where to start, it make sense to open the ParaView GUI, start a Python trace, and prototype the desired setup in the GUI interactively. When you want to generate an animation, you have to deal with the Animation View, obviously.

ParaView Animtion View

Unfortunately, ParaView is not willing to include all interactive settings in the trace. Some are just skipped, e.g. settings regarding the "TimeKeeper1 - Time" are NOT reflected in the trace. For this reason it makes sense to take a more closer look at the mechanisms and Python classes working behind the scene.

Basic Concept

The basic concept of how to animate "something", in this case the rendered ParaView scene, is quite easy to understand. The central element of any animation is a timeline with a start and end time and a mechanism to determine a number of descrete timesteps (frames). All this is implemented in the Python class paraview.simple.AnimationScene. Within the time interval defined in the timeline, properties of the scene can be changed. In the ParaView GUI this concept is reflected by so called "tracks" (or "cues") in the Animation View. Basically, each track defines the temporal change of one (or more) properties of the scene.

In ParaView-Python, different kinds (classes) of tracks/cues are available. We will try to explain four of them, which are implemented in the following Python classes:

  • paraview.simple.KeyFrameAnimationCue: basic cue to animate general properties of objects (readers, sources, filters) in the render pipeline
  • paraview.simple.CameraAnimationCue: cue to change camera parameters (e.g. position, focal point, up direction, view angle)
  • paraview.simple.PythonAnimationCue: cue to execute a Python script at a certain point in time
  • paraview.simple.TimeAnimationCue: cue to determine what data timesteps are loaded depending on the animation clock time

The (change of the) values of the properties in the timeline are defined by one or more keyframes included in each track. The key elements :) of a keyframe are keytime and keyvalues. The value(s) of the referred property is set to the keyvalues at the specified keytime. Some types of keyframes also have the ability to interpolate keyvalues from one keyframe to the next. Specifically these are paraview.simple.CameraKeyFrame, paraview.simple.CompositeKeyFrame, paraview.simple.ExponentialKeyFrame, paraview.simple.RampKeyFrame and paraview.simple.SinusoidKeyFrame.

In the next paragraphs we are going to explain the basic mechanisms of the relevat Python classes and we give some examples of typical use cases.

Class AnimationScene

The AnimationScene is responsible for steering the animation clock time. For this purpose, the AnimationScene has a StartTime, an EndTime, and a mechanism to determine the discrete time steps it will generate between StartTime and EndTime. The descrete timesteps are determined by the Mode (called PlayMode in Python) of the AnimationScene. Three different Modes are avilable:

  • 'Sequence': the timesteps are defined by the property NumberOfFrames
  • 'Snap To TimeSteps': the descrete timesteps are defined by the timesteps available in the (time dependend) data. The AnimationScene has knowledge about the available data timesteps by the help of a seperate object, the TimeKeeper.
  • 'RealTime': the timesteps are calculated on the fly (while rendering) to achieve a certain duration of the rendering. This mode is not useful for typical Python scripting, though.

Important properties of AnimationScene:

  • StartTime: the start time of the animation
  • EndTime: the end time of the animation
  • PlayMode: either 'Sequence', 'Snap To TimeSteps' or 'RealTime'
  • NumberOfFrames: number of frames, only used when PlayMode is set to 'Sequence'
  • Duration: duration of the animation in seconds, only used when PlayMode is set to 'RealTime'
  • AnimationTime: the actual animation clock time. Can be get or set.
  • TimeKeeper: the TimeKeeper-object
  • Cues: List of attached cues (=tracks)

Important methods of AnimationScene:

  • GoToFirst(): goto first frame
  • GoToLast(): goto last frame
  • GoToNext(): goto next frame
  • GoToPrevious(): goto previous frame
  • Play(): renders all timesteps one after another in a window
  • Stop(): stops the rendering

AnimationScene Use Cases

Get the animation scene and play a sequence of 100 timesteps:

from paraview.simple import *
animationScene = GetAnimationScene()
animationScene.StartTime = 0
animationScene.EndTime = 1
animationScene.NumberOfFrames = 100
animationScene.PlayMode = 'Sequence'
animationScene.GoToFirst()
while True:
   # render scene
   # safe image
   if animationScene.AnimationTime == animationScene.EndTime:
      break
   anmationScene.GoToNext()

Get the animation scene and play all available timesteps of the time dependent data:

from paraview.simple import *
animationScene = GetAnimationScene()
animationScene.PlayMode = 'Snap To TimeSteps'
animationScene.GoToFirst()
while True:
   # render scene
   # safe image
   if animationScene.AnimationTime == animationScene.EndTime:
      break
   anmationScene.GoToNext()

KeyFrameAnimationCue

As already mentioned, a KeyFrameAnimationCue connects the property of a pipeline object to the cue. This connection is defined via the attributes AnimatedProxy (proxy of the pipeline object) and AnimatedPropertyName (name of the connected property), though typically you do not have to set these attributes on your own. Instead they are set when constructing a KeyFrameAnimationCue by calling GetAnimationTrack(...) (see use case below). Similar to the AnimationScene, every cue also has the properties StartTime and EndTime. Typically these properties do not have the same values as the corresponding ones of AnimationScene. When TimeMode is set to 'Normalize', the start and end time of the animation scene is linearly interpolated to the interval [0,1]. But don't care, these values are the default ones anyhow.

KeyFrameAnimationCue Use Case

Create three different animation cues for three different properties of a sphere:

from paraview.simple import *
sphere = Sphere()
Show(sphere)
track1 = GetAnimationTrack("Visibility") # property of active source
track2 = GetAnimationTrack("Center", 0, sphere)
track3 = GetAnimationTrack(sphere.GetProperty("Radius"))

Attachments (1)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.