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

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