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

Revision 2577, 9.2 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
17
18class QWidget;
19
20
21
22namespace GtpVisibilityPreprocessor {
23
24
25class SceneGraph;
26class ViewCellsManager;
27class Mesh;
28class MeshInstance;
29class Intersectable;
30class Material;
31class Beam;
32class KdTree;
33class GlRendererBuffer;
34class BeamSampleStatistics;
35class OcclusionQuery;
36class TransformedMeshInstance;
37
38
39struct VssRayContainer;
40struct PvsRenderStatistics;
41struct RenderCostSample;
42
43
44class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer
45{
46        Q_OBJECT
47public:
48        QtGlRendererBuffer(const int w,
49                const int h,
50                SceneGraph *sceneGraph,
51                ViewCellsManager *viewcells,
52                KdTree *tree);
53
54  ~QtGlRendererBuffer() {}
55
56  virtual void MakeCurrent();
57  virtual void DoneCurrent();
58
59  virtual int GetWidth() const { return width(); }
60  virtual int GetHeight() const { return height(); }
61
62  int ComputePvs() const { return 0; }
63 
64  float
65  GetPixelError(int &pvsSize);
66 
67  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
68     
69 
70 
71 
72public:
73  signals:
74  void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
75};
76
77
78class QtRendererControlWidget : public QWidget
79{
80  Q_OBJECT
81public:
82
83  QListWidget *mPvsErrorWidget;
84
85  QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
86
87  QGroupBox *CreateVisualizationPanel(QWidget *parent);
88
89  public slots:
90
91  void FocusNextPvsErrorFrame();
92  void UpdatePvsErrorItem(int i,
93                                                  GlRendererBuffer::PvsErrorEntry &);
94
95 
96  QGroupBox *CreateRenderCostPanel(QWidget *parent);
97
98
99  signals:
100
101  void ComputeVisibility();
102  void StopComputation();
103  void SetRandomViewPoint();
104  void UpdateAllPvs();
105  void SetViewCellGranularity(int);
106  void SetTransferFunction(int);
107  void SetSceneCut(int);
108  void SetTopDistance(int);
109  void SetHidingCost(int);
110  void SetVisibilityFilterSize(int);
111  void SetSpatialFilterSize(int);
112  void SetTransparency(int);
113
114  void SetShowRays(bool);
115  void SetRenderFilter(bool);
116  void SetRenderVisibilityEstimates(bool);
117  void SetUseFilter(bool);
118  void SetUseSpatialFilter(bool);
119  void SetRenderErrors(bool);
120  void SetRenderBoxes(bool);
121  void SetShowViewCells(bool);
122  void SetShowRenderCost(bool);
123  void SetShowPvsSizes(bool);
124  void SetShowPiercingRays(bool);
125  void SetShowWeightedRays(bool);
126  void SetShowWeightedCost(bool);
127 
128  void SetTopView(bool);
129  void SetCutViewCells(bool);
130  void SetCutScene(bool);
131
132  void SetHideByCost(bool);
133  void SetUseTransparency(bool);
134
135  void SetShowDistanceWeightedTriangles(bool);
136  void SetShowWeightedTriangles(bool);
137  void SetShowDistanceWeightedPvs(bool);
138};
139
140
141class QtGlRendererWidget: public QGLWidget, public GlRendererWidget
142{
143        Q_OBJECT
144public:
145
146        // point of the last mouse click used for movement in the scene
147        Vector3 mousePoint;
148
149        bool mTopView;
150        bool mRenderViewCells;
151        bool mCutViewCells;
152        bool mCutScene;
153        bool mHideByCost;
154        bool mRenderErrors;
155        bool mRenderFilter;
156        bool mRenderVisibilityEstimates;
157        bool mUseFilter;
158        bool mUseSpatialFilter;
159        bool mShowRenderCost;
160        bool mShowPiercingRays;
161        bool mShowWeightedRays;
162        bool mShowRays;
163
164        bool mShowPvsSizes;
165        float mSpatialFilterSize;
166
167        Plane3 mSceneCutPlane;
168        float mHidingCost;
169
170        float mTopDistance;
171
172        float mTransparency;
173        bool mUseTransparency;
174
175        bool mShowWeightedCost;
176
177        bool mShowDistanceWeightedTriangles;
178        bool mShowDistanceWeightedPvs;
179        bool mShowWeightedTriangles;
180
181        /// the current number of samples
182        int mSamples;
183        /// the next number of samples where we record the data
184        int mNextSamples;
185        bool mRecordHist;
186
187        // some statistics
188        int mPvsSize;
189        float mRenderError;
190        float mTransferFunction;
191
192        unsigned int mIndexBufferSize;
193
194        bool mAssignImportanceByRelativeValue;
195
196        Vector3 mDummyViewPoint;
197
198        QtRendererControlWidget *mControlWidget;
199
200        QtPreprocessorThread *mPreprocessorThread;
201
202        int mCurrentSamples;
203
204        ViewCellHistoryContainer mCurrentHist;
205        ViewCellHistoryContainer mCompareHist;
206
207
208        QtGlRendererWidget(SceneGraph *sceneGraph,
209                ViewCellsManager *viewcells,
210                KdTree *tree,
211                QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
212                );
213
214        QtGlRendererWidget() {};
215
216        void FillNewContainer(const ViewCellContainer &viewCells, ViewCellInfoContainer &infos);
217
218
219        void SetThread(QtPreprocessorThread *t) {
220                mPreprocessorThread = t;
221        }
222        void RenderRenderCost();
223
224        virtual void SetupCamera();
225
226        void initializeGL() {
227                InitGL();
228        }
229
230        virtual void InitGL();
231
232        void resizeGL(int w, int h);
233        void paintGL();
234        void timerEvent(QTimerEvent *event);
235        void mousePressEvent(QMouseEvent *);
236        void mouseReleaseEvent(QMouseEvent *);
237        void mouseMoveEvent(QMouseEvent *);
238
239        void keyPressEvent(QKeyEvent * e);
240
241        void RenderPvs();
242
243        float RenderErrors();
244        void RenderInfo();
245
246        virtual int GetWidth() const { return width(); }
247        virtual int GetHeight() const { return height(); }
248
249        // virtual void
250        //  SetupProjection(const int w, const int h, const float angle = 70.0f);
251
252        virtual void
253                SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
254
255        void
256                RenderViewCells();
257
258
259        virtual void Show() {
260                show();
261        }
262
263        bool PvsChanged(ViewCell *viewcell) const;
264
265        void ComputeMaxValues(const ViewCellContainer &viewCells,
266                                                  int &maxPvs,
267                                                  int &maxPiercingRays,
268                                                  float &maxRelativeRays,
269                                                  float &maxRcCost);
270
271        void AssignImportanceByRelativeValue(const ViewCellContainer &viewCells,
272                                                                                 int &maxPvs,
273                                                                                 int &maxPiercingRays,
274                                                                                 float &maxRelativeRays,
275                                                                                 float &maxRcCost);
276
277        void AssignColorByComparison(const ViewCellContainer &viewcells,
278                                                                 const ViewCellInfoContainer &info1,
279                                                                 const ViewCellInfoContainer &info2);
280
281
282        /////////
283
284        //QMutex mMutex;
285
286
287public slots:
288
289        void UpdateAllPvs();
290        void ComputeVisibility();
291        void StopComputation();
292        void SetRandomViewPoint();
293
294        void SetRenderErrors(bool b) {
295                mRenderErrors = b;
296                updateGL();
297        }
298
299        void SetRenderBoxes(bool b) {
300                mRenderBoxes = b;
301                updateGL();
302        }
303
304        void SetRenderFilter(bool b) {
305                mRenderFilter = b;
306                updateGL();
307        }
308
309        void SetRenderVisibilityEstimates(bool b) {
310                mRenderVisibilityEstimates = b;
311                updateGL();
312        }
313
314        void SetUseFilter(bool b) {
315                mUseFilter = b;
316                mPvsCache.Reset();
317                updateGL();
318        }
319
320        void SetUseSpatialFilter(bool b) {
321                mUseSpatialFilter = b;
322                mPvsCache.Reset();
323                updateGL();
324        }
325
326
327        void
328                SetViewCellGranularity(int number);
329
330        void SetTransferFunction(int number)
331        {
332                mTransferFunction = number/1000.0f;
333                updateGL();
334        }
335
336        void SetVisibilityFilterSize(int number);
337
338        void
339                SetSpatialFilterSize(int number);
340
341        void
342                SetSceneCut(int cut);
343
344        void
345                SetTopDistance(int dist);
346
347        void
348                SetTransparency(int dist);
349
350        void
351                SetHidingCost(int dist);
352
353        void SetShowViewCells(bool b) {
354                mRenderViewCells = b;
355                updateGL();
356        }
357
358        void SetShowRays(bool b) {
359                mShowRays = b;
360                updateGL();
361        }
362
363        void SetShowRenderCost(bool b) {
364                mShowRenderCost = b;
365                updateGL();
366        }
367
368        void SetShowPvsSizes(bool b) {
369                mShowPvsSizes = b;
370                updateGL();
371        }
372
373        void SetShowPiercingRays(bool b) {
374                mShowPiercingRays = b;
375                updateGL();
376        }
377
378        void SetShowWeightedRays(bool b) {
379                mShowWeightedRays = b;
380                updateGL();
381        }
382
383        void SetTopView(bool b) {
384                mTopView = b;
385                updateGL();
386        }
387
388        void SetCutViewCells(bool b) {
389                mCutViewCells = b;
390                updateGL();
391        }
392        void SetCutScene(bool b) {
393                mCutScene = b;
394                updateGL();
395        }
396
397        void SetHideByCost(bool b) {
398                mHideByCost = b;
399                updateGL();
400        }
401
402        void SetUseTransparency(bool b) {
403                mUseTransparency = b;
404                updateGL();
405        }
406
407        void SetShowWeightedCost(bool b)
408        {
409                mShowWeightedCost = b;
410                updateGL();
411        }
412
413        void SetShowDistanceWeightedPvs(bool b)
414        {
415                mShowDistanceWeightedPvs = b;
416                updateGL();
417        }
418
419
420        void SetShowDistanceWeightedTriangles(bool b)
421        {
422                mShowDistanceWeightedTriangles = b;
423                updateGL();
424        }
425       
426        void SetShowWeightedTriangles(bool b)
427        {
428                mShowWeightedTriangles = b;
429                updateGL();
430        }
431
432
433        void _RenderPvs();
434
435        void _UpdatePvsIndices();
436
437        void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
438
439        float ComputeRenderCost(ViewCell *vc);
440
441        /////////
442
443signals:
444        void PvsUpdated();
445};
446
447
448class QtGlDebuggerWidget: public QGLWidget
449{
450        Q_OBJECT
451public:
452    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
453    ~QtGlDebuggerWidget();
454    void initializeGL();
455    void resizeGL(int w, int h);
456    void paintGL();
457    void timerEvent(QTimerEvent *) { update(); }
458    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
459    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
460
461    void initCommon();
462    void initPbuffer();
463
464 
465         QtGlRendererBuffer *mRenderBuffer;
466
467         Beam mBeam;
468         int mSamples;
469         Intersectable *mSourceObject;
470
471private:
472
473    GLuint dynamicTexture;
474    int timerId;
475};
476
477
478extern QtGlDebuggerWidget *debuggerWidget;
479
480};
481
482#endif
483
Note: See TracBrowser for help on using the repository browser.