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

Revision 1785, 7.0 KB checked in by bittner, 18 years ago (diff)

merge, filter update, renderebuffer made functional

  • Property svn:executable set to *
Line 
1#ifndef __GLRENDERER_H
2#define __GLRENDERER_H
3
4#include "Vector3.h"
5#include "Containers.h"
6#include "Halton.h"
7#include "Renderer.h"
8#include "Beam.h"
9#include "Pvs.h"
10
11
12namespace GtpVisibilityPreprocessor {
13
14class SceneGraph;
15class ViewCellsManager;
16class Mesh;
17class MeshInstance;
18class Intersectable;
19class Material;
20class Beam;
21class KdTree;
22class GlRendererBuffer;
23class BeamSampleStatistics;
24class OcclusionQuery;
25class TransformedMeshInstance;
26class TriangleIntersectable;
27  class BvhNode;
28 
29struct VssRayContainer;
30
31  struct GLUquadric;
32 
33struct PvsRenderStatistics {
34 
35  float maxError;
36  float sumError;
37  int sumPvsSize;
38  int frames;
39  int errorFreeFrames;
40
41  PvsRenderStatistics() { Reset(); }
42 
43  void Reset() {
44        maxError = 0.0f;
45        sumError = 0.0f;
46        frames = 0;
47        errorFreeFrames = 0;
48        sumPvsSize = 0;
49  }
50
51  float GetMaxError() { return maxError; }
52  float GetAvgError() { return sumError/frames; }
53  float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
54  float GetAvgPvs() { return sumPvsSize/(float)frames; }
55 
56};
57
58struct RenderCostSample {
59
60  RenderCostSample() {}
61
62  void Reset() {
63        mVisibleObjects = 0;
64        mVisiblePixels = 0;
65  }
66 
67  Vector3 mPosition;
68
69  // visible object from the given point
70  int mVisibleObjects;
71
72  // visible pixels
73  int mVisiblePixels;
74
75  ObjectPvs mPvs;
76 
77};
78
79/** Class encapsulating gl rendering for the scene.
80        There is no gl context binding so the binding is performed in the
81        derived classes
82*/
83class GlRenderer: public Renderer
84{
85
86public:
87
88  GlRenderer(SceneGraph *sceneGraph,
89                         ViewCellsManager *viewcells,
90                         KdTree *tree);
91 
92  GlRenderer() {}
93
94  virtual ~GlRenderer();
95
96
97  void SetupFalseColor(const int id);
98  void RenderIntersectable(Intersectable *);
99  void RenderViewCell(ViewCell *vc);
100  void RenderMeshInstance(MeshInstance *mi);
101  void RenderTransformedMeshInstance(TransformedMeshInstance *mi);
102  void RenderMesh(Mesh *m);
103  void SetupMaterial(Material *m);
104  virtual void SetupCamera();
105
106  void
107  RenderRays(const VssRayContainer &rays);
108
109  void
110  RenderTriangle(TriangleIntersectable *object);
111
112  void
113  RenderBox(const AxisAlignedBox3 &box);
114
115  void
116  RenderBvhNode(BvhNode *node);
117
118  void
119  RenderKdNode(KdNode *node);
120
121  bool
122  RenderScene();
123
124  void
125  _RenderScene();
126
127
128  virtual void
129  SetupProjection(const int w, const int h, const float angle = 70.0f);
130
131 
132 
133
134  void InitGL();
135
136  virtual int GetWidth() const = 0;
137  virtual int GetHeight() const = 0;
138
139  int GetId(int r, int g, int b) const;
140
141  inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
142  inline const string GetSnapPrefix() { return mSnapPrefix; }
143
144  inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
145  inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; }
146
147protected:
148
149
150  vector<OcclusionQuery *> mOcclusionQueries;
151
152  ObjectContainer mObjects;
153   
154  Vector3 mViewPoint;
155  Vector3 mViewDirection;
156
157  int timerId;
158  bool mUseFalseColors;
159  bool mUseForcedColors;
160
161  HaltonSequence halton;
162 
163  int mFrame;
164  bool mWireFrame;
165 
166  bool mDetectEmptyViewSpace;
167  bool mSnapErrorFrames;
168
169  bool mRenderBoxes;
170
171  bool mUseGlLists;
172 
173  string mSnapPrefix;
174
175  GLUquadric *mSphere;
176 
177  KdTree *mKdTree;
178
179};
180
181/* Class implementing an OpenGl render buffer.
182*/
183class GlRendererBuffer: public GlRenderer
184{
185
186public:
187
188GlRendererBuffer(SceneGraph *sceneGraph,
189                                 ViewCellsManager *viewcells,
190                                 KdTree *tree);
191
192  virtual ~GlRendererBuffer();
193
194        /** Evaluates render cost of a point sample.
195                @param sample the render cost sample to be evaluated
196                @param useOcclusionQueries if occlusion queries should be used or item buffer
197                @param threshold number of pixels / samples from where an object is considered visible.
198        */
199  virtual void EvalRenderCostSample(RenderCostSample &sample,
200                                                          const bool useOcclusionQueries,
201                                                          const int threshold);
202
203        /** Evaluates render cost of a number of point samples. The point samples
204                are distributed uniformly over the defined view space.
205
206                @param numSamples the number of point samples taken
207                @param samples stores the taken point samples in a container
208                @param useOcclusionQueries if occlusion queries should be used or item buffer
209                @param threshold number of pixels / samples from where an object is considered visible.
210        */
211  virtual void SampleRenderCost(const int numSamples,
212                                                                vector<RenderCostSample> &samples,
213                                                                const bool useOcclusionQueries,
214                                                                const int threshold = 0);
215 
216
217        /** Implerment in subclasses.
218        */
219  virtual void EvalPvsStat();
220
221  virtual void ClearErrorBuffer();
222 
223
224  virtual int GetWidth() const = 0;
225  virtual int GetHeight() const  = 0;
226
227  virtual void MakeCurrent() = 0;
228  virtual void DoneCurrent() = 0;
229 
230
231  virtual void RandomViewPoint();
232  virtual void SampleBeamContributions(
233                                                           Intersectable *sourceObject,
234                                                           Beam &beam,
235                                                           const int samples,
236                                                           BeamSampleStatistics &stat
237                                                           );
238
239  virtual void
240  SampleViewpointContributions(
241                                                           Intersectable *sourceObject,
242                                                           const Vector3 viewPoint,
243                                                           Beam &beam,
244                                                           const int desiredSamples,
245                                                           BeamSampleStatistics &stat
246                                                           );
247
248  virtual void InitGL();
249
250  /** Computes rays from information gained with hw sampling-
251  */
252  virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
253
254  virtual int ComputePvs() const = 0;
255
256  virtual float
257  GetPixelError(int &pvsSize) = 0;
258 
259  virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
260 
261  PvsRenderStatistics mPvsStat;
262   
263  int mPvsStatFrames;
264  struct PvsErrorEntry {
265          PvsErrorEntry() {}
266          float mError;
267          int mPvsSize;
268          Vector3 mPosition;
269          Vector3 mDirection;
270  };
271 
272  vector<PvsErrorEntry> mPvsErrorBuffer;
273
274 
275protected:
276  unsigned int *mPixelBuffer;
277 
278  static void GenQueries(const int numQueries);
279       
280  virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
281                                                                         const Beam &beam,
282
283                                                                         Intersectable *sourceObject);
284
285        /** Evaluates query for one direction using item buffer.
286        */
287  virtual void EvalQueryWithItemBuffer();
288
289        /** Evaluates query for one direction using occlusion queries.
290        */
291  virtual void EvalQueryWithOcclusionQueries();
292
293public:
294        // matt: remove qt dependencies
295 // signals:
296//      void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
297};
298
299
300/** Abstract class for implmenenting a gl render widget.
301*/
302class GlRendererWidget: public GlRenderer
303{
304public:
305       
306        GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
307          GlRenderer(sceneGraph, vcm, kdTree)
308        {}
309
310    GlRendererWidget() {}
311
312    virtual ~GlRendererWidget() {}
313
314        //virtual void Create() {}
315        virtual void Show() {}
316       
317
318protected:
319
320
321  //    SceneGraph *mSceneGraph;
322  //    ViewCellsManager *mViewCellsManager;
323  //    KdTree *mKdTree;
324};
325
326//extern GlRendererWidget *rendererWidget;
327
328};
329
330#endif
Note: See TracBrowser for help on using the repository browser.