VoxelBlur
Depth-of-field volume rendering
 All Classes Files Functions Variables Enumerations Enumerator
volumerenderer.h
Go to the documentation of this file.
1 #ifndef VOLUMERENDERER_H
2 #define VOLUMERENDERER_H
3 
4 #include <QObject>
5 #include <qopenglfunctions_3_3_core.h>
6 #include "volumeloader.h"
7 
17 class VolumeRenderer : public QObject, protected QOpenGLFunctions_3_3_Core
18 {
19  Q_OBJECT
20 
21 public:
22 
23  enum class ProjectionType
24  {
25  Perspective,
26  Orthographic
27  };
28 
33  explicit VolumeRenderer(QObject* parent = nullptr);
34  ~VolumeRenderer();
35 
39  QSurfaceFormat getDesiredFormat() const;
40 
48  bool initialize();
49 
54  inline const QString error() const { return m_errString; }
55 
61  void drawCurrent();
62 
66  void update();
67 
72  void setSize(int width, int height);
73 
77  float getFPS() const;
78 
82  int getLastSliceCount() const;
83 
87  int getLastRenderedSliceCount() const;
88 
96  bool loadVolume(const QString& metadataFile,VolumeMetaData* loadedVolume = nullptr);
97 
103  bool loadVolume(VolumeMetaData& metadata);
104 
109 
110 signals:
114  void distanceChanged(float d);
115 
119  void rotationChanged(float xRot, float yRot);
120 
124  void lightParamsChanged(float azimuth, float angle);
125 
135  void requestDraw();
136 
140  void requestUpdate();
141 public slots:
146  void setLightParameters(float azimuth, float angle);
150  void lightDelta(float azimuth, float angle);
151  void setRotation(float x, float y);
152  void rotationDelta(float x, float y);
153  void setDistance(float d);
154  void distanceDelta(float d);
155 
156  void setRenderBoundingBox(bool b);
157  void setFixSlicingMatrix(bool b);
158  void setShowLightDirection(bool b);
159 
160  void setSliceDelta(float sliceDelta);
161  void setProjectionType(ProjectionType pt);
162  void setLowerWindowLimit(float w);
163  void setUpperWindowLimit(float w);
164 
165  void setSmoothVolume(bool b);
166  void setGaussianSigma(float s);
167 
171  void setApplyDOF(bool v);
176  void setFocalPlane(float d);
177 
181  void setBlurAmount(float R);
182 private slots:
186  void processLogMessage(const QOpenGLDebugMessage& msg);
187 private:
188  Q_DISABLE_COPY(VolumeRenderer)
189 
190  //private d reference, see volumerenderer_private.h
191  class VolumeRendererPrivate& d;
192  QString m_errString;
193 
198  bool checkGLRequirements();
199 
203  QOpenGLShaderProgram* createShader(const QString& vShaderName, const QString& fShaderName, const QString& gShaderName="");
207  QOpenGLShaderProgram* createComputeShader(const QString& cShaderName);
211  bool initShaders();
215  bool initBuffers();
219  bool initTextures();
220 
224  void updateFBOs();
225 
226  //this stuff is in volumerenderer.cpp
232  QVector<float> setupGaussian(int& size);
238  void processVolume(const QByteArray& data);
242  void updateProjection();
243 
244  void traverseSlices(const QVector<QVector3D>& transformedBox, int count,float zStart, float zDelta);
245  int traverseSlicesDOF(const QVector<QVector3D>& transformedBox, int count,float zStart, float zDelta,float focusZ,QOpenGLFramebufferObject** buffers);
246  bool updateSliceGeometry(const QVector<QVector3D>& box, const float zPos, GLint& firstIdx, GLsizei& count);
247  void drawVolume();
248  void drawBoundingBox();
249  void drawLine(const QVector3D& pointA,const QVector3D& pointB, const QVector3D& color);
250 };
251 
252 #endif // VOLUMERENDERER_H
void requestUpdate()
Like requestDraw, but requests that the window call update instead.
void updateProjection()
Calculates a new projection matrix depending on current viewport parameters.
Definition: volumerenderer.cpp:905
QSurfaceFormat getDesiredFormat() const
Returns the surface format the renderer would like to have.
Definition: volumerenderer.cpp:13
void distanceChanged(float d)
Emitted when the camera distance is changed.
bool initBuffers()
Initializes VAOs/VBOs etc, for bounding box, slices ...
Definition: volumerenderer_init.cpp:283
VolumeRenderer(QObject *parent=nullptr)
Sets up basic stuff.
Definition: volumerenderer_init.cpp:10
bool initTextures()
Initializes the required textures, currently rather empty because they are recreated in processVolume...
Definition: volumerenderer_init.cpp:394
void processLogMessage(const QOpenGLDebugMessage &msg)
Currently unused due to a bug in Qt 5.2 with AMD graphics cards.
Definition: volumerenderer_init.cpp:25
bool initialize()
Initializes the volume renderer, using the currently bound OpenGL context.
Definition: volumerenderer_init.cpp:54
A state-based OpenGL renderer for simple volume rendering.
Definition: volumerenderer.h:17
void update()
Needs to be called with a valid GL context to finalize specific operations like volume loading...
Definition: volumerenderer.cpp:117
QVector< float > setupGaussian(int &size)
Calculates a 3D Gaussian convolution kernel depending on current sigma.
Definition: volumerenderer.cpp:127
void updateFBOs()
Creates/updates the required framebuffer objects to fit the current viewport size.
Definition: volumerenderer_init.cpp:400
int getLastSliceCount() const
Gets the total number of slices that were processed in the last frame.
Definition: volumerenderer.cpp:55
bool loadVolume(const QString &metadataFile, VolumeMetaData *loadedVolume=nullptr)
The VolumeRenderer, with help of a VolumeLoader, loads the volume metadata and then the volume specif...
Definition: volumerenderer.cpp:70
VolumeMetaData getCurrentVolume() const
Returns the currently loaded volume meta data, contains garbage if nothing loaded yet...
Definition: volumerenderer.cpp:65
void setBlurAmount(float R)
Sets the rate at which the blurring increases with distance to the focal plane.
Definition: volumerenderer.cpp:1050
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...
Definition: volumerenderer_init.cpp:175
float getFPS() const
Returns the current FPS.
Definition: volumerenderer.cpp:45
void processVolume(const QByteArray &data)
Processes the raw volume data passed according to the current metadata and settings.
Definition: volumerenderer.cpp:180
void lightParamsChanged(float azimuth, float angle)
Emitted when the light parameters changed.
int getLastRenderedSliceCount() const
Gets the number of processed slices which were actually rendered.
Definition: volumerenderer.cpp:60
Contains private data of the volume renderer.
Definition: volumerenderer_private.h:55
void setLightParameters(float azimuth, float angle)
Sets the light parameters.
Definition: volumerenderer.cpp:921
void drawCurrent()
Draws the current state.
Definition: volumerenderer.cpp:363
const QString error() const
Returns the current error text of the renderer.
Definition: volumerenderer.h:54
This file includes the VolumeLoader class, as well as the VolumeMetaData structure.
void setFocalPlane(float d)
Sets the distance to the focal plane, .
Definition: volumerenderer.cpp:1056
void rotationChanged(float xRot, float yRot)
Emitted when camera rotation is changed.
int traverseSlicesDOF(const QVector< QVector3D > &transformedBox, int count, float zStart, float zDelta, float focusZ, QOpenGLFramebufferObject **buffers)
Like traverseSlices, but applies the DOF effects.
Definition: volumerenderer.cpp:571
bool initShaders()
Loads, compiles & links all shaders the renderer requires.
Definition: volumerenderer_init.cpp:259
void requestDraw()
Emitted when the state of the renderer is changed in a way that would change the rendered image...
bool checkGLRequirements()
Tests if the current OpenGL context meets the requirements of the renderer.
Definition: volumerenderer_init.cpp:33
void setSize(int width, int height)
Call this to change the viewport and projection matrices.
Definition: volumerenderer.cpp:866
void setApplyDOF(bool v)
Toggles the depth-of-field effect on/off.
Definition: volumerenderer.cpp:1044
This class contains metadata for volumes, like dimensions and the file where the data can be found...
Definition: volumeloader.h:14
void lightDelta(float azimuth, float angle)
-form of setLightParameters which applies a change to the current values.
Definition: volumerenderer.cpp:944
QOpenGLShaderProgram * createComputeShader(const QString &cShaderName)
Helper function to create a OpenGL compute shader program.
Definition: volumerenderer_init.cpp:131
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 (del...
Definition: volumerenderer.cpp:684
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...
Definition: volumerenderer.cpp:740