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

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