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

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