[vtkusers] Interactor mouse events without disable rotation vtkActors

vacingforo vacingforo at gmail.com
Tue Apr 17 19:33:35 EDT 2018


This code is a selector actor. Once one actor is selected it prints the high
of the respective selected actor. the problem is that the rotation and
dragging is disable in the interactor and I want to include it.


*// Handle mouse events
class MouseInteractorStyle5 : public vtkInteractorStyleTrackballActor
{
    public:
    static MouseInteractorStyle5* New();
    vtkTypeMacro(MouseInteractorStyle5, vtkInteractorStyleTrackballActor);

    virtual void OnLeftButtonDown()
    {
        // Forward events
        vtkInteractorStyleTrackballActor::OnLeftButtonDown();

        for (auto it = actors.begin(); it != actors.end(); ++it)
        {
            if(this->InteractionProp == (*it))
            {
                std::cout << "Actor high: " <<
(*it)->GetMapper()->GetInput()->GetPoint(0)[2] << std::endl;
            }
        }

    }
    std::vector<vtkSmartPointer<vtkActor>> actors;
};

vtkStandardNewMacro(MouseInteractorStyle5);

void actorsMouseInteractor(const std::vector<vtkSmartPointer<vtkActor>> &
actors)
{
    // A renderer and render window
    vtkSmartPointer<vtkRenderer> renderer =
      vtkSmartPointer<vtkRenderer>::New();
    vtkSmartPointer<vtkRenderWindow> renderWindow =
      vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer(renderer);


    // An interactor
    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow(renderWindow);

    // Set the custom stype to use for interaction.
    vtkSmartPointer<MouseInteractorStyle5> style =
        vtkSmartPointer<MouseInteractorStyle5>::New();
    style->SetDefaultRenderer(renderer);
    style->actors = actors;

    renderWindowInteractor->SetInteractorStyle(style);

    renderer->AddActor(getPlatformActor());
    for (auto it = actors.begin(); it != actors.end(); ++it)
    {
        renderer->AddActor(*it);
    }
    renderer->SetBackground(.1, .2, .4);
    renderWindow->Render();
    renderWindow->SetSize(renderWindow->GetScreenSize());
    renderWindowInteractor->Start();
}*

the output is for example the position in Z:

Actor high: 1.800




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list