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

Revision 2615, 11.2 KB checked in by mattausch, 16 years ago (diff)

did some stuff for the visualization

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