Clipping a volume with a plane and vtkImplicitPlaneWidget2

Hi all,

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

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 unless I observe (basically) all mouse events and then translate the event to widget events.

Thanks

Edo

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.

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