Loading [MathJax]/extensions/tex2jax.js
Carna  Version 3.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Carna::presets::DVRStage Class Reference

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

#include <DVRStage.h>

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

Public Member Functions

 DVRStage (unsigned int geometryType)
 Instantiates. The created stage will render such base::Geometry scene graph nodes, whose geometry types equal geometryType.
 
virtual ~DVRStage ()
 Deletes.
 
DVRStageclone () const override
 Returns same RenderStage implementation with same configuration. More...
 
virtual void reshape (base::FrameRenderer &fr, unsigned int width, unsigned int height) override
 Orders this stage to reshape its buffers according to the specified dimensions. More...
 
virtual void renderPass (const base::math::Matrix4f &viewTransform, base::RenderTask &rt, const base::Viewport &vp) override
 Triggers the volume rendering.
 
void clearColorMap ()
 Clears the color map. All HU values are mapped to base::Color::BLACK_NO_ALPHA after calling this method.
 
void writeColorMap (const base::math::Span< base::HUV > &huRange, const base::math::Span< base::Color > colorRange)
 Maps all HU values from huRange to colorRange. The first/last HU value from huRange is mapped to the first/last value of colorRange, respectively. The values are interpolated linearly in between. More...
 
void writeColorMap (base::HUV huFirst, base::HUV huLast, const base::Color &colorFirst, const base::Color &colorLast)
 
void setTranslucence (float translucence)
 Sets the translucence property.
 
float translucence () const
 Tells current translucence.
 
void setDiffuseLight (float diffuseLight)
 Sets the diffuse light amount to diffuseLight and the ambient light amount to one minus diffuseLight. More...
 
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 Carna::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. More...
 
unsigned int sampleRate () const
 Tells number of slices to be rendered per segment. More...
 
- Public Member Functions inherited from Carna::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 Carna::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. More...
 
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 Carna::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. More...
 
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. More...
 
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. More...
 
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)\).
 

Static Public Attributes

static const unsigned int ROLE_HU_VOLUME = 0
 Holds the role that HU 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_TRANSLUCENCE
 Holds the default translucence.
 
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 Carna::presets::VolumeRenderingStage
static const unsigned int DEFAULT_SAMPLE_RATE = 100
 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. More...
 
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_HU_VOLUME to huVolume 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 Carna::presets::VolumeRenderingStage
virtual void render (const base::Renderable &) override
 Renders the renderable.
 
- Protected Member Functions inherited from Carna::base::GeometryStage< base::Renderable::BackToFront >
void activateGLContext () const
 Ensures that the OpenGL context of the hosting Carna::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

- Public Attributes inherited from Carna::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.
 
- Protected Attributes inherited from Carna::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 );

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 HU 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::loadData 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->writeColorMap( -400, 0, base::Color:: BLUE_NO_ALPHA, base::Color:: BLUE );
dvr->writeColorMap( 0, 400, base::Color::GREEN_NO_ALPHA, base::Color::GREEN );

This gives the following rendering:

withoutLighting.png
exemplary rendering without lighting from code above

Translucence

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

With Lighting Enabled

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

dvr->writeColorMap( -400, 0, base::Color:: BLUE_NO_ALPHA, base::Color:: BLUE );
dvr->writeColorMap( 0, 400, base::Color::GREEN_NO_ALPHA, base::Color::GREEN );
dvr->setSampleRate( 500 );
dvr->setTranslucence( 2 );

This gives the following rendering:

withLighting.png
exemplary rendering with lighting from code above
Author
Leonid Kostrykin
Date
25.3.15 - 29.3.15

Definition at line 101 of file DVRStage.h.

Member Function Documentation

DVRStage* Carna::presets::DVRStage::clone ( ) const
overridevirtual

Returns same RenderStage implementation with same configuration.

The listeners and the rendering state are not copied.

Deprecated:
Do not use this method. It will be removed shortly.

Implements Carna::base::RenderStage.

virtual unsigned int Carna::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 Carna::presets::VolumeRenderingStage.

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

Orders this stage to reshape its buffers according to the specified dimensions.

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 Carna::base::RenderStage.

void Carna::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.

void Carna::presets::DVRStage::writeColorMap ( const base::math::Span< base::HUV > &  huRange,
const base::math::Span< base::Color colorRange 
)

Maps all HU values from huRange to colorRange. The first/last HU value from huRange is mapped to the first/last value of colorRange, respectively. The values are interpolated linearly in between.

Nothing happens if the last HU value of huRange is smaller than the first. If the first and the last HU values of huRange are equal, they are mapped to the mean of the first and the last values from colorRange.

void Carna::presets::DVRStage::writeColorMap ( base::HUV  huFirst,
base::HUV  huLast,
const base::Color colorFirst,
const base::Color colorLast 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.


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