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

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