此代码是选择器actor。一旦选择了一个actor,它就会打印相应选定actor的高位。问题是在交互器中禁用旋转和拖动,我想要包含它。
// 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();
}
输出例如是Z中的位置:
演员高:1.800