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

Revision 1594, 7.8 KB checked in by bittner, 18 years ago (diff)

support for kd tree based pvs

  • Property svn:executable set to *
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
16class QWidget;
17
18namespace GtpVisibilityPreprocessor {
19
20class SceneGraph;
21class ViewCellsManager;
22class Mesh;
23class MeshInstance;
24class Intersectable;
25class Material;
26class Beam;
27class KdTree;
28class GlRendererBuffer;
29class BeamSampleStatistics;
30class OcclusionQuery;
31class TransformedMeshInstance;
32
33
34struct VssRayContainer;
35struct PvsRenderStatistics;
36struct RenderCostSample;
37
38
39class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer
40{
41        Q_OBJECT
42public:
43        QtGlRendererBuffer(const int w,
44                const int h,
45                SceneGraph *sceneGraph,
46                ViewCellsManager *viewcells,
47                KdTree *tree);
48
49        ~QtGlRendererBuffer();
50
51        /** Evaluates render cost of a point sample.
52        @param sample the render cost sample to be evaluated
53        @param useOcclusionQueries if occlusion queries should be used or item buffer
54        @param threshold number of pixels / samples from where an object is considered visible.
55        */
56        void EvalRenderCostSample(RenderCostSample &sample,
57                const bool useOcclusionQueries,
58                const int threshold);
59
60        /** Evaluates render cost of a number of point samples. The point samples
61        are distributed uniformly over the defined view space.
62
63        @param numSamples the number of point samples taken
64        @param samples stores the taken point samples in a container
65        @param useOcclusionQueries if occlusion queries should be used or item buffer
66        @param threshold number of pixels / samples from where an object is considered visible.
67        */
68        void SampleRenderCost(const int numSamples,
69                vector<RenderCostSample> &samples,
70                const bool useOcclusionQueries,
71                const int threshold = 0);
72
73
74  void
75  EvalPvsStat();
76
77  void
78  ClearErrorBuffer();
79 
80
81  virtual int GetWidth() const { return width(); }
82  virtual int GetHeight() const { return height(); }
83
84
85 
86  void SampleBeamContributions(
87                                                           Intersectable *sourceObject,
88                                                           Beam &beam,
89                                                           const int samples,
90                                                           BeamSampleStatistics &stat
91                                                           );
92
93  void
94  SampleViewpointContributions(
95                                                           Intersectable *sourceObject,
96                                                           const Vector3 viewPoint,
97                                                           Beam &beam,
98                                                           const int desiredSamples,
99                                                           BeamSampleStatistics &stat
100                                                           );
101
102  void InitGL();
103
104  /** Computes rays from information gained with hw sampling-
105  */
106  void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
107
108  int ComputePvs() const;
109
110  float
111  GetPixelError(int &pvsSize);
112
113  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
114     
115   
116private:
117       
118        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
119                                                                         const Beam &beam,
120                                                                         Intersectable *sourceObject);
121
122
123public:
124  signals:
125        void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
126};
127
128
129class QtRendererControlWidget : public QWidget
130{
131  Q_OBJECT
132public:
133
134  QListWidget *mPvsErrorWidget;
135
136  QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
137
138  public slots:
139
140  void FocusNextPvsErrorFrame();
141  void UpdatePvsErrorItem(int i,
142                                                  GlRendererBuffer::PvsErrorEntry &);
143
144  signals:
145 
146  void SetViewCellGranularity(int);
147  void SetSceneCut(int);
148  void SetTopDistance(int);
149  void SetVisibilityFilterSize(int);
150  void SetSpatialFilterSize(int);
151
152  void SetShowRays(bool);
153  void SetRenderFilter(bool);
154  void SetRenderVisibilityEstimates(bool);
155  void SetUseFilter(bool);
156  void SetUseSpatialFilter(bool);
157  void SetRenderErrors(bool);
158  void SetRenderBoxes(bool);
159  void SetShowViewCells(bool);
160  void SetShowRenderCost(bool);
161  void SetShowPvsSizes(bool);
162  void SetTopView(bool);
163  void SetCutViewCells(bool);
164  void SetCutScene(bool);
165
166 
167};
168
169class QtGlRendererWidget : public QGLWidget, public GlRendererWidget
170{
171  Q_OBJECT
172public:
173
174  // point of the last mouse click used for movement in the scene
175  Vector3 mousePoint;
176
177  bool mTopView;
178  bool mRenderViewCells;
179  bool mCutViewCells;
180  bool mCutScene;
181  bool mRenderErrors;
182  bool mRenderFilter;
183  bool mRenderVisibilityEstimates;
184  bool mUseFilter;
185  bool mUseSpatialFilter;
186  bool mShowRenderCost;
187  bool mShowRays;
188
189  bool mShowPvsSizes;
190  float mSpatialFilterSize;
191 
192  Plane3 mSceneCutPlane;
193  float mTopDistance;
194
195  // some statistics
196  int mPvsSize;
197  float mRenderError;
198
199
200  float mManipulatorLastQuat[4];
201  float mManipulatorScale;
202 
203  QtRendererControlWidget *mControlWidget;
204 
205  QtGlRendererWidget(SceneGraph *sceneGraph,
206                                         ViewCellsManager *viewcells,
207                                         KdTree *tree,
208                                         QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
209                                         );
210 
211  QtGlRendererWidget() {};
212
213  void
214  RenderRenderCost();
215
216  virtual void SetupCamera();
217  // setup a transformation for manipulator
218  void
219  SetupManipulator();
220
221  void initializeGL() {
222        InitGL();
223  }
224  void resizeGL(int w, int h);
225  void paintGL();
226  void timerEvent(QTimerEvent *) {
227          update();
228  }
229
230  void mousePressEvent(QMouseEvent *);
231  void mouseReleaseEvent(QMouseEvent *);
232  void mouseMoveEvent(QMouseEvent *);
233
234  void keyPressEvent ( QKeyEvent * e ) ;
235
236  void
237  RenderPvs();
238
239  float
240  RenderErrors();
241  void
242  RenderInfo();
243
244  virtual int GetWidth() const { return width(); }
245  virtual int GetHeight() const { return height(); }
246
247  // virtual void
248  //  SetupProjection(const int w, const int h, const float angle = 70.0f);
249
250  virtual void
251  SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
252
253  virtual void
254  SetupManipulatorProjection(const int w, const int h, const float angle = 70.0f);
255
256  void
257  RenderViewCells();
258
259
260  virtual void Show() {
261        show();
262  }
263
264 public slots:
265
266 void SetRenderErrors(bool b) {
267   mRenderErrors = b;
268   updateGL();
269 }
270
271  void SetRenderBoxes(bool b) {
272        mRenderBoxes = b;
273        updateGL();
274  }
275
276 void SetRenderFilter(bool b) {
277   mRenderFilter = b;
278   updateGL();
279 }
280
281  void SetRenderVisibilityEstimates(bool b) {
282        mRenderVisibilityEstimates = b;
283   updateGL();
284 }
285
286  void SetUseFilter(bool b) {
287   mUseFilter = b;
288   updateGL();
289 }
290
291  void SetUseSpatialFilter(bool b) {
292        mUseSpatialFilter = b;
293        updateGL();
294  }
295
296 
297  void
298  SetViewCellGranularity(int number);
299 
300  void
301  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 SetShowViewCells(bool b) {
313        mRenderViewCells = b;
314        updateGL();
315  }
316
317  void SetShowRays(bool b) {
318        mShowRays = b;
319        updateGL();
320  }
321
322  void SetShowRenderCost(bool b) {
323        mShowRenderCost = b;
324        updateGL();
325  }
326
327  void SetShowPvsSizes(bool b) {
328        mShowPvsSizes = b;
329        updateGL();
330  }
331
332  void SetTopView(bool b) {
333        mTopView = b;
334        updateGL();
335  }
336
337  void SetCutViewCells(bool b) {
338        mCutViewCells = b;
339        updateGL();
340  }
341  void SetCutScene(bool b) {
342        mCutScene = b;
343        updateGL();
344  }
345
346
347};
348
349
350class QtGlDebuggerWidget : public QGLWidget
351{
352        Q_OBJECT
353public:
354    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
355    ~QtGlDebuggerWidget();
356    void initializeGL();
357    void resizeGL(int w, int h);
358    void paintGL();
359    void timerEvent(QTimerEvent *) { update(); }
360    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
361    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
362
363    void initCommon();
364    void initPbuffer();
365
366 
367         QtGlRendererBuffer *mRenderBuffer;
368
369         Beam mBeam;
370         int mSamples;
371         Intersectable *mSourceObject;
372
373private:
374    GLuint dynamicTexture;
375    int timerId;
376};
377
378extern QtGlDebuggerWidget *debuggerWidget;
379
380};
381
382#endif
383
Note: See TracBrowser for help on using the repository browser.