QVTKOpenGLWidget 的使用

ui->qvtkWidget->GetRenderWindow() == nullptr

VTK 8.1 使用 QVTKOpenGLWidget

 注意:QVTKWidget有默认的RenderWindow,而QVTKOpenGLWidget是没有的(是空指针)

 RenderWindow 使用的是 vtkGenericOpenGLRenderWindow

VTK 8.1 使用 QVTKOpenGLWidget ,不再有 QVTKWidget;

在QT 中的init

#include "mainwindow.h"
#include "ui_mainwindow.h"
 
 #include 
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //*****************************************
    ///
    QVTKOpenGLWidget *qvtk=this->ui->qvtkWidget;

    // Setup window
    vtkSmartPointer renderWindow =
        vtkSmartPointer::New();
    // setup sphere
    vtkSmartPointer sphereSource =
            vtkSmartPointer::New();
        sphereSource->SetCenter(0.0, 0.0, 0.0);
        sphereSource->SetRadius(5.0);
        sphereSource->Update();
    // setup map and actor
    vtkSmartPointer mapper =
        vtkSmartPointer::New();
    mapper->SetInputConnection(sphereSource->GetOutputPort());
 
    vtkSmartPointer actor =
        vtkSmartPointer::New();
    actor->SetMapper(mapper);
 
    vtkSmartPointer colors =
        vtkSmartPointer::New();
 
    // Setup renderer
    vtkSmartPointer renderer =
        vtkSmartPointer::New();
    renderer->SetBackground(colors->GetColor3d("Slate_grey").GetData());
    renderWindow->AddRenderer(renderer);
    renderer->AddActor(actor);
    qvtk->SetRenderWindow(renderWindow);
    // create stuff for user interaction
    vtkSmartPointer renderWindowInteractor =
        vtkSmartPointer::New();
    /*
      vtkSmartPointer 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;
}

你可能感兴趣的:(VTK,gnu,蓝桥杯,c++)