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

Revision 713, 6.3 KB checked in by bittner, 18 years ago (diff)

visibility filter used in glrenderer

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