当前位置: 首页 > news >正文

3D医学影像开发入门<二>:VS2019+Qt5.15.2+VTK9.3.1编译及环境配置

  
  VTK(Visualization Toolkit)是一个开源的、跨平台的三维可视化开发库,用于处理和可视化三维数据。它提供了一系列算法和工具,用于创建、操作和渲染复杂的三维图形,并支持多种数据表示方式,包括点、线、面、体等。VTK提供了一套高效的算法,用于可视化医学图像、流体动力学模拟、地理信息系统等领域的数据。

1、VTK源码下载

  源码下载地址:https://vtk.org/download/
在这里插入图片描述

  将VTK-9.3.1.tar.gz ,VTKData-9.3.1.tar.gz,VTKLargeData-9.3.1.tar.gz解压到同一目录,并创建build和SDK文件夹。

在这里插入图片描述

在这里插入图片描述

2、CMake设置

  打开CMake-gui进行设置:
在这里插入图片描述
  开启支持Qt编译;电脑上会自动找到对应的Qt路径(Qt已经在电脑环境变量添加过路径)。

在这里插入图片描述

在这里插入图片描述

点击“config”按钮,没有错误提示后点击“Generate”按钮,最后点击“open project”按钮打开VS工程。

在这里插入图片描述

3、VS编译

  点击Open project 按钮打开VS项目工程,然后先选择 ALL_BUILD进行生成,随后选择INSTALL进行sdk整理。

在这里插入图片描述
在这里插入图片描述
编译后的VTK sdk如下所示:
在这里插入图片描述

4、示例demo

  编译完成后我们来验证一下VTK编译的是否正确可用。此处可以参考VTK提供的示例代码。我们用了Qt+VTK来进行验证。https://examples.vtk.org/site/。

在这里插入图片描述

4.1 演示效果

  演示效果如下图:

在这里插入图片描述

4.2 源码

#include <QtCore/QCoreApplication>#include <QVTKOpenGLNativeWidget.h>
#include <vtkActor.h>
#include <vtkDataSetMapper.h>
#include <vtkDoubleArray.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkPointData.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>#include <QApplication>
#include <QDockWidget>
#include <QGridLayout>
#include <QLabel>
#include <QMainWindow>
#include <QPointer>
#include <QPushButton>
#include <QVBoxLayout>#include <cmath>
#include <cstdlib>
#include <random>namespace {/*** Deform the sphere source using a random amplitude and modes and render it in* the window** @param sphere the original sphere source* @param mapper the mapper for the scene* @param window the window to render to* @param randEng the random number generator engine*/void Randomize(vtkSphereSource* sphere, vtkMapper* mapper,vtkGenericOpenGLRenderWindow* window, std::mt19937& randEng);
} // namespaceint main(int argc, char* argv[])
{QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());QApplication app(argc, argv);// Main window.QMainWindow mainWindow;mainWindow.resize(1200, 900);// Control area.QDockWidget controlDock;mainWindow.addDockWidget(Qt::LeftDockWidgetArea, &controlDock);QLabel controlDockTitle("Control Dock");controlDockTitle.setMargin(20);controlDock.setTitleBarWidget(&controlDockTitle);QPointer<QVBoxLayout> dockLayout = new QVBoxLayout();QWidget layoutContainer;layoutContainer.setLayout(dockLayout);controlDock.setWidget(&layoutContainer);QPushButton randomizeButton;randomizeButton.setText("Randomize");dockLayout->addWidget(&randomizeButton);// Render area.QPointer<QVTKOpenGLNativeWidget> vtkRenderWidget =new QVTKOpenGLNativeWidget();mainWindow.setCentralWidget(vtkRenderWidget);// VTK part.vtkNew<vtkGenericOpenGLRenderWindow> window;vtkRenderWidget->setRenderWindow(window.Get());vtkNew<vtkSphereSource> sphere;sphere->SetRadius(1.0);sphere->SetThetaResolution(100);sphere->SetPhiResolution(100);vtkNew<vtkDataSetMapper> mapper;mapper->SetInputConnection(sphere->GetOutputPort());vtkNew<vtkActor> actor;actor->SetMapper(mapper);actor->GetProperty()->SetEdgeVisibility(true);actor->GetProperty()->SetRepresentationToSurface();vtkNew<vtkRenderer> renderer;renderer->AddActor(actor);window->AddRenderer(renderer);// Setup initial status.std::mt19937 randEng(0);::Randomize(sphere, mapper, window, randEng);// connect the buttonsQObject::connect(&randomizeButton, &QPushButton::released,[&]() { ::Randomize(sphere, mapper, window, randEng); });mainWindow.show();return app.exec();
}namespace {void Randomize(vtkSphereSource* sphere, vtkMapper* mapper,vtkGenericOpenGLRenderWindow* window, std::mt19937& randEng){// Generate randomness.double randAmp = 0.2 + ((randEng() % 1000) / 1000.0) * 0.2;double randThetaFreq = 1.0 + (randEng() % 9);double randPhiFreq = 1.0 + (randEng() % 9);// Extract and prepare data.sphere->Update();vtkSmartPointer<vtkPolyData> newSphere;newSphere.TakeReference(sphere->GetOutput()->NewInstance());newSphere->DeepCopy(sphere->GetOutput());vtkNew<vtkDoubleArray> height;height->SetName("Height");height->SetNumberOfComponents(1);height->SetNumberOfTuples(newSphere->GetNumberOfPoints());newSphere->GetPointData()->AddArray(height);// Deform the sphere.for (int iP = 0; iP < newSphere->GetNumberOfPoints(); iP++){double pt[3] = { 0.0 };newSphere->GetPoint(iP, pt);double theta = std::atan2(pt[1], pt[0]);double phi =std::atan2(pt[2], std::sqrt(std::pow(pt[0], 2) + std::pow(pt[1], 2)));double thisAmp =randAmp * std::cos(randThetaFreq * theta) * std::sin(randPhiFreq * phi);height->SetValue(iP, thisAmp);pt[0] += thisAmp * std::cos(theta) * std::cos(phi);pt[1] += thisAmp * std::sin(theta) * std::cos(phi);pt[2] += thisAmp * std::sin(phi);newSphere->GetPoints()->SetPoint(iP, pt);}newSphere->GetPointData()->SetScalars(height);// Reconfigure the pipeline to take the new deformed sphere.mapper->SetInputDataObject(newSphere);mapper->SetScalarModeToUsePointData();mapper->ColorByArrayComponent("Height", 0);window->Render();}
} // namespace

4.3 项目属性设定

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

vtkGUISupportQt-9.3d.lib
vtkRenderingCore-9.3d.lib
vtkRenderingOpenGL2-9.3d.lib
vtkCommonCore-9.3d.lib
vtkCommonDataModel-9.3d.lib
vtkCommonExecutionModel-9.3d.lib
vtkFiltersCore-9.3d.lib
vtkFiltersSources-9.3d.lib
vtksys-9.3d.lib

http://www.mrgr.cn/news/49451.html

相关文章:

  • Gin入门指南:从零开始快速掌握Go Web框架Gin
  • 【10月13日晴】A股下周趋势分析
  • MongoDB的基本内容和应用场景介绍
  • pip安装指定版本的tensorflow
  • 卡尔曼滤波器原理介绍
  • leetcode 1027 最长等差数列 题目的思考
  • 【前端】Bootstrap:快速开始
  • DataStore存储数据+加上加密
  • C++的类和动态内存分配(深拷贝与浅拷贝)并实现自己的string类
  • vue3之 shallowRef、markRaw
  • [Linux] 软硬链接
  • 7.2-I2C的DMA中断
  • RAII - 安卓中的智能指针
  • 如何有效参与机器人顶会?——周易教授PRE-IROS 2024分享
  • GS-LRM: Large Reconstruction Model for 3D Gaussian Splatting 论文解读
  • 性能测试-JMeter(3)
  • 深度解读 JDK 8、JDK 11、JDK 17 和 JDK 21 的区别
  • CountUp.js 实现数字增长动画 Vue
  • 苏姿丰发布AMD最强AI芯片|苹果质疑大语言模型根本无法进行逻辑推理|Kimi的商业化困局|杰弗里·辛顿:“图灵诺奖双得主”、“AI教父”,至高荣誉加身
  • RabbitMQ 高级特性——死信队列