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

Revision 2564, 7.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  public slots:
86
87  void FocusNextPvsErrorFrame();
88  void UpdatePvsErrorItem(int i,
89                                                  GlRendererBuffer::PvsErrorEntry &);
90
91  signals:
92
93  void ComputeVisibility();
94  void StopComputation();
95  void SetRandomViewPoint();
96  void UpdateAllPvs();
97  void SetViewCellGranularity(int);
98  void SetTransferFunction(int);
99  void SetSceneCut(int);
100  void SetTopDistance(int);
101  void SetHidingCost(int);
102  void SetVisibilityFilterSize(int);
103  void SetSpatialFilterSize(int);
104  void SetTransparency(int);
105
106  void SetShowRays(bool);
107  void SetRenderFilter(bool);
108  void SetRenderVisibilityEstimates(bool);
109  void SetUseFilter(bool);
110  void SetUseSpatialFilter(bool);
111  void SetRenderErrors(bool);
112  void SetRenderBoxes(bool);
113  void SetShowViewCells(bool);
114  void SetShowRenderCost(bool);
115  void SetShowPvsSizes(bool);
116  void SetShowPiercingRays(bool);
117  void SetTopView(bool);
118  void SetCutViewCells(bool);
119  void SetCutScene(bool);
120
121  void SetHideByCost(bool);
122  void SetUseTransparency(bool);
123};
124
125
126class QtGlRendererWidget : public QGLWidget, public GlRendererWidget
127{
128        Q_OBJECT
129public:
130
131        // point of the last mouse click used for movement in the scene
132        Vector3 mousePoint;
133
134        bool mTopView;
135        bool mRenderViewCells;
136        bool mCutViewCells;
137        bool mCutScene;
138        bool mHideByCost;
139        bool mRenderErrors;
140        bool mRenderFilter;
141        bool mRenderVisibilityEstimates;
142        bool mUseFilter;
143        bool mUseSpatialFilter;
144        bool mShowRenderCost;
145        bool mShowPiercingRays;
146        bool mShowRays;
147
148        bool mShowPvsSizes;
149        float mSpatialFilterSize;
150
151        Plane3 mSceneCutPlane;
152        float mHidingCost;
153
154        float mTopDistance;
155
156        float mTransparency;
157        bool mUseTransparency;
158
159        // some statistics
160        int mPvsSize;
161        float mRenderError;
162        float mTransferFunction;
163
164        unsigned int mIndexBufferSize;
165
166        QtRendererControlWidget *mControlWidget;
167
168        QtPreprocessorThread *mPreprocessorThread;
169
170        QtGlRendererWidget(SceneGraph *sceneGraph,
171                ViewCellsManager *viewcells,
172                KdTree *tree,
173                QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
174                );
175
176        QtGlRendererWidget() {};
177
178        void SetThread(QtPreprocessorThread *t) {
179                mPreprocessorThread = t;
180        }
181        void
182                RenderRenderCost();
183
184        virtual void SetupCamera();
185
186        void initializeGL() {
187                InitGL();
188        }
189
190        virtual void InitGL();
191
192        void resizeGL(int w, int h);
193        void paintGL();
194        void timerEvent(QTimerEvent *event);
195        void mousePressEvent(QMouseEvent *);
196        void mouseReleaseEvent(QMouseEvent *);
197        void mouseMoveEvent(QMouseEvent *);
198
199        void keyPressEvent(QKeyEvent * e);
200
201        void RenderPvs();
202
203        float RenderErrors();
204        void RenderInfo();
205
206        virtual int GetWidth() const { return width(); }
207        virtual int GetHeight() const { return height(); }
208
209        // virtual void
210        //  SetupProjection(const int w, const int h, const float angle = 70.0f);
211
212        virtual void
213                SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
214
215        void
216                RenderViewCells();
217
218
219        virtual void Show() {
220                show();
221        }
222
223        bool PvsChanged(ViewCell *viewcell) const;
224
225        /////////
226
227        //QMutex mMutex;
228
229
230public slots:
231
232        void UpdateAllPvs();
233        void ComputeVisibility();
234        void StopComputation();
235        void SetRandomViewPoint();
236
237        void SetRenderErrors(bool b) {
238                mRenderErrors = b;
239                updateGL();
240        }
241
242        void SetRenderBoxes(bool b) {
243                mRenderBoxes = b;
244                updateGL();
245        }
246
247        void SetRenderFilter(bool b) {
248                mRenderFilter = b;
249                updateGL();
250        }
251
252        void SetRenderVisibilityEstimates(bool b) {
253                mRenderVisibilityEstimates = b;
254                updateGL();
255        }
256
257        void SetUseFilter(bool b) {
258                mUseFilter = b;
259                mPvsCache.Reset();
260                updateGL();
261        }
262
263        void SetUseSpatialFilter(bool b) {
264                mUseSpatialFilter = b;
265                mPvsCache.Reset();
266                updateGL();
267        }
268
269
270        void
271                SetViewCellGranularity(int number);
272
273        void SetTransferFunction(int number)
274        {
275                mTransferFunction = number/1000.0f;
276                updateGL();
277        }
278
279        void SetVisibilityFilterSize(int number);
280
281        void
282                SetSpatialFilterSize(int number);
283
284        void
285                SetSceneCut(int cut);
286
287        void
288                SetTopDistance(int dist);
289
290        void
291                SetTransparency(int dist);
292
293        void
294                SetHidingCost(int dist);
295
296        void SetShowViewCells(bool b) {
297                mRenderViewCells = b;
298                updateGL();
299        }
300
301        void SetShowRays(bool b) {
302                mShowRays = b;
303                updateGL();
304        }
305
306        void SetShowRenderCost(bool b) {
307                mShowRenderCost = b;
308                updateGL();
309        }
310
311        void SetShowPvsSizes(bool b) {
312                mShowPvsSizes = b;
313                updateGL();
314        }
315
316        void SetShowPiercingRays(bool b) {
317                mShowPiercingRays = b;
318                updateGL();
319        }
320
321        void SetTopView(bool b) {
322                mTopView = b;
323                updateGL();
324        }
325
326        void SetCutViewCells(bool b) {
327                mCutViewCells = b;
328                updateGL();
329        }
330        void SetCutScene(bool b) {
331                mCutScene = b;
332                updateGL();
333        }
334
335        void SetHideByCost(bool b) {
336                mHideByCost = b;
337                updateGL();
338        }
339
340        void SetUseTransparency(bool b) {
341                mUseTransparency = b;
342                updateGL();
343        }
344
345        void _RenderPvs();
346
347        void _UpdatePvsIndices();
348
349        void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
350
351
352
353        /////////
354
355signals:
356        void PvsUpdated();
357};
358
359
360class QtGlDebuggerWidget : public QGLWidget
361{
362        Q_OBJECT
363public:
364    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
365    ~QtGlDebuggerWidget();
366    void initializeGL();
367    void resizeGL(int w, int h);
368    void paintGL();
369    void timerEvent(QTimerEvent *) { update(); }
370    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
371    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
372
373    void initCommon();
374    void initPbuffer();
375
376 
377         QtGlRendererBuffer *mRenderBuffer;
378
379         Beam mBeam;
380         int mSamples;
381         Intersectable *mSourceObject;
382
383private:
384
385    GLuint dynamicTexture;
386    int timerId;
387};
388
389
390extern QtGlDebuggerWidget *debuggerWidget;
391
392};
393
394#endif
395
Note: See TracBrowser for help on using the repository browser.