VoxelBlur
Depth-of-field volume rendering
 All Classes Files Functions Variables Enumerations Enumerator
Public Types | Public Slots | Signals | Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
VolumeRenderer Class Reference

A state-based OpenGL renderer for simple volume rendering. More...

#include <volumerenderer.h>

Inheritance diagram for VolumeRenderer:
Inheritance graph
[legend]
Collaboration diagram for VolumeRenderer:
Collaboration graph
[legend]

Public Types

enum  ProjectionType { Perspective, Orthographic }
 

Public Slots

void setLightParameters (float azimuth, float angle)
 Sets the light parameters. More...
 
void lightDelta (float azimuth, float angle)
 \( \delta \)-form of setLightParameters which applies a change to the current values.
 
void setRotation (float x, float y)
 
void rotationDelta (float x, float y)
 
void setDistance (float d)
 
void distanceDelta (float d)
 
void setRenderBoundingBox (bool b)
 
void setFixSlicingMatrix (bool b)
 
void setShowLightDirection (bool b)
 
void setSliceDelta (float sliceDelta)
 
void setProjectionType (ProjectionType pt)
 
void setLowerWindowLimit (float w)
 
void setUpperWindowLimit (float w)
 
void setSmoothVolume (bool b)
 
void setGaussianSigma (float s)
 
void setApplyDOF (bool v)
 Toggles the depth-of-field effect on/off.
 
void setFocalPlane (float d)
 Sets the distance to the focal plane, \( d \in [0,1]\). More...
 
void setBlurAmount (float R)
 Sets the rate at which the blurring increases with distance to the focal plane. More...
 

Signals

void distanceChanged (float d)
 Emitted when the camera distance is changed.
 
void rotationChanged (float xRot, float yRot)
 Emitted when camera rotation is changed.
 
void lightParamsChanged (float azimuth, float angle)
 Emitted when the light parameters changed.
 
void requestDraw ()
 Emitted when the state of the renderer is changed in a way that would change the rendered image. More...
 
void requestUpdate ()
 Like requestDraw, but requests that the window call update instead.
 

Public Member Functions

 VolumeRenderer (QObject *parent=nullptr)
 Sets up basic stuff. More...
 
QSurfaceFormat getDesiredFormat () const
 Returns the surface format the renderer would like to have.
 
bool initialize ()
 Initializes the volume renderer, using the currently bound OpenGL context. More...
 
const QString error () const
 Returns the current error text of the renderer. More...
 
void drawCurrent ()
 Draws the current state. More...
 
void update ()
 Needs to be called with a valid GL context to finalize specific operations like volume loading.
 
void setSize (int width, int height)
 Call this to change the viewport and projection matrices. More...
 
float getFPS () const
 Returns the current FPS. More...
 
int getLastSliceCount () const
 Gets the total number of slices that were processed in the last frame.
 
int getLastRenderedSliceCount () const
 Gets the number of processed slices which were actually rendered. More...
 
bool loadVolume (const QString &metadataFile, VolumeMetaData *loadedVolume=nullptr)
 The VolumeRenderer, with help of a VolumeLoader, loads the volume metadata and then the volume specified in the file given. More...
 
bool loadVolume (VolumeMetaData &metadata)
 Loads the volume specified by the given metadata information, using the VolumeLoader. More...
 
VolumeMetaData getCurrentVolume () const
 Returns the currently loaded volume meta data, contains garbage if nothing loaded yet.
 

Private Slots

void processLogMessage (const QOpenGLDebugMessage &msg)
 Currently unused due to a bug in Qt 5.2 with AMD graphics cards.
 

Private Member Functions

bool checkGLRequirements ()
 Tests if the current OpenGL context meets the requirements of the renderer. More...
 
QOpenGLShaderProgram * createShader (const QString &vShaderName, const QString &fShaderName, const QString &gShaderName="")
 Helper function to create a OpenGL shader program, with vertex, fragment and optional geometry shader.
 
QOpenGLShaderProgram * createComputeShader (const QString &cShaderName)
 Helper function to create a OpenGL compute shader program.
 
bool initShaders ()
 Loads, compiles & links all shaders the renderer requires. More...
 
bool initBuffers ()
 Initializes VAOs/VBOs etc, for bounding box, slices ... More...
 
bool initTextures ()
 Initializes the required textures, currently rather empty because they are recreated in processVolume.
 
void updateFBOs ()
 Creates/updates the required framebuffer objects to fit the current viewport size.
 
QVector< float > setupGaussian (int &size)
 Calculates a 3D Gaussian convolution kernel depending on current sigma. More...
 
void processVolume (const QByteArray &data)
 Processes the raw volume data passed according to the current metadata and settings. More...
 
void updateProjection ()
 Calculates a new projection matrix depending on current viewport parameters.
 
void traverseSlices (const QVector< QVector3D > &transformedBox, int count, float zStart, float zDelta)
 Traverses the transformed bounding box from the specified start point in the specified direction (delta).
 
int traverseSlicesDOF (const QVector< QVector3D > &transformedBox, int count, float zStart, float zDelta, float focusZ, QOpenGLFramebufferObject **buffers)
 Like traverseSlices, but applies the DOF effects. More...
 
bool updateSliceGeometry (const QVector< QVector3D > &box, const float zPos, GLint &firstIdx, GLsizei &count)
 Performs slicing of a view-aligned plane with the view-transformed volume bounding box, and uploads the slice to OpenGL, if it has intersections.
 
void drawVolume ()
 
void drawBoundingBox ()
 
void drawLine (const QVector3D &pointA, const QVector3D &pointB, const QVector3D &color)
 

Private Attributes

class VolumeRendererPrivated
 
QString m_errString
 

Detailed Description

A state-based OpenGL renderer for simple volume rendering.

Nearly all functions assume a usable OpenGL context is available, the caller has to make sure that this is the case.

Constructor & Destructor Documentation

VolumeRenderer::VolumeRenderer ( QObject *  parent = nullptr)
explicit

Sets up basic stuff.

initialize has to be called before the class is usable. The only method guaranteed to be usable before initialize is getDesiredFormat.

Member Function Documentation

bool VolumeRenderer::checkGLRequirements ( )
private

Tests if the current OpenGL context meets the requirements of the renderer.

The most "modern" feature required are compute shaders.

Here is the caller graph for this function:

void VolumeRenderer::drawCurrent ( )

Draws the current state.

The caller has to make sure all OpenGL stuff is valid (context, visible window etc.).

Note
The VolumeRenderWindow calls this in VoxelBlur.

Here is the caller graph for this function:

const QString VolumeRenderer::error ( ) const
inline

Returns the current error text of the renderer.

Currently only set when initialize fails.

Here is the caller graph for this function:

float VolumeRenderer::getFPS ( ) const

Returns the current FPS.

Only makes sense in animation mode. The value only uses the last frame, so it may be drastically inaccurate.

int VolumeRenderer::getLastRenderedSliceCount ( ) const

Gets the number of processed slices which were actually rendered.

This number is smaller than getLastSliceCount, and excludes slices with less than 3 intersections.

bool VolumeRenderer::initBuffers ( )
private

Initializes VAOs/VBOs etc, for bounding box, slices ...

*** BOX

*** LINE

*** SLICES

Here is the call graph for this function:

Here is the caller graph for this function:

bool VolumeRenderer::initialize ( )

Initializes the volume renderer, using the currently bound OpenGL context.

This loads all needed shaders, initializes buffers, FBOs etc. If this fails for some reason (unsupported GL version), false is returned and error returns an error text.

Note
The VolumeRenderWindow calls this in VoxelBlur.
Returns
true when all is correctly initialized.

Here is the call graph for this function:

Here is the caller graph for this function:

bool VolumeRenderer::initShaders ( )
private

Loads, compiles & links all shaders the renderer requires.

They are loaded through the Qt resource system.

Here is the call graph for this function:

Here is the caller graph for this function:

bool VolumeRenderer::loadVolume ( const QString &  metadataFile,
VolumeMetaData loadedVolume = nullptr 
)

The VolumeRenderer, with help of a VolumeLoader, loads the volume metadata and then the volume specified in the file given.

See Also
VolumeLoader
Parameters
metadataFilea string identifying the metadata file that includes volume information
loadedVolumeif the volume loaded successfully, returns the metadata of the volume
Returns
true if loading ok, false if not

Here is the call graph for this function:

bool VolumeRenderer::loadVolume ( VolumeMetaData metadata)

Loads the volume specified by the given metadata information, using the VolumeLoader.

Parameters
metadataThe metadata which identify a volume file to load
Returns
true of loading ok

Here is the call graph for this function:

void VolumeRenderer::processVolume ( const QByteArray &  data)
private

Processes the raw volume data passed according to the current metadata and settings.

This includes Gaussian filtering, Gradient calculation, data scaling and flipping.

Parameters
datathe raw volume data

Here is the call graph for this function:

Here is the caller graph for this function:

void VolumeRenderer::requestDraw ( )
signal

Emitted when the state of the renderer is changed in a way that would change the rendered image.

Because the VolumeRenderer can not start rendering itself (it has no way to be sure the context is bound, that the window is visible etc), it instead notifies interested object that a change has occurred.

Things that cause the signal to be emitted include changes in camera parameters (like setRotation or setDistance). If another signal is associated with this changes (like distanceChanged), it will always be emitted before requestDraw is emitted.

Note
The VolumeRenderWindow handles this in VoxelBlur.

Here is the caller graph for this function:

void VolumeRenderer::setBlurAmount ( float  R)
slot

Sets the rate at which the blurring increases with distance to the focal plane.

Should be larger than zero.

void VolumeRenderer::setFocalPlane ( float  d)
slot

Sets the distance to the focal plane, \( d \in [0,1]\).

0 corresponds to the Z value nearest to the camera, 1 to the one farthest away

void VolumeRenderer::setLightParameters ( float  azimuth,
float  angle 
)
slot

Sets the light parameters.

The light source is directional, identified by azimuth angle around the Y vector and elevation angle around the local Z. When both are 0, this corresponds to a light vector of \( (1,0,0) \).

Here is the caller graph for this function:

void VolumeRenderer::setSize ( int  width,
int  height 
)

Call this to change the viewport and projection matrices.

Note
This does NOT emit the requestDraw signal.

Here is the call graph for this function:

Here is the caller graph for this function:

QVector< float > VolumeRenderer::setupGaussian ( int &  size)
private

Calculates a 3D Gaussian convolution kernel depending on current sigma.

The kernel has equal size in all dimensions.

Parameters
sizean output parameter, containing the size of the kernel in each dimension.
Returns
a 3D Gaussian convolution kernel in linear form

Here is the caller graph for this function:

int VolumeRenderer::traverseSlicesDOF ( const QVector< QVector3D > &  transformedBox,
int  count,
float  zStart,
float  zDelta,
float  focusZ,
QOpenGLFramebufferObject **  buffers 
)
private

Like traverseSlices, but applies the DOF effects.

The returned int is the index of the last draw buffer which should be merged with the other direction result.

Here is the call graph for this function:


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