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

Revision 2644, 11.4 KB checked in by mattausch, 17 years ago (diff)

redoing stuff from submission

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