很高兴在雪易的CSDN遇见你
VTK技术爱好者 QQ:870202403
本文分享VTK中体绘制中的vtkLODProp3D对象,希望对各位小伙伴有所帮助!
感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步!
你的点赞就是我的动力(^U^)ノ~YO
vtkLODProp3D与vtkVolume用法类似,两者均继承自vtkProp3D。但vtkLODProp3D支持多个Mapper、Property和Texture对象,并由它选择Mapper对象实现绘制。例如,当绘制一个数据量非常大的不规则网格数据时,可以添加一个vtkPolyDataMapper来渲染一个表面模型,作为最低级别分辨率的渲染;然后将数据采样为vtkImageData数据,并添加一个vtkVolumeTextureMapper3D进行体绘制,作为一个中等级别渲染;最后通过ZSweep技术(vtkUnstructureGridVolumeZSWeepMapper)渲染原始数据,作为最高级别的渲染。vtkLODProp3D在渲染过程中,会为每一个Mapper估计一个渲染时间,并选择一个最优的实现渲染。
其重要参数有:
/**
* 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); }
//@{
/**
* 添加不同级别的的映射器、属性、背面属性、纹理和渲染时间。
* 属性和纹理字段可以设置为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);
//@}
//@{
/**
* 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);
//@}
/**
* Delete a level of detail given an ID. This is the ID returned by the
* AddLOD method
*/
void RemoveLOD(int id);
//@{
/**
* 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);
//@}
//@{
/**
* 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);
//@{
/**
* 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);
//@}
//@{
/**
* 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);
//@}
//@{
/**
* 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);
//@}
//@{
/**
* 设置特定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);
//@}
//@{
/**
* 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);
//@}
//@{
/**
* 开启/关闭自动选择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);
//@}
//@{
/**
* Set the id of the LOD that is to be drawn when automatic LOD selection
* is turned off.
*/
vtkSetMacro(SelectedLODID, int);
vtkGetMacro(SelectedLODID, int);
//@}
//@{
/**
* 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;
//@}
//@{
/**
* 开启/关闭自动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);
//@}
//@{
/**
* 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代替。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
void RefreshCallback( vtkObject* vtkNotUsed(caller),
long unsigned int vtkNotUsed(eventId),
void* clientData,
void* vtkNotUsed(callData) )
{
vtkSmartPointer lodProp =
static_cast(clientData);
std::cout << "Last rendered LOD: " << lodProp->GetLastRenderedLODID() << std::endl;
}
int main (int, char *[])
{
// High res sphere
vtkSmartPointer highResSphereSource =
vtkSmartPointer::New();
int res = 100;
highResSphereSource->SetThetaResolution(res);
highResSphereSource->SetPhiResolution(res);
highResSphereSource->Update();
vtkSmartPointer highResMapper =
vtkSmartPointer::New();
highResMapper->SetInputConnection(highResSphereSource->GetOutputPort());
// Low res sphere
vtkSmartPointer lowResSphereSource =
vtkSmartPointer::New();
vtkSmartPointer lowResMapper =
vtkSmartPointer::New();
lowResMapper->SetInputConnection(lowResSphereSource->GetOutputPort());
vtkSmartPointer propertyLowRes =
vtkSmartPointer::New();
propertyLowRes->SetDiffuseColor(0.89, 0.81, 0.34);
propertyLowRes->SetInterpolationToFlat();
vtkSmartPointer propertyHighRes =
vtkSmartPointer::New();
propertyHighRes->SetDiffuseColor(1.0, 0.3882, 0.2784);
propertyHighRes->SetInterpolationToFlat();
vtkSmartPointer prop =
vtkSmartPointer::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 renderer =
vtkSmartPointer::New();
vtkSmartPointer renderWindow =
vtkSmartPointer::New();
renderWindow->AddRenderer(renderer);
//prop->SetAllocatedRenderTime(1e-6,renderer);
prop->SetAllocatedRenderTime(1e-10,renderer);
// An interactor
vtkSmartPointer renderWindowInteractor =
vtkSmartPointer::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actors to the scene
renderer->AddActor(prop);
vtkSmartPointer refreshCallback =
vtkSmartPointer::New();
refreshCallback->SetCallback (RefreshCallback);
refreshCallback->SetClientData(prop);
renderWindow->AddObserver(vtkCommand::ModifiedEvent,refreshCallback);
renderWindow->Render();
// Begin mouse interaction
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步!
你的赞赏是我的最最最最大的动力(^U^)ノ~YO