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

Revision 2686, 8.7 KB checked in by mattausch, 16 years ago (diff)

fixed several problems

  • 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{
65        PvsCache():mViewCell(NULL), mUnfilteredPvsSize(0) {}
[1824]66
[2593]67        void Reset()
68        {
[2643]69                mViewCell = NULL;
70                mPvs.Clear();
[2593]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
[2615]163  void _RenderDynamicObject(SceneGraphLeaf *leaf);
164
[608]165  virtual void
[811]166  SetupProjection(const int w, const int h, const float angle = 70.0f);
[496]167
[2023]168  virtual bool ValidViewPoint();
[496]169 
[2664]170  virtual float GetPixelError(int &pvsSize);
[496]171 
[2664]172  virtual void EvalPvsStat();
[496]173
[2670]174  /** Prepare the pvs for rendering.
175  */
176  virtual void PreparePvs(const ObjectPvs &pvs);
177  /** Helper function that recursively prepares the indices for VBO renderin.
178  */
[2620]179  void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
180
181       
[2048]182  virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
183
[1997]184  virtual void InitGL();
[496]185
[1940]186  virtual int GetWidth() const { return 0; }
187  virtual int GetHeight() const { return 0; }
[540]188
[1960]189  unsigned int GetId(const unsigned char r,
190                                         const unsigned char g,
191                                         const unsigned char b) const;
[1151]192
193  inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
[2176]194  inline const std::string GetSnapPrefix() { return mSnapPrefix; }
[1151]195
196  inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
[2176]197  inline void SetSnapPrefix(const std::string &pref) { mSnapPrefix = pref; }
[1151]198
[1931]199  virtual void ClearErrorBuffer();
200 
[2002]201  virtual float GetAvgPixelError() {
202        return mPvsStat.GetAvgError()*GetWidth()*GetHeight();
203  }
[2008]204
205  virtual float GetMaxPixelError() {
[2543]206          return mPvsStat.GetMaxError()*GetWidth()*GetHeight();
[2008]207  }
[2543]208
[2598]209  void SetViewPoint(const Vector3 &vp) { mViewPoint = vp; }
210  void SetViewDirection(const Vector3 &vd) { mViewDirection = vd; }
211
[2625]212  Vector3 GetViewPoint() const { return mViewPoint; }
[2670]213
[2686]214  bool GetUseVbos() const { return mUseVbos; }
[2670]215
[2686]216
[1832]217public:
[1940]218
[2543]219        int mCurrentFrame;
220        int mFrame;
221        bool mWireFrame;
[1931]222
[2543]223        PvsRenderStatistics mPvsStat;
[2017]224
[2620]225        unsigned int mIndexBufferSize;
226
[2543]227        int mPvsStatFrames;
228        struct PvsErrorEntry {
229                PvsErrorEntry() {}
230                float mError;
231                int mPvsSize;
232                Vector3 mPosition;
233                Vector3 mDirection;
234        };
[2050]235
[2543]236        vector<PvsErrorEntry> mPvsErrorBuffer;
[2671]237
[2643]238        bool mComputeGVS;
[2543]239
[1151]240protected:
241
[2600]242        void CreateVertexArrays(SceneGraphLeaf *leaf);
[2538]243        void DeleteVbos();
244        void EnableDrawArrays();
245        void DisableDrawArrays();
[1151]246
[2538]247        void RenderKdLeaf(KdLeaf *leaf);
[1931]248
[2686]249       
[2538]250        //////////////////
[1151]251
[2538]252        PvsCache mPvsCache;
[1151]253
[2538]254        unsigned int mVboId;
255        vector<OcclusionQuery *> mOcclusionQueries;
[1151]256
[2538]257        ObjectContainer mObjects;
[1594]258
[2538]259        Vector3 mViewPoint;
260        Vector3 mViewDirection;
[1151]261
[2538]262        int timerId;
263        bool mUseFalseColors;
264        bool mUseForcedColors;
[1151]265
[2538]266        HaltonSequence halton;
267
268
269        bool mDetectEmptyViewSpace;
270        bool mSnapErrorFrames;
271
272        bool mRenderBoxes;
273
274        bool mUseGlLists;
275
276        std::string mSnapPrefix;
277
278        GLUquadric *mSphere;
279
280        KdTree *mKdTree;
281
282        Vector3 *mData;
283        unsigned int *mIndices;
284
285        bool mUseVbos;
[2671]286
287        int mRenderedNodes;
[496]288};
289
[2538]290
[1146]291/* Class implementing an OpenGl render buffer.
292*/
[1145]293class GlRendererBuffer: public GlRenderer
[496]294{
[1145]295
[496]296public:
[1151]297
[1968]298        GlRendererBuffer(SceneGraph *sceneGraph,
299                ViewCellsManager *viewcells,
300                KdTree *tree);
[589]301
[1968]302        virtual ~GlRendererBuffer();
[811]303
[1001]304        /** Evaluates render cost of a point sample.
[1968]305        @param sample the render cost sample to be evaluated
306        @param useOcclusionQueries if occlusion queries should be used or item buffer
307        @param threshold number of pixels / samples from where an object is considered visible.
[1001]308        */
[1968]309        virtual void EvalRenderCostSample(RenderCostSample &sample,
310                const bool useOcclusionQueries,
311                const int threshold);
[811]312
[1001]313        /** Evaluates render cost of a number of point samples. The point samples
[1968]314        are distributed uniformly over the defined view space.
[811]315
[1968]316        @param numSamples the number of point samples taken
317        @param samples stores the taken point samples in a container
318        @param useOcclusionQueries if occlusion queries should be used or item buffer
319        @param threshold number of pixels / samples from where an object is considered visible.
[1001]320        */
[1968]321        virtual void SampleRenderCost(const int numSamples,
[2538]322                                                                  vector<RenderCostSample> &samples,
323                                                                  const bool useOcclusionQueries,
324                                                                  const int threshold = 0);
[1145]325        /** Implerment in subclasses.
326        */
[1968]327        virtual void EvalPvsStat();
[1001]328
[2048]329        virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
[496]330
[1968]331        virtual int GetWidth() const = 0;
332        virtual int GetHeight() const  = 0;
[496]333
[2677]334        virtual void MakeLive() = 0;
335        virtual void DoneLive() = 0;
[507]336
[2023]337        virtual bool ValidViewPoint();
[507]338
[1968]339        virtual void SampleBeamContributions(
[2538]340                                                                                 Intersectable *sourceObject,
341                                                                                 Beam &beam,
342                                                                                 const int samples,
343                                                                                 BeamSampleStatistics &stat
344                                                                                 );
[507]345
[2538]346        virtual void SampleViewpointContributions(
347                                                                                          Intersectable *sourceObject,
348                                                                                          const Vector3 viewPoint,
349                                                                                          Beam &beam,
350                                                                                          const int desiredSamples,
351                                                                                          BeamSampleStatistics &stat
352                                                                                          );
[540]353
[1968]354        virtual void InitGL();
355        /** Computes rays from information gained with hw sampling-
356        */
357        virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
[540]358
[1968]359        virtual int ComputePvs() const = 0;
[713]360
[1968]361        virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
[1931]362
363
[1145]364protected:
[746]365
[1968]366        unsigned int *mPixelBuffer;
[746]367
[2663]368        static void GenQueries(int numQueries);
[1968]369
370        virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
[2538]371                                                                                         const Beam &beam,
372                                                                                         Intersectable *sourceObject);
[1001]373        /** Evaluates query for one direction using item buffer.
374        */
[1968]375        virtual void EvalQueryWithItemBuffer();
[1001]376        /** Evaluates query for one direction using occlusion queries.
377        */
[1968]378        virtual void EvalQueryWithOcclusionQueries();
[496]379};
380
[1146]381
382/** Abstract class for implmenenting a gl render widget.
383*/
[1151]384class GlRendererWidget: public GlRenderer
[1146]385{
386public:
[1968]387
[1151]388        GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
389          GlRenderer(sceneGraph, vcm, kdTree)
[1968]390          {}
[1146]391
[1968]392          GlRendererWidget() {}
[1146]393
[1968]394          virtual ~GlRendererWidget() {}
[2538]395         
[1968]396          virtual void Show() {}
[608]397};
398
[1151]399
[1146]400};
[492]401
[1387]402#endif
Note: See TracBrowser for help on using the repository browser.