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

Revision 2176, 7.8 KB checked in by mattausch, 18 years ago (diff)

removed using namespace std from .h

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