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

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.

3 Likes

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.

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
1 Like

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

Hi @Tarik_Hadzovic could you create a new topic with your question and post the full script there and we can debug in that topic? Thanks.