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

Revision 2615, 8.3 KB checked in by mattausch, 16 years ago (diff)

did some stuff for the visualization

  • 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  virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
177
178  virtual void InitGL();
179
180  virtual int GetWidth() const { return 0; }
181  virtual int GetHeight() const { return 0; }
182
183  unsigned int GetId(const unsigned char r,
184                                         const unsigned char g,
185                                         const unsigned char b) const;
186
187  inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
188  inline const std::string GetSnapPrefix() { return mSnapPrefix; }
189
190  inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
191  inline void SetSnapPrefix(const std::string &pref) { mSnapPrefix = pref; }
192
193  virtual void ClearErrorBuffer();
194 
195  virtual float GetAvgPixelError() {
196        return mPvsStat.GetAvgError()*GetWidth()*GetHeight();
197  }
198
199  virtual float GetMaxPixelError() {
200          return mPvsStat.GetMaxError()*GetWidth()*GetHeight();
201  }
202
203  void SetViewPoint(const Vector3 &vp) { mViewPoint = vp; }
204  void SetViewDirection(const Vector3 &vd) { mViewDirection = vd; }
205
206public:
207
208        int mCurrentFrame;
209        int mFrame;
210        bool mWireFrame;
211
212        PvsRenderStatistics mPvsStat;
213
214        int mPvsStatFrames;
215        struct PvsErrorEntry {
216                PvsErrorEntry() {}
217                float mError;
218                int mPvsSize;
219                Vector3 mPosition;
220                Vector3 mDirection;
221        };
222
223        vector<PvsErrorEntry> mPvsErrorBuffer;
224
225protected:
226
227        void CreateVertexArrays(SceneGraphLeaf *leaf);
228        void DeleteVbos();
229        void EnableDrawArrays();
230        void DisableDrawArrays();
231
232        void RenderKdLeaf(KdLeaf *leaf);
233
234
235        //////////////////
236
237        PvsCache mPvsCache;
238
239        unsigned int mVboId;
240        vector<OcclusionQuery *> mOcclusionQueries;
241
242        ObjectContainer mObjects;
243
244        Vector3 mViewPoint;
245        Vector3 mViewDirection;
246
247        int timerId;
248        bool mUseFalseColors;
249        bool mUseForcedColors;
250
251        HaltonSequence halton;
252
253
254        bool mDetectEmptyViewSpace;
255        bool mSnapErrorFrames;
256
257        bool mRenderBoxes;
258
259        bool mUseGlLists;
260
261        std::string mSnapPrefix;
262
263        GLUquadric *mSphere;
264
265        KdTree *mKdTree;
266
267        Vector3 *mData;
268        unsigned int *mIndices;
269
270        bool mUseVbos;
271};
272
273
274/* Class implementing an OpenGl render buffer.
275*/
276class GlRendererBuffer: public GlRenderer
277{
278
279public:
280
281        GlRendererBuffer(SceneGraph *sceneGraph,
282                ViewCellsManager *viewcells,
283                KdTree *tree);
284
285        virtual ~GlRendererBuffer();
286
287        /** Evaluates render cost of a point sample.
288        @param sample the render cost sample to be evaluated
289        @param useOcclusionQueries if occlusion queries should be used or item buffer
290        @param threshold number of pixels / samples from where an object is considered visible.
291        */
292        virtual void EvalRenderCostSample(RenderCostSample &sample,
293                const bool useOcclusionQueries,
294                const int threshold);
295
296        /** Evaluates render cost of a number of point samples. The point samples
297        are distributed uniformly over the defined view space.
298
299        @param numSamples the number of point samples taken
300        @param samples stores the taken point samples in a container
301        @param useOcclusionQueries if occlusion queries should be used or item buffer
302        @param threshold number of pixels / samples from where an object is considered visible.
303        */
304        virtual void SampleRenderCost(const int numSamples,
305                                                                  vector<RenderCostSample> &samples,
306                                                                  const bool useOcclusionQueries,
307                                                                  const int threshold = 0);
308        /** Implerment in subclasses.
309        */
310        virtual void EvalPvsStat();
311
312        virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
313
314        virtual int GetWidth() const = 0;
315        virtual int GetHeight() const  = 0;
316
317        virtual void MakeCurrent() = 0;
318        virtual void DoneCurrent() = 0;
319
320        virtual bool ValidViewPoint();
321
322        virtual void SampleBeamContributions(
323                                                                                 Intersectable *sourceObject,
324                                                                                 Beam &beam,
325                                                                                 const int samples,
326                                                                                 BeamSampleStatistics &stat
327                                                                                 );
328
329        virtual void SampleViewpointContributions(
330                                                                                          Intersectable *sourceObject,
331                                                                                          const Vector3 viewPoint,
332                                                                                          Beam &beam,
333                                                                                          const int desiredSamples,
334                                                                                          BeamSampleStatistics &stat
335                                                                                          );
336
337        virtual void InitGL();
338        /** Computes rays from information gained with hw sampling-
339        */
340        virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
341
342        virtual int ComputePvs() const = 0;
343
344        virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
345
346
347protected:
348
349        unsigned int *mPixelBuffer;
350
351        static void GenQueries(const int numQueries);
352
353        virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
354                                                                                         const Beam &beam,
355                                                                                         Intersectable *sourceObject);
356        /** Evaluates query for one direction using item buffer.
357        */
358        virtual void EvalQueryWithItemBuffer();
359        /** Evaluates query for one direction using occlusion queries.
360        */
361        virtual void EvalQueryWithOcclusionQueries();
362};
363
364
365/** Abstract class for implmenenting a gl render widget.
366*/
367class GlRendererWidget: public GlRenderer
368{
369public:
370
371        GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
372          GlRenderer(sceneGraph, vcm, kdTree)
373          {}
374
375          GlRendererWidget() {}
376
377          virtual ~GlRendererWidget() {}
378         
379          virtual void Show() {}
380};
381
382
383};
384
385#endif
Note: See TracBrowser for help on using the repository browser.