当前位置:网站首页>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;
}
边栏推荐
- SQL函数 TO_DATE(一)
- 【LeetCode】Day109-the longest palindrome string
- 7月30号|来一场手把手助您打造智能视觉新爆款的技术动手实验
- odoo coding conventions (programming conventions, coding guidelines)
- 明日盛会|ApacheCon Asia 2022 Pulsar 技术议题一览
- How to record and analyze your alchemy process - use notes of the visual artifact Wandb [1]
- To drive efficient upstream and downstream collaboration, how can cross-border B2B e-commerce platforms release the core value of the LED industry supply chain?
- MySQL数据库————存储过程和函数
- 生命周期和作用域
- 哈哈!一个 print 函数,还挺会玩啊!
猜你喜欢

Shell script topic (07): file from cfs to bos

首篇 NLP 领域图神经网络综述:127 页,从图构建到实际应用面面观

DAO开发教程【WEB3.0】

Prometheus的Recording rules实践

网站建设流程

#yyds dry goods inventory# Interview must brush TOP101: the last k nodes in the linked list

三种方案解决:npm WARN config global --global, --local are deprecated. Use --location=global instead.

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

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

力扣刷题之合并两个有序数组
随机推荐
explain 各字段介绍
如何让固定点的监控设备在EasyCVR平台GIS电子地图上显示地理位置?
英国伦敦大学|眼科强化学习:潜在应用和实施挑战
对于web性能优化我有话说!
Clip-on multimeter use method, how to measure the voltage, current, resistance?
Become a Contributor in 30 minutes | How to participate in OpenHarmony's open source contributions in multiple ways?
【服务器数据恢复】服务器Raid5阵列mdisk组中多块磁盘离线的数据恢复案例
消息模板占位符的使用
Tencent Cloud Hosting Security x Lightweight Application Server | Powerful Joint Hosting Security Pratt & Whitney Version Released
TestNG multiple xml for automated testing
30分钟成为Contributor|如何多方位参与OpenHarmony开源贡献?
GBase 8c中怎么查询数据库配置参数,例如datestyle。使用什么函数或者语法呢?
深入浅出Flask PIN
用VS2013编译带boost库程序时提示 fatal error C1001: 编译器中发生内部错误
Shell script topic (07): file from cfs to bos
LeetCode 0151. Reverse a string of words
Goldfish Brother RHCA Memoirs: CL210 manages OPENSTACK network -- network configuration options
XML配置
The function realization of the national standard GB28181 protocol EasyGBS platform compatible with the old version of the inflow port
首篇 NLP 领域图神经网络综述:127 页,从图构建到实际应用面面观