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

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