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

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