[vtkusers] BoxWidget problem - can't interact with multiple box widgets in the same window
Greg Ushomirsky
gregus at gmail.com
Tue Apr 22 11:44:23 EDT 2008
Hi,
I'm having a weird problem using multiple 3D box widgets in the same
window. I'm probably not setting something correctly, but cannot
off-hand figure out what. I have several actors in the same render
window, each of which has a vtkBoxWidget associated with it. I would
like to be able to manipulate (rotate, translate, scale) each actor
separately. I assume that, if I point the mouse at the desired actor
and press "i", I should activate the widget that is associated with
the actor I am pointing to. However, this is not how it works --
regardless of where I point in the window, the widget I created first
gets activated, and never the second one. The only way to activate
the second widget is to call its On() method.
Below is Python code that illustrates the problem (the code is kind of
repetitive, but it makes the point). It creates a sphere and a cube,
each of which has a BoxWidget associated with it. However no matter
here I point the mouse when I press "i", only the sphere's box widget
gets activated. This is contrary to what the documentation of
BoxWidget claims. Am I doing something incorrectly??
Thanks for your help
Greg
==== python code follows ====
import vtk
class TransformData:
def __init__(self,data):
self.data=data
def update_transform(self,obj,event):
t=vtk.vtkTransform()
obj.GetTransform(t);
self.data.SetTransform(t)
if __name__ == "__main__":
sphere = vtk.vtkSphereSource()
sphere_xform=vtk.vtkTransformPolyDataFilter()
sphere_xform.SetTransform(vtk.vtkIdentityTransform())
sphere_xform.SetInputConnection(sphere.GetOutputPort())
sphere_mapper = vtk.vtkPolyDataMapper()
sphere_mapper.SetInputConnection(sphere_xform.GetOutputPort())
sphere_actor = vtk.vtkActor()
sphere_actor.SetMapper(sphere_mapper)
sphere_xform_callback = TransformData(sphere_xform)
cube = vtk.vtkCubeSource()
cube_xform=vtk.vtkTransformPolyDataFilter()
cube_xform.SetInput(cube.GetOutput())
tr = vtk.vtkTransform()
tr.Translate(2,0,0)
cube_xform.SetTransform(tr)
cube_mapper = vtk.vtkPolyDataMapper()
cube_mapper.SetInputConnection(cube_xform.GetOutputPort())
cube_actor = vtk.vtkActor()
cube_actor.SetMapper(cube_mapper)
cube_xform_callback = TransformData(cube_xform)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
renWin.SetSize(768,768)
ren.AddActor(sphere_actor)
ren.AddActor(cube_actor)
sphere_box_widget = vtk.vtkBoxWidget()
sphere_box_widget.SetInteractor(iren)
sphere_box_widget.SetPlaceFactor(1.25)
sphere_box_widget.SetProp3D(sphere_actor)
sphere_box_widget.PlaceWidget()
sphere_box_widget.AddObserver("InteractionEvent",sphere_xform_callback.update_transform)
# sphere_box_widget.On()
cube_box_widget = vtk.vtkBoxWidget()
cube_box_widget.SetInteractor(iren)
cube_box_widget.SetPlaceFactor(1.25)
cube_box_widget.SetProp3D(cube_actor)
cube_box_widget.PlaceWidget()
cube_box_widget.AddObserver("InteractionEvent",cube_xform_callback.update_transform)
# cube_box_widget.On()
iren.Initialize()
renWin.Render()
iren.Start()
More information about the vtkusers
mailing list