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

Revision 2702, 8.8 KB checked in by mattausch, 16 years ago (diff)

implemented dynamic object placement / removal

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