当前位置:网站首页>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;
}
边栏推荐
- LeetCode 0152. 乘积最大子数组:dp + 原地滚动
- [Neural Network] This article will take you to easily analyze the neural network (with an example of spoofing your girlfriend)
- Every calculation, & say what mean
- TestNG multiple xml for automated testing
- 选择合适的 DevOps 工具,从理解 DevOps 开始
- Stop using MySQL online DDL
- MySQL database - stored procedures and functions
- In the background of the GBase 8c database, what command is used to perform the master-slave switchover operation for the gtm and dn nodes?
- 日志工厂(详细)
- Break the performance ceiling!AsiaInfo database supports more than 1 billion users, with a peak of one million transactions per second
猜你喜欢
随机推荐
ExcelPatternTool: Excel表格-数据库互导工具
How to query database configuration parameters in GBase 8c, such as datestyle.What function or syntax to use?
【LeetCode】Day109-the longest palindrome string
COS User Practice Call for Papers
力扣刷题之求两数之和
123123123123
Live chat system technology (8) : vivo live IM message module architecture practice in the system
【综述专栏】IJCAI 2022 | 图结构学习最新综述:研究进展与未来展望
DAO development tutorial [WEB3.0]
MySQL数据库————流程控制
7月30号|来一场手把手助您打造智能视觉新爆款的技术动手实验
[Server data recovery] Data recovery case of offline multiple disks in mdisk group of server Raid5 array
【pyqt5】自定义控件 实现能够保持长宽比地缩放子控件
C#/VB.NET Extract table from PDF
网站建设流程
屏:全贴合工艺之GFF、OGS、Oncell、Incell
明尼苏达大学团队结合高通量实验与机器学习,实现有效可预测的特定位点重组过程,可调节基因编辑速度
Prometheus's Recording rules practice
SaaS管理系统的应用优势在哪里?如何高效提升食品制造业数智化发展水平?
ClassID的计算中,&表示啥意思







