If you have a dataset that moves over time and you would like a Clip filter to follow the center of that dataset, you can do the following.
Load or create the data set. Assume the name of the data source in the Pipeline Browser is “DataSource1” (if you loaded a file, e.g. “can.ex2”, the data set will be named “can.ex2” in the Pipeline Browser).
Add a Clip filter and set the Clip Type to “Plane”. Assume this filter is named “Clip1” in the Pipeline Browser.
Open up the Animation View under the View menu.
Next to the blue plus sign, change the combo box to the “Python” option and then click the plus sign.
To the right of the “Python” animation track, double click the long rectangle under the time line. In the dialog that pops up, enter the following code:
from paraview.simple import FindSource
def start_cue(self): pass
def tick(self):
s = FindSource('DataSource1')
bounds = s.GetDataInformation().GetBounds()
center = [0.5*(bounds[0]+bounds[1]), 0.5*(bounds[2]+bounds[3]), 0.5*(bounds[4]+bounds[5])]
c = FindSource('Clip1')
c.ClipType.Origin = center
def end_cue(self): pass
This will set the origin of the Clip filter’s plane to the center of the bounding box of the data source. The tick function is called each time the timestep is updated, so the Clip filter origin will be updated to the center of the dataset each time the time step changes.
To have a Clip filter track a single cell in data set over time, first select the cell using ParaView’s selection tools. Then, apply an Extract Selection filter, and replace ‘DataSource1’ with the name of the Extract Selection filter in the Pipeline Browser in the Python script above.
Another thing you can do is track the distance between two selected points by setting the ends of the Ruler source to two selected points. First, select one point to which you want to anchor one end of the rule, and apply an Extract Selection filter. Do the same for a second point so that you have a second Extract Selection filter. Now add a Ruler source. Finally, set the Python script for the Python track in the Animation View to:
Hi Mr. Quammen,
do you think this would also be possible for a cylinder type of clip? I tried using the same code and just changed the line “c.ClipType.Origin = center” with “c.ClipType.Center = center”. What I have as a data are particles from SPH simulation for planetary gears. For the planets, I extracted just the particles belonging to specific planets using Threshold filter and then in the code changed “DataSource1” to “Threshold”. The clip actually starts following the planet gear but it is not 100% correct (it is lagging behind).
Kind regards,
Tarik Hadzovic