[1387] | 1 | #ifndef __QTGLRENDERER_H
|
---|
| 2 | #define __QTGLRENDERER_H
|
---|
| 3 |
|
---|
| 4 | #include <QtOpenGL>
|
---|
| 5 | #include <QWaitCondition>
|
---|
| 6 |
|
---|
| 7 | //#include <QGLPixelBuffer>
|
---|
| 8 |
|
---|
| 9 | #include "Vector3.h"
|
---|
| 10 | #include "Containers.h"
|
---|
| 11 | #include "Halton.h"
|
---|
| 12 | #include "Renderer.h"
|
---|
| 13 | #include "GlRenderer.h"
|
---|
| 14 | #include "Beam.h"
|
---|
[1613] | 15 | #include "QtPreprocessorThread.h"
|
---|
[1387] | 16 | class QWidget;
|
---|
[1613] | 17 | //class QtPreprocessorThread;
|
---|
[1387] | 18 |
|
---|
| 19 | namespace GtpVisibilityPreprocessor {
|
---|
| 20 |
|
---|
| 21 | class SceneGraph;
|
---|
| 22 | class ViewCellsManager;
|
---|
| 23 | class Mesh;
|
---|
| 24 | class MeshInstance;
|
---|
| 25 | class Intersectable;
|
---|
| 26 | class Material;
|
---|
| 27 | class Beam;
|
---|
| 28 | class KdTree;
|
---|
| 29 | class GlRendererBuffer;
|
---|
| 30 | class BeamSampleStatistics;
|
---|
| 31 | class OcclusionQuery;
|
---|
| 32 | class TransformedMeshInstance;
|
---|
| 33 |
|
---|
[1581] | 34 |
|
---|
[1387] | 35 | struct VssRayContainer;
|
---|
| 36 | struct PvsRenderStatistics;
|
---|
| 37 | struct RenderCostSample;
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer
|
---|
| 41 | {
|
---|
| 42 | Q_OBJECT
|
---|
| 43 | public:
|
---|
| 44 | QtGlRendererBuffer(const int w,
|
---|
| 45 | const int h,
|
---|
| 46 | SceneGraph *sceneGraph,
|
---|
| 47 | ViewCellsManager *viewcells,
|
---|
| 48 | KdTree *tree);
|
---|
| 49 |
|
---|
| 50 | ~QtGlRendererBuffer();
|
---|
| 51 |
|
---|
| 52 | /** Evaluates render cost of a point sample.
|
---|
| 53 | @param sample the render cost sample to be evaluated
|
---|
| 54 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 55 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
| 56 | */
|
---|
| 57 | void EvalRenderCostSample(RenderCostSample &sample,
|
---|
| 58 | const bool useOcclusionQueries,
|
---|
| 59 | const int threshold);
|
---|
| 60 |
|
---|
| 61 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
| 62 | are distributed uniformly over the defined view space.
|
---|
| 63 |
|
---|
| 64 | @param numSamples the number of point samples taken
|
---|
| 65 | @param samples stores the taken point samples in a container
|
---|
| 66 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 67 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
| 68 | */
|
---|
| 69 | void SampleRenderCost(const int numSamples,
|
---|
| 70 | vector<RenderCostSample> &samples,
|
---|
| 71 | const bool useOcclusionQueries,
|
---|
| 72 | const int threshold = 0);
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | void
|
---|
| 76 | EvalPvsStat();
|
---|
| 77 |
|
---|
| 78 | void
|
---|
| 79 | ClearErrorBuffer();
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | virtual int GetWidth() const { return width(); }
|
---|
| 83 | virtual int GetHeight() const { return height(); }
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | void SampleBeamContributions(
|
---|
| 88 | Intersectable *sourceObject,
|
---|
| 89 | Beam &beam,
|
---|
| 90 | const int samples,
|
---|
| 91 | BeamSampleStatistics &stat
|
---|
| 92 | );
|
---|
| 93 |
|
---|
| 94 | void
|
---|
| 95 | SampleViewpointContributions(
|
---|
| 96 | Intersectable *sourceObject,
|
---|
| 97 | const Vector3 viewPoint,
|
---|
| 98 | Beam &beam,
|
---|
| 99 | const int desiredSamples,
|
---|
| 100 | BeamSampleStatistics &stat
|
---|
| 101 | );
|
---|
| 102 |
|
---|
| 103 | void InitGL();
|
---|
| 104 |
|
---|
| 105 | /** Computes rays from information gained with hw sampling-
|
---|
| 106 | */
|
---|
| 107 | void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
| 108 |
|
---|
| 109 | int ComputePvs() const;
|
---|
| 110 |
|
---|
| 111 | float
|
---|
| 112 | GetPixelError(int &pvsSize);
|
---|
| 113 |
|
---|
| 114 | int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 | private:
|
---|
| 118 |
|
---|
| 119 | void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
| 120 | const Beam &beam,
|
---|
| 121 | Intersectable *sourceObject);
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | public:
|
---|
| 125 | signals:
|
---|
| 126 | void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
| 127 | };
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | class QtRendererControlWidget : public QWidget
|
---|
| 131 | {
|
---|
| 132 | Q_OBJECT
|
---|
| 133 | public:
|
---|
| 134 |
|
---|
| 135 | QListWidget *mPvsErrorWidget;
|
---|
| 136 |
|
---|
| 137 | QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
|
---|
| 138 |
|
---|
| 139 | public slots:
|
---|
| 140 |
|
---|
| 141 | void FocusNextPvsErrorFrame();
|
---|
| 142 | void UpdatePvsErrorItem(int i,
|
---|
| 143 | GlRendererBuffer::PvsErrorEntry &);
|
---|
| 144 |
|
---|
| 145 | signals:
|
---|
[1613] | 146 |
|
---|
| 147 | void ComputeVisibility();
|
---|
| 148 | void StopComputation();
|
---|
| 149 | void UpdateAllPvs();
|
---|
[1387] | 150 | void SetViewCellGranularity(int);
|
---|
| 151 | void SetSceneCut(int);
|
---|
| 152 | void SetTopDistance(int);
|
---|
| 153 | void SetVisibilityFilterSize(int);
|
---|
| 154 | void SetSpatialFilterSize(int);
|
---|
| 155 |
|
---|
[1581] | 156 | void SetShowRays(bool);
|
---|
[1387] | 157 | void SetRenderFilter(bool);
|
---|
[1594] | 158 | void SetRenderVisibilityEstimates(bool);
|
---|
[1387] | 159 | void SetUseFilter(bool);
|
---|
| 160 | void SetUseSpatialFilter(bool);
|
---|
| 161 | void SetRenderErrors(bool);
|
---|
[1594] | 162 | void SetRenderBoxes(bool);
|
---|
[1387] | 163 | void SetShowViewCells(bool);
|
---|
| 164 | void SetShowRenderCost(bool);
|
---|
| 165 | void SetShowPvsSizes(bool);
|
---|
| 166 | void SetTopView(bool);
|
---|
| 167 | void SetCutViewCells(bool);
|
---|
| 168 | void SetCutScene(bool);
|
---|
| 169 |
|
---|
| 170 |
|
---|
| 171 | };
|
---|
| 172 |
|
---|
| 173 | class QtGlRendererWidget : public QGLWidget, public GlRendererWidget
|
---|
| 174 | {
|
---|
| 175 | Q_OBJECT
|
---|
| 176 | public:
|
---|
| 177 |
|
---|
| 178 | // point of the last mouse click used for movement in the scene
|
---|
| 179 | Vector3 mousePoint;
|
---|
| 180 |
|
---|
| 181 | bool mTopView;
|
---|
| 182 | bool mRenderViewCells;
|
---|
| 183 | bool mCutViewCells;
|
---|
| 184 | bool mCutScene;
|
---|
| 185 | bool mRenderErrors;
|
---|
| 186 | bool mRenderFilter;
|
---|
[1594] | 187 | bool mRenderVisibilityEstimates;
|
---|
[1387] | 188 | bool mUseFilter;
|
---|
| 189 | bool mUseSpatialFilter;
|
---|
| 190 | bool mShowRenderCost;
|
---|
[1581] | 191 | bool mShowRays;
|
---|
| 192 |
|
---|
[1387] | 193 | bool mShowPvsSizes;
|
---|
| 194 | float mSpatialFilterSize;
|
---|
| 195 |
|
---|
| 196 | Plane3 mSceneCutPlane;
|
---|
| 197 | float mTopDistance;
|
---|
| 198 |
|
---|
| 199 | // some statistics
|
---|
| 200 | int mPvsSize;
|
---|
| 201 | float mRenderError;
|
---|
| 202 |
|
---|
[1581] | 203 |
|
---|
| 204 | float mManipulatorLastQuat[4];
|
---|
| 205 | float mManipulatorScale;
|
---|
| 206 |
|
---|
[1387] | 207 | QtRendererControlWidget *mControlWidget;
|
---|
[1613] | 208 |
|
---|
| 209 | QtPreprocessorThread *mPreprocessorThread;
|
---|
[1387] | 210 |
|
---|
| 211 | QtGlRendererWidget(SceneGraph *sceneGraph,
|
---|
| 212 | ViewCellsManager *viewcells,
|
---|
| 213 | KdTree *tree,
|
---|
| 214 | QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
|
---|
| 215 | );
|
---|
| 216 |
|
---|
| 217 | QtGlRendererWidget() {};
|
---|
| 218 |
|
---|
[1613] | 219 | void SetThread(QtPreprocessorThread *t) {
|
---|
| 220 | mPreprocessorThread = t;
|
---|
| 221 | }
|
---|
[1584] | 222 | void
|
---|
| 223 | RenderRenderCost();
|
---|
| 224 |
|
---|
[1387] | 225 | virtual void SetupCamera();
|
---|
[1581] | 226 | // setup a transformation for manipulator
|
---|
| 227 | void
|
---|
| 228 | SetupManipulator();
|
---|
[1387] | 229 |
|
---|
| 230 | void initializeGL() {
|
---|
| 231 | InitGL();
|
---|
| 232 | }
|
---|
| 233 | void resizeGL(int w, int h);
|
---|
| 234 | void paintGL();
|
---|
| 235 | void timerEvent(QTimerEvent *) {
|
---|
| 236 | update();
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | void mousePressEvent(QMouseEvent *);
|
---|
| 240 | void mouseReleaseEvent(QMouseEvent *);
|
---|
| 241 | void mouseMoveEvent(QMouseEvent *);
|
---|
| 242 |
|
---|
| 243 | void keyPressEvent ( QKeyEvent * e ) ;
|
---|
| 244 |
|
---|
| 245 | void
|
---|
| 246 | RenderPvs();
|
---|
| 247 |
|
---|
| 248 | float
|
---|
| 249 | RenderErrors();
|
---|
| 250 | void
|
---|
| 251 | RenderInfo();
|
---|
| 252 |
|
---|
| 253 | virtual int GetWidth() const { return width(); }
|
---|
| 254 | virtual int GetHeight() const { return height(); }
|
---|
| 255 |
|
---|
[1581] | 256 | // virtual void
|
---|
| 257 | // SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
[1387] | 258 |
|
---|
[1581] | 259 | virtual void
|
---|
| 260 | SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
|
---|
| 261 |
|
---|
| 262 | virtual void
|
---|
| 263 | SetupManipulatorProjection(const int w, const int h, const float angle = 70.0f);
|
---|
| 264 |
|
---|
[1387] | 265 | void
|
---|
| 266 | RenderViewCells();
|
---|
| 267 |
|
---|
| 268 |
|
---|
| 269 | virtual void Show() {
|
---|
| 270 | show();
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | public slots:
|
---|
| 274 |
|
---|
[1613] | 275 | void UpdateAllPvs();
|
---|
| 276 | void ComputeVisibility();
|
---|
| 277 | void StopComputation();
|
---|
| 278 |
|
---|
[1387] | 279 | void SetRenderErrors(bool b) {
|
---|
| 280 | mRenderErrors = b;
|
---|
| 281 | updateGL();
|
---|
| 282 | }
|
---|
| 283 |
|
---|
[1594] | 284 | void SetRenderBoxes(bool b) {
|
---|
| 285 | mRenderBoxes = b;
|
---|
| 286 | updateGL();
|
---|
| 287 | }
|
---|
| 288 |
|
---|
[1387] | 289 | void SetRenderFilter(bool b) {
|
---|
| 290 | mRenderFilter = b;
|
---|
| 291 | updateGL();
|
---|
| 292 | }
|
---|
| 293 |
|
---|
[1594] | 294 | void SetRenderVisibilityEstimates(bool b) {
|
---|
| 295 | mRenderVisibilityEstimates = b;
|
---|
| 296 | updateGL();
|
---|
| 297 | }
|
---|
| 298 |
|
---|
[1387] | 299 | void SetUseFilter(bool b) {
|
---|
| 300 | mUseFilter = b;
|
---|
| 301 | updateGL();
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | void SetUseSpatialFilter(bool b) {
|
---|
| 305 | mUseSpatialFilter = b;
|
---|
| 306 | updateGL();
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 |
|
---|
| 310 | void
|
---|
| 311 | SetViewCellGranularity(int number);
|
---|
| 312 |
|
---|
| 313 | void
|
---|
| 314 | SetVisibilityFilterSize(int number);
|
---|
| 315 |
|
---|
| 316 | void
|
---|
| 317 | SetSpatialFilterSize(int number);
|
---|
| 318 |
|
---|
| 319 | void
|
---|
| 320 | SetSceneCut(int cut);
|
---|
| 321 |
|
---|
| 322 | void
|
---|
| 323 | SetTopDistance(int dist);
|
---|
| 324 |
|
---|
| 325 | void SetShowViewCells(bool b) {
|
---|
| 326 | mRenderViewCells = b;
|
---|
| 327 | updateGL();
|
---|
| 328 | }
|
---|
| 329 |
|
---|
[1581] | 330 | void SetShowRays(bool b) {
|
---|
| 331 | mShowRays = b;
|
---|
| 332 | updateGL();
|
---|
| 333 | }
|
---|
| 334 |
|
---|
[1387] | 335 | void SetShowRenderCost(bool b) {
|
---|
| 336 | mShowRenderCost = b;
|
---|
| 337 | updateGL();
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | void SetShowPvsSizes(bool b) {
|
---|
| 341 | mShowPvsSizes = b;
|
---|
| 342 | updateGL();
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | void SetTopView(bool b) {
|
---|
| 346 | mTopView = b;
|
---|
| 347 | updateGL();
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | void SetCutViewCells(bool b) {
|
---|
| 351 | mCutViewCells = b;
|
---|
| 352 | updateGL();
|
---|
| 353 | }
|
---|
| 354 | void SetCutScene(bool b) {
|
---|
| 355 | mCutScene = b;
|
---|
| 356 | updateGL();
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 |
|
---|
| 360 | };
|
---|
| 361 |
|
---|
| 362 |
|
---|
| 363 | class QtGlDebuggerWidget : public QGLWidget
|
---|
| 364 | {
|
---|
| 365 | Q_OBJECT
|
---|
| 366 | public:
|
---|
| 367 | QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
|
---|
| 368 | ~QtGlDebuggerWidget();
|
---|
| 369 | void initializeGL();
|
---|
| 370 | void resizeGL(int w, int h);
|
---|
| 371 | void paintGL();
|
---|
| 372 | void timerEvent(QTimerEvent *) { update(); }
|
---|
| 373 | void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
|
---|
| 374 | void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
|
---|
| 375 |
|
---|
| 376 | void initCommon();
|
---|
| 377 | void initPbuffer();
|
---|
| 378 |
|
---|
| 379 |
|
---|
| 380 | QtGlRendererBuffer *mRenderBuffer;
|
---|
| 381 |
|
---|
| 382 | Beam mBeam;
|
---|
| 383 | int mSamples;
|
---|
| 384 | Intersectable *mSourceObject;
|
---|
| 385 |
|
---|
| 386 | private:
|
---|
| 387 | GLuint dynamicTexture;
|
---|
| 388 | int timerId;
|
---|
| 389 | };
|
---|
| 390 |
|
---|
| 391 | extern QtGlDebuggerWidget *debuggerWidget;
|
---|
| 392 |
|
---|
| 393 | };
|
---|
| 394 |
|
---|
| 395 | #endif
|
---|
| 396 |
|
---|