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

Revision 2600, 8.2 KB checked in by mattausch, 17 years ago (diff)

preparing for moving objects (contains compile errors!)

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