2、VDK 使用QVTKOpenGLNativeWidget嵌入到QT窗体中

MainWindow.h

cpp 复制代码
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QVTKOpenGLNativeWidget.h>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    QVTKOpenGLNativeWidget *m_vtkWd = nullptr;

    void InitVDK();
};
#endif // MAINWINDOW_H

MainWindow.cpp

cpp 复制代码
#include "MainWindow.h"
#include "./ui_MainWindow.h"
#include <QVBoxLayout>
#include <vtkConeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    InitVDK();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::InitVDK()
{
    m_vtkWd = new QVTKOpenGLNativeWidget(this);

    auto ly = new QVBoxLayout();
    ui->centralwidget->setLayout(ly);
    ly->addWidget(m_vtkWd);

    auto cone = vtkSmartPointer<vtkConeSource>::New();
    cone->SetRadius(1);
    cone->SetHeight(3);
    cone->SetResolution(100);

    auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(cone->GetOutputPort());

    auto actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetColor(0, 1, 0);
    actor->GetProperty()->SetRepresentationToWireframe();


    auto mapper2 = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper2->SetInputConnection(cone->GetOutputPort());

    auto actor2 = vtkSmartPointer<vtkActor>::New();
    actor2->SetMapper(mapper2);
    actor2->GetProperty()->SetColor(1, 0, 0);
    actor2->GetProperty()->SetOpacity(0.5);

    auto render = vtkSmartPointer<vtkRenderer>::New();
    render->AddActor(actor);
    render->AddActor(actor2);

    m_vtkWd->renderWindow()->AddRenderer(render);
}
相关推荐
Quz4 天前
QML Hello World 入门示例
qt
xcyxiner7 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner8 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner8 天前
DicomViewer (添加模型类)3
qt
xcyxiner9 天前
DicomViewer (目录调整) 2
qt
xcyxiner9 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能11 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G11 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt
森G11 天前
77、线程池原理和实现------服务器源码解析----云视频服务项目
服务器·c++·qt
森G11 天前
71、打包发布---------打包发布
c++·qt