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

Revision 2017, 7.6 KB checked in by mattausch, 18 years ago (diff)

changed to static cast

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