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

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