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

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