source: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h @ 608

Revision 608, 6.0 KB checked in by bittner, 18 years ago (diff)

slider support 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 frames;
33  int errorFreeFrames;
34
35  PvsRenderStatistics() { Reset(); }
36 
37  void Reset() {
38        maxError = 0.0f;
39        sumError = 0.0f;
40        frames = 0;
41        errorFreeFrames = 0;
42  }
43
44  float GetMaxError() { return maxError; }
45  float GetAvgError() { return sumError/frames; }
46  float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
47 
48};
49
50
51/** Class encapsulating gl rendering for the scene.
52        There is no gl context binding so the binding is performed in the
53        derived classes
54*/
55
56class GlRenderer: public Renderer
57{
58
59public:
60  ObjectContainer mObjects;
61   
62  Vector3 mViewPoint;
63  Vector3 mViewDirection;
64
65  int timerId;
66  bool mUseFalseColors;
67
68  HaltonSequence halton;
69 
70  int mFrame;
71  bool mWireFrame;
72 
73bool mDetectEmptyViewSpace;
74  bool mSnapErrorFrames;
75  QString mSnapPrefix;
76
77  KdTree *mKdTree;
78
79  QWaitCondition mRenderingFinished;
80 
81 
82  GlRenderer(SceneGraph *sceneGraph,
83                         ViewCellsManager *viewcells,
84                         KdTree *tree);
85 
86  ~GlRenderer();
87
88
89  void SetupFalseColor(const int id);
90  void RenderIntersectable(Intersectable *);
91  void RenderViewCell(ViewCell *vc);
92  void RenderMeshInstance(MeshInstance *mi);
93  void RenderMesh(Mesh *m);
94  void SetupMaterial(Material *m);
95  virtual void SetupCamera();
96 
97  bool
98  RenderScene();
99
100
101  virtual void
102  SetupProjection(const int w, const int h);
103
104 
105 
106
107  void InitGL();
108
109  virtual int GetWidth() const = 0;
110  virtual int GetHeight() const = 0;
111
112  int GetId(int r, int g, int b) const;
113};
114
115
116class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
117{
118public:
119        GlRendererBuffer(const int w,
120                                         const int h,
121                                         SceneGraph *sceneGraph,
122                                         ViewCellsManager *viewcells,
123                                         KdTree *tree);
124
125 
126  void
127  EvalPvsStat();
128
129  void
130  ClearErrorBuffer();
131 
132
133  virtual int GetWidth() const { return width(); }
134  virtual int GetHeight() const { return height(); }
135
136
137  void RandomViewPoint();
138  void SampleBeamContributions(
139                                                           Intersectable *sourceObject,
140                                                           Beam &beam,
141                                                           const int samples,
142                                                           BeamSampleStatistics &stat
143                                                           );
144
145  void
146  SampleViewpointContributions(
147                                                           Intersectable *sourceObject,
148                                                           const Vector3 viewPoint,
149                                                           Beam &beam,
150                                                           const int desiredSamples,
151                                                           BeamSampleStatistics &stat
152                                                           );
153
154  void InitGL();
155
156  /** Computes rays from information gained with hw sampling-
157  */
158  void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
159
160  int ComputePvs() const;
161
162  float
163  GetPixelError();
164
165  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
166
167  PvsRenderStatistics mPvsStat;
168   
169  int mPvsStatFrames;
170  vector<float> mPvsErrorBuffer;
171private:
172       
173        static void GenQueries(const int numQueries);
174       
175        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
176                                                                         const Beam &beam,
177                                                                         Intersectable *sourceObject);
178};
179
180
181class RendererControlWidget : public QWidget
182{
183  Q_OBJECT
184public:
185  RendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
186
187  signals:
188 
189  SetViewCellGranularity(int);
190  SetSceneCut(int);
191  SetTopDistance(int);
192
193  SetShowViewCells(bool);
194  SetTopView(bool);
195  SetCutViewCells(bool);
196  SetCutScene(bool);
197
198};
199
200class GlRendererWidget : public QGLWidget, public GlRenderer
201{
202  Q_OBJECT
203public:
204
205  // point of the last mouse click used for movement in the scene
206  Vector3 mousePoint;
207
208  bool mTopView;
209  bool mRenderViewCells;
210  bool mCutViewCells;
211  bool mCutScene;
212 
213  Plane3 mSceneCutPlane;
214  float mTopDistance;
215 
216  GlRendererWidget(SceneGraph *sceneGraph,
217                                   ViewCellsManager *viewcells,
218                                   KdTree *tree,
219                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
220                                   );
221
222
223  virtual void SetupCamera();
224
225  void initializeGL() {
226        InitGL();
227  }
228  void resizeGL(int w, int h);
229  void paintGL();
230  void timerEvent(QTimerEvent *) {
231          update();
232  }
233
234  void mousePressEvent(QMouseEvent *);
235  void mouseReleaseEvent(QMouseEvent *);
236  void mouseMoveEvent(QMouseEvent *);
237
238  void keyPressEvent ( QKeyEvent * e ) ;
239 
240  float
241  RenderErrors();
242  void
243  RenderInfo();
244
245  virtual int GetWidth() const { return width(); }
246  virtual int GetHeight() const { return height(); }
247
248  virtual void
249  SetupProjection(const int w, const int h);
250
251  void
252  RenderViewCells();
253
254 public slots:
255 void
256 SetViewCellGranularity(int number);
257
258 void
259 SetSceneCut(int cut);
260
261 void
262 SetTopDistance(int dist);
263
264  void SetShowViewCells(bool b) {
265        mRenderViewCells = b;
266        updateGL();
267  }
268 
269  void SetTopView(bool b) {
270        mTopView = b;
271        updateGL();
272  }
273
274  void SetCutViewCells(bool b) {
275        mCutViewCells = b;
276        updateGL();
277  }
278  void SetCutScene(bool b) {
279        mCutScene = b;
280        updateGL();
281  }
282
283};
284
285
286extern GlRendererWidget *rendererWidget;
287
288class GlDebuggerWidget : public QGLWidget
289{
290        Q_OBJECT
291public:
292    GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL);
293    ~GlDebuggerWidget();
294    void initializeGL();
295    void resizeGL(int w, int h);
296    void paintGL();
297    void timerEvent(QTimerEvent *) { update(); }
298    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
299    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
300
301    void initCommon();
302    void initPbuffer();
303
304 
305         GlRendererBuffer *mRenderBuffer;
306
307         Beam mBeam;
308         int mSamples;
309         Intersectable *mSourceObject;
310
311private:
312    GLuint dynamicTexture;
313    int timerId;
314};
315
316extern GlDebuggerWidget *debuggerWidget;
317
318#endif
319
Note: See TracBrowser for help on using the repository browser.