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

Revision 1613, 8.1 KB checked in by bittner, 18 years ago (diff)

kd-tree hack active

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