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

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