Carna  Version 3.3.2
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Carna::presets::DRRStage Class Reference

Renders digital radiograph reconstructs of volume geometries in the scene. More...

#include <DRRStage.h>

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

Public Member Functions

 DRRStage (unsigned int geometryType)
 Instantiates. The created stage will render such base::Geometry scene graph nodes, whose geometry types equal geometryType.
 
virtual ~DRRStage ()
 Deletes.
 
DRRStageclone () 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
 Computes the digital radiograph reconstruct like described here.
 
float waterAttenuation () const
 Tells \(\mu_\text{water}\). The parameters are described here.
 
float baseIntensity () const
 Tells \(I_0\). The parameters are described here.
 
base::HUV lowerThreshold () const
 Tells \(\mathrm{hu}_\text{lower}\). The parameters are described here.
 
base::HUV upperThreshold () const
 Tells \(\mathrm{hu}_\text{upper}\). The parameters are described here.
 
float upperMultiplier () const
 Tells \(\lambda\). The parameters are described here.
 
bool isRenderingInverse () const
 Tells whether ray attenuation at any particular pixel is inverse proportional to the brightness of that pixel or just proportional.
 
void setWaterAttenuation (float muWater)
 Sets \(\mu_\text{water}\) to muWater. The parameters are described here.
 
void setBaseIntensity (float baseIntensity)
 Sets \(I_0\) to baseIntensity. The parameters are described here.
 
void setLowerThreshold (base::HUV lower)
 Sets \(\mathrm{hu}_\text{lower}\) to lower. The parameters are described here.
 
void setUpperThreshold (base::HUV upper)
 Sets \(\mathrm{hu}_\text{upper}\) to upper. The parameters are described here.
 
void setUpperMultiplier (float multiplier)
 Sets \(\lambda\) to multiplier. The parameters are described here.
 
void setRenderingInverse (bool inverse)
 Sets whether the colors of the DRR should be inverse or not. The ray attenuation at a particular pixel is proportional to the brightness of that pixel if inverse is false. More...
 
- 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 float DEFAULT_WATER_ATTENUATION
 Holds default value for \(\mu_\text{water}\).
 
static const float DEFAULT_BASE_INTENSITY
 Holds default value for \(I_0\).
 
static const base::HUV DEFAULT_LOWER_THRESHOLD
 Holds default value for \(\mathrm{hu}_\text{lower}\).
 
static const base::HUV DEFAULT_UPPER_THRESHOLD
 Holds default value for \(\mathrm{hu}_\text{upper}\).
 
static const float DEFAULT_UPPER_MULTIPLIER
 Holds default value for \(\lambda\).
 
static const bool DEFAULT_RENDER_INVERSE
 Holds default value for inverse rendering.
 
static const unsigned int ROLE_INTENSITIES = 0
 Holds the role that HU volume data is expected to take when attached to base::Geometry nodes.
 
- Static Public Attributes inherited from Carna::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. 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 drr_accumulation shader from the base::ShaderManager.
 
virtual const std::string & uniformName (unsigned int role) const override
 Maps ROLE_INTENSITIES to huVolume.
 
virtual void configureShader () override
 Uploads the parameters to the shader.
 
virtual void configureShader (const base::Renderable &) override
 Does nothing.
 
- 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

Renders digital radiograph reconstructs of volume geometries in the scene.

Background

For each pixel of the output framebuffer, a ray is casted into the scene. This ray occasionally intersects volumetric data, that is assigned to geometry nodes. This ray defines a one-dimensional space. We denote its coordinates with \(x\). Further, we write \(\mathrm{hu}\left(x\right)\) to denote the HU value at location \(x\).

This rendering stage computes

\[ I = I_o \exp\left( -\int_{-\infty}^{\infty} g\left(x\right) \mu\left(x\right) \,\mathrm dx \right) \]

with

\[ \mu\left(x\right) = \mu_\text{water} \cdot \left(1+\frac{\mathrm{hu}\left(x\right)}{1000}\right)\text. \]

The function \(g\left(x\right)\) yields some non-linearity, where \(\lambda\) is an arbitrary positive factor:

\[ g\left(x\right) = \begin{cases} 0 & \text{if} & \mathrm{hu}_\text{lower} > \mathrm{hu}\left(x\right) \\ 1 & \text{if} & \mathrm{hu}_\text{lower} \geq \mathrm{hu}\left(x\right) < \mathrm{hu}_\text{upper} \\ \lambda & \text{if} & \mathrm{hu}_\text{upper} \leq \mathrm{hu}\left(x\right) \end{cases} \]

The integral \(y = \int_{-\infty}^{\infty} g\left(x\right) \mu\left(x\right) \,\mathrm dx\) is computed through VolumeRenderingStage::renderPass. For each pixel, the result is written to a texture. Afterwards this texture is drawn back to the output buffer, using a shader the computes \(I = I_0 \exp\left(-y\right)\). The resulting colors are defined as \(I \mapsto \left(1, 1, 1, 1 - I\right)^\mathrm T\) if inverse rendering is disabled, or \(I \mapsto \left(0, 0, 0, 1 - I\right)^\mathrm T\) otherwise. The fourth component of the color vector is the opacity.

Usage

The DRRStage constructor takes a geometry type parameter:

drr = new presets::DRRStage( 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 following example code configures the DRRStage s.t. it produces the rendering presented further below:

drr->setSampleRate( 100 );
drr->setWaterAttenuation( 5e-3f );
drr->setBaseIntensity( 1.f );
drr->setLowerThreshold( base::HUV::abs( -400 ) );
drr->setUpperThreshold( base::HUV::abs( +400 ) );
drr->setUpperMultiplier( 1.5f );

The last step is to state that the brightness of any particular pixel shall be inverse proportional to the ray attenuation at that pixel:

drr->setRenderingInverse( true );
inverted.png
exemplary rendering in inverse-mode from code above
Author
Leonid Kostrykin
Date
22.2.15 - 11.3.15

Definition at line 106 of file DRRStage.h.

Member Function Documentation

◆ clone()

DRRStage* Carna::presets::DRRStage::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.

◆ loadVideoResources()

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

◆ reshape()

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

◆ setRenderingInverse()

void Carna::presets::DRRStage::setRenderingInverse ( bool  inverse)

Sets whether the colors of the DRR should be inverse or not. The ray attenuation at a particular pixel is proportional to the brightness of that pixel if inverse is false.

If you set inverse to true, you will also have to change the rendering's background color from default black to something brighter, like white. Otherwise you might not see any rendering results from this stage. Default value is false.


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