[vtkusers] Interactor on vtkWidget

Dean Inglis dean.inglis at camris.ca
Wed Sep 22 10:01:57 EDT 2010


vtkDistanceWidget has an internal representation: the visible part which
is a subclass of vtkProp.  However, its not directly pickable, but it
has an internal actor which is. In this case, its a vtkAxisActor2D which
is a subclass of vtkActor2D.
If you want to pick this actor or several instances of them, you could
instantiate and maintain your own vtkPropPicker and add a callback to
listen for pick events. You can add specific actors for it to pick:
picker->PickFromListOn();
picker->AddPickList(
  vtkDistanceRepresentation2D::SafeDownCast(
     widget->GetRepresentation())->GetAxis() );
picker->AddObserver( vtkCommand::PickEvent, mycallback );

where mycallback is a subclass of vtkCommand in which
you could traverse the list of props in the picker, see which
one was picked by mouse click then remove it and its
associated parent widget from your renderwindow.

Or, you could add an observer to the renderwindow's interactor
and listen for keypress events.  In that observer/callback, you could
retrieve the mouse coordinates, and fire a pick into the renderer, and
then see which prop was picked and delete it.

Dean

On 2010-09-22 09:44:08 +0530, rakesh patil wrote:
> Well,
>
> This is what I have done. I subclassed contourWidget, and added one 
> memder,
> ID for it. And in the mouse click event, i added shift click to pick the
> object. i.e. i maintain a separate list to store ids of selected widgets.
> And on shift click, id of that object is pushed on to this list. In this
> way, multiple widgets can also be picked.
>
> Then when i delete, i traverse the list of picked ids, and delete those
> widgets.
>
> Hope this may help.
>
> Good luck
>
> Thanks
>
> Regards
>
> Rakesh Patil
>


Thanks Rakesh, thanks for commenting this out.

I was thinking on using a similar solution to my problem, but I just
can't find the way to trigger the Mouse Click event on a
vtkDistanceWidget or vtkAngleWidget.

I tried adding observers with myDistanceWidget->AddObserver(...) but the
event wasn't fired. I also used
myDistanceWidget->GetInteractos()->AddObserver(...), in this case the
event is fired, but not for my widget, but for the whole interactor.

Could you show me the code to handle the mouse click event on the
widget?.





More information about the vtkusers mailing list