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

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