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

news/2024/7/21 5:44:38 标签: 算法, VTK, 图像处理, qt

很高兴在雪易的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.niftyadmin.cn/n/5303805.html

相关文章

stm32学习总结:5、Proteus8+STM32CubeMX+MDK仿真串口并使用串口打印日志(注意重定向printf到串口打印的问题)

stm32学习总结&#xff1a;5、Proteus8STM32CubeMXMDK仿真串口并使用串口打印日志&#xff08;注意重定向printf到串口打印的问题&#xff09; 文章目录 stm32学习总结&#xff1a;5、Proteus8STM32CubeMXMDK仿真串口并使用串口打印日志&#xff08;注意重定向printf到串口打印…

在页面中获取iframe中window对象,在iframe中获取上级window对象

1 在页面中获取iframe中window对象 const iframedocument.getElementById("myiframe") iframe.contentWindow 获取iframe中的window对象 iframe.contentDocument 获取iframe中的document对象2 在iframe中获取上级window对象 window.parent 获取上一级的windo…

Word与Excel对应的Python 函数库

本文主要讲Word与Excel格式的文件 Word 格式与 Python 函数库 Python 操作 Word 格式的库是 python-docx 库 安装与导入方法 pip install python-docx ... import docx Excel 格式与 Python 函数库 xlsx 格式⼀般采⽤ openpyxl 进⾏读写如果是 xls 格式&#xff0c;对 Wor…

Python实现观察者模式

观察者模式是一种设计模式&#xff0c;其中一个对象&#xff08;称为主题&#xff09;维护一组依赖于它的对象&#xff08;称为观察者&#xff09;&#xff0c;当主题的状态发生变化时&#xff0c;它会通知所有观察者。这种模式常用于实现分布式事件处理系统。 下面是一个简单…

探索计算机视觉CV领域的顶级期刊和会议

引言 简要介绍计算机视觉的重要性以及跟踪领域最新研究的必要性。提出期刊和会议是获取最新信息和研究成果的重要途径。 顶级期刊 Nature Machine Intelligence 重点&#xff1a;跨学科的机器智能研究&#xff0c;包括计算机视觉​​。 【Nature 官方网站】优点&#xff1a;…

Kasada p.js (x-kpsdk-cd、x-kpsdk-ct、integrity)

提供x-kpsdk-cd的API服务 详细请私信~ 可试用~ V:zhzhsgg 一、简述 integrity是通过身份验证Kasada检测机器人流量后获得的一个检测结果&#xff08;数据完整性&#xff09; x-kpsdk-cd 是经过编码计算等等获得。当你得到正确的解决验证码值之后&#xff0c;解码会看到如下图…

VSCode上远程调试代码出现的问题

记录一下&#xff1a; 真的是汗流浃背了&#xff0c;师妹叫帮忙如何在VSCode上远程调试代码&#xff0c;一些自己已经经历过的问题&#xff0c;现在已经忘记了。又在网上一顿搜索&#xff0c;这次记录下吧。。。 出现以下问题&#xff1a; 1. 终端界面总是sh-4.4 $ &#xff…

杨中科 ASP.NETCore开发效率利器 HOT RELOAD

HOT RELOAD 1、困惑:修改了服务器端的代码&#xff0c;必须重新运行程序。 2、方法1: [启动 (不调试) ] 3、方法2: .NET 6开始的Hot Reload(热重载) 正常修改代码后 不重启&#xff0c;是无法看到新的数据展示在页面 修改 运行结果&#xff1a; 方式一&#xff1a;设置开始…