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

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