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

Revision 746, 7.3 KB checked in by bittner, 18 years ago (diff)

visualization of the render cost and pvs sizes for viewcells

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