-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInteractiveRenderer.h
More file actions
124 lines (102 loc) · 4.09 KB
/
InteractiveRenderer.h
File metadata and controls
124 lines (102 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef INTERACTIVERENDERER_H
#define INTERACTIVERENDERER_H
#include <QThread>
#include <QImage>
#include "Vec3D.h"
#include "GLViewer.h"
#include <QMutex>
#include <QMutexLocker>
//macros
#define RESET_INTERACTIVITY_BEGIN \
RayTracer::getInstance()->getInterRenderer().cancel(); \
RayTracer::getInstance()->getInterRenderer().lock();
#define RESET_INTERACTIVITY_END \
RayTracer::getInstance()->getInterRenderer().unlock();
/*!
* \brief The InteractiveRenderer class implements interactive rendering thread.
*/
class InteractiveRenderer: public QThread {
friend class RayTracer;
public:
/*!
* \brief Launches interactive rendering.
* \param viewer QGLViewer instance used to display the rendered content.
*/
void begin(GLViewer* viewer);
/*!
* \brief Quitting interactive mode.
*/
inline void disable() { fEnabled = false; }
/*!
* \brief Aborts current rendering.
* Used when a parameter change occurs. Causes current rendering break and waits until the
* thread stops. All the rendered content will be freed.
*/
void cancel();
/*!
* \brief Interactive mode flag.
* \return `true` if the interactive mode is considered to be enabled by the renderer.
*/
inline bool isEnabled() const { return fEnabled; }
/*!
* \brief Gives actually rendered image.
* This routine must be called when the renderer is in locked state.
* \return QImage object pointer contained actually rendered image.
*/
inline QImage* getImage() const { return fResult; }
/*!
* \brief Frames per second value as interactivity speed indicator.
* \return frames per second value.
*/
inline float getFPS() const { return fFPS; }
/*!
* \brief Retrieving information about interactivity rendering process.
* \return different information concerning the process, basicly actual image construction
* or anti-aliasing progress.
*/
const QString getStatus() const;
/*!
* \brief Locks renderer state signifying entering into critical section protecting rendering parameters.
*/
inline void lock() { fMutex.lock(); }
/*!
* \brief Unlocks renderer state after locking it by InteractiveRenderer::lock().
*/
inline void unlock() { fMutex.unlock(); }
/*!
* \brief Class constructor.
*/
InteractiveRenderer();
/*!
* \brief Class destructor.
*/
~InteractiveRenderer();
protected:
void run();
inline bool wasCancelled() const { return fCancelled; }
private:
float getXOffset() const; //!< Downsampled image horizontal offset in pixels
float getYOffset() const; //!< Downsampled image vertical offset in pixels
static const int SUBDIVISION = 8; //!< Downsampling factor
GLViewer *fViewer; //!< Rendering target
QImage
*fRenderedStock, //!< Stock of rendered content
*fResult; //!< Resulted image
QMutex fMutex; //!< Internal instance data access control
bool
fEnabled, //!< `true` if interactive mode is enabled
fCancelled; //!< `true` if the rendering is aborted (because of parameter change)
unsigned int fPass; //!< Number of pass of image construction. Controls instance state.
float fFPS; //!< Frames per second (in fact, inversed time of last rendered image)
Vec3Df
fCamPos, //!< Current camera position
fUpVector; //!< Current camera up vector
unsigned int
fScreenWidth, //!< Current width of the rendering target in pixels
fScreenHeight; //!< Current height of the rendering target in pixels
float fFOV; //!< Current field of view value
unsigned int
fSmpX [SUBDIVISION * SUBDIVISION], //!< Donwsampled image horizontal offset in function of \var fPass
fSmpY [SUBDIVISION * SUBDIVISION]; //!< Donwsampled image vertical offset in function of \var fPass
};
#endif // INTERACTIVERENDERER_H