我是VTK的新用户,我需要在其中添加renderWindowInteractorQVTKWidgetQTCreator。我有这个:

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();

07-25 20:29