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

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