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

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