LibCarna Version 3.4.0
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
LibCarna::presets::DVRStage Class Reference

Performs direct volume renderings of the volume geometries in the scene. More...

#include <DVRStage.hpp>

+ Inheritance diagram for LibCarna::presets::DVRStage:
+ Collaboration diagram for LibCarna::presets::DVRStage:

Public Member Functions

 DVRStage (unsigned int geometryType, unsigned int colorMapResolution=base::ColorMap::DEFAULT_RESOLUTION)
 Instantiates. The created stage will render such base::Geometry scene graph nodes, whose geometry types equal geometryType.
 
virtual ~DVRStage ()
 Deletes.
 
virtual void reshape (base::FrameRenderer &fr, unsigned int width, unsigned int height) override
 Orders this stage to reshape its buffers according to the specified width and height.
 
virtual void renderPass (const base::math::Matrix4f &viewTransform, base::RenderTask &rt, const base::Viewport &vp) override
 Triggers the volume rendering.
 
void setTranslucency (float translucency)
 Sets the translucency property.
 
float translucency () const
 Tells current translucency.
 
void setDiffuseLight (float diffuseLight)
 Sets the diffuse light amount to diffuseLight and the ambient light amount to one minus diffuseLight.
 
float diffuseLight () const
 Tells the diffuse light amount. The ambient light amount is one minus the diffuse light amount.
 
bool isLightingUsed () const
 Tells whether lighting was used during the last rendering. The return value is undefined if nothing was rendered yet.
 
- Public Member Functions inherited from LibCarna::presets::VolumeRenderingStage
 VolumeRenderingStage (unsigned int geometryType)
 Instantiates. The created stage will render such base::Geometry scene graph nodes, whose geometry types equal geometryType.
 
virtual ~VolumeRenderingStage ()
 Deletes.
 
void setSampleRate (unsigned int sampleRate)
 Sets number of slices to be rendered per segment.
 
unsigned int sampleRate () const
 Tells number of slices to be rendered per segment.
 
- Public Member Functions inherited from LibCarna::base::GeometryStage< base::Renderable::BackToFront >
 GeometryStage (unsigned int geometryType, unsigned int geometryTypeMask=RenderQueue< base::Renderable::BackToFront >::EXACT_MATCH_GEOMETRY_TYPE_MASK)
 Instantiates s.t. the predefined rendering queue enqueues such LibCarna::base::Geometry scene graph nodes, whose geometry type AND-linked with geometryTypeMask equals the geometryType specified here.
 
virtual ~GeometryStage ()
 Releases acquired video resources.
 
virtual void prepareFrame (Node &root) override
 Called once before each frame.
 
std::size_t renderedPassesCount () const
 Tells the number of passes rendered so far since the beginning of the current frame.
 
GeometryFeatureType::ManagedInterface & videoResource (GeometryFeatureType &geometryFeature) const
 Interfaces the geometryFeature video resources that were acquired by this rendering stage.
 
const GeometryFeatureType::ManagedInterface & videoResource (const GeometryFeatureType &geometryFeature) const
 
- Public Member Functions inherited from LibCarna::base::RenderStage
 RenderStage ()
 Instantiates in enabled-state.
 
virtual ~RenderStage ()
 Deletes.
 
void setViewTransformFixed (bool viewTransformFixed)
 Sets whether the view transform is pass-invariant for the duration of a single frame.
 
bool isViewTransformFixed () const
 Tells whether the view transform is pass-invariant for the duration of a single frame.
 
bool isInitialized () const
 Tells whether this stage is ready for rendering.
 
bool isEnabled () const
 Tells whether this stage is enabled. Disabled stages are not rendered by render tasks.
 
void setEnabled (bool)
 Sets whether this stage is enabled. Disabled stages are not rendered by render tasks.
 
base::FrameRendererrenderer ()
 References the renderer this stage belongs to.
 
const base::FrameRendererrenderer () const
 
void addRenderStageListener (RenderStageListener &listener)
 Adds listener to the set of listeners this instance notifies in \(\mathcal O\left(\log n\right)\).
 
void removeRenderStageListener (RenderStageListener &listener)
 Removes listener from the set of listeners this instance notifies in \(\mathcal O\left(\log n\right)\).
 

Public Attributes

base::ColorMap colorMap
 The color map used for the rendering.
 
- Public Attributes inherited from LibCarna::base::GeometryStage< base::Renderable::BackToFront >
const unsigned int geometryType
 Renders such geometries whose type AND-linked with geometryTypeMask equals this.
 
const unsigned int geometryTypeMask
 Renders such geometries whose type AND-linked with this equals geometryType.
 

Static Public Attributes

static const unsigned int ROLE_INTENSITIES = 0
 Holds the role that intensity volume data is expected to take when attached to base::Geometry nodes.
 
static const unsigned int ROLE_NORMALS = 1
 Holds the role that the normal map is expected to take when attached to base::Geometry nodes.
 
static const float DEFAULT_TRANSLUCENCY
 Holds the default translucency.
 
static const float DEFAULT_DIFFUSE_LIGHT
 Holds the default diffuse light amount. The ambient light amount is always one minus the diffuse light amount.
 
- Static Public Attributes inherited from LibCarna::presets::VolumeRenderingStage
static const unsigned int DEFAULT_SAMPLE_RATE = 200
 Holds the default number of slices rendered per segment.
 

Protected Member Functions

virtual unsigned int loadVideoResources () override
 Loads video resources when rendering is triggered for the first time. Override this method if you need any additional resources to be loaded, but always call the base implementation.
 
virtual void createVolumeSamplers (const std::function< void(unsigned int, base::Sampler *) > &registerSampler) override
 Creates texture samplers for volume textures and uses registerSampler to assign them to the roles that they should be used with.
 
virtual const base::ShaderProgramacquireShader () override
 Acquires the dvr shader from the base::ShaderManager.
 
virtual const std::string & uniformName (unsigned int role) const override
 Maps ROLE_INTENSITIES to intensities and ROLE_NORMALS to normalMap.
 
virtual void configureShader () override
 Performs custom shader configuration on a per-pass level.
 
virtual void configureShader (const base::Renderable &) override
 Computes and uploads the normals transformation matrix.
 
- Protected Member Functions inherited from LibCarna::presets::VolumeRenderingStage
virtual void render (const base::Renderable &) override
 Renders the renderable.
 
- Protected Member Functions inherited from LibCarna::base::GeometryStage< base::Renderable::BackToFront >
void activateGLContext () const
 Ensures that the OpenGL context of the hosting LibCarna::base::FrameRenderer is the current one.
 
virtual void buildRenderQueues (Node &root, const math::Matrix4f &viewTransform)
 Builds the rendering queues of this stage.
 
virtual void rewindRenderQueues ()
 Rewinds the rendering queues of this stage.
 
virtual void updateRenderQueues (const math::Matrix4f &viewTransform)
 Recomputes the model-view transforms of the renderables enqueued by this stage.
 

Additional Inherited Members

- Protected Attributes inherited from LibCarna::base::GeometryStage< base::Renderable::BackToFront >
RenderQueue< base::Renderable::BackToFrontrq
 Holds the predefined rendering queue of this rendering stage.
 

Detailed Description

Performs direct volume renderings of the volume geometries in the scene.

Usage

The DVRStage constructor takes a geometry type parameter:

dvr = new presets::DVRStage( GEOMETRY_TYPE_VOLUMETRIC );
void appendStage(RenderStage *stage)
Appends stage to the rendering stages sequence.
base::FrameRenderer & renderer()
References the renderer this stage belongs to.
Performs direct volume renderings of the volume geometries in the scene.
Definition DVRStage.hpp:106

The concept of geometry types is explained here.

Note
In the rendering process this stage will usually be inserted after such stages that render opaque geometry, like CuttingPlanesStage and OpaqueRenderingStage.

The DVRStage supports two types of rendering modes: Rendering with lighting enabled and rendering without lighting. In general, lighting produces more sculptural results, but it comes at the cost of additional requirements: Not only the intensity volume must be uploaded to the GPU, but also another 3D texture that maps texture space coordinates to the normal vectors of the surface at a particular location. Depending on the resolution of the data, this might cause noteworthy memory consumption.

Luckily the helpers::VolumeGridHelper class does everything that is needed in order to compute the normal vectors and upload them to the GPU, if it is instructed to do so: Its second type argument is optional and set to void by default. This disables its normal vectors support. Setting it to anything different, like base::NormalMap3DInt8 for example, makes it compute the normal vectors when helpers::VolumeGridHelper::loadIntensities or its computeNormals method are called.

The DVRStage decides which mode to use depending on whether the normal vectors are provided or not.

Without Lighting

The following example code configures the DVRStage s.t. it produces the rendering presented further below:

dvr->colorMap.writeLinearSegment( base::HUV( -400 ).intensity(), base::HUV( 0 ).intensity(), base::Color:: BLUE_NO_ALPHA, base::Color:: BLUE );
dvr->colorMap.writeLinearSegment( base::HUV( 0 ).intensity(), base::HUV( 400 ).intensity(), base::Color::GREEN_NO_ALPHA, base::Color::GREEN );
dvr->setDiffuseLight( 0 );
static const Color GREEN
Holds Color(0, 255, 0, 255).
Definition Color.hpp:55
static const Color BLUE_NO_ALPHA
Holds Color(0, 0, 255, 0).
Definition Color.hpp:58
static const Color GREEN_NO_ALPHA
Holds Color(0, 255, 0, 0).
Definition Color.hpp:56
static const Color BLUE
Holds Color(0, 0, 255, 255).
Definition Color.hpp:57
Represents Hounsfield Units Values in , usually used in CT imaging.
Definition HUV.hpp:45

This gives the following rendering:

exemplary rendering without lighting from code above

Translucency

The translucency scales the opacity values queried from the color map. Assuming that \(\alpha\) was the value from the color map, the translucency \(t \geq 0\) scales the actual opacity to \(\frac{\alpha}{1 + t}\).

With Lighting Enabled

The default translucency is quite high, which is fine for rendering without lighting. You might consider setting it down when rendering with lighting enabled:

dvr->colorMap.writeLinearSegment( base::HUV( -400 ).intensity(), base::HUV( 0 ).intensity(), base::Color:: BLUE_NO_ALPHA, base::Color:: BLUE );
dvr->colorMap.writeLinearSegment( base::HUV( 0 ).intensity(), base::HUV( 400 ).intensity(), base::Color::GREEN_NO_ALPHA, base::Color::GREEN );
dvr->setSampleRate( 1000 );
dvr->setTranslucency( 2 );

This gives the following rendering:

exemplary rendering with lighting from code above
Author
Leonid Kostrykin

Definition at line 105 of file DVRStage.hpp.

Constructor & Destructor Documentation

◆ DVRStage()

LibCarna::presets::DVRStage::DVRStage ( unsigned int  geometryType,
unsigned int  colorMapResolution = base::ColorMap::DEFAULT_RESOLUTION 
)
explicit

Instantiates. The created stage will render such base::Geometry scene graph nodes, whose geometry types equal geometryType.

The parameter colorMapResolution determines the resolution of the color map. If your data is 8bit, using 8bit color map is sufficient. If your data is 32bit, you probably also want to use a 32bit color map.

Member Function Documentation

◆ acquireShader()

virtual const base::ShaderProgram & LibCarna::presets::DVRStage::acquireShader ( )
overrideprotectedvirtual

Acquires the dvr shader from the base::ShaderManager.

Implements LibCarna::presets::VolumeRenderingStage.

◆ configureShader() [1/2]

virtual void LibCarna::presets::DVRStage::configureShader ( )
overrideprotectedvirtual

Performs custom shader configuration on a per-pass level.

Implements LibCarna::presets::VolumeRenderingStage.

◆ configureShader() [2/2]

virtual void LibCarna::presets::DVRStage::configureShader ( const base::Renderable )
overrideprotectedvirtual

Computes and uploads the normals transformation matrix.

Implements LibCarna::presets::VolumeRenderingStage.

◆ createVolumeSamplers()

virtual void LibCarna::presets::DVRStage::createVolumeSamplers ( const std::function< void(unsigned int, base::Sampler *) > &  registerSampler)
overrideprotectedvirtual

Creates texture samplers for volume textures and uses registerSampler to assign them to the roles that they should be used with.

Implements LibCarna::presets::VolumeRenderingStage.

◆ loadVideoResources()

virtual unsigned int LibCarna::presets::DVRStage::loadVideoResources ( )
overrideprotectedvirtual

Loads video resources when rendering is triggered for the first time. Override this method if you need any additional resources to be loaded, but always call the base implementation.

Returns
the first texture unit to use for volume textures. The dafault implementation returns base::Texture<0>::SETUP_UNIT +1.

Reimplemented from LibCarna::presets::VolumeRenderingStage.

◆ renderPass()

virtual void LibCarna::presets::DVRStage::renderPass ( const base::math::Matrix4f viewTransform,
base::RenderTask rt,
const base::Viewport vp 
)
overridevirtual

Triggers the volume rendering.

Reimplemented from LibCarna::presets::VolumeRenderingStage.

◆ reshape()

virtual void LibCarna::presets::DVRStage::reshape ( base::FrameRenderer fr,
unsigned int  width,
unsigned int  height 
)
overridevirtual

Orders this stage to reshape its buffers according to the specified width and height.

Attention
Always call the base implementaion!
Parameters
frreferences the frame renderer this stage belongs to.
widthis the root viewport width.
heightis the root viewport height.

Reimplemented from LibCarna::base::RenderStage.

◆ setDiffuseLight()

void LibCarna::presets::DVRStage::setDiffuseLight ( float  diffuseLight)

Sets the diffuse light amount to diffuseLight and the ambient light amount to one minus diffuseLight.

Precondition
diffuseLight >= 0 && diffuseLight <= 1

This only has an effect if lighting is enabled. If lighting is enabled, setting this to \(0\) virtually disables the lighting.

◆ uniformName()

virtual const std::string & LibCarna::presets::DVRStage::uniformName ( unsigned int  role) const
overrideprotectedvirtual

Maps ROLE_INTENSITIES to intensities and ROLE_NORMALS to normalMap.

Implements LibCarna::presets::VolumeRenderingStage.

Member Data Documentation

◆ colorMap

base::ColorMap LibCarna::presets::DVRStage::colorMap

The color map used for the rendering.

Definition at line 163 of file DVRStage.hpp.

◆ DEFAULT_DIFFUSE_LIGHT

const float LibCarna::presets::DVRStage::DEFAULT_DIFFUSE_LIGHT
static

Holds the default diffuse light amount. The ambient light amount is always one minus the diffuse light amount.

Definition at line 134 of file DVRStage.hpp.

◆ DEFAULT_TRANSLUCENCY

const float LibCarna::presets::DVRStage::DEFAULT_TRANSLUCENCY
static

Holds the default translucency.

Definition at line 128 of file DVRStage.hpp.

◆ ROLE_INTENSITIES

const unsigned int LibCarna::presets::DVRStage::ROLE_INTENSITIES = 0
static

Holds the role that intensity volume data is expected to take when attached to base::Geometry nodes.

Definition at line 117 of file DVRStage.hpp.

◆ ROLE_NORMALS

const unsigned int LibCarna::presets::DVRStage::ROLE_NORMALS = 1
static

Holds the role that the normal map is expected to take when attached to base::Geometry nodes.

Definition at line 123 of file DVRStage.hpp.


The documentation for this class was generated from the following file: