【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 sphere
  vtkSmartPointer<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 sphere
  vtkSmartPointer<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 window
  vtkSmartPointer<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 interactor
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  // Add the actors to the scene
  renderer->AddActor(prop);
  
  vtkSmartPointer<vtkCallbackCommand> refreshCallback =
    vtkSmartPointer<vtkCallbackCommand>::New();
  refreshCallback->SetCallback (RefreshCallback);
  refreshCallback->SetClientData(prop);

  renderWindow->AddObserver(vtkCommand::ModifiedEvent,refreshCallback);
  
  renderWindow->Render();

  // Begin mouse interaction
  renderWindowInteractor->Start();
  
  return EXIT_SUCCESS;
}

结论:

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

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

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【数据挖掘】基于 LightGBM 的系统访问风险识别(附源码)

基于 LightGBM 的系统访问风险识别 文章目录 基于 LightGBM 的系统访问风险识别一、课题来源二、任务描述三、课题背景四、数据获取分析及说明&#xff08;1&#xff09;登录https://www.datafountain.cn并获取相关数据&#xff08;2&#xff09;数据集文件说明&#xff08;3&a…

好代码网同款wordpress主题,适合搭建资源分享类网站,自带五六百的精品资源数据

代码简介&#xff1a; 好代码资源网是个还不错的资源分享类网站&#xff0c;基于wordpress搭建的。它的主题看起来还是不错的。这里分享一下这个网站的主题包。说是主题包&#xff0c;其实就是整站打包的&#xff0c;集成了主题&#xff08;wordpress美化主题包几个插件&#…

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

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

05-微服务-RabbitMQ-概述

RabbitMQ 1.初识MQ 1.1.同步和异步通讯 微服务间通讯有同步和异步两种方式&#xff1a; 同步通讯&#xff1a;就像打电话&#xff0c;需要实时响应。 异步通讯&#xff1a;就像发邮件&#xff0c;不需要马上回复。 两种方式各有优劣&#xff0c;打电话可以立即得到响应&am…

深入解析美颜SDK:绿幕抠图功能的算法原理

当下&#xff0c;美颜SDK绿幕抠图功能成为许多应用中不可或缺的一环。本文将深入解析美颜SDK中绿幕抠图功能的算法原理&#xff0c;揭示其背后的技术奥秘。 一、什么是美颜SDK绿幕抠图&#xff1f; 美颜SDK的绿幕抠图功能是一种通过计算机视觉技术&#xff0c;将视频或图像中…

十六:爬虫-验证码与字体反爬

一&#xff1a;验证码 验证码&#xff08;CAPTCHA&#xff09;是一种计算机程序设计技术&#xff0c;用于确定用户是人类而不是机器。它通常表现为一种图像或声音&#xff0c;要求用户在输入框中输入正确的文本或数字来证明自己是人类。因为机器人和计算机程序无法像人类一样理…

《深入理解C++11:C++11新特性解析与应用》笔记八

第八章 融入实际应用 8.1 对齐支持 8.1.1 数据对齐 c可以通过sizeof查询数据的长度&#xff0c;但是没有对对齐方式有关的查询或者设定进行标准化。c11标准定义的alignof函数可以查看数据的对齐方式。 现在的计算机通常会支持许多向量指令&#xff0c;4组8字节的浮点数据&a…

C++ namespace 学习

源自&#xff1a;【C】-命名空间的概念及使用_命名空间的概念及作用-CSDN博客 摘抄&#xff1a;

ISP 基础知识积累

Amber&#xff1a;现有工作必要的技术补充&#xff0c;认识需要不断深入&#xff0c;这个文档后续还会增加内容进行完善。 镜头成像资料 ——干货满满&#xff0c;看懂了这四篇文章&#xff0c;下面的问题基本都能解答 看完思考 1、ISP 是什么&#xff0c;有什么作用&#xff…

加密算法和身份认证

前瞻概念 在了解加密和解密的过程前&#xff0c;我们先了解一些基础概念 明文&#xff1a;加密前的消息叫 “明文” &#xff08;plain text&#xff09;密文: 加密后的文本叫 “密文” (cipher text)密钥: 只有掌握特殊“钥匙”的人&#xff0c;才能对加密的文本进行解密,这里…

前端实战第一期:悬浮动画

悬浮动画 像这样的悬浮动画该怎么做&#xff0c;让我们按照以下步骤完成 步骤&#xff1a; 先把HTML内容做起来&#xff0c;用button属性创建一个按钮&#xff0c;按钮内写上悬浮效果 <button classbtn>悬浮动画</button>在style标签内设置样式,先设置盒子大小&…

显示所有中国城市需要多少个汉字?

显示所有中国城市需要多少个汉字呢&#xff1f; 需要3678个汉字&#xff0c;看看我怎么知道的。 第一步&#xff1a;先找到中国的所有城市的名称 去哪里找到中国的所有城市的名称呢&#xff1f; 进入中国天气网&#xff1a;http://www.weather.com.cn/ 使用 F12 打开浏览器的调…

使用results.csv文件数据绘制mAP对比图

yolov5每次train完成&#xff08;如果没有中途退出&#xff09;都会在run目录下生成expX目录&#xff08;X代表生成结果次数 第一次训练完成生成exp0 第二次生成exp1…以此类推&#xff09;。expX目录下会保存训练生成的weights以及result.txt文件&#xff0c;其中weights是训练…

【MFC】计算机图形学实验:熟悉开发环境及工具(代码)

实验内容&#xff1a; 【MFC】计算机图形学实验1&#xff1a;熟悉开发环境及工具_绘制多义线mfc-CSDN博客 画笔和字体只给出两处代码&#xff1a; //创建刷子&#xff0c;设置填充色为黑色 CBrush NewBrush; NewBrush.CreateSolidBrush(RGB(0, 0, 0)); pDC->SelectObjec…

excel公式名称管理器

1.问题 在日常使用excel的时候&#xff0c;发布一个表格文件&#xff0c;需要限制表格的某列或某行只能从我们提供的选项中选择&#xff0c;自己随便填写视为无效&#xff0c;如下图所示&#xff0c;上午的行程安排只能从"在岗"、"出差"、"病假"…

seo分享:慎重使用蜘蛛池

其实要提高搜索引擎蜘蛛的来访次数&#xff0c;唯一的方法还是要通过网站本身的内容更新。频繁更新有质量的内容&#xff0c;才能够提高蜘蛛的来访次数。如果本身内容更新不多&#xff0c;外部引流的蜘蛛过多&#xff0c;最终发现没什么内容索引&#xff0c;蜘蛛来访的次数也会…

x-cmd pkg | 比 du 更好用的查看磁盘空间工具:dust

目录 简介首次用户技术特点竞品和相关作品进一步探索 简介 Dust 是一个用于分析磁盘空间使用情况的命令行工具&#xff0c;旨在提供直观的磁盘分布信息&#xff0c;它的名字是由 “du” 和 Rust 编程语言组合而来。 Dust 的主要功能是提供实时的磁盘空间概览&#xff0c;并以…

华为HCIE-Datacom课程介绍

厦门微思网络HCIE-Datacom课程介绍 一、认证简介 HCIE-Datacom&#xff08;Huawei Certified ICT Expert-Datacom&#xff09;认证是华为认证体系中的顶级认证&#xff0c;HCIE-Datacom认证定位具备坚实的企业网络跨场景融合解决方案理论知识&#xff0c;能够使用华为数通产品…

数据库存储过程

存储过程(特定功能的 SQL 语句集) 一组为了完成特定功能的 SQL 语句集&#xff0c;存储在数据库中&#xff0c;经过第一次编译后再次调用不需要再次编译&#xff0c;用户通过指定存储过程的名字并给出参数&#xff08;如果该存储过程带有参数&#xff09;来执行它。存储过程是…

计算机视觉入门与调优

大家好啊&#xff0c;我是董董灿。 在 CSDN 上写文章写了有一段时间了&#xff0c;期间不少小伙伴私信我&#xff0c;咨询如何自学入门AI&#xff0c;或者咨询一些AI算法。 90%的问题我都回复了&#xff0c;但有时确实因为太忙&#xff0c;没顾得过来。 在这个过程中&#x…
最新文章