当前位置:网站首页>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;
}
边栏推荐
- [Neural Network] This article will take you to easily analyze the neural network (with an example of spoofing your girlfriend)
- Clip-on multimeter use method, how to measure the voltage, current, resistance?
- No need to crack, install Visual Studio 2013 Community Edition on the official website
- 重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
- C#/VB.NET Extract table from PDF
- Heavy cover special | build the first line of defense, cloud firewall offensive and defensive drills best practices
- Three solutions: npm WARN config global --global, --local are deprecated. Use --location=global instead.
- 1065 A+B and C (64bit)
- kubernetes - deploy nfs storage class
- 金鱼哥RHCA回忆录:CL210管理OPENSTACK网络--网络配置选项
猜你喜欢

MLX90640 红外热成像仪测温模块开发笔记(完整篇)

Website construction process

30分钟成为Contributor|如何多方位参与OpenHarmony开源贡献?

Win11如何开启剪贴板自动复制?Win11开启剪贴板自动复制的方法

有点奇怪!访问目的网址,主机能容器却不行

LeetCode 0152. 乘积最大子数组:dp + 原地滚动

MySQL数据库————流程控制

Fuzzy query in Map pass-by-value and object pass-by-value

log factory (detail)

No need to crack, install Visual Studio 2013 Community Edition on the official website
随机推荐
2022,程序员应该如何找工作
explain 各字段介绍
Goldfish Brother RHCA Memoirs: CL210 manages OPENSTACK network -- network configuration options
The XML configuration
Map传值
【LeetCode】Day109-the longest palindrome string
【LeetCode】Day109-最长回文串
What are the application advantages of SaaS management system?How to efficiently improve the digital and intelligent development level of food manufacturing industry?
力扣刷题之移动零
Library website construction source code sharing
Choosing the right DevOps tool starts with understanding DevOps
Summer vacation first week wrap-up blog
C#/VB.NET 从PDF中提取表格
如何让固定点的监控设备在EasyCVR平台GIS电子地图上显示地理位置?
小白系统初始化配置资源失败怎么办
Try compiling QT test on Allwinner V853 development board
选择合适的 DevOps 工具,从理解 DevOps 开始
生命周期和作用域
Three solutions: npm WARN config global --global, --local are deprecated. Use --location=global instead.
【全民编程】《软件编程-讲课视频》【零基础入门到实战应用】