QVTKOpenGLWidget 的使用
作者:互联网
ui->qvtkWidget->GetRenderWindow() == nullptr
注意:QVTKWidget有默认的RenderWindow,而QVTKOpenGLWidget是没有的(是空指针)
VTK 8.1 使用 QVTKOpenGLWidget ,不再有 QVTKWidget;
在QT 中的init
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//*****************************************
///
QVTKOpenGLWidget *qvtk=this->ui->qvtkWidget;
// Setup window
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
// setup sphere
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(0.0, 0.0, 0.0);
sphereSource->SetRadius(5.0);
sphereSource->Update();
// setup map and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkNamedColors> colors =
vtkSmartPointer<vtkNamedColors>::New();
// Setup renderer
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->SetBackground(colors->GetColor3d("Slate_grey").GetData());
renderWindow->AddRenderer(renderer);
renderer->AddActor(actor);
qvtk->SetRenderWindow(renderWindow);
// 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 );
qvtk->show();
renderWindow->Render ();
renderWindowInteractor->Initialize();
}
MainWindow::~MainWindow()
{
delete ui;
}
标签:sphereSource,QVTKOpenGLWidget,vtkSmartPointer,ui,renderer,使用,renderWindow,New 来源: https://blog.csdn.net/q610098308/article/details/122492663