当前位置:网站首页>The solution to the vtk volume rendering code error (the code can run in vtk7, 8, 9), and the VTK dataset website
The solution to the vtk volume rendering code error (the code can run in vtk7, 8, 9), and the VTK dataset website
2022-08-01 19:01:00 【Zong Hao Duo Lao】
链接:vtk7.1.1官方文档
链接:官方示例代码
链接:VTK资源网站(Just search for whatever resource you need,The dataset in the official website example、resources are basically)
Volume rendering code does not run,The solution that keeps giving errors
- 大家应该都看过VTKGraphics and images advanced that book,那本书的VTK版本为5.10.1,The volume rendering part of the code with the book is inVTK7 8 9version does not work,Something needs to be changed a bit(没有《VTKAdvanced graphics》You can chat with me privately for this book and the code accompanying the book,I can send Baidu network disk)
- Also need to pay attention to adding:
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
否则会报错
#include<vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
#include <vtkSmartPointer.h>
#include <vtkImageData.h>
#include <vtkStructuredPoints.h>
#include <vtkStructuredPointsReader.h>
#include <vtkVolumeRayCastCompositeFunction.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkVolumeRayCastMapper.h>
#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkVolumeProperty.h>
#include <vtkAxesActor.h>
#include <vtkImageShiftScale.h>
#include <vtkImageCast.h>
#include <vtkFixedPointVolumeRayCastMapper.h>
// ../data/mummy.128.vtk
int main(int argc, char *argv[])
{
vtkSmartPointer<vtkStructuredPointsReader> reader =
vtkSmartPointer<vtkStructuredPointsReader>::New();
reader->SetFileName(../data/mummy.128.vtk);
reader->Update();
//vtkSmartPointer<vtkVolumeRayCastCompositeFunction> rayCastFun = vtkSmartPointer<vtkVolumeRayCastCompositeFunction>::New(); // 舍弃了
vtkSmartPointer<vtkFixedPointVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>::New();
volumeMapper->SetInputDataObject(reader->GetOutput());
//volumeMapper->SetVolumeRayCastFunction(rayCastFun); // 舍弃了
vtkSmartPointer<vtkVolumeProperty> volumeProperty = vtkSmartPointer<vtkVolumeProperty>::New();
volumeProperty->SetInterpolationTypeToLinear();
volumeProperty->ShadeOn(); //Turn light shading on or off
volumeProperty->SetAmbient(0.4);
volumeProperty->SetDiffuse(0.6);
volumeProperty->SetSpecular(0.2);
vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New();
compositeOpacity->AddPoint(70, 0.00);
compositeOpacity->AddPoint(90, 0.40);
compositeOpacity->AddPoint(180, 0.60);
volumeProperty->SetScalarOpacity(compositeOpacity); //设置不透明度传输函数
vtkSmartPointer<vtkPiecewiseFunction> volumeGradientOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New();
volumeGradientOpacity->AddPoint(10, 0.0);
volumeGradientOpacity->AddPoint(90, 0.5);
volumeGradientOpacity->AddPoint(100, 1.0);
//volumeProperty->SetGradientOpacity(volumeGradientOpacity);//Sets the gradient opacity effect contrast
vtkSmartPointer<vtkColorTransferFunction> color = vtkSmartPointer<vtkColorTransferFunction>::New();
color->AddRGBPoint(0.000, 0.00, 0.00, 0.00);
color->AddRGBPoint(64.00, 1.00, 0.52, 0.30);
color->AddRGBPoint(190.0, 1.00, 1.00, 1.00);
color->AddRGBPoint(220.0, 0.20, 0.20, 0.20);
volumeProperty->SetColor(color);
vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
ren->SetBackground(1, 1, 0);
ren->AddVolume( volume );
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(ren);
renWin->SetSize(640, 480);
renWin->Render();
renWin->SetWindowName("VolumeRenderingApp");
vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
ren->ResetCamera();
renWin->Render();
iren->Start();
std::cin.get();
return EXIT_SUCCESS;
}
边栏推荐
- 【全民编程】《软件编程-讲课视频》【零基础入门到实战应用】
- Win11如何删除升级包?Win11删除升级包的方法
- 力扣刷题之移动零
- 安装GBase 8c数据库的时候,报错显示“Resource:gbase8c already in use”,这怎么处理呢?
- The life cycle and scope
- 请你说说多线程
- The elder brother of the goldfish RHCA memoirs: CL210 experiment management it network - chapter
- 重保特辑|拦截99%恶意流量,揭秘WAF攻防演练最佳实践
- ClassID的计算中,&表示啥意思
- 如何记录分析你的炼丹流程—可视化神器Wandb使用笔记【1】
猜你喜欢
【pyqt5】自定义控件 实现能够保持长宽比地缩放子控件
首篇 NLP 领域图神经网络综述:127 页,从图构建到实际应用面面观
A simple Flask PIN
How many steps does it take to convert an ENS domain name into music?
log factory (detail)
小白系统初始化配置资源失败怎么办
使用常见问题解答软件的好处有哪些?
Three solutions: npm WARN config global --global, --local are deprecated. Use --location=global instead.
Flowable-based upp (unified process platform) running performance optimization
Shell script topic (07): file from cfs to bos
随机推荐
odoo 编码规范(编程规范、编码指南)
How many steps does it take to convert an ENS domain name into music?
力扣刷题之合并两个有序数组
小白系统初始化配置资源失败怎么办
在Map传值与对象传值中模糊查询
暑假第二周总结博客
Keras deep learning practice - traffic sign recognition
Redis启动时提示Creating Server TCP listening socket *:6379: bind: No error
Redis的内存淘汰策略和过期删除策略的区别是什么
C#/VB.NET 从PDF中提取表格
LeetCode 0151.颠倒字符串中的单词
[pyqt5] Custom controls to achieve scaling sub-controls that maintain the aspect ratio
SaaS管理系统的应用优势在哪里?如何高效提升食品制造业数智化发展水平?
Map传值
2022,程序员应该如何找工作
ExcelPatternTool: Excel form-database mutual import tool
C#/VB.NET: extracted from the PDF document all form
483-82(23、239、450、113)
【LeetCode】Day109-the longest palindrome string
【蓝桥杯选拔赛真题47】Scratch潜艇游戏 少儿编程scratch蓝桥杯选拔赛真题讲解