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

Revision 589, 5.2 KB checked in by bittner, 18 years ago (diff)

unix2dos on all sources

  • 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  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
181
182class GlRendererWidget : public QGLWidget, public GlRenderer
183{
184  Q_OBJECT
185public:
186
187  // point of the last mouse click used for movement in the scene
188  Vector3 mousePoint;
189
190  bool mTopView;
191 
192  GlRendererWidget(SceneGraph *sceneGraph,
193                                   ViewCellsManager *viewcells,
194                                   KdTree *tree,
195                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
196                                   ):
197        GlRenderer(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
198  {
199        mTopView = false;
200  }
201
202  virtual void SetupCamera();
203
204  void initializeGL() {
205        InitGL();
206  }
207  void resizeGL(int w, int h);
208  void paintGL();
209  void timerEvent(QTimerEvent *) {
210          update();
211  }
212
213  void mousePressEvent(QMouseEvent *);
214  void mouseReleaseEvent(QMouseEvent *);
215  void mouseMoveEvent(QMouseEvent *);
216
217  void keyPressEvent ( QKeyEvent * e ) ;
218 
219  float
220  RenderErrors();
221  void
222  RenderInfo();
223
224  virtual int GetWidth() const { return width(); }
225  virtual int GetHeight() const { return height(); }
226};
227
228
229extern GlRendererWidget *rendererWidget;
230
231class GlDebuggerWidget : public QGLWidget
232{
233        Q_OBJECT
234public:
235    GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL);
236    ~GlDebuggerWidget();
237    void initializeGL();
238    void resizeGL(int w, int h);
239    void paintGL();
240    void timerEvent(QTimerEvent *) { update(); }
241    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
242    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
243
244    void initCommon();
245    void initPbuffer();
246
247         GlRendererBuffer *mRenderBuffer;
248
249         Beam mBeam;
250         int mSamples;
251         Intersectable *mSourceObject;
252private:
253    GLuint dynamicTexture;
254    int timerId;
255};
256
257extern GlDebuggerWidget *debuggerWidget;
258
259#endif
260
Note: See TracBrowser for help on using the repository browser.