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

Revision 2709, 12.0 KB checked in by mattausch, 16 years ago (diff)

sheduling dynamic object only when necessary

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