我是VTK
的新用户,我需要在其中添加renderWindowInteractor
QVTKWidget
的QTCreator
。我有这个:
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderWindow->Render();
renderWindowInteractor->Initialize();
但是如何将
RenderWindowInteractor
放在QVTKWidget
中呢?我尝试了这个但是不工作。
this->qvtkWidget->GetRenderWindow()->AddRenderer(renderer);
对不起,我的英语,我来自哥伦比亚。
最佳答案
QVTKWidget
具有SetRenderWindow
方法,可让您在QVTK引擎中设置渲染窗口。如果您已经为RenderWindowInteractor设置了相同的renderWindow,它应该可以工作。
这是我与自定义InteractionStyle一起使用的代码示例
QVTKWidget *engine = new QVTKWidget ();
// Setup window
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
// Setup renderer
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderWindow->AddRenderer(renderer);
engine->SetRenderWindow(renderWindow); // make the link between VTK and QT
// create stuff for user interaction
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
/*
vtkSmartPointer<vtkUserInteractionStyle> inter = vtkUserInteractionStyle::New ();
inter->SetDefaultRenderer(renderer);
renderWindowInteractor->SetInteractorStyle( inter );
*/
// make the link between the renderwindow and the interactor
renderWindowInteractor->SetRenderWindow ( renderWindow );
engine->show();
renderWindow->Render ();
renderWindowInteractor->Initialize();