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

Revision 2625, 8.5 KB checked in by mattausch, 16 years ago (diff)

added new view cell
deleted other view cell generation stuff (please use generate_viewcells.sh script)
added visualizaton method for gvs

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