[492] | 1 | #ifndef __RENDERER_H
|
---|
| 2 | #define __RENDERER_H
|
---|
| 3 |
|
---|
| 4 | #include <QtOpenGL>
|
---|
| 5 | #include <QWaitCondition>
|
---|
[500] | 6 | //#include <QGLPixelBuffer>
|
---|
[492] | 7 |
|
---|
| 8 | #include "Vector3.h"
|
---|
| 9 | #include "Containers.h"
|
---|
| 10 | #include "Halton.h"
|
---|
[497] | 11 | #include "Renderer.h"
|
---|
[540] | 12 | #include "Beam.h"
|
---|
[492] | 13 |
|
---|
| 14 | class SceneGraph;
|
---|
| 15 | class ViewCellsManager;
|
---|
| 16 | class Mesh;
|
---|
| 17 | class MeshInstance;
|
---|
| 18 | class Intersectable;
|
---|
| 19 | class Material;
|
---|
[512] | 20 | class Beam;
|
---|
[532] | 21 | class KdTree;
|
---|
[538] | 22 | class QWidget;
|
---|
| 23 | class GlRendererBuffer;
|
---|
[531] | 24 | class BeamSampleStatistics;
|
---|
| 25 |
|
---|
[540] | 26 | struct VssRayContainer;
|
---|
| 27 |
|
---|
[492] | 28 | struct PvsRenderStatistics {
|
---|
| 29 |
|
---|
| 30 | float maxError;
|
---|
| 31 | float sumError;
|
---|
[713] | 32 | int sumPvsSize;
|
---|
[492] | 33 | int frames;
|
---|
| 34 | int errorFreeFrames;
|
---|
[502] | 35 |
|
---|
[492] | 36 | PvsRenderStatistics() { Reset(); }
|
---|
| 37 |
|
---|
[498] | 38 | void Reset() {
|
---|
[492] | 39 | maxError = 0.0f;
|
---|
| 40 | sumError = 0.0f;
|
---|
| 41 | frames = 0;
|
---|
| 42 | errorFreeFrames = 0;
|
---|
[713] | 43 | sumPvsSize = 0;
|
---|
[492] | 44 | }
|
---|
| 45 |
|
---|
| 46 | float GetMaxError() { return maxError; }
|
---|
| 47 | float GetAvgError() { return sumError/frames; }
|
---|
| 48 | float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
|
---|
[713] | 49 | float GetAvgPvs() { return sumPvsSize/(float)frames; }
|
---|
[492] | 50 |
|
---|
| 51 | };
|
---|
| 52 |
|
---|
[496] | 53 |
|
---|
| 54 | /** Class encapsulating gl rendering for the scene.
|
---|
| 55 | There is no gl context binding so the binding is performed in the
|
---|
| 56 | derived classes
|
---|
| 57 | */
|
---|
| 58 |
|
---|
[497] | 59 | class GlRenderer: public Renderer
|
---|
[492] | 60 | {
|
---|
[496] | 61 |
|
---|
[492] | 62 | public:
|
---|
| 63 | ObjectContainer mObjects;
|
---|
[498] | 64 |
|
---|
[492] | 65 | Vector3 mViewPoint;
|
---|
| 66 | Vector3 mViewDirection;
|
---|
| 67 |
|
---|
| 68 | int timerId;
|
---|
| 69 | bool mUseFalseColors;
|
---|
| 70 |
|
---|
| 71 | HaltonSequence halton;
|
---|
| 72 |
|
---|
| 73 | int mFrame;
|
---|
[502] | 74 | bool mWireFrame;
|
---|
[589] | 75 |
|
---|
| 76 | bool mDetectEmptyViewSpace;
|
---|
| 77 | bool mSnapErrorFrames;
|
---|
| 78 | QString mSnapPrefix;
|
---|
[502] | 79 |
|
---|
[532] | 80 | KdTree *mKdTree;
|
---|
| 81 |
|
---|
[492] | 82 | QWaitCondition mRenderingFinished;
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | GlRenderer(SceneGraph *sceneGraph,
|
---|
[532] | 86 | ViewCellsManager *viewcells,
|
---|
| 87 | KdTree *tree);
|
---|
[496] | 88 |
|
---|
[492] | 89 | ~GlRenderer();
|
---|
| 90 |
|
---|
[496] | 91 |
|
---|
[492] | 92 | void SetupFalseColor(const int id);
|
---|
| 93 | void RenderIntersectable(Intersectable *);
|
---|
[535] | 94 | void RenderViewCell(ViewCell *vc);
|
---|
[492] | 95 | void RenderMeshInstance(MeshInstance *mi);
|
---|
| 96 | void RenderMesh(Mesh *m);
|
---|
| 97 | void SetupMaterial(Material *m);
|
---|
[502] | 98 | virtual void SetupCamera();
|
---|
[496] | 99 |
|
---|
[497] | 100 | bool
|
---|
[496] | 101 | RenderScene();
|
---|
[492] | 102 |
|
---|
[589] | 103 |
|
---|
[608] | 104 | virtual void
|
---|
[496] | 105 | SetupProjection(const int w, const int h);
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | void InitGL();
|
---|
| 111 |
|
---|
| 112 | virtual int GetWidth() const = 0;
|
---|
| 113 | virtual int GetHeight() const = 0;
|
---|
[540] | 114 |
|
---|
| 115 | int GetId(int r, int g, int b) const;
|
---|
[496] | 116 | };
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 | class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
|
---|
| 120 | {
|
---|
| 121 | public:
|
---|
[532] | 122 | GlRendererBuffer(const int w,
|
---|
| 123 | const int h,
|
---|
| 124 | SceneGraph *sceneGraph,
|
---|
| 125 | ViewCellsManager *viewcells,
|
---|
[589] | 126 | KdTree *tree);
|
---|
| 127 |
|
---|
[496] | 128 |
|
---|
| 129 | void
|
---|
| 130 | EvalPvsStat();
|
---|
| 131 |
|
---|
| 132 | void
|
---|
| 133 | ClearErrorBuffer();
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | virtual int GetWidth() const { return width(); }
|
---|
| 137 | virtual int GetHeight() const { return height(); }
|
---|
| 138 |
|
---|
[507] | 139 |
|
---|
[563] | 140 | void RandomViewPoint();
|
---|
[507] | 141 | void SampleBeamContributions(
|
---|
| 142 | Intersectable *sourceObject,
|
---|
[512] | 143 | Beam &beam,
|
---|
[507] | 144 | const int samples,
|
---|
| 145 | BeamSampleStatistics &stat
|
---|
| 146 | );
|
---|
| 147 |
|
---|
| 148 | void
|
---|
| 149 | SampleViewpointContributions(
|
---|
| 150 | Intersectable *sourceObject,
|
---|
[514] | 151 | const Vector3 viewPoint,
|
---|
[512] | 152 | Beam &beam,
|
---|
[507] | 153 | const int desiredSamples,
|
---|
| 154 | BeamSampleStatistics &stat
|
---|
| 155 | );
|
---|
| 156 |
|
---|
[540] | 157 | void InitGL();
|
---|
| 158 |
|
---|
| 159 | /** Computes rays from information gained with hw sampling-
|
---|
| 160 | */
|
---|
| 161 | void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
| 162 |
|
---|
| 163 | int ComputePvs() const;
|
---|
| 164 |
|
---|
[576] | 165 | float
|
---|
[713] | 166 | GetPixelError(int &pvsSize);
|
---|
[540] | 167 |
|
---|
| 168 | int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
|
---|
| 169 |
|
---|
| 170 | PvsRenderStatistics mPvsStat;
|
---|
[532] | 171 |
|
---|
[540] | 172 | int mPvsStatFrames;
|
---|
[713] | 173 | struct PvsErrorEntry {
|
---|
| 174 | PvsErrorEntry() {}
|
---|
| 175 | float mError;
|
---|
| 176 | int mPvsSize;
|
---|
| 177 | };
|
---|
| 178 |
|
---|
| 179 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
| 180 |
|
---|
[513] | 181 | private:
|
---|
[540] | 182 |
|
---|
[513] | 183 | static void GenQueries(const int numQueries);
|
---|
[589] | 184 |
|
---|
| 185 | void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
| 186 | const Beam &beam,
|
---|
[525] | 187 | Intersectable *sourceObject);
|
---|
[496] | 188 | };
|
---|
| 189 |
|
---|
| 190 |
|
---|
[608] | 191 | class RendererControlWidget : public QWidget
|
---|
| 192 | {
|
---|
| 193 | Q_OBJECT
|
---|
| 194 | public:
|
---|
| 195 | RendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
|
---|
[496] | 196 |
|
---|
[608] | 197 | signals:
|
---|
| 198 |
|
---|
| 199 | SetViewCellGranularity(int);
|
---|
| 200 | SetSceneCut(int);
|
---|
| 201 | SetTopDistance(int);
|
---|
[713] | 202 | SetVisibilityFilterSize(int);
|
---|
[608] | 203 |
|
---|
| 204 | SetShowViewCells(bool);
|
---|
| 205 | SetTopView(bool);
|
---|
| 206 | SetCutViewCells(bool);
|
---|
| 207 | SetCutScene(bool);
|
---|
| 208 |
|
---|
[713] | 209 |
|
---|
[608] | 210 | };
|
---|
| 211 |
|
---|
[496] | 212 | class GlRendererWidget : public QGLWidget, public GlRenderer
|
---|
| 213 | {
|
---|
| 214 | Q_OBJECT
|
---|
| 215 | public:
|
---|
| 216 |
|
---|
[502] | 217 | // point of the last mouse click used for movement in the scene
|
---|
| 218 | Vector3 mousePoint;
|
---|
| 219 |
|
---|
| 220 | bool mTopView;
|
---|
[599] | 221 | bool mRenderViewCells;
|
---|
[608] | 222 | bool mCutViewCells;
|
---|
| 223 | bool mCutScene;
|
---|
[502] | 224 |
|
---|
[608] | 225 | Plane3 mSceneCutPlane;
|
---|
| 226 | float mTopDistance;
|
---|
| 227 |
|
---|
[496] | 228 | GlRendererWidget(SceneGraph *sceneGraph,
|
---|
| 229 | ViewCellsManager *viewcells,
|
---|
[532] | 230 | KdTree *tree,
|
---|
[496] | 231 | QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
|
---|
[599] | 232 | );
|
---|
[496] | 233 |
|
---|
[599] | 234 |
|
---|
[502] | 235 | virtual void SetupCamera();
|
---|
| 236 |
|
---|
[496] | 237 | void initializeGL() {
|
---|
| 238 | InitGL();
|
---|
| 239 | }
|
---|
[492] | 240 | void resizeGL(int w, int h);
|
---|
| 241 | void paintGL();
|
---|
| 242 | void timerEvent(QTimerEvent *) {
|
---|
| 243 | update();
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | void mousePressEvent(QMouseEvent *);
|
---|
| 247 | void mouseReleaseEvent(QMouseEvent *);
|
---|
| 248 | void mouseMoveEvent(QMouseEvent *);
|
---|
| 249 |
|
---|
[504] | 250 | void keyPressEvent ( QKeyEvent * e ) ;
|
---|
| 251 |
|
---|
[492] | 252 | float
|
---|
[589] | 253 | RenderErrors();
|
---|
| 254 | void
|
---|
| 255 | RenderInfo();
|
---|
[492] | 256 |
|
---|
[496] | 257 | virtual int GetWidth() const { return width(); }
|
---|
| 258 | virtual int GetHeight() const { return height(); }
|
---|
[599] | 259 |
|
---|
[608] | 260 | virtual void
|
---|
| 261 | SetupProjection(const int w, const int h);
|
---|
[599] | 262 |
|
---|
| 263 | void
|
---|
| 264 | RenderViewCells();
|
---|
| 265 |
|
---|
| 266 | public slots:
|
---|
| 267 | void
|
---|
[608] | 268 | SetViewCellGranularity(int number);
|
---|
[599] | 269 |
|
---|
[713] | 270 | void
|
---|
| 271 | SetVisibilityFilterSize(int number);
|
---|
[599] | 272 |
|
---|
[713] | 273 | void
|
---|
| 274 | SetSceneCut(int cut);
|
---|
| 275 |
|
---|
| 276 | void
|
---|
| 277 | SetTopDistance(int dist);
|
---|
| 278 |
|
---|
[608] | 279 | void SetShowViewCells(bool b) {
|
---|
| 280 | mRenderViewCells = b;
|
---|
| 281 | updateGL();
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | void SetTopView(bool b) {
|
---|
| 285 | mTopView = b;
|
---|
| 286 | updateGL();
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | void SetCutViewCells(bool b) {
|
---|
| 290 | mCutViewCells = b;
|
---|
| 291 | updateGL();
|
---|
| 292 | }
|
---|
| 293 | void SetCutScene(bool b) {
|
---|
| 294 | mCutScene = b;
|
---|
| 295 | updateGL();
|
---|
| 296 | }
|
---|
| 297 |
|
---|
[492] | 298 | };
|
---|
| 299 |
|
---|
| 300 |
|
---|
[496] | 301 | extern GlRendererWidget *rendererWidget;
|
---|
[492] | 302 |
|
---|
[538] | 303 | class GlDebuggerWidget : public QGLWidget
|
---|
| 304 | {
|
---|
[540] | 305 | Q_OBJECT
|
---|
[538] | 306 | public:
|
---|
[540] | 307 | GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL);
|
---|
[538] | 308 | ~GlDebuggerWidget();
|
---|
| 309 | void initializeGL();
|
---|
| 310 | void resizeGL(int w, int h);
|
---|
| 311 | void paintGL();
|
---|
| 312 | void timerEvent(QTimerEvent *) { update(); }
|
---|
| 313 | void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
|
---|
| 314 | void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
|
---|
| 315 |
|
---|
| 316 | void initCommon();
|
---|
| 317 | void initPbuffer();
|
---|
| 318 |
|
---|
[608] | 319 |
|
---|
[538] | 320 | GlRendererBuffer *mRenderBuffer;
|
---|
| 321 |
|
---|
[540] | 322 | Beam mBeam;
|
---|
| 323 | int mSamples;
|
---|
| 324 | Intersectable *mSourceObject;
|
---|
[608] | 325 |
|
---|
[538] | 326 | private:
|
---|
| 327 | GLuint dynamicTexture;
|
---|
| 328 | int timerId;
|
---|
| 329 | };
|
---|
| 330 |
|
---|
| 331 | extern GlDebuggerWidget *debuggerWidget;
|
---|
| 332 |
|
---|
[492] | 333 | #endif
|
---|
| 334 |
|
---|