source: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h @ 2591

Revision 2591, 10.5 KB checked in by mattausch, 16 years ago (diff)
RevLine 
[1252]1#ifndef __QTGLRENDERER_H
2#define __QTGLRENDERER_H
3
4#include <QtOpenGL>
5#include <QWaitCondition>
[2543]6#include <QMutex>
[1252]7
8#include "Vector3.h"
9#include "Containers.h"
10#include "Halton.h"
11#include "Renderer.h"
12#include "GlRenderer.h"
13#include "Beam.h"
[1942]14#include "QtPreprocessorThread.h"
[2576]15#include "LogReader.h"
[2543]16
17
[1252]18class QWidget;
19
[2543]20
21
[1252]22namespace GtpVisibilityPreprocessor {
23
[2576]24
[1252]25class SceneGraph;
26class ViewCellsManager;
27class Mesh;
28class MeshInstance;
29class Intersectable;
30class Material;
31class Beam;
32class KdTree;
33class GlRendererBuffer;
34class BeamSampleStatistics;
35class OcclusionQuery;
36class TransformedMeshInstance;
37
[1942]38
[1252]39struct VssRayContainer;
40struct PvsRenderStatistics;
41struct RenderCostSample;
42
[2580]43//class LogWriter;
[1252]44
[2580]45
46
[1942]47class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer
[1252]48{
49        Q_OBJECT
50public:
51        QtGlRendererBuffer(const int w,
[1942]52                const int h,
53                SceneGraph *sceneGraph,
54                ViewCellsManager *viewcells,
55                KdTree *tree);
[1252]56
[1942]57  ~QtGlRendererBuffer() {}
[1252]58
[1942]59  virtual void MakeCurrent();
60  virtual void DoneCurrent();
[1252]61
[1942]62  virtual int GetWidth() const { return width(); }
63  virtual int GetHeight() const { return height(); }
[1252]64
[1942]65  int ComputePvs() const { return 0; }
66 
67  float
68  GetPixelError(int &pvsSize);
69 
70  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
71     
72 
73 
74 
[1252]75public:
[1942]76  signals:
77  void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
[1252]78};
79
80
[1942]81class QtRendererControlWidget : public QWidget
[1252]82{
[1942]83  Q_OBJECT
[1252]84public:
85
[1942]86  QListWidget *mPvsErrorWidget;
[1252]87
[1942]88  QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
[1252]89
[2569]90  QGroupBox *CreateVisualizationPanel(QWidget *parent);
91
[1942]92  public slots:
[1252]93
[1942]94  void FocusNextPvsErrorFrame();
95  void UpdatePvsErrorItem(int i,
96                                                  GlRendererBuffer::PvsErrorEntry &);
[1252]97
[2569]98 
99  QGroupBox *CreateRenderCostPanel(QWidget *parent);
[2587]100  QGroupBox *CreateRayVisualizationPanel(QWidget *parent);
[2569]101
102
[1942]103  signals:
[1252]104
[1942]105  void ComputeVisibility();
106  void StopComputation();
107  void SetRandomViewPoint();
[2584]108  void StoreStatistics();
[1942]109  void UpdateAllPvs();
110  void SetViewCellGranularity(int);
111  void SetTransferFunction(int);
112  void SetSceneCut(int);
113  void SetTopDistance(int);
[2562]114  void SetHidingCost(int);
[1942]115  void SetVisibilityFilterSize(int);
116  void SetSpatialFilterSize(int);
[2563]117  void SetTransparency(int);
[1252]118
[1942]119  void SetShowRays(bool);
120  void SetRenderFilter(bool);
121  void SetRenderVisibilityEstimates(bool);
122  void SetUseFilter(bool);
123  void SetUseSpatialFilter(bool);
124  void SetRenderErrors(bool);
125  void SetRenderBoxes(bool);
126  void SetShowViewCells(bool);
127  void SetShowRenderCost(bool);
128  void SetShowPvsSizes(bool);
[2560]129  void SetShowPiercingRays(bool);
[2566]130  void SetShowWeightedRays(bool);
[2580]131   void SetShowComparison(bool);
[2569]132  void SetShowWeightedCost(bool);
133 
[1942]134  void SetTopView(bool);
135  void SetCutViewCells(bool);
136  void SetCutScene(bool);
[2562]137
138  void SetHideByCost(bool);
[2564]139  void SetUseTransparency(bool);
[2569]140
141  void SetShowDistanceWeightedTriangles(bool);
142  void SetShowWeightedTriangles(bool);
143  void SetShowDistanceWeightedPvs(bool);
[2587]144
145  void UseConstColorForRayViz(bool);
146  void UseRayLengthForRayViz(bool);
147  void SetShowContribution(bool);
148  void SetShowDistribution(bool);
[2591]149
150  void SetShowDistribution1(bool);
151  void SetShowDistribution2(bool);
152  void SetShowDistribution3(bool);
153  void SetShowDistribution4(bool);
[1252]154};
155
[1926]156
[2576]157class QtGlRendererWidget: public QGLWidget, public GlRendererWidget
[1252]158{
[2543]159        Q_OBJECT
[1252]160public:
161
[2543]162        // point of the last mouse click used for movement in the scene
163        Vector3 mousePoint;
[1252]164
[2543]165        bool mTopView;
166        bool mRenderViewCells;
167        bool mCutViewCells;
168        bool mCutScene;
[2562]169        bool mHideByCost;
[2543]170        bool mRenderErrors;
171        bool mRenderFilter;
172        bool mRenderVisibilityEstimates;
173        bool mUseFilter;
174        bool mUseSpatialFilter;
175        bool mShowRenderCost;
[2560]176        bool mShowPiercingRays;
[2566]177        bool mShowWeightedRays;
[2543]178        bool mShowRays;
[1252]179
[2543]180        bool mShowPvsSizes;
[2580]181        bool mShowComparison;
[2543]182        float mSpatialFilterSize;
[1252]183
[2580]184        //LogWriter *mLogWriter;
[2543]185        Plane3 mSceneCutPlane;
[2562]186        float mHidingCost;
187
[2543]188        float mTopDistance;
[1252]189
[2563]190        float mTransparency;
[2564]191        bool mUseTransparency;
[2563]192
[2569]193        bool mShowWeightedCost;
194
195        bool mShowDistanceWeightedTriangles;
196        bool mShowDistanceWeightedPvs;
197        bool mShowWeightedTriangles;
[2591]198       
199        int mShowDistribution;
[2569]200
[2543]201        // some statistics
202        int mPvsSize;
203        float mRenderError;
204        float mTransferFunction;
[1252]205
[2543]206        unsigned int mIndexBufferSize;
[1252]207
[2566]208        Vector3 mDummyViewPoint;
209
[2587]210        int mRayVisualizationMethod;
211
[2543]212        QtRendererControlWidget *mControlWidget;
[1252]213
[2543]214        QtPreprocessorThread *mPreprocessorThread;
[1252]215
[2580]216        ViewCellInfoContainer mCompareInfo;
[2576]217
[2543]218        QtGlRendererWidget(SceneGraph *sceneGraph,
[2580]219                               ViewCellsManager *viewcells,
220                                           KdTree *tree,
221                                           QWidget * parent = 0,
222                                           const QGLWidget *shareWidget = 0,
223                                           Qt::WFlags f = 0);
[1997]224
[2543]225        QtGlRendererWidget() {};
[1252]226
[2584]227        void SetThread(QtPreprocessorThread *t)
228        {
[2543]229                mPreprocessorThread = t;
230        }
[2576]231        void RenderRenderCost();
[1252]232
[2543]233        virtual void SetupCamera();
[1252]234
[2543]235        void initializeGL() {
236                InitGL();
237        }
[1252]238
[2543]239        virtual void InitGL();
[1252]240
[2543]241        void resizeGL(int w, int h);
242        void paintGL();
243        void timerEvent(QTimerEvent *event);
244        void mousePressEvent(QMouseEvent *);
245        void mouseReleaseEvent(QMouseEvent *);
246        void mouseMoveEvent(QMouseEvent *);
[1252]247
[2543]248        void keyPressEvent(QKeyEvent * e);
[1252]249
[2543]250        void RenderPvs();
[1252]251
[2543]252        float RenderErrors();
253        void RenderInfo();
[1252]254
[2543]255        virtual int GetWidth() const { return width(); }
256        virtual int GetHeight() const { return height(); }
[1252]257
[2543]258        // virtual void
259        //  SetupProjection(const int w, const int h, const float angle = 70.0f);
[2538]260
[2543]261        virtual void
262                SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
[2538]263
[2543]264        void
265                RenderViewCells();
[1252]266
267
[2543]268        virtual void Show() {
269                show();
270        }
[1252]271
[2543]272        bool PvsChanged(ViewCell *viewcell) const;
[1252]273
[2576]274        void ComputeMaxValues(const ViewCellContainer &viewCells,
275                                                  int &maxPvs,
276                                                  int &maxPiercingRays,
277                                                  float &maxRelativeRays,
278                                                  float &maxRcCost);
279
280        void AssignImportanceByRelativeValue(const ViewCellContainer &viewCells,
281                                                                                 int &maxPvs,
282                                                                                 int &maxPiercingRays,
283                                                                                 float &maxRelativeRays,
284                                                                                 float &maxRcCost);
285
286        void AssignColorByComparison(const ViewCellContainer &viewcells,
[2580]287                                                                 //const ViewCellInfoContainer &info1,
288                                                                 const ViewCellInfoContainer &compareInfo);
[2576]289
[2584]290        void WriteViewCellInfos();
[2576]291
[2584]292
[2543]293        /////////
[1252]294
[2543]295        //QMutex mMutex;
[1252]296
297
[2543]298public slots:
[1926]299
[2543]300        void UpdateAllPvs();
301        void ComputeVisibility();
302        void StopComputation();
303        void SetRandomViewPoint();
[2584]304        void StoreStatistics();
[1926]305
[2543]306        void SetRenderErrors(bool b) {
307                mRenderErrors = b;
308                updateGL();
309        }
[1926]310
[2543]311        void SetRenderBoxes(bool b) {
312                mRenderBoxes = b;
313                updateGL();
314        }
[1926]315
[2543]316        void SetRenderFilter(bool b) {
317                mRenderFilter = b;
318                updateGL();
319        }
[1926]320
[2543]321        void SetRenderVisibilityEstimates(bool b) {
322                mRenderVisibilityEstimates = b;
323                updateGL();
324        }
[1926]325
[2543]326        void SetUseFilter(bool b) {
327                mUseFilter = b;
328                mPvsCache.Reset();
329                updateGL();
330        }
[1926]331
[2543]332        void SetUseSpatialFilter(bool b) {
333                mUseSpatialFilter = b;
334                mPvsCache.Reset();
335                updateGL();
336        }
[1926]337
[1942]338
[2543]339        void
340                SetViewCellGranularity(int number);
[1942]341
[2543]342        void SetTransferFunction(int number)
343        {
344                mTransferFunction = number/1000.0f;
345                updateGL();
346        }
[2538]347
[2543]348        void SetVisibilityFilterSize(int number);
[2538]349
[2543]350        void
351                SetSpatialFilterSize(int number);
352
353        void
354                SetSceneCut(int cut);
355
356        void
357                SetTopDistance(int dist);
358
[2562]359        void
[2563]360                SetTransparency(int dist);
361
362        void
[2562]363                SetHidingCost(int dist);
364
[2543]365        void SetShowViewCells(bool b) {
366                mRenderViewCells = b;
367                updateGL();
368        }
369
370        void SetShowRays(bool b) {
371                mShowRays = b;
372                updateGL();
373        }
374
375        void SetShowRenderCost(bool b) {
376                mShowRenderCost = b;
377                updateGL();
378        }
379
380        void SetShowPvsSizes(bool b) {
381                mShowPvsSizes = b;
382                updateGL();
383        }
384
[2580]385        void SetShowComparison(bool b) {
386                mShowComparison = b;
387                updateGL();
388        }
389
[2560]390        void SetShowPiercingRays(bool b) {
391                mShowPiercingRays = b;
392                updateGL();
393        }
394
[2566]395        void SetShowWeightedRays(bool b) {
396                mShowWeightedRays = b;
397                updateGL();
398        }
399
[2543]400        void SetTopView(bool b) {
401                mTopView = b;
402                updateGL();
403        }
404
405        void SetCutViewCells(bool b) {
406                mCutViewCells = b;
407                updateGL();
408        }
409        void SetCutScene(bool b) {
410                mCutScene = b;
411                updateGL();
412        }
413
[2562]414        void SetHideByCost(bool b) {
415                mHideByCost = b;
416                updateGL();
417        }
418
[2564]419        void SetUseTransparency(bool b) {
420                mUseTransparency = b;
421                updateGL();
422        }
423
[2569]424        void SetShowWeightedCost(bool b)
425        {
426                mShowWeightedCost = b;
427                updateGL();
428        }
429
430        void SetShowDistanceWeightedPvs(bool b)
431        {
432                mShowDistanceWeightedPvs = b;
433                updateGL();
434        }
435
436
437        void SetShowDistanceWeightedTriangles(bool b)
438        {
439                mShowDistanceWeightedTriangles = b;
440                updateGL();
441        }
442       
443        void SetShowWeightedTriangles(bool b)
444        {
445                mShowWeightedTriangles = b;
446                updateGL();
447        }
448
[2587]449        void UseConstColorForRayViz(bool b)
450        {
451                mRayVisualizationMethod = 0;
452        }
453   
454        void UseRayLengthForRayViz(bool b)
455        {
456                mRayVisualizationMethod = 1;
457        }
[2569]458
[2587]459        void SetShowContribution(bool b)
460        {
461                mRayVisualizationMethod = 2;
462        }
463   
464        void SetShowDistribution(bool b)
465        {
466                mRayVisualizationMethod = 3;
467        }
[2591]468       
469        void SetShowDistribution1(bool b)
470        {
471                if (b)
472                        mShowDistribution |= 1;
473                else
474                        mShowDistribution ^= 1;
[2587]475
[2591]476                std::cout << "b: " << (mShowDistribution & 1) << " " << (mShowDistribution & 2) << " " << (mShowDistribution & 4) << " " << (mShowDistribution & 8) << std::endl;
477        }
[2587]478
[2591]479       
480        void SetShowDistribution2(bool b)
481        {
482                if (b)
483                        mShowDistribution |= 2;
484                else
485                        mShowDistribution ^= 2;
486        }
487
488       
489        void SetShowDistribution3(bool b)
490        {
491                if (b)
492                        mShowDistribution |= 4;
493                else
494                        mShowDistribution ^= 4;
495        }
496       
497        void SetShowDistribution4(bool b)
498        {
499                if (b)
500                        mShowDistribution |= 8;
501                else
502                        mShowDistribution ^= 8;
503        }
504
[2543]505        void _RenderPvs();
506
507        void _UpdatePvsIndices();
508
509        void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
510
[2569]511        float ComputeRenderCost(ViewCell *vc);
[2543]512
[2584]513
514
[2543]515        /////////
516
517signals:
518        void PvsUpdated();
[1252]519};
520
521
[2576]522class QtGlDebuggerWidget: public QGLWidget
[1252]523{
524        Q_OBJECT
525public:
[1942]526    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
527    ~QtGlDebuggerWidget();
528    void initializeGL();
529    void resizeGL(int w, int h);
530    void paintGL();
531    void timerEvent(QTimerEvent *) { update(); }
532    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
533    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
[1252]534
[1942]535    void initCommon();
536    void initPbuffer();
[1252]537
[1942]538 
539         QtGlRendererBuffer *mRenderBuffer;
[1252]540
[1942]541         Beam mBeam;
542         int mSamples;
543         Intersectable *mSourceObject;
[1252]544
545private:
[2543]546
[1942]547    GLuint dynamicTexture;
548    int timerId;
[1252]549};
550
[2543]551
[1252]552extern QtGlDebuggerWidget *debuggerWidget;
553
554};
555
556#endif
557
Note: See TracBrowser for help on using the repository browser.