VTK 鼠标交互只操作一个Actor

窗口有多个Actor,只操作其中一个Actor:

class MouseInteractorStyle5 : public vtkInteractorStyleTrackballActor
{
public:
    static MouseInteractorStyle5* New();
    vtkTypeMacro(MouseInteractorStyle5, vtkInteractorStyleTrackballActor);
    
    virtual void OnLeftButtonDown()
    {
        // Forward events
        vtkInteractorStyleTrackballActor::OnLeftButtonDown();
        
        if(this->InteractionProp == this-> ActorA)
        {
            std::cout << "Picked ActorA." << std::endl;
        }
        else if(this->InteractionProp == this-> ActorB)
        {
            std::cout << "Picked ActorB." << std::endl;
        }
    }
    
    vtkActor* ActorA;
    vtkActor* ActorB;
};

vtkStandardNewMacro(MouseInteractorStyle5);




//主函数里面的重要代码:
 vtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();
 
    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow(renderWindow);
    
vtkSmartPointer<MouseInteractorStyle5> style = vtkSmartPointer <MouseInteractorStyle5>::New();
    style->SetDefaultRenderer(renderer);
    style-> ActorA = Actor1;
    style-> ActorB = Actor2;
    
    renderWindowInteractor->SetInteractorStyle(style);
    
    renderer->AddActor(Actor1);
    renderer->AddActor(Actor2);

猜你喜欢

转载自blog.csdn.net/qq_35007834/article/details/85245037