VoxelBlur
Depth-of-field volume rendering
|
A state-based OpenGL renderer for simple volume rendering. More...
#include <volumerenderer.h>
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 VolumeRendererPrivate & | d |
QString | m_errString |
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.
|
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.
|
private |
Tests if the current OpenGL context meets the requirements of the renderer.
The most "modern" feature required are compute shaders.
void VolumeRenderer::drawCurrent | ( | ) |
Draws the current state.
The caller has to make sure all OpenGL stuff is valid (context, visible window etc.).
|
inline |
Returns the current error text of the renderer.
Currently only set when initialize fails.
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.
|
private |
Initializes VAOs/VBOs etc, for bounding box, slices ...
*** BOX
*** LINE
*** SLICES
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.
|
private |
Loads, compiles & links all shaders the renderer requires.
They are loaded through the Qt resource system.
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.
metadataFile | a string identifying the metadata file that includes volume information |
loadedVolume | if the volume loaded successfully, returns the metadata of the volume |
bool VolumeRenderer::loadVolume | ( | VolumeMetaData & | metadata | ) |
Loads the volume specified by the given metadata information, using the VolumeLoader.
metadata | The metadata which identify a volume file to load |
|
private |
Processes the raw volume data passed according to the current metadata and settings.
This includes Gaussian filtering, Gradient calculation, data scaling and flipping.
data | the raw volume data |
|
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.
|
slot |
Sets the rate at which the blurring increases with distance to the focal plane.
Should be larger than zero.
|
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
|
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) \).
void VolumeRenderer::setSize | ( | int | width, |
int | height | ||
) |
Call this to change the viewport and projection matrices.
|
private |
Calculates a 3D Gaussian convolution kernel depending on current sigma.
The kernel has equal size in all dimensions.
size | an output parameter, containing the size of the kernel in each dimension. |
|
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.