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

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