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

ubuntu18.04 编译VTK

VTK源码下载:github、csdn

一、准备环境

1、安装3.12版本cmake

sudo apt remove cmake
sudo apt update
sudo apt install -y wget build-essential
wget https://cmake.org/files/v3.21/cmake-3.21.3.tar.gz
tar -zxvf cmake-3.21.3.tar.gz
cd cmake-3.21.3
./bootstrap
make
sudo make install
cmake --version

2、安装至少8.0版本的gcc、g++。

sudo apt update
sudo apt install gcc-8 g++-8
gcc --version//若gcc默认不是8.x版本,需要修改,如我的默认是7.x
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 7
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 8
sudo update-alternatives --set gcc /usr/bin/gcc-8
sudo update-alternatives --set g++ /usr/bin/g++-8

二、编译vtk

mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=/opt/qt5.12.5 -DCMAKE_INSTALL_PREFIX=/opt/vtk
make -j8
sudo make install

三、验证

#.pro
QMAKE_RPATHDIR += /opt/vtk/lib
LIBS += -L/opt/vtk/libLIBS += -L/opt/vtk/lib \-lvtkCommonCore-9.5 \-lvtkInfovisCore-9.5 \-lvtkRenderingFreeType-9.5 \-lvtksys-9.5 \-lvtkRenderingOpenGL2-9.5 \-lvtkInteractionStyle-9.5 \-lvtkFiltersSources-9.5 \-lvtkRenderingCore-9.5 \-lvtkCommonExecutionModel-9.5 \-lvtkCommonDataModel-9.5 \-lvtkIOImage-9.5VTK_VERSION = 9.5  # 根据您的 VTK 版本调整
INCLUDEPATH += /opt/vtk/include/vtk-$${VTK_VERSION}
DEPENDPATH += /opt/vtk/include/vtk-$${VTK_VERSION}
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkConeSource.h>
#include <iostream>#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2); // 这个宏用于初始化渲染器
VTK_MODULE_INIT(vtkInteractionStyle); // 这个宏用于初始化交互样式int main(int argc, char *argv[])
{QApplication a(argc, argv);// 创建圆锥体数据源auto coneSource = vtkSmartPointer<vtkConeSource>::New();coneSource->SetHeight(3.0); // 设置圆锥体的高度coneSource->SetRadius(1.5); // 设置圆锥体的半径coneSource->SetResolution(6); // 设置圆锥体的分辨率,即圆锥体的面数// 创建映射器和演员auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();mapper->SetInputConnection(coneSource->GetOutputPort()); // 设置输入数据auto actor = vtkSmartPointer<vtkActor>::New(); // 创建演员对象,并将其与映射器关联起来。actor->SetMapper(mapper);// 创建渲染器和窗口auto renderer = vtkSmartPointer<vtkRenderer>::New();  // 创建渲染器auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); // 创建渲染窗口renderWindow->SetWindowName("VTK最简单示例"); // 设置渲染窗口的标题renderWindow->AddRenderer(renderer); // 将渲染器添加到渲染窗口renderWindow->SetSize(800, 600); // 设置渲染窗口的大小// 设置交互器auto interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();interactor->SetRenderWindow(renderWindow);// 添加演员到场景renderer->AddActor(actor);renderer->SetBackground(0.2, 0.3, 0.4);  // 设置背景颜色// 启动渲染循环renderWindow->Render(); // 渲染窗口interactor->Start(); // 启动交互器,进入事件循环。等待用户进行操作(例如旋转、缩放等)return a.exec();
}

点击扫码加入群聊

觉得有帮助的话,打赏一下呗。。

           

需要商务合作(定制程序)的欢迎私信!! 

http://www.dtcms.com/a/392819.html

相关文章:

  • ES6 新增特性
  • Pycharm中切换虚拟环境
  • 人工智能训练师
  • 【Linux】权限管理
  • C++哈希进阶:位图与布隆过滤器+海量信息处理
  • 林曦词典|无痛学习法
  • 树莓派CM4显示测序合集
  • python创建虚拟环境相关命令
  • 如何用AI把博客文章,“洗”成一篇学术论文?
  • 应用密码学课程复习汇总2——古典密码学
  • 应用密码学课程复习汇总1——课程导入
  • PyTorch 中 AlexNet 的构建与核心技术解析
  • 一文读懂:三防手机的定义、特性与使用场景
  • EG800G-CN不联网不定位
  • sqzb_alldsd——板子
  • Windows 快速检测 Docker / WSL2 安装环境脚本(附 GUI 版本)
  • Redis最佳实践——电商应用的性能监控与告警体系设计详解
  • 【C++】C++11(二)
  • 如何解决 pip install 安装报错 ModuleNotFoundError: No module named ‘selenium’ 问题
  • 实测美团LongCat-Flash:当大模型装上“速度引擎”,能否改写智能体战局?
  • unicode ascii utf-8的区别
  • Rust_2025:阶段1:day6.1 collect补充 ,迭代器补充 ,闭包,Hashmap搜索指定值的个数,合并迭代器
  • ESP32- 项目应用2 音乐播放器之音响驱动 #2
  • Datawhale25年9月组队学习:llm-preview+Task2:大模型使用
  • Agent记忆:Memvid、Memary、MemoryOS
  • 《主流PLC品牌型号大全解析》,电气设计时PLC应该怎么选
  • 从92到102,一建实务突破之路:坚持与自我超越
  • 探索C语言中字符串长度的计算方法
  • 使用node框架 Express开发仓库管理系统练习项目
  • 网络系统管理