[vtkusers] Which object picked ?

Obada Mahdi omahdi at gmx.de
Thu Aug 31 11:43:09 EDT 2006

Hi Kamran!

On Aug 29, 2006, at 7:51 PM, Kamran Iranpour wrote:
> I have a few objects in a window and use picker->GetActor() to get the
> actor of the object just picked inside the callback function. Now I
> need to know which of those objects I  have picked. One of those is a
> vtkCubeSource and wondered  how to "recast" this back to a
> vtkCubeSource so I could manipulate some of its properties (change
> size ...). Is there a way to know the type of the picked object from
> the given actor or recast somehow from the actor to the object ?

You could, of course, try to crawl up the pipeline by taking that  
actor, then looking at its mapper, then looking at the mapper's input  
and so on, until you reach the object in the filtering pipeline that  
you are looking for.
However, I would strongly suggest you not to do that -- doing so  
means to makes assumptions about the pipeline structure, and sooner  
or later things get too complicated.

Since your picked actor effectively represents the whole pipeline  
complex its mapper is bound to, it is probably a good idea to store  
(part of) the pipeline structure explicitly (like in a C struct, a  
class, instance variables...) in a way so that you can look them up  
later using the actor as a key.  How elaborate this lookup mechanism  
should be depends on your needs.  If you have a static scene with  
just a few actors, you could hold references to an actor and its  
corresponding vtkCubeSource in explicitly named variables, say  
cubeActor1/cubeSource1 and so on, and find the right one with a  
number of `if' statements; with lots of actors, using data structures  
like linked lists or even maps becomes more feasible.

HTH, just suggesting :-)


More information about the vtkusers mailing list