[vtkusers] bug in clipping planes + fix

Charl P. Botha cpbotha at gmail.com
Wed Feb 28 11:27:24 EST 2007


Dear list,

One of our PhD candidates (Stef Busking) has discovered and fixed a
bug in the clipping plane handling of VTK.

The attached Python file is a small example with which the bug can be
reproduced: it starts with a cone inside a sphere, both clipped by the
same plane.  Rotating / moving the cone works fine, but as soon as
it's resized in a single direction (i.e. non-uniformly), the clipping
is obviously incorrect.  This has to do with how the clipping plane is
transformed according to the actor transform.

Stef has devised a more elegant way of correcting the transformation
of the clipping plane (IMHO) by modifying the gl modelview matrix with
the inverse actor transform (and popping it off later).  The fix is in
the attached unified diff.  I'd like to check this patch in in a few
days, if there are no comments.

Thanks,
Charl



-- 
dr. charl p. botha - http://visualisation.tudelft.nl/
work: c.p.botha%tudelft.nl other: cpbotha%cpbotha.net
-------------- next part --------------
#!/usr/bin/env python
#
# This example is based on the Cone6 example from the tutorial. The only
# difference is an added clipping plane, and a second (non-movable) actor
# for reference, sharing the same clipping plane.
# Note that when moving, rotating and uniformly scaling the cone actor,
# both actors are clipped by the same plane. However, when the cone actor
# is scaled non-uniformly and then rotated, the clipping planes are
# different.

import vtk

cone = vtk.vtkConeSource()
cone.SetHeight(3.0)
cone.SetRadius(1.0)
cone.SetResolution(10)

coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())

# Create a simple clipping plane
clipplane = vtk.vtkPlane()
clipplane.SetNormal(0.0, 1.0, 0.0)
clipplane.SetOrigin(0.0, 0.0, 0.0)
coneMapper.AddClippingPlane(clipplane)

coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)

# Add a second actor for reference, using the same clipping plane
sphere = vtk.vtkSphereSource()
sphere.SetRadius(2.0)
sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(sphere.GetOutputPort())
sphereMapper.AddClippingPlane(clipplane)
sphereActor = vtk.vtkActor()
sphereActor.SetMapper(sphereMapper)

ren1 = vtk.vtkRenderer()
ren1.AddActor(coneActor)
ren1.AddActor(sphereActor)
ren1.SetBackground(0.1, 0.2, 0.4)

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.SetSize(500, 500)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

style = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(style)

boxWidget = vtk.vtkBoxWidget()
boxWidget.SetInteractor(iren)
boxWidget.SetPlaceFactor(1.25)

boxWidget.SetProp3D(coneActor)
boxWidget.PlaceWidget()

def myCallback(widget, event_string):
    t = vtk.vtkTransform()
    boxWidget.GetTransform(t)
    boxWidget.GetProp3D().SetUserTransform(t)
        
boxWidget.AddObserver("InteractionEvent", myCallback)

boxWidget.On()

# Start the event loop.
iren.Initialize()
iren.Start()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ClipPlanesFix.diff
Type: application/octet-stream
Size: 1751 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070228/2027176d/attachment.obj>


More information about the vtkusers mailing list