Slice/Clip with a surface

It is possible to slice and clip a volume with a surface by using a Phyton Programmable Filter.
This relies on the vtkImplicitPolyDataDistance, so the result is an approximation, not an actual boolean operation.

Steps for clip:

  • Open a volume, apply
  • Open a surface, apply
  • In the pipeline browser, click on the volume, then press Ctrl, then click on the surface
  • Add a Programmable Filter
  • Set the output type to vtkUnstructuredGrid
  • Set the script to
import paraview.modules.vtkPVVTKExtensionsFiltersGeneral as ext

inpMain = self.GetInputDataObject( 0, 0 )
inp = self.GetInputDataObject( 0, 1 )
out = self.GetOutput()

clipper = ext.vtkPVMetaClipDataSet()
clipper.SetInputDataObject(inpMain)
clipper.SetInsideOut(True)
function = vtk.vtkImplicitPolyDataDistance()
function.SetInput(inp)
clipper.SetDataSetClipFunction(function)
clipper.Update()

outData = clipper.GetOutputDataObject(0)
out.DeepCopy(outData) 
  • Press Apply

Steps for slice:

  • Open a volume, apply
  • Open a surface, apply
  • In the pipeline browser, click on the volume, then press Ctrl, then click on the surface
  • Add a Programmable Filter
  • Set the output type to vtkPolyData
  • Set the script to
import paraview.modules.vtkPVVTKExtensionsFiltersGeneral as ext

inpMain = self.GetInputDataObject( 0, 0 )
inp = self.GetInputDataObject( 0, 1 )
out = self.GetOutput()

slicer = ext.vtkPVMetaSliceDataSet()
slicer.SetInputDataObject(inpMain)

function = vtk.vtkImplicitPolyDataDistance()
function.SetInput(inp)
slicer.SetDataSetCutFunction(function)
slicer.Update()

outData = slicer.GetOutputDataObject(0)
out.DeepCopy(outData) 

  • Press Apply

There is an issue to add that in ParaView proper: https://gitlab.kitware.com/paraview/paraview/-/issues/18138

3 Likes

A post was split to a new topic: Slice/clip with surface not working

How difficult would this be to parallelize for large volume data?

If your volume is partitioned across ranks, you should be able to use these scripts as written. You just need to make sure copy of the entire surface is duplicated on each rank, which can be done with the Append Reduce filter with the Reduction Mode set to “Reduce all data to all processors”

1 Like