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

Revision 1983, 7.3 KB checked in by bittner, 17 years ago (diff)

merge

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