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

Revision 1960, 7.4 KB checked in by mattausch, 18 years ago (diff)

worked on depth peeling

  • 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
[811]138
[608]139  virtual void
[811]140  SetupProjection(const int w, const int h, const float angle = 70.0f);
[496]141
142 
[1931]143  virtual float
144  GetPixelError(int &pvsSize);
[496]145 
[1931]146  virtual void
147  EvalPvsStat();
[496]148
149  void InitGL();
150
[1940]151  virtual int GetWidth() const { return 0; }
152  virtual int GetHeight() const { return 0; }
[540]153
[1960]154  unsigned int GetId(const unsigned char r,
155                                         const unsigned char g,
156                                         const unsigned char b) const;
[1151]157
158  inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
159  inline const string GetSnapPrefix() { return mSnapPrefix; }
160
161  inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
162  inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; }
163
[1931]164  virtual void ClearErrorBuffer();
165 
166
[1832]167public:
[1940]168
[1832]169  int mFrame;
170  bool mWireFrame;
[1931]171
172  PvsRenderStatistics mPvsStat;
173 
174  int mPvsStatFrames;
175  struct PvsErrorEntry {
176          PvsErrorEntry() {}
177          float mError;
178          int mPvsSize;
179          Vector3 mPosition;
180          Vector3 mDirection;
181  };
[1944]182friend class GlobalLinesRenderer;
[1151]183protected:
184
[1931]185 
186  vector<PvsErrorEntry> mPvsErrorBuffer;
[1151]187
[1931]188  PvsCache mPvsCache;
189
[1151]190  vector<OcclusionQuery *> mOcclusionQueries;
191
192  ObjectContainer mObjects;
193   
194  Vector3 mViewPoint;
195  Vector3 mViewDirection;
196
197  int timerId;
198  bool mUseFalseColors;
199  bool mUseForcedColors;
200
201  HaltonSequence halton;
202 
203 
204  bool mDetectEmptyViewSpace;
205  bool mSnapErrorFrames;
206
[1594]207  bool mRenderBoxes;
208
[1151]209  bool mUseGlLists;
210 
211  string mSnapPrefix;
212
[1608]213  GLUquadric *mSphere;
214 
[1151]215  KdTree *mKdTree;
216
[496]217};
218
[1146]219/* Class implementing an OpenGl render buffer.
220*/
[1145]221class GlRendererBuffer: public GlRenderer
[496]222{
[1145]223
[496]224public:
[1151]225
[1145]226GlRendererBuffer(SceneGraph *sceneGraph,
[811]227                                 ViewCellsManager *viewcells,
228                                 KdTree *tree);
[589]229
[1785]230  virtual ~GlRendererBuffer();
[811]231
[1001]232        /** Evaluates render cost of a point sample.
233                @param sample the render cost sample to be evaluated
234                @param useOcclusionQueries if occlusion queries should be used or item buffer
235                @param threshold number of pixels / samples from where an object is considered visible.
236        */
[1785]237  virtual void EvalRenderCostSample(RenderCostSample &sample,
[1001]238                                                          const bool useOcclusionQueries,
239                                                          const int threshold);
[811]240
[1001]241        /** Evaluates render cost of a number of point samples. The point samples
242                are distributed uniformly over the defined view space.
[811]243
[1001]244                @param numSamples the number of point samples taken
245                @param samples stores the taken point samples in a container
246                @param useOcclusionQueries if occlusion queries should be used or item buffer
247                @param threshold number of pixels / samples from where an object is considered visible.
248        */
[1785]249  virtual void SampleRenderCost(const int numSamples,
250                                                                vector<RenderCostSample> &samples,
251                                                                const bool useOcclusionQueries,
252                                                                const int threshold = 0);
253 
[811]254
[1145]255        /** Implerment in subclasses.
256        */
[1785]257  virtual void EvalPvsStat();
[1001]258
[496]259
[1785]260  virtual int GetWidth() const = 0;
261  virtual int GetHeight() const  = 0;
[496]262
[1785]263  virtual void MakeCurrent() = 0;
264  virtual void DoneCurrent() = 0;
265 
[507]266
[1785]267  virtual void SampleBeamContributions(
[507]268                                                           Intersectable *sourceObject,
[512]269                                                           Beam &beam,
[507]270                                                           const int samples,
271                                                           BeamSampleStatistics &stat
272                                                           );
273
[1785]274  virtual void
[507]275  SampleViewpointContributions(
276                                                           Intersectable *sourceObject,
[514]277                                                           const Vector3 viewPoint,
[512]278                                                           Beam &beam,
[507]279                                                           const int desiredSamples,
280                                                           BeamSampleStatistics &stat
281                                                           );
282
[1785]283  virtual void InitGL();
[540]284
285  /** Computes rays from information gained with hw sampling-
286  */
[1785]287  virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
[540]288
[1785]289  virtual int ComputePvs() const = 0;
[540]290
[1785]291 
292  virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
[713]293
[1931]294
295
[997]296 
[1145]297protected:
[1785]298  unsigned int *mPixelBuffer;
[811]299 
[1785]300  static void GenQueries(const int numQueries);
[589]301       
[1785]302  virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
[589]303                                                                         const Beam &beam,
[746]304
[525]305                                                                         Intersectable *sourceObject);
[746]306
[1001]307        /** Evaluates query for one direction using item buffer.
308        */
[1785]309  virtual void EvalQueryWithItemBuffer();
[1146]310
[1001]311        /** Evaluates query for one direction using occlusion queries.
312        */
[1785]313  virtual void EvalQueryWithOcclusionQueries();
[997]314
[746]315public:
[1145]316        // matt: remove qt dependencies
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:
327       
[1151]328        GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
329          GlRenderer(sceneGraph, vcm, kdTree)
330        {}
[1146]331
[1151]332    GlRendererWidget() {}
[1146]333
[1151]334    virtual ~GlRendererWidget() {}
[1146]335
336        //virtual void Create() {}
337        virtual void Show() {}
338       
339
340protected:
341
342
[1387]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.