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

Revision 884, 8.3 KB checked in by bittner, 18 years ago (diff)

Spatial visibility filter

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