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

Revision 2686, 11.6 KB checked in by mattausch, 16 years ago (diff)

fixed several problems

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