[vtkusers] Interacting with Actor2D?

David Gobbi david.gobbi at gmail.com
Tue Oct 13 18:57:05 EDT 2009


On Tue, Oct 13, 2009 at 4:00 PM, Quy Pham Sy <phamsyquybk at gmail.com> wrote:

> 2009/10/14 David Doria <daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>
> >:
> > On Tue, Oct 13, 2009 at 5:06 PM, David Gobbi <david.gobbi at gmail.com>
> wrote:
> >>
> >> Hi David,
> >> That example is very misleading.  The vtkCamera and the most
> >> vtkInteractorStyles do nothing with 2D actors.  The vtkActor2D uses the
> >> "display" coordinate system, but for displaying data, you almost always
> want
> >> to use the "world" coordinate system that vtkActor and vtkCamera use.
> >> So: even with 2D data, you should use vtkActor, not vtkActor2D.  That
> way
> >> the vtkCamera can control the view, just set
> camera->ParallelProjectionOn()
> >> so that it will display a "flat" projection rather than a perspective
> >> projection.  Interactor styles like the vtkInteractorStyleRubberBand2D
> are
> >> specifically designed for use with 2D data.  But you must use vtkActor
> for
> >> your data, don't use vtkActor2D.
> >>     David
> >
> > Haha - the "misleading-ness" is what I am trying to sort through and
> remove
> > with these examples :)
> >
> > vtkActor2D has to be around for something right? What would one use it
> for?
> >
> > If you simply set the camera to parallel projection, you can still rotate
> > "out of plane" which makes the whole thing not really seem like 2D any
> more.
> > That's what I thought this Actor2D was going to - provide a more 2D
> "feel".
> > Is there nothing that does this (excluding simply not using the rotate
> > buttons in the 3d view)?
> >
> > Thanks,
> >
> > David
> >
>
> hi,
>
> To prevent rotating your 2D object "out of plane" u can derive
> vtkInteractorStyles and
> re-implement mouse or key event handle function for your purpose,
>
> for  example:
>
> -----------------------
> void vtkYourInteractorStyle::OnLeftButtonDown()
> {
>        int x = this->Interactor->GetEventPosition()[0];
>        int y = this->Interactor->GetEventPosition()[1];
>
>        this->FindPokedRenderer(x, y);
>        this->FindPickedActor(x, y);
>        if (this->CurrentRenderer == NULL || this->InteractionProp == NULL)
>        {
>                return;
>        }
>
>        this->GrabFocus(this->EventCallbackCommand);
>
>        if (this->Interactor->GetShiftKey())
>        {
>                this->StartPan();
>        }
>        else
>        {
>                //this->StartRotate();
>                /* your custom interaction such as spin, scale, ..etc*/
>        }
> }
> --------------------------------
>
> it actually interact with vtkProp3D ( the one you have from
>        this->FindPickedActor(x, y)  )
>
> I never try, but it is probably possible to create "real" interactor
> style which interact with actor2D.
> And you also notice that when you interact with 2D actors, your actor
> actually lie on "view plane"
> so it will not be affected by camera transform (in camera based-
> interactor style).
> your interactor style should be type of actor-based interactor.
>
> Hope it help.
>
>
Yes, I also use this trick of overriding the left mouse button so that
instead of "rotating", it does something more useful for 2D.

The Actor2D is mainly used for adding a 2D overlay.  For example, you can
use it to add some text that will always stay at the top of the screen (or
bottom, or wherever you want).  I sometimes use Actor2D to add a red border
around my "active" renderer, if I have multiple renderers in my application.
 Also, I used to use Actor2D to display images, but now I use vtkImageActor
instead.

  David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091013/713679d0/attachment.htm>


More information about the vtkusers mailing list