当前位置:网站首页>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;
}
边栏推荐
- 暑假第二周总结博客
- What is the JVM runtime data area and the JMM memory model
- [Kapok] #Summer Challenge# Hongmeng mini game project - Sudoku (3)
- Industry Salon Phase II丨How to enable chemical companies to reduce costs and increase efficiency through supply chain digital business collaboration?
- LeetCode 1374. Generate an odd number of each character string
- Stop using MySQL online DDL
- 在全志V853开发板试编译QT测试
- 【Translation】OpenMetrics cultivated by CNCF becomes an incubation project
- 硬件大熊原创合集(2022/07更新)
- Shell script topic (07): file from cfs to bos
猜你喜欢

在Map传值与对象传值中模糊查询

How many steps does it take to convert an ENS domain name into music?

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

MySQL中超键、主键及候选键的区别是什么

明尼苏达大学团队结合高通量实验与机器学习,实现有效可预测的特定位点重组过程,可调节基因编辑速度

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

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

Leetcode74. Search 2D Matrix

MySQL database - stored procedures and functions

483-82(23、239、450、113)
随机推荐
Flowable-based upp (unified process platform) running performance optimization
Leetcode75. 颜色分类
odoo coding conventions (programming conventions, coding guidelines)
Leetcode71. Simplified Paths
483-82 (23, 239, 450, 113)
【Translation】OpenMetrics cultivated by CNCF becomes an incubation project
Shell script topic (07): file from cfs to bos
odoo 编码规范(编程规范、编码指南)
SaaS管理系统的应用优势在哪里?如何高效提升食品制造业数智化发展水平?
A simple Flask PIN
The function realization of the national standard GB28181 protocol EasyGBS platform compatible with the old version of the inflow port
基于flowable的upp(统一流程平台)运行性能优化
AntDB database appeared in the 24th high-speed exhibition, helping smart high-speed innovative applications
Summer vacation second week wrap-up blog
无需破解,官网安装Visual Studio 2013社区版
How opencv implements image skew correction
How to solve the dynamic binding of el-form-item prop attribute does not take effect
以消费场景为驱动的CMDB要怎么建?
选择合适的 DevOps 工具,从理解 DevOps 开始
塔防海岸线用户协议