当前位置:网站首页>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;
}
边栏推荐
- How to install voice pack in Win11?Win11 Voice Pack Installation Tutorial
- GZIPOutputStream 类源码分析
- Three solutions: npm WARN config global --global, --local are deprecated. Use --location=global instead.
- 明日盛会|ApacheCon Asia 2022 Pulsar 技术议题一览
- How to query database configuration parameters in GBase 8c, such as datestyle.What function or syntax to use?
- 日志工厂(详细)
- No need to crack, install Visual Studio 2013 Community Edition on the official website
- 30分钟成为Contributor|如何多方位参与OpenHarmony开源贡献?
- LeetCode 0151.颠倒字符串中的单词
- The elder brother of the goldfish RHCA memoirs: CL210 experiment management it network - chapter
猜你喜欢

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

C#/VB.NET:从 PDF 文档中提取所有表格

Source code analysis of GZIPOutputStream class
![DAO development tutorial [WEB3.0]](/img/fa/4406317241973d15d776c4f2f0890d.png)
DAO development tutorial [WEB3.0]

面试必问的HashCode技术内幕

Zabbix6.0钉钉机器人告警

Website construction process

使用常见问题解答软件的好处有哪些?

odoo coding conventions (programming conventions, coding guidelines)

The XML configuration
随机推荐
ExcelPatternTool: Excel form-database mutual import tool
在全志V853开发板试编译QT测试
MLX90640 Infrared Thermal Imager Temperature Measurement Module Development Notes (Complete)
ClassID的计算中,&表示啥意思
力扣刷题之移动零
深入浅出Flask PIN
Redis的内存淘汰策略和过期删除策略的区别是什么
MySQL database - stored procedures and functions
生命周期和作用域
通配符 SSL/TLS 证书
请你说说多线程
kubernetes - deploy nfs storage class
modbus bus module DAM-8082
有点奇怪!访问目的网址,主机能容器却不行
30分钟成为Contributor|如何多方位参与OpenHarmony开源贡献?
无需破解,官网安装Visual Studio 2013社区版
Summer vacation first week wrap-up blog
2022,程序员应该如何找工作
DAO development tutorial [WEB3.0]
GBase 8c中怎么查询数据库配置参数,例如datestyle。使用什么函数或者语法呢?