# Clipping a volume with a plane and vtkImplicitPlaneWidget2

**URL:** https://discourse.vtk.org/t/clipping-a-volume-with-a-plane-and-vtkimplicitplanewidget2/6168
**Category:** Support
**Created:** [July 12, 2021, 8:22am UTC](https://discourse.vtk.org/t/clipping-a-volume-with-a-plane-and-vtkimplicitplanewidget2/6168 "2021-07-12T08:22:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Edoardo\_Pasca](https://discourse.vtk.org/user_avatar/discourse.vtk.org/edoardo_pasca/32/742_2.png) [@Edoardo\_Pasca](https://discourse.vtk.org/u/Edoardo_Pasca)
#### Post date: [July 12, 2021, 8:22am UTC](https://discourse.vtk.org/t/clipping-a-volume-with-a-plane-and-vtkimplicitplanewidget2/6168/1 "2021-07-12T08:22:58Z")

</div>

Hi all,

I’m successfully clipping a volume render using the mapper’s (`vtkSmartVolumeMapper`) `AddClippingPlane`, passing a fully configured `vtkPlane`:

```auto
plane = vtk.vtkPlane()
plane.SetOrigin(0,125,0)
plane.SetNormal(0.,1.,0.)
volume_mapper.AddClippingPlane(plane)

```

What I would like to do now is to update the plane with the `vtkImplicitPlaneWidget2`. I suppose I have to add an observer to update the plane. I’ve got 2 questions:

1. does using the `AddClippingPlane(plane)` keep a reference to the `plane` in the `volume_mapper` so that if the plane changes also the `volume_mapper` is aware of it, or do I have to remove the plane and add the new one?
2. What event should I observe? I did not really manage to understand how to observe the widget’s [events](https://vtk.org/doc/nightly/html/classvtkImplicitPlaneWidget2.html#details) unless I observe (basically) all mouse events and then translate the event to widget events.

Thanks

Edo

---

<div class="post-metadata">

### Author: ![Edoardo\_Pasca](https://discourse.vtk.org/user_avatar/discourse.vtk.org/edoardo_pasca/32/742_2.png) [@Edoardo\_Pasca](https://discourse.vtk.org/u/Edoardo_Pasca)
#### Post date: [July 14, 2021, 7:49pm UTC](https://discourse.vtk.org/t/clipping-a-volume-with-a-plane-and-vtkimplicitplanewidget2/6168/2 "2021-07-14T19:49:09Z")

</div>

Hi

I made some progress here.

My plan is to update the clipping plane once the user has finished to position it with the `vtkImplicitPlaneWidget2` by releasing the left mouse button. This works somehow, but after I reposition the plane with the widget the clipping plane is not updated. To trigger an update I need to click the left button without interacting with the widget.

Is there any other event I should observe?

Below a little pseudo Python code where `viewer` is an object that contains the interactor, the renderer, the render window, a `vtkVolume` and a `vtkVolumeMapper`.

```auto
def update_clipping_plane(viewer, planewidget, interactor, event):
    event_translator = planewidget.GetEventTranslator()
    pevent = event_translator.GetTranslation(event)
    print ("pevent", pevent)
    if pevent =='EndSelect':
        rep = planewidget.GetRepresentation()
        plane = vtk.vtkPlane()
        rep.GetPlane(plane)
        print (plane)
    
        volume_mapper = viewer.GetVolumeMapper()
        volume = viewer.GetVolume()
        volume_mapper.RemoveAllClippingPlanes()
        volume_mapper.AddClippingPlane(plane)
        volume.Modified()

planew = vtk.vtkImplicitPlaneWidget2()
            
rep = vtk.vtkImplicitPlaneRepresentation()
planewidget.SetInteractor(viewer.GetInteractor())
planewidget.SetRepresentation(rep)

plane = vtk.vtkPlane()
rep.GetPlane(plane)
rep.UpdatePlacement()
rep.PlaceWidget(viewer.GetVolume().GetBounds())
viewer.GetVolume().GetMapper().AddClippingPlane(plane)
viewer.GetVolume().Modified()
planewidget.On()

viewer.interactor.AddObserver('LeftButtonReleaseEvent', functools.partial(update_clipping_plane, viewer, planewidget), 1.0)

```

Thanks

Edo
