当前位置:网站首页>vtk体绘制代码报错的解决办法(代码在vtk7,8,9中都能运行),以及VTK数据集网站
vtk体绘制代码报错的解决办法(代码在vtk7,8,9中都能运行),以及VTK数据集网站
2022-08-01 18:56:00 【宗浩多捞】
链接:vtk7.1.1官方文档
链接:官方示例代码
链接:VTK资源网站(需要什么资源搜索就行,官网示例中的数据集、资源基本都有)
体绘制代码运行不了,一直报错的解决方案
- 大家应该都看过VTK图形图像进阶那本书了,那本书的VTK版本为5.10.1,随书代码中体绘制部分在VTK7 8 9版本中是不能运行的,需要稍微改一些东西(没有《VTK图形图像进阶》这本书和随书代码的可以找我私聊,我可以发百度网盘)
- 还需要注意添加:
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(); //打开或者关闭光照着色
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);//设置梯度不透明度效果对比
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;
}
边栏推荐
猜你喜欢

el-form-item prop属性动态绑定不生效如何解决

在表格数据上,为什么基于树的模型仍然优于深度学习?

Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读

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

Prometheus's Recording rules practice

电商库存系统的防超卖和高并发扣减方案

无需破解,官网安装Visual Studio 2013社区版

30分钟成为Contributor|如何多方位参与OpenHarmony开源贡献?
![[Neural Network] This article will take you to easily analyze the neural network (with an example of spoofing your girlfriend)](/img/2c/18ce72dfd0889d901ea0d95721ed19.png)
[Neural Network] This article will take you to easily analyze the neural network (with an example of spoofing your girlfriend)

网站建设流程
随机推荐
Flowable-based upp (unified process platform) running performance optimization
MySQL数据库————存储过程和函数
WinRAR | 将多个安装程序生成一个安装程序
SQL函数 TO_DATE(一)
安徽建筑大学&杭州电子科技大学|基于机器学习方法的建筑可再生能源优化控制
将ENS域名转化为音乐需要几步?
#yyds dry goods inventory# Interview must brush TOP101: the last k nodes in the linked list
Zabbix6.0 DingTalk robot alarm
[Kapok] #Summer Challenge# Hongmeng mini game project - Sudoku (3)
重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
When compiling a program with boost library with VS2013, it prompts fatal error C1001: An internal error occurred in the compiler
Leetcode74. Search 2D Matrix
如何让固定点的监控设备在EasyCVR平台GIS电子地图上显示地理位置?
【木棉花】#夏日挑战赛# 鸿蒙小游戏项目——数独Sudoku(3)
odoo+物联网
C#/VB.NET Extract table from PDF
暑假第二周总结博客
生命周期和作用域
Screenshot of Selenium in Remote
kubernetes-部署nfs存储类