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

Revision 2538, 6.7 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
7//#include <QGLPixelBuffer>
8
9#include "Vector3.h"
10#include "Containers.h"
11#include "Halton.h"
12#include "Renderer.h"
13#include "GlRenderer.h"
14#include "Beam.h"
15#include "QtPreprocessorThread.h"
16class QWidget;
17//class QtPreprocessorThread;
18
19namespace GtpVisibilityPreprocessor {
20
21class SceneGraph;
22class ViewCellsManager;
23class Mesh;
24class MeshInstance;
25class Intersectable;
26class Material;
27class Beam;
28class KdTree;
29class GlRendererBuffer;
30class BeamSampleStatistics;
31class OcclusionQuery;
32class TransformedMeshInstance;
33
34
35struct VssRayContainer;
36struct PvsRenderStatistics;
37struct RenderCostSample;
38
39
40class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer
41{
42        Q_OBJECT
43public:
44        QtGlRendererBuffer(const int w,
45                const int h,
46                SceneGraph *sceneGraph,
47                ViewCellsManager *viewcells,
48                KdTree *tree);
49
50  ~QtGlRendererBuffer() {}
51
52  virtual void MakeCurrent();
53  virtual void DoneCurrent();
54
55  virtual int GetWidth() const { return width(); }
56  virtual int GetHeight() const { return height(); }
57
58  int ComputePvs() const { return 0; }
59 
60  float
61  GetPixelError(int &pvsSize);
62 
63  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
64     
65 
66 
67 
68public:
69  signals:
70  void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
71};
72
73
74class QtRendererControlWidget : public QWidget
75{
76  Q_OBJECT
77public:
78
79  QListWidget *mPvsErrorWidget;
80
81  QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
82
83  public slots:
84
85  void FocusNextPvsErrorFrame();
86  void UpdatePvsErrorItem(int i,
87                                                  GlRendererBuffer::PvsErrorEntry &);
88
89  signals:
90
91  void ComputeVisibility();
92  void StopComputation();
93  void SetRandomViewPoint();
94  void UpdateAllPvs();
95  void SetViewCellGranularity(int);
96  void SetTransferFunction(int);
97  void SetSceneCut(int);
98  void SetTopDistance(int);
99  void SetVisibilityFilterSize(int);
100  void SetSpatialFilterSize(int);
101
102  void SetShowRays(bool);
103  void SetRenderFilter(bool);
104  void SetRenderVisibilityEstimates(bool);
105  void SetUseFilter(bool);
106  void SetUseSpatialFilter(bool);
107  void SetRenderErrors(bool);
108  void SetRenderBoxes(bool);
109  void SetShowViewCells(bool);
110  void SetShowRenderCost(bool);
111  void SetShowPvsSizes(bool);
112  void SetTopView(bool);
113  void SetCutViewCells(bool);
114  void SetCutScene(bool);
115
116};
117
118
119class QtGlRendererWidget : public QGLWidget, public GlRendererWidget
120{
121  Q_OBJECT
122public:
123
124  // point of the last mouse click used for movement in the scene
125  Vector3 mousePoint;
126
127  bool mTopView;
128  bool mRenderViewCells;
129  bool mCutViewCells;
130  bool mCutScene;
131  bool mRenderErrors;
132  bool mRenderFilter;
133  bool mRenderVisibilityEstimates;
134  bool mUseFilter;
135  bool mUseSpatialFilter;
136  bool mShowRenderCost;
137  bool mShowRays;
138
139  bool mShowPvsSizes;
140  float mSpatialFilterSize;
141 
142  Plane3 mSceneCutPlane;
143  float mTopDistance;
144
145  // some statistics
146  int mPvsSize;
147  float mRenderError;
148  float mTransferFunction;
149
150  unsigned int mIndexBufferSize;
151 
152  QtRendererControlWidget *mControlWidget;
153
154  QtPreprocessorThread *mPreprocessorThread;
155 
156  QtGlRendererWidget(SceneGraph *sceneGraph,
157                                         ViewCellsManager *viewcells,
158                                         KdTree *tree,
159                                         QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
160                                         );
161 
162  QtGlRendererWidget() {};
163
164  void SetThread(QtPreprocessorThread *t) {
165        mPreprocessorThread = t;
166  }
167  void
168  RenderRenderCost();
169
170  virtual void SetupCamera();
171
172  void initializeGL() {
173        InitGL();
174  }
175
176  virtual void InitGL();
177 
178  void resizeGL(int w, int h);
179  void paintGL();
180  void timerEvent(QTimerEvent *event);
181  void mousePressEvent(QMouseEvent *);
182  void mouseReleaseEvent(QMouseEvent *);
183  void mouseMoveEvent(QMouseEvent *);
184
185  void keyPressEvent(QKeyEvent * e);
186
187  void RenderPvs();
188
189  float RenderErrors();
190  void RenderInfo();
191
192  virtual int GetWidth() const { return width(); }
193  virtual int GetHeight() const { return height(); }
194
195  // virtual void
196  //  SetupProjection(const int w, const int h, const float angle = 70.0f);
197
198  virtual void
199  SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
200
201  void
202  RenderViewCells();
203
204
205  virtual void Show() {
206        show();
207  }
208
209  bool PvsChanged(ViewCell *viewcell) const;
210
211
212 public slots:
213
214 void UpdateAllPvs();
215  void ComputeVisibility();
216  void StopComputation();
217  void SetRandomViewPoint();
218
219 void SetRenderErrors(bool b) {
220   mRenderErrors = b;
221   updateGL();
222 }
223
224  void SetRenderBoxes(bool b) {
225        mRenderBoxes = b;
226        updateGL();
227  }
228
229 void SetRenderFilter(bool b) {
230   mRenderFilter = b;
231   updateGL();
232 }
233
234  void SetRenderVisibilityEstimates(bool b) {
235        mRenderVisibilityEstimates = b;
236   updateGL();
237 }
238
239  void SetUseFilter(bool b) {
240   mUseFilter = b;
241   mPvsCache.Reset();
242   updateGL();
243 }
244
245  void SetUseSpatialFilter(bool b) {
246        mUseSpatialFilter = b;
247        mPvsCache.Reset();
248        updateGL();
249  }
250
251 
252  void
253  SetViewCellGranularity(int number);
254
255  void
256  SetTransferFunction(int number) {
257        mTransferFunction = number/1000.0f;
258        updateGL();
259  }
260
261  void
262  SetVisibilityFilterSize(int number);
263
264  void
265  SetSpatialFilterSize(int number);
266 
267  void
268  SetSceneCut(int cut);
269 
270  void
271  SetTopDistance(int dist);
272 
273  void SetShowViewCells(bool b) {
274        mRenderViewCells = b;
275        updateGL();
276  }
277
278  void SetShowRays(bool b) {
279        mShowRays = b;
280        updateGL();
281  }
282
283  void SetShowRenderCost(bool b) {
284        mShowRenderCost = b;
285        updateGL();
286  }
287
288  void SetShowPvsSizes(bool b) {
289        mShowPvsSizes = b;
290        updateGL();
291  }
292
293  void SetTopView(bool b) {
294        mTopView = b;
295        updateGL();
296  }
297
298  void SetCutViewCells(bool b) {
299        mCutViewCells = b;
300        updateGL();
301  }
302  void SetCutScene(bool b) {
303        mCutScene = b;
304        updateGL();
305  }
306
307  void _RenderPvs();
308
309  void _UpdatePvsIndices();
310  void _UpdatePvsIndices(KdNode *node);
311
312  signals:
313  void PvsUpdated();
314};
315
316
317class QtGlDebuggerWidget : public QGLWidget
318{
319        Q_OBJECT
320public:
321    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
322    ~QtGlDebuggerWidget();
323    void initializeGL();
324    void resizeGL(int w, int h);
325    void paintGL();
326    void timerEvent(QTimerEvent *) { update(); }
327    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
328    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
329
330    void initCommon();
331    void initPbuffer();
332
333 
334         QtGlRendererBuffer *mRenderBuffer;
335
336         Beam mBeam;
337         int mSamples;
338         Intersectable *mSourceObject;
339
340private:
341    GLuint dynamicTexture;
342    int timerId;
343};
344
345extern QtGlDebuggerWidget *debuggerWidget;
346
347};
348
349#endif
350
Note: See TracBrowser for help on using the repository browser.