VTK-helloworld官网案例使用(A hello world example)

1 篇文章 0 订阅
订阅专栏

配置环境:windows11、qt6、cmake3.26.3、vtk9.2.6、vs2019

进入vtk官网,找到案例

 新建一个空文件夹,名称为CylinderExample(名称随意)

在CylinderExample文件夹下新建CMakeLists.txt文本文档

打开CMakeLists.txt,把下面代码复制进去(官方提供的代码)

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(CylinderExample)

find_package(VTK COMPONENTS 
  CommonColor
  CommonCore
  FiltersSources
  InteractionStyle
  RenderingContextOpenGL2
  RenderingCore
  RenderingFreeType
  RenderingGL2PSOpenGL2
  RenderingOpenGL2
)

if (NOT VTK_FOUND)
  message(FATAL_ERROR "CylinderExample: Unable to find the VTK build folder.")
endif()

# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(CylinderExample MACOSX_BUNDLE CylinderExample.cxx )
  target_link_libraries(CylinderExample PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
  TARGETS CylinderExample
  MODULES ${VTK_LIBRARIES}
)

在CylinderExample文件夹下新建CylinderExample.cxx文件

把下面代码复制到CylinderExample.cxx中(记事本打开)

#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCylinderSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>

#include <array>

int main(int, char*[])
{
  vtkNew<vtkNamedColors> colors;

  // Set the background color.
  std::array<unsigned char, 4> bkg{{26, 51, 102, 255}};
  colors->SetColor("BkgColor", bkg.data());

  // This creates a polygonal cylinder model with eight circumferential facets
  // (i.e, in practice an octagonal prism).
  vtkNew<vtkCylinderSource> cylinder;
  cylinder->SetResolution(8);

  // The mapper is responsible for pushing the geometry into the graphics
  // library. It may also do color mapping, if scalars or other attributes are
  // defined.
  vtkNew<vtkPolyDataMapper> cylinderMapper;
  cylinderMapper->SetInputConnection(cylinder->GetOutputPort());

  // The actor is a grouping mechanism: besides the geometry (mapper), it
  // also has a property, transformation matrix, and/or texture map.
  // Here we set its color and rotate it around the X and Y axes.
  vtkNew<vtkActor> cylinderActor;
  cylinderActor->SetMapper(cylinderMapper);
  cylinderActor->GetProperty()->SetColor(
      colors->GetColor4d("Tomato").GetData());
  cylinderActor->RotateX(30.0);
  cylinderActor->RotateY(-45.0);

  // The renderer generates the image
  // which is then displayed on the render window.
  // It can be thought of as a scene to which the actor is added
  vtkNew<vtkRenderer> renderer;
  renderer->AddActor(cylinderActor);
  renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());
  // Zoom in a little by accessing the camera and invoking its "Zoom" method.
  renderer->ResetCamera();
  renderer->GetActiveCamera()->Zoom(1.5);

  // The render window is the actual GUI window
  // that appears on the computer screen
  vtkNew<vtkRenderWindow> renderWindow;
  renderWindow->SetSize(300, 300);
  renderWindow->AddRenderer(renderer);
  renderWindow->SetWindowName("Cylinder");

  // The render window interactor captures mouse events
  // and will perform appropriate camera or actor manipulation
  // depending on the nature of the events.
  vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
  renderWindowInteractor->SetRenderWindow(renderWindow);

  // This starts the event loop and as a side effect causes an initial render.
  renderWindow->Render();
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

接着在CylinderExample文件夹下新建bin文件夹,如下图

 打开cmake,设置好源码和生成路径后点击Configure

 报了个错,如下图,原因是VTK_DIR-NOTFOUND(没找到VTK所在目录)

 手动指定一下VTK所在目录(就是VTK源码编译后生成文件所在的目录)

 

 之后打开CylinderExample文件夹下的bin文件夹,里面生成了很多文件,如下图

 用vs打开CylinderExample文件夹下的bin文件夹里的CylinderExample.sln文件,右键ALL BUILD,点击生成

 直接运行vs会报无法启动程序错误,如下

在解决方案资源管理器中右键CylinderExample,点击设为启动项目

 

 之后再运行,会报“由于找不到vtklnteractionStyle-9.2d.dll,无法继续执行代码。重新安装程序可能会解决此问题。”错误

 在解决方案资源管理器中右键CylinderExample-->属性-->配置属性-->调试-->工作目录,把工作目录里的路径改成“vtklnteractionStyle-9.2d.dll”所在的路径(就是vtk源码编译后生成文件里bin下的Debug目录)

 
 再次点击运行即可

 

 如果遇到其他问题可以在网上寻找解决方案

写文章

热门文章

  • MITK详细安装教程 2244
  • MySQL单表查询练习 1571
  • MySQL多表查询练习 988
  • java类的定义和使用 920
  • VMware Workstation Pro创建linux虚拟机 690

分类专栏

  • MITK 1篇
  • VTK 1篇
  • JAVASE 9篇
  • MySQL数据库 8篇
  • HCIP 6篇
  • Linux 1篇
  • HCIA 1篇

最新评论

  • MITK详细安装教程

    迟懒chun胖: 你的教程真的,very高质量

  • MITK详细安装教程

    2301_79943471: 博主您好 请问怎么开启VPN啊 小白不太会搞

  • MITK详细安装教程

    大哥739: 编译完成 创建工程啊

  • MITK详细安装教程

    打野的小盖伦zh: 博主您好,我在编译2023库的时候遇到了这个问题: 错误 LNK1104 无法打开文件“libcrypto.lib” [D:\MITK\build\ep\src\Poco-build\Crypto\Crypto.vcxproj] Poco 请问这个是因为什么呢

  • MITK详细安装教程

    &沢渡雫: MSB6006基本上是在生成时需要的软件包没下载成功,先看看.patch文件的格式改了没,再解决C4819警告。或者看看是不是网络环境的问题。MSB6006解决了,MSB1009的错误也就没有了

大家在看

  • 【Ant design ProTable多选操作代码】 54
  • day01|计算机网络重难点之TCP/IP模型和OSI模型的区别、从输入 URL 到页面展示
  • 霹雳吧啦wz3(膨胀卷积)
  • 研发运营一体化(DevOps)能力成熟度模型 223
  • C语言链表

最新文章

  • MITK详细安装教程
  • ArrayList类
  • Scanner类
2023年2篇
2022年4篇
2021年19篇
2020年2篇

目录

目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值

玻璃钢生产厂家玄武玻璃钢雕塑公司仿古玻璃钢花盆造型山西石雕雕塑玻璃钢辽宁动物雕塑玻璃钢玻璃钢瓜果雕塑咨询迪庆玻璃钢动物雕塑多少钱溧水商场美陈策划玻璃钢雕塑海关编码衢州玻璃钢陶瓷雕塑图片重庆玻璃钢雕塑厂打磨工招聘锦州玻璃钢花盆花器玻璃钢沙盘雕塑宝坻区商场美陈汕尾玻璃钢卡通雕塑厂金昌城市玻璃钢雕塑厂家丹东玻璃钢雕塑雕花推荐广东商业商场美陈价格上海大型玻璃钢雕塑多少钱松原玻璃钢雕塑佛像上海装饰商场美陈报价泸水市玻璃钢雕塑供应雕塑玻璃钢粉登封玻璃钢雕塑厂兰州卡通玻璃钢雕塑厂家温岭玻璃钢雕塑玻璃钢雕塑厂家咨询杭州玻璃钢雕塑摆件采购美陈创意商场呼市玻璃钢雕塑厂家商场美陈理念香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警汪小菲曝离婚始末遭遇山火的松茸之乡雅江山火三名扑火人员牺牲系谣言何赛飞追着代拍打萧美琴窜访捷克 外交部回应卫健委通报少年有偿捐血浆16次猝死手机成瘾是影响睡眠质量重要因素高校汽车撞人致3死16伤 司机系学生315晚会后胖东来又人满为患了小米汽车超级工厂正式揭幕中国拥有亿元资产的家庭达13.3万户周杰伦一审败诉网易男孩8年未见母亲被告知被遗忘许家印被限制高消费饲养员用铁锨驱打大熊猫被辞退男子被猫抓伤后确诊“猫抓病”特朗普无法缴纳4.54亿美元罚金倪萍分享减重40斤方法联合利华开始重组张家界的山上“长”满了韩国人?张立群任西安交通大学校长杨倩无缘巴黎奥运“重生之我在北大当嫡校长”黑马情侣提车了专访95后高颜值猪保姆考生莫言也上北大硕士复试名单了网友洛杉矶偶遇贾玲专家建议不必谈骨泥色变沉迷短剧的人就像掉进了杀猪盘奥巴马现身唐宁街 黑色着装引猜测七年后宇文玥被薅头发捞上岸事业单位女子向同事水杯投不明物质凯特王妃现身!外出购物视频曝光河南驻马店通报西平中学跳楼事件王树国卸任西安交大校长 师生送别恒大被罚41.75亿到底怎么缴男子被流浪猫绊倒 投喂者赔24万房客欠租失踪 房东直发愁西双版纳热带植物园回应蜉蝣大爆发钱人豪晒法院裁定实锤抄袭外国人感慨凌晨的中国很安全胖东来员工每周单休无小长假白宫:哈马斯三号人物被杀测试车高速逃费 小米:已补缴老人退休金被冒领16年 金额超20万

玻璃钢生产厂家 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化