背景:

多个面数据(例如obj数据等)使用同一个Renderer通过增加多个Actor的方式是可以映射到一起的,但是如果透明度不是1的话深度层次会发生错乱。可以使用Renderer的UseDepthPeelingOn进行深度剥离,来使深度关系是正确的。

但是体数据通过这种方式是达不到深度关系正确的,类似于这种,是按照加入actor的顺序来排序的。

解决方案:

使用vtkMultiVolume来达到多个体数据在同一个空间映射的方案。

    vtkNew<vtkMultiVolume> overlappingVol;vtkNew<vtkGPUVolumeRayCastMapper> mapper;mapper->SetUseJittering(0);overlappingVol->SetMapper(mapper);//一个数据对应一个映射端口mapper->SetInputConnection(0, Source1->GetOutputPort());overlappingVol->SetVolume(vol, 0);mapper->SetInputConnection(1, Source2->GetOutputPort());overlappingVol->SetVolume(vol1, 1);

下图中左边与中间的体数据成功映射到了一起,深度关系也是正确的。

注意:

1、vtk-8.2.0版本中对volume开启阴影等效果是不起作用的。需要使用vtk-9.1.0以上的版本。

2、vtk-9.1.0版本使用的时候必须对volume设置梯度透明参数,哪怕不用从直接将插入的点透明度设置成1也要设置梯度透明参数,不然会报着色器错误。8.2.0版本不需要设置梯度透明也不会报错。

代码:

#include "vtkAxesActor.h"
#include "vtkCamera.h"
#include "vtkColorTransferFunction.h"
#include "vtkCommand.h"
#include "vtkConeSource.h"
#include "vtkGPUVolumeRayCastMapper.h"
#include "vtkImageResample.h"
#include "vtkImageResize.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkMultiVolume.h"
#include "vtkNew.h"
#include "vtkPiecewiseFunction.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkVolume16Reader.h"
#include "vtkVolumeProperty.h"
#include "vtkXMLImageDataReader.h"#include "vtkAbstractMapper.h"
#include "vtkImageData.h"
#include "vtkOutlineFilter.h"
#include "vtkPolyDataMapper.h"#include "vtkMath.h"
#include <chrono>void CamereTrans(vtkCamera* cam) {cam->SetFocalPoint(41.9596, -17.9662, 78.5903);cam->SetPosition(373.891, 619.954, -53.5932);cam->SetViewUp(-0.0358384, -0.184856, -0.982112);
}int main(int argc, char* argv[])
{double leftViewport[4] = { 0.0, 0.0, 0.33, 1.0 };double middleViewport[4] = { 0.33, 0.0, 0.66, 1.0 };double rightViewport[4] = { 0.66, 0.0, 1.0, 1.0 };// Load datavtkNew<vtkVolume16Reader> reader;reader->SetDataDimensions(64, 64);  //设置长和宽reader->SetImageRange(1, 93);  //设置切片张数reader->SetDataByteOrderToLittleEndian();reader->SetFilePrefix("headsq/quarter");reader->SetDataSpacing(3.2, 3.2, 1.5);vtkSmartPointer<vtkXMLImageDataReader> xmlReader = vtkSmartPointer<vtkXMLImageDataReader>::New();xmlReader->SetFileName("hncma-atlas.vti");xmlReader->Update();// Volume 0 (upsampled headmr)// ---------------------------vtkNew<vtkImageResize> headmrSource;headmrSource->SetInputConnection(reader->GetOutputPort());headmrSource->SetResizeMethodToOutputDimensions();headmrSource->SetOutputDimensions(128, 128, 128);headmrSource->Update();vtkNew<vtkVolumeProperty> volumeProperty;volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);volumeProperty->SetShade(0,1);  //打开或者关闭阴影测试volumeProperty->SetAmbient(0.8);volumeProperty->SetDiffuse(0.3);  //漫反射volumeProperty->SetSpecular(0.2); //镜面反射volumeProperty->SetSpecularPower(10);vtkNew<vtkColorTransferFunction> ctf;ctf->AddRGBPoint(0, 0.0, 0.0, 0.0);ctf->AddRGBPoint(500, 1.0, 0.5, 0.3);ctf->AddRGBPoint(1000, 1.0, 0.5, 0.3);ctf->AddRGBPoint(1150, 1.0, 1.0, 0.9);vtkNew<vtkPiecewiseFunction> pf;pf->AddPoint(0, 0.00);pf->AddPoint(500, 0.35);pf->AddPoint(1000, 0.75);pf->AddPoint(1150, 0.85);vtkNew<vtkPiecewiseFunction> gf;gf->AddPoint(0, 0.0);gf->AddPoint(90, 0.1);gf->AddPoint(100, 0.7);volumeProperty->SetScalarOpacity(pf);volumeProperty->SetColor(ctf);volumeProperty->SetGradientOpacity(gf);vtkNew<vtkVolume> vol;vol->SetProperty(volumeProperty);// Volume 1 (brain)// -----------------------------vtkNew<vtkVolumeProperty> volumeProperty1;volumeProperty1->SetInterpolationType(VTK_LINEAR_INTERPOLATION);vtkNew<vtkPiecewiseFunction> pf1;pf1->AddPoint(0, 0.0);pf1->AddPoint(2511, 0.5);pf1->AddPoint(5022, 1);vtkNew<vtkColorTransferFunction> ctf1;ctf1->AddRGBPoint(0, 1.0, 0.3, 0.2);ctf1->AddRGBPoint(2511, 0.3, 0.2, 0.9);ctf1->AddRGBPoint(5022, 0.5, 0.6, 1.0);vtkNew<vtkPiecewiseFunction> gf1;gf1->AddPoint(0, 0.0);gf1->AddPoint(550, 0.5);volumeProperty1->SetScalarOpacity(pf1);volumeProperty1->SetColor(ctf1);volumeProperty1->SetGradientOpacity(gf1);vtkNew<vtkVolume> vol1;vol1->SetProperty(volumeProperty1);vol1->SetScale(0.8, 0.8, 0.8);vol1->SetPosition(210., 200., -90.);vol1->RotateX(90.);vol1->RotateY(-95.);vol1->RotateZ(-5.);// Multi volume instance// ---------------------vtkNew<vtkMultiVolume> overlappingVol;vtkNew<vtkGPUVolumeRayCastMapper> mapper;mapper->SetUseJittering(0);overlappingVol->SetMapper(mapper);mapper->SetInputConnection(0, headmrSource->GetOutputPort());overlappingVol->SetVolume(vol, 0);mapper->SetInputConnection(1, xmlReader->GetOutputPort());overlappingVol->SetVolume(vol1, 1);// Rendering contextvtkNew<vtkRenderer> ren;ren->SetBackground(0.0, 0.0, 0.0);ren->SetViewport(rightViewport);ren->AddVolume(overlappingVol);CamereTrans(ren->GetActiveCamera());//left rendervtkNew<vtkGPUVolumeRayCastMapper> leftMapper;leftMapper->SetInputConnection(headmrSource->GetOutputPort());leftMapper->SetUseJittering(0);vtkNew<vtkVolume> leftVol;leftVol->SetProperty(volumeProperty);leftVol->SetMapper(leftMapper);vtkNew<vtkRenderer> leftren;leftren->SetBackground(0.0, 0.0, 0.0);leftren->SetViewport(leftViewport);leftren->AddVolume(leftVol);CamereTrans(leftren->GetActiveCamera());//middle rendervtkNew<vtkGPUVolumeRayCastMapper> middleMapper;middleMapper->SetInputConnection(xmlReader->GetOutputPort());middleMapper->SetUseJittering(0);vtkNew<vtkVolume> middleVol;middleVol->SetProperty(volumeProperty1);middleVol->SetMapper(middleMapper);vtkNew<vtkRenderer> middleren;middleren->SetBackground(0.0, 0.0, 0.0);middleren->SetViewport(middleViewport);middleren->AddVolume(middleVol);vtkNew<vtkRenderWindow> renWin;renWin->SetSize(1366, 512);renWin->AddRenderer(ren);renWin->AddRenderer(leftren);renWin->AddRenderer(middleren);renWin->SetMultiSamples(0);vtkNew<vtkRenderWindowInteractor> iren;iren->SetRenderWindow(renWin);vtkNew<vtkInteractorStyleTrackballCamera> style;iren->SetInteractorStyle(style);renWin->Render();iren->Initialize();iren->Start();return 0;
}

数据:

多个体数据映射到一起进行渲染的demo数据-C++文档类资源-CSDN文库

或者留下邮箱。

VTK实现多个体数据映射到一起进行渲染相关推荐

  1. VTK:标记数据映射器用法实战

    VTK:标记数据映射器用法实战 程序输出 程序完整源代码 程序输出 程序完整源代码 #include <vtkActor.h> #include <vtkActor2D.h> ...

  2. 映射到此登录名的用户_小课堂:什么是数据映射以及如何进行数据映射

    全文共1500字,预计学习时长5分钟 数据映射是数据处理的重要组成部分. 数据映射中的一个错误可以在组织中引起连锁反应,并由于重复的错误和不准确的分析对组织造成破坏. 因此,如果你不了解数据映射的重要 ...

  3. 使用FoundationDB高效地将SQL数据映射到NoSQL存储系统中

    NoSQL数据库 --FoundationDB的键-值存储系统 FoundationDB是一个分布式的键-值存储系统,支持全局ACID事务操作,并且性能出众.在安装系统时,可以指定数据分发的级别.数据 ...

  4. 数据源架构模式之数据映射器

    http://lobert.iteye.com/blog/2102312 前面分别介绍了数据源架构模式之表数据入口.数据源架构模式之行和数据入口数据源架构模式之活动记录,相较于这三种数据源架构模式,数 ...

  5. JNI学习开始篇 基础知识 数据映射及学习资料收集

    JNI学习开始篇 基础知识 数据映射及学习资料收集 JNI介绍 JNI(Java Native Interface) ,Java本地接口. 用Java去调用其他语言编写的程序,比如C或C++. JNI ...

  6. Elasticsearch的智能判断:动态添加数据映射

    Solr在新增数据时,只能使用提前配置好映射属性的字段,否则就会报错. 不过在Elasticsearch中并没有这样的规定. 事实上Elasticsearch非常智能,你不需要给索引库设置任何mapp ...

  7. 数据映射--平衡二叉有序树

    http://blog.sina.com.cn/s/blog_693f08470101mnna.html 上次我们提到了使用有序的数组来进行二分查找,从而提高映射查询的效率,使时间复杂度从O(n)降低 ...

  8. VTK:在多面体数据上使用裁剪和封盖用法实战

    VTK:在多面体数据上使用裁剪和封盖用法实战 程序输出 程序完整源代码 程序输出 程序完整源代码 #include <vtkActor.h> #include <vtkCamera. ...

  9. VTK:演示调用数据的用法实战

    VTK:演示调用数据的用法实战 程序输出 程序完整源代码 程序输出 程序完整源代码 #include <vtkActor.h> #include <vtkAppendPolyData ...

  10. iBatis.Net(C#)SQL数据映射

    转载请注明 http://www.cnblogs.com/13590/archive/2013/03/01/2938126.html 摘要:本文探讨了iBatis.Net框架的XML数据映射文件各配置 ...

最新文章

  1. BZOJ 1040 ZJOI2008 骑士 树形DP
  2. SpringBoot系列二:搭建自己的第一个SpringBoot程序
  3. 京东8.27算法笔试-滚雪球(动态规划python)
  4. c++hello world代码_在 Rust 代码中编写 Python 是种怎样的体验?
  5. 山寨今日头条的标题title效果
  6. VMWare 安装 Eclipse
  7. 记一次理想浪漫的毕旅
  8. jpg png webp_为在线图像删除PNG和JPG:使用WebP
  9. JavaScript字符串判断某个字符是否存在
  10. Python+OpenCV:直方图均衡化(Histogram Equalization)
  11. Debian - NFS搭建 + 测试
  12. 中国34个省级行政区2000年-2021年逐月NDVI统计分析结果
  13. 计算机硬盘的参数错误,电脑提示移动硬盘参数错误的解决方法
  14. JQUERY本地自动保存插件Sisyphus.js
  15. 粗同步 符号同步 matlab,OFDM系统在衰落信道中帧同步算法研究(毕业论文)
  16. BUUCTF之Ping Ping Ping
  17. 图片转文字、视频转文字 超赞网页分享
  18. ubuntu卡在无限循环登录界面,进不去桌面的问题#不重装是我们最后的倔强!#
  19. u盘启动 联想一体机_联想一体机如何设置U盘启动
  20. 使用wget下载GEO数据

热门文章

  1. 山东CIO智库——山东省两化融合深度行龙口站成功举办
  2. 马未都说收藏:陶瓷篇(3、4、5)宋瓷-官窑-汝官哥钧定
  3. 超有范的 logo 在线设计制作工具
  4. 一个不超过200行的游戏
  5. vb.net 教程 3-4 窗体编程 公共控件7 DateTimePicker MonthCalendar
  6. 不用找了,大厂在用的分库分表方案,都在这了
  7. 一份完整的 IPv6 环境下 DNS 相关测试
  8. spoon链接本地的db2报错
  9. base64格式转换成普通png格式
  10. python3 import的一个细节