[vtkusers] Picking 2D Actors and tolerance/accuracy

Jesús Spí­nola jspinola at gmail.com
Fri Mar 31 06:24:02 EST 2006


Hello,

I have a scene with some 2d actors and I want to be able to move them with
mouse interaction.
The behaviour would be this:
1. When the left button is pressed I call the picker with the current mouse
point. Ten get the picked actor, if exists at least one under that point.
2. Once picked, move the actor when the mouse moves and the button remains
clicked

I have some questions:
-what's the best picker class to do this?
-how can I control the tolerance so I don't have to click in the exact pixel
if I want to pick a thin line, for example
-what's the better methods to retrieve the actors? ( GetPropAssembly()?
GetActors()? )

Some example code with the explanation would be apreciated.

Now I'm doing this when the left button is clicked but I'am not controlling
the tolerance of the picker, so I have to pick over an exact pixel of the
actor to get it
The picker ( m_linePicker ) is a vtkPropPicker

                             int x, y;
            x = *this*->getInteractor()->GetEventPosition()[0];
            y = *this*->getInteractor()->GetEventPosition()[1];

            m_linePicker->Pick( x, y, 0.0, *this*->getRenderer() );

            vtkAssemblyPath * Path;
            m_actorsAssembly = NULL;
            vtkProp *prop = NULL;
            *if* ( m_linePicker->GetPropAssembly() )
            {
                prop = m_linePicker->GetPath()->GetFirstNode()->GetViewProp();
                m_actorsAssembly = vtkPropAssembly::SafeDownCast( prop );

            }
            *else*
                prop = m_linePicker->GetViewProp();

            *if* ( m_actorsAssembly )
            {

                m_picked = *true*;
                vtkPropCollection *col = m_actorsAssembly->GetParts();
                col->InitTraversal();
                m_pickedAxisActor = vtkAxisActor2D::SafeDownCast(
col->GetNextProp() );
                m_pickedActorPosition = m_pickedAxisActor->GetPosition();
                m_initialPickedActorPositionX = m_pickedActorPosition[0];
                m_initialPickedActorPositionY = m_pickedActorPosition[1];
                m_initialPickX = x;
                m_initialPickY = y;

            }
            *else*
                *if* ( prop )
                {
                    m_picked = *true*;
                    m_pickedAxisActor = vtkAxisActor2D::SafeDownCast( prop );
                    *if*( m_pickedAxisActor )
                    {
                        m_pickedActorPosition =
m_pickedAxisActor->GetPosition();
                        m_initialPickedActorPositionX =
m_pickedActorPosition[0];
                        m_initialPickedActorPositionY =
m_pickedActorPosition[1];
                        m_initialPickX = x;
                        m_initialPickY = y;

                    }
                }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060331/1c55d692/attachment.htm>


More information about the vtkusers mailing list