Make a Clip filter with Plane Clip Type follow a data set


(Cory Quammen (Kitware)) #1

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.


(Cory Quammen (Kitware)) #2

With minor changes, this same trick can be used to make a Slice filter named “Slice1” in the Pipeline Browser follow the center of a dataset:

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('Slice1')
  c.SliceType.Origin = center

def end_cue(self): pass

Note that the main difference is the line

c.SliceType.Origin = center

which is different from

c.ClipType.Origin = center

in the script in the original post. Otherwise the recipe is the same.


(Cory Quammen (Kitware)) #3

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:

from paraview.simple import FindSource

def start_cue(self): pass

def tick(self):
  p1 = FindSource('ExtractSelection1')
  p2 = FindSource('ExtractSelection2')
  p1bounds = p1.GetDataInformation().GetBounds()
  p2bounds = p2.GetDataInformation().GetBounds()
  ruler = FindSource('Ruler1')
  ruler.Point1 = (p1bounds[0], p1bounds[2], p1bounds[4])
  ruler.Point2 = (p2bounds[0], p2bounds[2], p2bounds[4])

def end_cue(self): pass