[vtkusers] how to select a 3D object using mouse left button click

HuaweiTu tuhuawei09 at gmail.com
Tue Jan 1 07:59:05 EST 2013


Hi all,

Happy New Year!

I would like to ask about how to select  a 3D object using mouse left button
click. Supposing two 3D objects are shown, all of them are objects of
vtkCylinderSource, named arm and forearm respectively. 

  vtkCylinderSource arm = new vtkCylinderSource();
            arm.SetRadius(8);
            arm.SetHeight(20);
            arm.SetResolution(20);

            vtkPolyDataMapper armMapper = vtkPolyDataMapper.New();
            armMapper.SetInputConnection(arm.GetOutputPort());

            armTransform = vtkTransform.New();

            armActor = vtkActor.New();
            armActor.SetUserTransform(armTransform);
            armActor.SetMapper(armMapper);
            armActor.GetProperty().SetColor(0.7, 0.6, 0.3);

            vtkCylinderSource forearm = vtkCylinderSource.New();
            forearm.SetRadius(6);
            forearm.SetHeight(15);
            forearm.SetResolution(20);
            forearm.SetCenter(arm.GetCenter()[0], arm.GetCenter()[1] +
forearm.GetHeight(), arm.GetCenter()[2]);

            vtkPolyDataMapper forearmMapper = vtkPolyDataMapper.New();
            forearmMapper.SetInputConnection(forearm.GetOutputPort());

            forearmTransform = vtkTransform.New();
            forearmTransform.SetInput(armTransform);

             forearmActor = vtkActor.New();
            forearmActor.SetUserTransform(forearmTransform);
            forearmActor.SetMapper(forearmMapper);
            forearmActor.GetProperty().SetColor(0.1, 0.2, 0.9);

            renderer =
_renderControl.RenderWindow.GetRenderers().GetFirstRenderer();

            renderer.AddActor(armActor);
            renderer.AddActor(forearmActor);

            _renderControl.RenderWindow.GetInteractor().Render();

What I want to do is to select one of these two objects by performing a
mouse left button event when the mouse cursor is on the object. It would be
nice if I can know how to get the corresponding actor of the object. Any
suggestions are appreciated.

void OnLeftButtonDown() 
{
  //here, we can get the x, y coordinates of left button clicking.
}




--
View this message in context: http://vtk.1045678.n5.nabble.com/how-to-select-a-3D-object-using-mouse-left-button-click-tp5717759.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list