1 | #ifndef __RENDERER_H
|
---|
2 | #define __RENDERER_H
|
---|
3 |
|
---|
4 | #include <QtOpenGL>
|
---|
5 | #include <QWaitCondition>
|
---|
6 | //#include <QGLPixelBuffer>
|
---|
7 |
|
---|
8 | #include "Vector3.h"
|
---|
9 | #include "Containers.h"
|
---|
10 | #include "Halton.h"
|
---|
11 | #include "Renderer.h"
|
---|
12 |
|
---|
13 | class SceneGraph;
|
---|
14 | class ViewCellsManager;
|
---|
15 | class Mesh;
|
---|
16 | class MeshInstance;
|
---|
17 | class Intersectable;
|
---|
18 | class Material;
|
---|
19 | class Beam;
|
---|
20 | class KdTree;
|
---|
21 |
|
---|
22 | class BeamSampleStatistics;
|
---|
23 |
|
---|
24 | struct PvsRenderStatistics {
|
---|
25 |
|
---|
26 | float maxError;
|
---|
27 | float sumError;
|
---|
28 | int frames;
|
---|
29 | int errorFreeFrames;
|
---|
30 |
|
---|
31 | PvsRenderStatistics() { Reset(); }
|
---|
32 |
|
---|
33 | void Reset() {
|
---|
34 | maxError = 0.0f;
|
---|
35 | sumError = 0.0f;
|
---|
36 | frames = 0;
|
---|
37 | errorFreeFrames = 0;
|
---|
38 | }
|
---|
39 |
|
---|
40 | float GetMaxError() { return maxError; }
|
---|
41 | float GetAvgError() { return sumError/frames; }
|
---|
42 | float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
|
---|
43 |
|
---|
44 | };
|
---|
45 |
|
---|
46 |
|
---|
47 | /** Class encapsulating gl rendering for the scene.
|
---|
48 | There is no gl context binding so the binding is performed in the
|
---|
49 | derived classes
|
---|
50 | */
|
---|
51 |
|
---|
52 | class GlRenderer: public Renderer
|
---|
53 | {
|
---|
54 |
|
---|
55 | public:
|
---|
56 | ObjectContainer mObjects;
|
---|
57 |
|
---|
58 | Vector3 mViewPoint;
|
---|
59 | Vector3 mViewDirection;
|
---|
60 |
|
---|
61 | int timerId;
|
---|
62 | bool mUseFalseColors;
|
---|
63 |
|
---|
64 | HaltonSequence halton;
|
---|
65 |
|
---|
66 | int mFrame;
|
---|
67 | bool mWireFrame;
|
---|
68 |
|
---|
69 | KdTree *mKdTree;
|
---|
70 |
|
---|
71 | QWaitCondition mRenderingFinished;
|
---|
72 |
|
---|
73 |
|
---|
74 | GlRenderer(SceneGraph *sceneGraph,
|
---|
75 | ViewCellsManager *viewcells,
|
---|
76 | KdTree *tree);
|
---|
77 |
|
---|
78 | ~GlRenderer();
|
---|
79 |
|
---|
80 |
|
---|
81 | void SetupFalseColor(const int id);
|
---|
82 | void RenderIntersectable(Intersectable *);
|
---|
83 | void RenderViewCell(ViewCell *vc);
|
---|
84 | void RenderMeshInstance(MeshInstance *mi);
|
---|
85 | void RenderMesh(Mesh *m);
|
---|
86 | void SetupMaterial(Material *m);
|
---|
87 | virtual void SetupCamera();
|
---|
88 | void RandomViewPoint();
|
---|
89 |
|
---|
90 | bool
|
---|
91 | RenderScene();
|
---|
92 |
|
---|
93 | void
|
---|
94 | SetupProjection(const int w, const int h);
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|
98 | float
|
---|
99 | GetPixelError();
|
---|
100 |
|
---|
101 | void InitGL();
|
---|
102 |
|
---|
103 | virtual int GetWidth() const = 0;
|
---|
104 | virtual int GetHeight() const = 0;
|
---|
105 | };
|
---|
106 |
|
---|
107 |
|
---|
108 | class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
|
---|
109 | {
|
---|
110 | public:
|
---|
111 | GlRendererBuffer(const int w,
|
---|
112 | const int h,
|
---|
113 | SceneGraph *sceneGraph,
|
---|
114 | ViewCellsManager *viewcells,
|
---|
115 | KdTree *tree):
|
---|
116 | QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells, tree) {
|
---|
117 |
|
---|
118 | mPvsStatFrames = 10000;
|
---|
119 | mPvsErrorBuffer.resize(mPvsStatFrames);
|
---|
120 | ClearErrorBuffer();
|
---|
121 |
|
---|
122 | makeCurrent();
|
---|
123 | InitGL();
|
---|
124 | doneCurrent();
|
---|
125 |
|
---|
126 | }
|
---|
127 |
|
---|
128 | void
|
---|
129 | EvalPvsStat();
|
---|
130 |
|
---|
131 | void
|
---|
132 | ClearErrorBuffer();
|
---|
133 |
|
---|
134 |
|
---|
135 | virtual int GetWidth() const { return width(); }
|
---|
136 | virtual int GetHeight() const { return height(); }
|
---|
137 |
|
---|
138 |
|
---|
139 | void SampleBeamContributions(
|
---|
140 | Intersectable *sourceObject,
|
---|
141 | Beam &beam,
|
---|
142 | const int samples,
|
---|
143 | BeamSampleStatistics &stat
|
---|
144 | );
|
---|
145 |
|
---|
146 | void
|
---|
147 | SampleViewpointContributions(
|
---|
148 | Intersectable *sourceObject,
|
---|
149 | const Vector3 viewPoint,
|
---|
150 | Beam &beam,
|
---|
151 | const int desiredSamples,
|
---|
152 | BeamSampleStatistics &stat
|
---|
153 | );
|
---|
154 |
|
---|
155 | PvsRenderStatistics mPvsStat;
|
---|
156 |
|
---|
157 | int mPvsStatFrames;
|
---|
158 | vector<float> mPvsErrorBuffer;
|
---|
159 |
|
---|
160 | private:
|
---|
161 | static void GenQueries(const int numQueries);
|
---|
162 | void SetupProjectionForViewPoint(const Vector3 &viewPoint, |
---|
163 | const Beam &beam, |
---|
164 | Intersectable *sourceObject);
|
---|
165 | };
|
---|
166 |
|
---|
167 |
|
---|
168 |
|
---|
169 | class GlRendererWidget : public QGLWidget, public GlRenderer
|
---|
170 | {
|
---|
171 | Q_OBJECT
|
---|
172 | public:
|
---|
173 |
|
---|
174 | // point of the last mouse click used for movement in the scene
|
---|
175 | Vector3 mousePoint;
|
---|
176 |
|
---|
177 | bool mTopView;
|
---|
178 |
|
---|
179 | GlRendererWidget(SceneGraph *sceneGraph,
|
---|
180 | ViewCellsManager *viewcells,
|
---|
181 | KdTree *tree,
|
---|
182 | QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
|
---|
183 | ):
|
---|
184 | GlRenderer(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
|
---|
185 | {
|
---|
186 | mTopView = false;
|
---|
187 | }
|
---|
188 |
|
---|
189 | virtual void SetupCamera();
|
---|
190 |
|
---|
191 | void initializeGL() {
|
---|
192 | InitGL();
|
---|
193 | }
|
---|
194 | void resizeGL(int w, int h);
|
---|
195 | void paintGL();
|
---|
196 | void timerEvent(QTimerEvent *) {
|
---|
197 | update();
|
---|
198 | }
|
---|
199 |
|
---|
200 | void mousePressEvent(QMouseEvent *);
|
---|
201 | void mouseReleaseEvent(QMouseEvent *);
|
---|
202 | void mouseMoveEvent(QMouseEvent *);
|
---|
203 |
|
---|
204 | void keyPressEvent ( QKeyEvent * e ) ;
|
---|
205 |
|
---|
206 | float
|
---|
207 | RenderErrors();
|
---|
208 |
|
---|
209 | virtual int GetWidth() const { return width(); }
|
---|
210 | virtual int GetHeight() const { return height(); }
|
---|
211 | };
|
---|
212 |
|
---|
213 |
|
---|
214 | extern GlRendererWidget *rendererWidget;
|
---|
215 |
|
---|
216 | #endif
|
---|
217 |
|
---|