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

Revision 563, 5.1 KB checked in by bittner, 18 years ago (diff)

rss sampling changes, preprocessor::GenerateRays?

  • 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
73  KdTree *mKdTree;
74
75  QWaitCondition mRenderingFinished;
76 
77 
78  GlRenderer(SceneGraph *sceneGraph,
79                         ViewCellsManager *viewcells,
80                         KdTree *tree);
81 
82  ~GlRenderer();
83
84
85  void SetupFalseColor(const int id);
86  void RenderIntersectable(Intersectable *);
87  void RenderViewCell(ViewCell *vc);
88  void RenderMeshInstance(MeshInstance *mi);
89  void RenderMesh(Mesh *m);
90  void SetupMaterial(Material *m);
91  virtual void SetupCamera();
92 
93  bool
94  RenderScene();
95
96  void
97  SetupProjection(const int w, const int h);
98
99 
100 
101  float
102  GetPixelError();
103
104  void InitGL();
105
106  virtual int GetWidth() const = 0;
107  virtual int GetHeight() const = 0;
108
109  int GetId(int r, int g, int b) const;
110};
111
112
113class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
114{
115public:
116        GlRendererBuffer(const int w,
117                                         const int h,
118                                         SceneGraph *sceneGraph,
119                                         ViewCellsManager *viewcells,
120                                         KdTree *tree);
121
122 
123  void
124  EvalPvsStat();
125
126  void
127  ClearErrorBuffer();
128 
129
130  virtual int GetWidth() const { return width(); }
131  virtual int GetHeight() const { return height(); }
132
133
134  void RandomViewPoint();
135  void SampleBeamContributions(
136                                                           Intersectable *sourceObject,
137                                                           Beam &beam,
138                                                           const int samples,
139                                                           BeamSampleStatistics &stat
140                                                           );
141
142  void
143  SampleViewpointContributions(
144                                                           Intersectable *sourceObject,
145                                                           const Vector3 viewPoint,
146                                                           Beam &beam,
147                                                           const int desiredSamples,
148                                                           BeamSampleStatistics &stat
149                                                           );
150
151  void InitGL();
152
153  /** Computes rays from information gained with hw sampling-
154  */
155  void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
156
157  int ComputePvs() const;
158
159
160  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
161
162  PvsRenderStatistics mPvsStat;
163   
164  int mPvsStatFrames;
165  vector<float> mPvsErrorBuffer;
166
167private:
168       
169        static void GenQueries(const int numQueries);
170       
171        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
172                                                                         const Beam &beam,
173                                                                         Intersectable *sourceObject);
174};
175
176
177
178class GlRendererWidget : public QGLWidget, public GlRenderer
179{
180  Q_OBJECT
181public:
182
183  // point of the last mouse click used for movement in the scene
184  Vector3 mousePoint;
185
186  bool mTopView;
187 
188  GlRendererWidget(SceneGraph *sceneGraph,
189                                   ViewCellsManager *viewcells,
190                                   KdTree *tree,
191                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
192                                   ):
193        GlRenderer(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
194  {
195        mTopView = false;
196  }
197
198  virtual void SetupCamera();
199
200  void initializeGL() {
201        InitGL();
202  }
203  void resizeGL(int w, int h);
204  void paintGL();
205  void timerEvent(QTimerEvent *) {
206          update();
207  }
208
209  void mousePressEvent(QMouseEvent *);
210  void mouseReleaseEvent(QMouseEvent *);
211  void mouseMoveEvent(QMouseEvent *);
212
213  void keyPressEvent ( QKeyEvent * e ) ;
214 
215  float
216  RenderErrors();
217
218  virtual int GetWidth() const { return width(); }
219  virtual int GetHeight() const { return height(); }
220};
221
222
223extern GlRendererWidget *rendererWidget;
224
225class GlDebuggerWidget : public QGLWidget
226{
227        Q_OBJECT
228public:
229    GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL);
230    ~GlDebuggerWidget();
231    void initializeGL();
232    void resizeGL(int w, int h);
233    void paintGL();
234    void timerEvent(QTimerEvent *) { update(); }
235    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
236    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
237
238    void initCommon();
239    void initPbuffer();
240
241         GlRendererBuffer *mRenderBuffer;
242
243         Beam mBeam;
244         int mSamples;
245         Intersectable *mSourceObject;
246private:
247    GLuint dynamicTexture;
248    int timerId;
249};
250
251extern GlDebuggerWidget *debuggerWidget;
252
253#endif
254
Note: See TracBrowser for help on using the repository browser.