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

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