【VTK三维重建-体绘制】第五期 vtkLODProp3D

很高兴在雪易的CSDN遇见你 

VTK技术爱好者 QQ:870202403


前言

本文分享VTK中体绘制中的vtkLODProp3D对象,希望对各位小伙伴有所帮助!

感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步!

你的点赞就是我的动力(^U^)ノ~YO

  


1. vtkLODProp3D

        vtkLODProp3D与vtkVolume用法类似,两者均继承自vtkProp3D。但vtkLODProp3D支持多个Mapper、Property和Texture对象,并由它选择Mapper对象实现绘制。例如,当绘制一个数据量非常大的不规则网格数据时,可以添加一个vtkPolyDataMapper来渲染一个表面模型,作为最低级别分辨率的渲染;然后将数据采样为vtkImageData数据,并添加一个vtkVolumeTextureMapper3D进行体绘制,作为一个中等级别渲染;最后通过ZSweep技术(vtkUnstructureGridVolumeZSWeepMapper)渲染原始数据,作为最高级别的渲染。vtkLODProp3D在渲染过程中,会为每一个Mapper估计一个渲染时间,并选择一个最优的实现渲染。

        其重要参数有:

1.1 获取边界包围盒

  /*** Standard vtkProp method to get 3D bounds of a 3D prop*/double* GetBounds() VTK_SIZEHINT(6) override;void GetBounds(double bounds[6]) { this->vtkProp3D::GetBounds(bounds); }

1.2 添加不同级别的Mapper

  //@{/*** 添加不同级别的的映射器、属性、背面属性、纹理和渲染时间。* 属性和纹理字段可以设置为NULL(其他方法包含在不允许NULL变量的脚本访问中)。* time字段可以设置为0.0,表示没有提供渲染时间的初始猜测。* 返回的整数值是一个ID,稍后可以使用该ID删除该LOD,或者将其设置为所选LOD。* Add a level of detail with a given mapper, property, backface property,* texture, and guess of rendering time.  The property and texture fields* can be set to NULL (the other methods are included for script access* where null variables are not allowed). The time field can be set to 0.0* indicating that no initial guess for rendering time is being supplied.* The returned integer value is an ID that can be used later to delete* this LOD, or set it as the selected LOD.*/int AddLOD(vtkMapper* m, vtkProperty* p, vtkProperty* back, vtkTexture* t, double time);int AddLOD(vtkMapper* m, vtkProperty* p, vtkTexture* t, double time);int AddLOD(vtkMapper* m, vtkProperty* p, vtkProperty* back, double time);int AddLOD(vtkMapper* m, vtkProperty* p, double time);int AddLOD(vtkMapper* m, vtkTexture* t, double time);int AddLOD(vtkMapper* m, double time);int AddLOD(vtkAbstractVolumeMapper* m, vtkVolumeProperty* p, double time);int AddLOD(vtkAbstractVolumeMapper* m, double time);int AddLOD(vtkImageMapper3D* m, vtkImageProperty* p, double time);int AddLOD(vtkImageMapper3D* m, double time);//@}

1.3 获取LOD数量及当前Index

  //@{/*** Get the current number of LODs.*/vtkGetMacro(NumberOfLODs, int);//@}//@{/*** Get the current index, used to determine the ID of the next LOD that is* added.  Useful for guessing what IDs have been used (with NumberOfLODs,* without depending on the constructor initialization to 1000.*/vtkGetMacro(CurrentIndex, int);//@}

1.4 删除指定Index的LOD

  /*** Delete a level of detail given an ID. This is the ID returned by the* AddLOD method*/void RemoveLOD(int id);

1.5 获取指定Index的属性

  //@{/*** Methods to set / get the property of an LOD. Since the LOD could be* a volume or an actor, you have to pass in the pointer to the property* to get it. The returned property will be NULL if the id is not valid,* or the property is of the wrong type for the corresponding Prop3D.*/void SetLODProperty(int id, vtkProperty* p);void GetLODProperty(int id, vtkProperty** p);void SetLODProperty(int id, vtkVolumeProperty* p);void GetLODProperty(int id, vtkVolumeProperty** p);void SetLODProperty(int id, vtkImageProperty* p);void GetLODProperty(int id, vtkImageProperty** p);//@}

1.6 设置/获取Mapper

  //@{/*** Methods to set / get the mapper of an LOD. Since the LOD could be* a volume or an actor, you have to pass in the pointer to the mapper* to get it. The returned mapper will be NULL if the id is not valid,* or the mapper is of the wrong type for the corresponding Prop3D.*/void SetLODMapper(int id, vtkMapper* m);void GetLODMapper(int id, vtkMapper** m);void SetLODMapper(int id, vtkAbstractVolumeMapper* m);void GetLODMapper(int id, vtkAbstractVolumeMapper** m);void SetLODMapper(int id, vtkImageMapper3D* m);void GetLODMapper(int id, vtkImageMapper3D** m);//@}/*** Get the LODMapper as an vtkAbstractMapper3D.  It is the user's* respondibility to safe down cast this to a vtkMapper or vtkVolumeMapper* as appropriate.*/vtkAbstractMapper3D* GetLODMapper(int id);

1.7 获取Backface属性

  //@{/*** Methods to set / get the backface property of an LOD. This method is only* valid for LOD ids that are Actors (not Volumes)*/void SetLODBackfaceProperty(int id, vtkProperty* t);void GetLODBackfaceProperty(int id, vtkProperty** t);//@}

1.8 获取纹理

  //@{/*** Methods to set / get the texture of an LOD. This method is only* valid for LOD ids that are Actors (not Volumes)*/void SetLODTexture(int id, vtkTexture* t);void GetLODTexture(int id, vtkTexture** t);//@}

1.9 EnableLOD

  //@{/*** Enable / disable a particular LOD. If it is disabled, it will not* be used during automatic selection, but can be selected as the* LOD if automatic LOD selection is off.*/void EnableLOD(int id);void DisableLOD(int id);int IsLODEnabled(int id);//@}

1.10 设置LOD的级别

  //@{/*** 设置特定LOD的级别。当选择一个LOD进行渲染时,因为它在分配的时间内具有最大的渲染时间,* 然后检查所有LOD,看看是否有任何LOD可以渲染得更快,但具有较低(更高分辨率/更好)的级别。* 该数量为双精度,以确保可以插入2和3之间* Set the level of a particular LOD. When a LOD is selected for* rendering because it has the largest render time that fits within* the allocated time, all LOD are then checked to see if any one can* render faster but has a lower (more resolution/better) level.* This quantity is a double to ensure that a level can be inserted* between 2 and 3.*/void SetLODLevel(int id, double level);double GetLODLevel(int id);double GetLODIndexLevel(int index);//@}

1.11 获取指定Index的LOD渲染时间

  //@{/*** Access method that can be used to find out the estimated render time* (the thing used to select an LOD) for a given LOD ID or index.* Value is returned in seconds.*/double GetLODEstimatedRenderTime(int id);double GetLODIndexEstimatedRenderTime(int index);//@}

1.12 开启/关闭自动选择渲染的LOD

  //@{/*** 开启/关闭自动选择LOD。默认为开启。* 如果它是关闭的,那么无论呈现时间或所需的更新速率如何,都会呈现SelectedLODID。* Turn on / off automatic selection of LOD.* This is on by default. If it is off, then the SelectedLODID is* rendered regardless of rendering time or desired update rate.*/vtkSetClampMacro(AutomaticLODSelection, vtkTypeBool, 0, 1);vtkGetMacro(AutomaticLODSelection, vtkTypeBool);vtkBooleanMacro(AutomaticLODSelection, vtkTypeBool);//@}

1.13 设置选择的ID

  //@{/*** Set the id of the LOD that is to be drawn when automatic LOD selection* is turned off.*/vtkSetMacro(SelectedLODID, int);vtkGetMacro(SelectedLODID, int);//@}

1.14 返回对象

  //@{/*** For some exporters and other other operations we must be* able to collect all the actors or volumes. These methods* are used in that process.*/void GetActors(vtkPropCollection*) override;void GetVolumes(vtkPropCollection*) override;//@}

1.15 开始/关闭自动拾取LOD

  //@{/*** 开启/关闭自动Pick的LOD。默认是开启的。* 如果它是关闭的,那么无论呈现时间或所需的更新速率如何,都会呈现SelectedLODID。* Turn on / off automatic selection of picking LOD.* This is on by default. If it is off, then the SelectedLODID is* rendered regardless of rendering time or desired update rate.*/vtkSetClampMacro(AutomaticPickLODSelection, vtkTypeBool, 0, 1);vtkGetMacro(AutomaticPickLODSelection, vtkTypeBool);vtkBooleanMacro(AutomaticPickLODSelection, vtkTypeBool);//@}

1.16 设置选择Pick的LOD Index

  //@{/*** Set the id of the LOD that is to be used for picking when automatic* LOD pick selection is turned off.*/void SetSelectedPickLODID(int id);vtkGetMacro(SelectedPickLODID, int);//@}

注意:vtkVolumeTextureMapper3D在9.0.3及以后的版本中已不存在,由vtkOpenGLGPUVolumeRayCastMapper代替。

2. 示例

      

#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkLODProp3D.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkSphereSource.h>
#include <vtkCallbackCommand.h>
#include <vtkProperty.h>void RefreshCallback( vtkObject* vtkNotUsed(caller),long unsigned int vtkNotUsed(eventId),void* clientData,void* vtkNotUsed(callData) )
{vtkSmartPointer<vtkLODProp3D> lodProp = static_cast<vtkLODProp3D*>(clientData);std::cout << "Last rendered LOD: " << lodProp->GetLastRenderedLODID() << std::endl;
}int main (int, char *[])
{// High res spherevtkSmartPointer<vtkSphereSource> highResSphereSource = vtkSmartPointer<vtkSphereSource>::New();int res = 100;highResSphereSource->SetThetaResolution(res);highResSphereSource->SetPhiResolution(res);highResSphereSource->Update();vtkSmartPointer<vtkPolyDataMapper> highResMapper = vtkSmartPointer<vtkPolyDataMapper>::New();highResMapper->SetInputConnection(highResSphereSource->GetOutputPort());// Low res spherevtkSmartPointer<vtkSphereSource> lowResSphereSource = vtkSmartPointer<vtkSphereSource>::New();vtkSmartPointer<vtkPolyDataMapper> lowResMapper = vtkSmartPointer<vtkPolyDataMapper>::New();lowResMapper->SetInputConnection(lowResSphereSource->GetOutputPort());vtkSmartPointer<vtkProperty> propertyLowRes = vtkSmartPointer<vtkProperty>::New();propertyLowRes->SetDiffuseColor(0.89, 0.81, 0.34);propertyLowRes->SetInterpolationToFlat();vtkSmartPointer<vtkProperty> propertyHighRes = vtkSmartPointer<vtkProperty>::New();propertyHighRes->SetDiffuseColor(1.0, 0.3882, 0.2784);propertyHighRes->SetInterpolationToFlat();vtkSmartPointer<vtkLODProp3D> prop = vtkSmartPointer<vtkLODProp3D>::New();prop->AddLOD(lowResMapper, propertyLowRes, 0.0);prop->AddLOD(highResMapper, propertyHighRes, 0.0);std::cout << "There are " << prop->GetNumberOfLODs() << " LODs" << std::endl;// A renderer and render windowvtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();renderWindow->AddRenderer(renderer);//prop->SetAllocatedRenderTime(1e-6,renderer);prop->SetAllocatedRenderTime(1e-10,renderer);// An interactorvtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();renderWindowInteractor->SetRenderWindow(renderWindow);// Add the actors to the scenerenderer->AddActor(prop);vtkSmartPointer<vtkCallbackCommand> refreshCallback =vtkSmartPointer<vtkCallbackCommand>::New();refreshCallback->SetCallback (RefreshCallback);refreshCallback->SetClientData(prop);renderWindow->AddObserver(vtkCommand::ModifiedEvent,refreshCallback);renderWindow->Render();// Begin mouse interactionrenderWindowInteractor->Start();return EXIT_SUCCESS;
}

结论:

感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步!

你的赞赏是我的最最最最大的动力(^U^)ノ~YO

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/321430.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

力扣-42.接雨水

题目&#xff1a; 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图&#xff0c;计算按此排列的柱子&#xff0c;下雨之后能接多少雨水。 示例 1&#xff1a; 输入&#xff1a;height [0,1,0,2,1,0,1,3,2,1,2,1] 输出&#xff1a;6 解释&#xff1a;上面是由数组[0,1,0,2…

水稻潜在产量估算解决方案

1.背景与技术路线 统计资料表明&#xff0c;尽管我国粮食单产已由 50 年代初期的 1.2t/ha 增加到如今的 5.2t/h&#xff0c;粮食产量增加了 4 倍&#xff0c;但我国人口的增长速度与气候变化导致的农业生产的不确定性&#xff0c; 在水稻收获指数保持稳定的情况下&#xff0c;…

话不多说,在Linux上完成Python从源码编译安装全流程

话不多说&#xff0c;直接上代码&#xff1a; # 安装工具链&#xff0c;如果已装完请跳过 sudo apt-get install -y gcc g make cmake zlib1g zlib1g-dev libbz2-dev libsqlite3-dev libssl-dev libxslt1-dev libffi-dev unzip pciutils net-tools libncursesw5-dev# 把需要安…

从vue小白到高手,从一个内容管理网站开始实战开发第六天,登录功能后台功能设计--API项目中的登录实现(一)

从vue小白到高手,从一个内容管理网站开始实战开发第五天,登录功能后台功能设计--数据库与API项目-CSDN博客文章浏览阅读348次,点赞9次,收藏7次。本次文章主要讲了开发后台API项目给前台vue调用的话,需要使用的数据库并新建数据库和表、安装开发工具、如何创建API项目以及A…

mysql死锁排查

查看正在进行中的事务 SELECT * FROM information_schema.INNODB_TRX;字段解释trx_id唯一事务id号&#xff0c;只读事务和非锁事务是不会创建id的trx_state事务的执行状态&#xff0c;值一般分为&#xff1a;RUNNING, LOCK WAIT, ROLLING BACK, and COMMITTING.trx_started事务…

私域和微商有什么区别?

私域和微商到底有什么区别呢&#xff1f;其实这两个东西有着本质性区别。 私域&#xff1a; 通过原有商业或者新媒体方式获取粉丝或顾客&#xff0c;然后用微信等社交工具&#xff0c;多方位展现&#xff0c;人格专业。 最终目标是让粉丝或顾客成为品牌或IP的朋友&#xff0…

3个.NET开源简单易用的任务调度框架

前言 今天分享3个.NET开源、简单、易用的任务调度框架&#xff0c;帮助大家在做定时任务调度框架技术选型的时候有一个参考。 Quartz.Net Quartz.NET是一个功能齐全的开源作业调度系统&#xff0c;可用于从最小的应用程序到大规模企业系统。 Quartz.NetUI Quartz.NetUI是一…

HackTheBox - Medium - Linux - BroScience

BroScience BroScience 是一款中等难度的 Linux 机器&#xff0c;其特点是 Web 应用程序容易受到“LFI”的攻击。通过读取目标上的任意文件的能力&#xff0c;攻击者可以深入了解帐户激活码的生成方式&#xff0c;从而能够创建一组可能有效的令牌来激活新创建的帐户。登录后&a…

Linux之IP地址、主机名、域名解析

一、IP地址 可以通过ifconfig命令查看本机的ip地址&#xff0c;如果无法使用ifconfig命令&#xff0c;可以安装 安装&#xff1a;yum -y install net-tools ens33&#xff1a;主网卡&#xff0c;里面的inet就是ip地址 lo&#xff1a;本地回环网卡&#xff0c;127.0.0.1&…

202365读书笔记|《温暖和百感交集的旅程》——时间帮助着一个人的一生在几千字的篇幅里栩栩如生

202365读书笔记|《温暖和百感交集的旅程》——时间帮助着一个人的一生在几千字的篇幅里栩栩如生 我能否相信自己温暖和百感交集的旅程前言和后记 《温暖和百感交集的旅程》作者余华&#xff0c;之前读完的一本书&#xff0c;已经不太记得内容了&#xff0c;看着笔记整理的这篇书…

LangChain初学者指南

LLM可以帮助我们将AI能力接入应用&#xff0c;LangChain作为开源工具&#xff0c;提供了接入各种主流LLM的接口&#xff0c;从而让我们以非常低的成本构建基于LLM的AI应用。原文: Getting Started with LangChain: A Beginner’s Guide to Building LLM-Powered Applications 自…

EViews13安装包下载及安装教程

EViews 13下载链接&#xff1a;https://docs.qq.com/doc/DUndYV3FxZkd0d0dI 1.选择下载好的安装包&#xff0c;鼠标右键解压到“EViews13”文件夹 2.打开文件夹 3.选择“13Installer(64-bit).exe”鼠标右键“以管理员身份运行” 4.点击“Install” 5.软件正在初始化 6.点击“N…