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