source: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h @ 865

Revision 865, 8.0 KB checked in by mattausch, 18 years ago (diff)

fixed uint bug

  • Property svn:executable set to *
Line 
1#ifndef __GLRENDERER_H
2#define __GLRENDERER_H
3
4#include <QtOpenGL>
5#include <QWaitCondition>
6//#include <QGLPixelBuffer>
7
8#include "Vector3.h"
9#include "Containers.h"
10#include "Halton.h"
11#include "Renderer.h"
12#include "Beam.h"
13
14class QWidget;
15
16namespace GtpVisibilityPreprocessor {
17
18class SceneGraph;
19class ViewCellsManager;
20class Mesh;
21class MeshInstance;
22class Intersectable;
23class Material;
24class Beam;
25class KdTree;
26class GlRendererBuffer;
27class BeamSampleStatistics;
28
29struct VssRayContainer;
30
31struct PvsRenderStatistics {
32 
33  float maxError;
34  float sumError;
35  int sumPvsSize;
36  int frames;
37  int errorFreeFrames;
38
39  PvsRenderStatistics() { Reset(); }
40 
41  void Reset() {
42        maxError = 0.0f;
43        sumError = 0.0f;
44        frames = 0;
45        errorFreeFrames = 0;
46        sumPvsSize = 0;
47  }
48
49  float GetMaxError() { return maxError; }
50  float GetAvgError() { return sumError/frames; }
51  float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
52  float GetAvgPvs() { return sumPvsSize/(float)frames; }
53 
54};
55
56struct RenderCostSample {
57
58  RenderCostSample() {}
59
60  void Reset() {
61        mVisibleObjects = 0;
62        mVisiblePixels = 0;
63  }
64 
65  // visible object from the given point
66  int mVisibleObjects;
67
68  // visible pixels
69  int mVisiblePixels;
70 
71};
72
73/** Class encapsulating gl rendering for the scene.
74        There is no gl context binding so the binding is performed in the
75        derived classes
76*/
77
78class GlRenderer: public Renderer
79{
80
81public:
82  ObjectContainer mObjects;
83   
84  Vector3 mViewPoint;
85  Vector3 mViewDirection;
86
87  int timerId;
88  bool mUseFalseColors;
89  bool mUseForcedColors;
90
91  HaltonSequence halton;
92 
93  int mFrame;
94  bool mWireFrame;
95 
96  bool mDetectEmptyViewSpace;
97  bool mSnapErrorFrames;
98
99  bool mUseGlLists;
100 
101  QString mSnapPrefix;
102
103  KdTree *mKdTree;
104
105  QWaitCondition mRenderingFinished;
106 
107  vector<unsigned int> mOcclusionQueries;
108 
109  GlRenderer(SceneGraph *sceneGraph,
110                         ViewCellsManager *viewcells,
111                         KdTree *tree);
112 
113  ~GlRenderer();
114
115
116  void SetupFalseColor(const int id);
117  void RenderIntersectable(Intersectable *);
118  void RenderViewCell(ViewCell *vc);
119  void RenderMeshInstance(MeshInstance *mi);
120  void RenderMesh(Mesh *m);
121  void SetupMaterial(Material *m);
122  virtual void SetupCamera();
123 
124  bool
125  RenderScene();
126
127  void
128  _RenderScene();
129
130
131  virtual void
132  SetupProjection(const int w, const int h, const float angle = 70.0f);
133
134 
135 
136
137  void InitGL();
138
139  virtual int GetWidth() const = 0;
140  virtual int GetHeight() const = 0;
141
142  int GetId(int r, int g, int b) const;
143};
144
145
146class GlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRenderer
147{
148Q_OBJECT
149public:
150GlRendererBuffer(const int w,
151                                 const int h,
152                                 SceneGraph *sceneGraph,
153                                 ViewCellsManager *viewcells,
154                                 KdTree *tree);
155
156
157  void
158  EvalRenderCostSample(
159                                           RenderCostSample &sample
160                                           );
161
162  void
163  SampleRenderCost(
164                                   const int n,
165                                   vector<RenderCostSample> &samples
166                                   );
167
168
169  void
170  EvalPvsStat();
171
172  void
173  ClearErrorBuffer();
174 
175
176  virtual int GetWidth() const { return width(); }
177  virtual int GetHeight() const { return height(); }
178
179
180  void RandomViewPoint();
181  void SampleBeamContributions(
182                                                           Intersectable *sourceObject,
183                                                           Beam &beam,
184                                                           const int samples,
185                                                           BeamSampleStatistics &stat
186                                                           );
187
188  void
189  SampleViewpointContributions(
190                                                           Intersectable *sourceObject,
191                                                           const Vector3 viewPoint,
192                                                           Beam &beam,
193                                                           const int desiredSamples,
194                                                           BeamSampleStatistics &stat
195                                                           );
196
197  void InitGL();
198
199  /** Computes rays from information gained with hw sampling-
200  */
201  void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
202
203  int ComputePvs() const;
204
205  float
206  GetPixelError(int &pvsSize);
207
208  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
209
210  PvsRenderStatistics mPvsStat;
211   
212  int mPvsStatFrames;
213  struct PvsErrorEntry {
214        PvsErrorEntry() {}
215        float mError;
216        int mPvsSize;
217        Vector3 mPosition;
218        Vector3 mDirection;
219  };
220 
221  vector<PvsErrorEntry> mPvsErrorBuffer;
222
223private:
224  unsigned int *mPixelBuffer;
225 
226        static void GenQueries(const int numQueries);
227       
228        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
229                                                                         const Beam &beam,
230
231                                                                         Intersectable *sourceObject);
232
233public:
234  signals:
235        UpdatePvsErrorItem(int i,
236                                           GlRendererBuffer::PvsErrorEntry &);
237};
238
239
240class RendererControlWidget : public QWidget
241{
242  Q_OBJECT
243public:
244
245  QListWidget *mPvsErrorWidget;
246
247  RendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
248
249  public slots:
250
251  void FocusNextPvsErrorFrame();
252  void UpdatePvsErrorItem(int i,
253                                                  GlRendererBuffer::PvsErrorEntry &);
254
255  signals:
256 
257  SetViewCellGranularity(int);
258  SetSceneCut(int);
259  SetTopDistance(int);
260  SetVisibilityFilterSize(int);
261
262  SetRenderFilter(bool);
263  SetRenderErrors(bool);
264  SetShowViewCells(bool);
265  SetShowRenderCost(bool);
266  SetShowPvsSizes(bool);
267  SetTopView(bool);
268  SetCutViewCells(bool);
269  SetCutScene(bool);
270
271 
272};
273
274class GlRendererWidget : public QGLWidget, public GlRenderer
275{
276  Q_OBJECT
277public:
278
279  // point of the last mouse click used for movement in the scene
280  Vector3 mousePoint;
281
282  bool mTopView;
283  bool mRenderViewCells;
284  bool mCutViewCells;
285  bool mCutScene;
286  bool mRenderErrors;
287  bool mRenderFilter;
288  bool mShowRenderCost;
289  bool mShowPvsSizes;
290
291  Plane3 mSceneCutPlane;
292  float mTopDistance;
293
294  // some statistics
295  int mPvsSize;
296  float mRenderError;
297
298  RendererControlWidget *mControlWidget;
299 
300  GlRendererWidget(SceneGraph *sceneGraph,
301                                   ViewCellsManager *viewcells,
302                                   KdTree *tree,
303                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
304                                   );
305
306
307  virtual void SetupCamera();
308
309  void initializeGL() {
310        InitGL();
311  }
312  void resizeGL(int w, int h);
313  void paintGL();
314  void timerEvent(QTimerEvent *) {
315          update();
316  }
317
318  void mousePressEvent(QMouseEvent *);
319  void mouseReleaseEvent(QMouseEvent *);
320  void mouseMoveEvent(QMouseEvent *);
321
322  void keyPressEvent ( QKeyEvent * e ) ;
323
324  void
325  RenderPvs();
326
327  float
328  RenderErrors();
329  void
330  RenderInfo();
331
332  virtual int GetWidth() const { return width(); }
333  virtual int GetHeight() const { return height(); }
334
335  virtual void
336  SetupProjection(const int w, const int h);
337
338  void
339  RenderViewCells();
340
341 public slots:
342
343 void SetRenderErrors(bool b) {
344   mRenderErrors = b;
345   updateGL();
346 }
347
348 void SetRenderFilter(bool b) {
349   mRenderFilter = b;
350   updateGL();
351 }
352
353 
354  void
355  SetViewCellGranularity(int number);
356 
357  void
358  SetVisibilityFilterSize(int number);
359 
360  void
361  SetSceneCut(int cut);
362 
363  void
364  SetTopDistance(int dist);
365 
366  void SetShowViewCells(bool b) {
367        mRenderViewCells = b;
368        updateGL();
369  }
370
371  void SetShowRenderCost(bool b) {
372        mShowRenderCost = b;
373        updateGL();
374  }
375
376  void SetShowPvsSizes(bool b) {
377        mShowPvsSizes = b;
378        updateGL();
379  }
380
381  void SetTopView(bool b) {
382        mTopView = b;
383        updateGL();
384  }
385
386  void SetCutViewCells(bool b) {
387        mCutViewCells = b;
388        updateGL();
389  }
390  void SetCutScene(bool b) {
391        mCutScene = b;
392        updateGL();
393  }
394
395
396};
397
398
399extern GlRendererWidget *rendererWidget;
400
401class GlDebuggerWidget : public QGLWidget
402{
403        Q_OBJECT
404public:
405    GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL);
406    ~GlDebuggerWidget();
407    void initializeGL();
408    void resizeGL(int w, int h);
409    void paintGL();
410    void timerEvent(QTimerEvent *) { update(); }
411    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
412    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
413
414    void initCommon();
415    void initPbuffer();
416
417 
418         GlRendererBuffer *mRenderBuffer;
419
420         Beam mBeam;
421         int mSamples;
422         Intersectable *mSourceObject;
423
424private:
425    GLuint dynamicTexture;
426    int timerId;
427};
428
429extern GlDebuggerWidget *debuggerWidget;
430
431};
432
433#endif
434
Note: See TracBrowser for help on using the repository browser.