网站开发工作室策划案,域名的价格,餐厅网站模板,网校网站毕业设计的方案很高兴在雪易的CSDN遇见你
VTK技术爱好者 QQ#xff1a;870202403 前言
本文分享VTK中体绘制中的vtkLODProp3D对象#xff0c;希望对各位小伙伴有所帮助#xff01;
感谢各位小伙伴的点赞关注#xff0c;小易会继续努力分享#xff0c;一起进步#xff01;
你的点赞…很高兴在雪易的CSDN遇见你
VTK技术爱好者 QQ870202403 前言
本文分享VTK中体绘制中的vtkLODProp3D对象希望对各位小伙伴有所帮助
感谢各位小伙伴的点赞关注小易会继续努力分享一起进步
你的点赞就是我的动力()ノ~ 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 users* 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.hvoid RefreshCallback( vtkObject* vtkNotUsed(caller),long unsigned int vtkNotUsed(eventId),void* clientData,void* vtkNotUsed(callData) )
{vtkSmartPointervtkLODProp3D lodProp static_castvtkLODProp3D*(clientData);std::cout Last rendered LOD: lodProp-GetLastRenderedLODID() std::endl;
}int main (int, char *[])
{// High res spherevtkSmartPointervtkSphereSource highResSphereSource vtkSmartPointervtkSphereSource::New();int res 100;highResSphereSource-SetThetaResolution(res);highResSphereSource-SetPhiResolution(res);highResSphereSource-Update();vtkSmartPointervtkPolyDataMapper highResMapper vtkSmartPointervtkPolyDataMapper::New();highResMapper-SetInputConnection(highResSphereSource-GetOutputPort());// Low res spherevtkSmartPointervtkSphereSource lowResSphereSource vtkSmartPointervtkSphereSource::New();vtkSmartPointervtkPolyDataMapper lowResMapper vtkSmartPointervtkPolyDataMapper::New();lowResMapper-SetInputConnection(lowResSphereSource-GetOutputPort());vtkSmartPointervtkProperty propertyLowRes vtkSmartPointervtkProperty::New();propertyLowRes-SetDiffuseColor(0.89, 0.81, 0.34);propertyLowRes-SetInterpolationToFlat();vtkSmartPointervtkProperty propertyHighRes vtkSmartPointervtkProperty::New();propertyHighRes-SetDiffuseColor(1.0, 0.3882, 0.2784);propertyHighRes-SetInterpolationToFlat();vtkSmartPointervtkLODProp3D prop vtkSmartPointervtkLODProp3D::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 windowvtkSmartPointervtkRenderer renderer vtkSmartPointervtkRenderer::New();vtkSmartPointervtkRenderWindow renderWindow vtkSmartPointervtkRenderWindow::New();renderWindow-AddRenderer(renderer);//prop-SetAllocatedRenderTime(1e-6,renderer);prop-SetAllocatedRenderTime(1e-10,renderer);// An interactorvtkSmartPointervtkRenderWindowInteractor renderWindowInteractor vtkSmartPointervtkRenderWindowInteractor::New();renderWindowInteractor-SetRenderWindow(renderWindow);// Add the actors to the scenerenderer-AddActor(prop);vtkSmartPointervtkCallbackCommand refreshCallback vtkSmartPointervtkCallbackCommand::New();refreshCallback-SetCallback (RefreshCallback);refreshCallback-SetClientData(prop);renderWindow-AddObserver(vtkCommand::ModifiedEvent,refreshCallback);renderWindow-Render();// Begin mouse interactionrenderWindowInteractor-Start();return EXIT_SUCCESS;
}结论 感谢各位小伙伴的点赞关注小易会继续努力分享一起进步
你的赞赏是我的最最最最大的动力()ノ~