1

我是新用户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);

对不起我的英语,我来自哥伦比亚。

4

2 回答 2

1

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();
于 2014-08-15T03:02:26.127 回答
0

发现不需要使用,先绑定widget就可以解决这个问题,代码测试一下就可以了。

/////////////////////////////////////////////////////
//CODE    author:Bing_Lee 2018-9-13
/////////////////////////////////////////////////////
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<QVTKWidget> widget = vtkSmartPointer<QVTKWidget>::NEW();
widget->SetRenderWindow(renderWindow);

/*//comment
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();

renderWindowInteractor->SetRenderWindow(renderWindow);
*/

renderer->AddActor(actor);

/*//comment
renderWindow->Render();
renderWindowInteractor->Initialize();
*/
于 2018-09-13T14:36:59.887 回答