# Slice/Clip with a surface

**URL:** https://discourse.paraview.org/t/slice-clip-with-a-surface/9436
**Category:** Tips and Tricks
**Tags:** python
**Created:** [April 15, 2022, 9:33am UTC](https://discourse.paraview.org/t/slice-clip-with-a-surface/9436 "2022-04-15T09:33:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [April 15, 2022, 9:33am UTC](https://discourse.paraview.org/t/slice-clip-with-a-surface/9436/1 "2022-04-15T09:33:03Z")

</div>

It is possible to slice and clip a volume with a surface by using a Python Programmable Filter.  
This relies on the [vtkImplicitPolyDataDistance](https://vtk.org/doc/nightly/html/classvtkImplicitPolyDataDistance.html#details), 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

```python
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

```python
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

 ![image](https://discourse.paraview.org/uploads/default/original/2X/9/9984a112d06959d00778517268daa42953417853.jpeg)

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

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [January 20, 2025, 5:00pm UTC](https://discourse.paraview.org/t/slice-clip-with-a-surface/9436/2 "2025-01-20T17:00:35Z")

</div>

A post was split to a new topic: [Slice/clip with surface not working](https://discourse.paraview.org/t/slice-clip-with-surface-not-working/16004)

---

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [June 5, 2025, 8:52pm UTC](https://discourse.paraview.org/t/slice-clip-with-a-surface/9436/3 "2025-06-05T20:52:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [June 5, 2025, 11:18pm UTC](https://discourse.paraview.org/t/slice-clip-with-a-surface/9436/4 "2025-06-05T23:18:07Z")

</div>

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”
