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

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