[vtkusers] Picking with python

Harris Scott R CIV AFRL/SNJM Scott.Harris at wpafb.af.mil
Wed Mar 13 15:06:29 EST 2002


My app uses vtk3.1, python 1.52, and wxPython and I'm having a bit of trouble with picking.

Basically, I have a class hierarchy where every object has an associated vtkActor. When I pick an actor
I pop open an editor box for my enclosing class. 

When I pick, I search my objects trying to find what object corresponds to the actor I clicked. 
Here's how I do it:

for i in myobjects:
	if pickedactor==i.thisactor:
		object_i_clicked_on=i

The problem is that this only works some of the time. I can go into the code and print all the actors and
compare this with printing pickedactor and often nothing matches. Anyhow, I get around this in an ugly way by
doing this:

pickedactor.GetProperty().SetSomePropertyToAFunnyValue()

for i in myobjects:
	if i.actor.GetProperty().GetFunnyValue()==FunnyValueAbove:
		object_i_clicked_on=i

pickedactor.GetProperty().RestoreThisToWhatItWas()

This works, and I do it by setting the color of the actor I clicked to some unlikely value. This works
for me, but I'm sure the unlikely value I choose will be very popular with ever other user. I could
use some other property that I don't let users change, like some shading style, but this is approach is
still a inelegant.

What I'd really like to do is just add a member to vtkActor so I can have a reference back to the enclosing
object in my code. However, I can't do this naively since vtkActor is a wrapped C++ class.  Can I just subclass
vtkActor in python so I can then add my own customizations?

Does anyone have any ideas?

Thanks,
-Scott

Scott Harris, Ph.D.
AFRL/SNJM
3109 P Street Bldg 622
WPAFB OH 45433-7700
937/255-9614x285




More information about the vtkusers mailing list