尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

Win10系统VS2019+Cmake+vtk_8.2.0环境配置

Win10系统VS2019+Cmake+vtk_8.2.0环境配置
📅 发布时间:2026/6/19 5:14:45

Win10系统VS2019+Cmake+vtk_8.2.0环境配置

1 vtk

1.1 简要介绍

VTK(visualization toolkit)是一个开源的BSD许可证免费软件系统,主要用于三维计算机图形学、图像处理和科学计算可视化。VTK是在三角函数库OpenGL的基础上采用面向对象的设计方法发展起来的,它将我们在可视化开发过程中会经常遇到的细节屏蔽起来,并将一些常用的算法封装起来。

1.2 依赖库

vtk一般不需要再配置其他库。

1.2.1 MPI

非必选,如果想要编译vtkIOMPIImage或vtkIOMPIParallel模块,需要依赖MPI库,用于加速。
MPI库下载地址:
https://www.microsoft.com/en-us/download/details.aspx?id=57467

注:对于编译vtk,下载msmpisdk.msi即可,即MPI库的SDK,安装后生成include和Lib两个文件夹。

1.3 源码包下载

vtk源码地址:
github: https://github.com/Kitware/VTK.git

2Cmake构建项目

2.1 路径

源代码路径:D:/ThirdParty/vtk/VTK_8.2.0
构建项目路径:D:/ThirdParty/vtk/VTK_8.2.0_build

2.2 构建选项

名称值备注
BUILD_TESTINGfalse
CMAKE_INSTALL_PREFIXpath编译时生成的安装文件路径
CMAKE_DEBUG_POSTFIX-ddebug版本库名称后缀,需要勾选Cmake中的Advanced
CMAKE_CXX_MP_FLAGtrue

如果想要编译vtkIOMPIImage或vtkIOMPIParallel这两个模块,还需要如下设置:

名称值备注
Module_vtkIOMPIImagetrue编译vtkIOMPIImage模块
Module_vtkIOMPIParalleltrue编译vtkIOMPIParallel模块
VTK_Group_MPItrue
MPI_CXX_INCLUDE_PATHpathMPI库Include文件夹路径../mpi/Include
MPI_CXX_LIBRARIESpathMPI库Lib文件夹路径../mpi/Lib/x64
MPI_C_INCLUDE_PATHpathMPI库Include文件夹路径../mpi/Include
MPI_C_LIBRARIESpathMPI库Lib文件夹路径../mpi/Lib/x64

注:这样的配置仅能保证Configure能过,Generate代码时会有一堆报警,但也能成功生成项目,但这在编译vtkParallelMPI,vtkIOMPIImage和vtkIOParallelNetCDF这3个项目时,仍会报MPI中无法解析的外部符号错误,我是针对这3个项目,在附加依赖项中,手动添加了MPI库Lib/x64文件夹下的几个库文件名,我对cmake不熟,没有找到更好的办法,大家要是有更好的方法,欢迎留言赐教。
另外,针对这3个项目,在附加库目录中,手动添加了MPI库Include/x64文件夹的路径。

2.3 构建项目

步骤如下:

  1. 指定源码路径;

  2. 指定构建项目路径;

  3. 点击Configure;

  4. 按照2.2节表中的值进行设置;

  5. 再次点击Configure;

  6. 点击Generate,构建项目路径中将生成解决方案文件VTK.sln。

点击Configure或Generate后,如果顺利,会出现Configuring done或Generating done。

3 打开解决方案并编译

3.1 编译解决方案

点击Open Project(或者在2.3节步骤2中指定的构建项目路径中,找到生成的解决方案文件VTK.sln,通过Visual Studio打开),打开通过Cmake构建的项目;
选中ALL_BUILD项目,分别在Debug和Release模式下,重新生成解决方案。

3.2 安装vtk

选中INSTALL项目,右击,重新生成,此时,将会在指定路径下(2.2节表中CMAKE_INSTALL_PREFIX选项的值)主要生成3个文件夹include和lib和bin。

4 实际项目环境配置

注:以下通过属性表的方式进行环境配置。

4.1 附加包含目录

  1. $(vtk)\vtk-8.2\include

$(vtk)(在系统环境变量中添加并设置)就是2.2节表中CMAKE_INSTALL_PREFIX选项的值。

4.2 附加库目录

  1. $(vtk)\lib

4.3 附加依赖项

将库目录$(vtk)\lib中文件后缀名为.lib的文件依次添加至附加依赖项中,并依次配置debug版本(文件名中有d)和release版本。

注意,添加附加依赖项时,不要漏掉文件后缀名.lib!

4.4动态库

将动态库目录添加至系统环境变量Path,步骤如下:

  1. 计算机右击,点击“属性”;

  2. 点击“高级系统设置”;

  3. 点击“环境变量”;

  4. 双击Path;

  5. 添加%vtk%\bin,该目录下是包含了动态库文件。

本文使用的都是相对路径,因此需事先设置好环境变量vtk,值为CMAKE_INSTALL_PREFIX对应的目录,也可以使用绝对路径。

注:上述步骤是按照加载vtk动态库的方式进行配置的;
当然也可以按照静态库的方式配置,可省略步骤4.4。

4.5 测试代码

/*========================================================================= Program: Visualization Toolkit Module: Cone.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*///// This example creates a polygonal model of a cone, and then renders it to// the screen. It will rotate the cone 360 degrees and then exit. The basic// setup of source -> mapper -> actor -> renderer -> renderwindow is// typical of most VTK programs.//// First include the required header files for the VTK classes we are using.#include<vtkAutoInit.h>VTK_MODULE_INIT(vtkRenderingOpenGL2);VTK_MODULE_INIT(vtkInteractionStyle);VTK_MODULE_INIT(vtkRenderingFreeType);//#define vtkRenderingCore_AUTOINIT 2(vtkInteractionStyle,vtkRenderingOpenGL2)#include"vtkConeSource.h"#include"vtkPolyDataMapper.h"#include"vtkRenderWindow.h"#include"vtkCamera.h"#include"vtkActor.h"#include"vtkRenderer.h"intmain(){//// Next we create an instance of vtkConeSource and set some of its// properties. The instance of vtkConeSource "cone" is part of a// visualization pipeline (it is a source process object); it produces data// (output type is vtkPolyData) which other filters may process.//vtkConeSource*cone=vtkConeSource::New();cone->SetHeight(3.0);cone->SetRadius(1.0);cone->SetResolution(10);//// In this example we terminate the pipeline with a mapper process object.// (Intermediate filters such as vtkShrinkPolyData could be inserted in// between the source and the mapper.) We create an instance of// vtkPolyDataMapper to map the polygonal data into graphics primitives. We// connect the output of the cone source to the input of this mapper.//vtkPolyDataMapper*coneMapper=vtkPolyDataMapper::New();coneMapper->SetInputConnection(cone->GetOutputPort());//// Create an actor to represent the cone. The actor orchestrates rendering// of the mapper's graphics primitives. An actor also refers to properties// via a vtkProperty instance, and includes an internal transformation// matrix. We set this actor's mapper to be coneMapper which we created// above.//vtkActor*coneActor=vtkActor::New();coneActor->SetMapper(coneMapper);//// Create the Renderer and assign actors to it. A renderer is like a// viewport. It is part or all of a window on the screen and it is// responsible for drawing the actors it has. We also set the background// color here.//vtkRenderer*ren1=vtkRenderer::New();ren1->AddActor(coneActor);ren1->SetBackground(0.1,0.2,0.4);//// Finally we create the render window which will show up on the screen.// We put our renderer into the render window using AddRenderer. We also// set the size to be 300 pixels by 300.//vtkRenderWindow*renWin=vtkRenderWindow::New();renWin->AddRenderer(ren1);renWin->SetSize(300,300);//// Now we loop over 360 degrees and render the cone each time.//inti;for(i=0;i<360;++i){// render the imagerenWin->Render();// rotate the active camera by one degreeren1->GetActiveCamera()->Azimuth(1);}//// Free up any objects we created. All instances in VTK are deleted by// using the Delete() method.//cone->Delete();coneMapper->Delete();coneActor->Delete();ren1->Delete();renWin->Delete();std::system("pause");return0;}

如果编译时报错,提示error LNK2019:无法解析的外部符号 __imp_SymGetLineFromAddr64,解决方案如下:
“项目”–>“属性”–>“链接器”–>“输入”–>“附加依赖项”,添加dgbhelp.lib。

如果运行时报错,提示Error: no override found for 'vtkPolyDataMapper',解决方案如下:

  1. 在附加依赖项中添加opengl32.lib;

  2. 程序开头添加如下代码:

#include<vtkAutoInit.h>VTK_MODULE_INIT(vtkRenderingOpenGL2);// 也有可能是VTK_MODULE_INIT(vtkRenderingOpenGL);VTK_MODULE_INIT(vtkInteractionStyle);VTK_MODULE_INIT(vtkRenderingFreeType);

或者程序开头直接添加一句代码:
#define vtkRenderingCore_AUTOINIT 2(vtkInteractionStyle,vtkRenderingOpenGL2)。

这句代码来源于编译代码生成目录D:\ThirdParty\vtk\VTK_8.2.0_build\CMakeFiles下的vtkRenderingCore_AUTOINIT_vtkInteractionStyle_vtkRenderingOpenGL2.h文件内。

相关新闻

  • YOLO如何应对恶劣天气下的检测挑战?
  • 基于Vector工具链的AUTOSAR架构配置深度剖析
  • YOLOv10相比YOLOv8有哪些核心改进?一文说清

最新新闻

  • 文心5.0实测:2.4万亿参数原生全模态架构解析
  • 事件序列特征工程与嵌入学习的双向优化实践
  • 2026年石家庄市CPPM考试最新全攻略:科目题型、通过率、备考重点及官方双认证报考机构推荐 - 众智商学院课程中心
  • 谷歌Gemini联席负责人跳槽OpenAI,AI人才争夺战再升级!
  • 深度解析银狐木马攻击链:从社工投递到白利用的防御实战
  • 高速MOSFET驱动器MCP14E9选型、设计与调试全解析

日新闻

  • 5分钟掌握Python进化算法:Geatpy高性能优化工具完全指南
  • Microchip 24AA044 EEPROM选型与应用全指南:从参数解析到实战编程
  • 华为的鸿蒙到底有多牛?为什么称作遥遥领先?

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号