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

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