[vtkusers] How to pick an AxesActor?

Lee Gross lmg at amoebatech.com
Wed Jul 29 14:42:49 EDT 2009


I haven't seen any responses to this post so I'm including some code which
demonstrates the problem.  I'm looking for an example (preferably in Python)
of how to pick a vtkAxesActor.  I need to be able to distinguish between
picks of the X, Y, and Z axes.  I am currently able to pick other OpenGL
actors.  But trying to pick any of the axes is the same as picking nothing.
 I have tried setting PickableOn but it didn't help.  Is there some setting
to use with vtkOrientationMarkerWidget?

Thank you.

Lee Gross
Amoeba Technologies, Inc.

========================

#!/usr/bin/env python

import vtk

def handle_pick(obj, event):
    # Print the picked actor type, if any
    picker = vtk.vtkPropPicker()
    mousePos = obj.GetEventPosition()
    picker.PickProp(mousePos[0], mousePos[1], ren)
    pickedActor = picker.GetActor()
    print "picked actor type=", type(pickedActor)


# Create the usual rendering stuff
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.AddObserver("LeftButtonPressEvent", handle_pick)

istyle = vtk.vtkInteractorStyleSwitch()
iren.SetInteractorStyle(istyle)
istyle.SetCurrentStyleToTrackballCamera()

# Create reference axes
axes = vtk.vtkAxesActor()
axes.SetShaftTypeToCylinder()
axes.PickableOn()

marker = vtk.vtkOrientationMarkerWidget()
marker.SetOrientationMarker(axes)
marker.SetViewport(0, 0, 0.3, 0.3)
marker.SetInteractor(iren)
marker.EnabledOn()
marker.InteractiveOff()
marker.KeyPressActivationOff()

# Create a box
box = vtk.vtkCubeSource()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(box.GetOutput())
boxActor = vtk.vtkActor()
boxActor.SetMapper(mapper)

# Add the actor to the renderer, set the background and size
ren.AddActor(boxActor)
ren.SetBackground(0.1, 0.2, 0.2)
renWin.SetSize(500, 500)
ren.ResetCamera()
ren.ResetCameraClippingRange()

iren.Initialize()
renWin.Render()
iren.Start()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090729/c1d98eae/attachment.htm>


More information about the vtkusers mailing list