[vtkusers] Interaction using vtkRenderWindowInteractor

stoptv stoptv at gmail.com
Mon Apr 17 15:28:57 EDT 2006


On 4/17/06, Marc Cotran <marc at cotran.ca> wrote:
>
> Here is some sample code that might assist you:
>
> // First create the callback comand
> class LeftClickCallback : public vtkCommand
> {
> public:
>     static LeftClickCallback *New()
>         { return new LeftClickCallback ; }
>
>     virtual void Execute(
>         vtkObject *caller,
>         unsigned long /* eventId */,
>         void * /*callData*/)
>     {
>           // left click was pressed, do what we want to do here
>           // in your case, you probably want to find out which actor
>           // was clicked (if any) and then set the actor's color (somehow)
>     }
> };
>
> // Then use the callback by attaching a new instance to the interactor
> style
> LeftClickCallback *callback = LeftClickCallback ::New();
> myInteractorStyle->AddObserver(vtkCommand::LeftButtonPressEvent,
> callback, 0);


Thanks Marc, this was most helpful!! Clicking left mouse button now runs my
callback :-)

I'm still struggling with finding out which actor I had just clicked, which
was the original intention!

Inside the LeftClickCallback::Execute

vtkObject* caller

is set to the vtkInteractorStyle I am observing. I then create a
vtkInteractorStyle* style = vktInteractorStyle::SafeDownCast( caller );

but am still having trouble finding the Actor I had just clicked on, because

style->GetInteractor()->GetPicker()

is a vtkAbstractPicker and does not know anything about it's derived's

vtkPicker::GetActors()

hm... I've tried reinterpret_casting vtkAbstractPicker to vtkPicker but it
(predictably) segfaults :-/

any insights?

Thank you for your patience and help!

--
stoptv at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060417/0a3f467e/attachment.htm>


More information about the vtkusers mailing list