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

Revision 2023, 7.6 KB checked in by mattausch, 17 years ago (diff)
  • 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 ValidViewPoint();
148 
149  virtual float
150  GetPixelError(int &pvsSize);
151 
152  virtual void
153  EvalPvsStat();
154
155  virtual void InitGL();
156
157  virtual int GetWidth() const { return 0; }
158  virtual int GetHeight() const { return 0; }
159
160  unsigned int GetId(const unsigned char r,
161                                         const unsigned char g,
162                                         const unsigned char b) const;
163
164  inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
165  inline const string GetSnapPrefix() { return mSnapPrefix; }
166
167  inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
168  inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; }
169
170  virtual void ClearErrorBuffer();
171 
172  virtual float GetAvgPixelError() {
173        return mPvsStat.GetAvgError()*GetWidth()*GetHeight();
174  }
175
176  virtual float GetMaxPixelError() {
177        return mPvsStat.GetMaxError()*GetWidth()*GetHeight();
178  }
179 
180public:
181
182  int mFrame;
183  bool mWireFrame;
184
185  PvsRenderStatistics mPvsStat;
186 
187  int mPvsStatFrames;
188  struct PvsErrorEntry {
189          PvsErrorEntry() {}
190          float mError;
191          int mPvsSize;
192          Vector3 mPosition;
193          Vector3 mDirection;
194  };
195friend class GlobalLinesRenderer;
196friend class ViewCellsManager;
197
198protected:
199
200 
201  vector<PvsErrorEntry> mPvsErrorBuffer;
202
203  PvsCache mPvsCache;
204
205  vector<OcclusionQuery *> mOcclusionQueries;
206
207  ObjectContainer mObjects;
208   
209  Vector3 mViewPoint;
210  Vector3 mViewDirection;
211
212  int timerId;
213  bool mUseFalseColors;
214  bool mUseForcedColors;
215
216  HaltonSequence halton;
217 
218 
219  bool mDetectEmptyViewSpace;
220  bool mSnapErrorFrames;
221
222  bool mRenderBoxes;
223
224  bool mUseGlLists;
225 
226  string mSnapPrefix;
227
228  GLUquadric *mSphere;
229 
230  KdTree *mKdTree;
231
232};
233
234/* Class implementing an OpenGl render buffer.
235*/
236class GlRendererBuffer: public GlRenderer
237{
238
239public:
240
241        GlRendererBuffer(SceneGraph *sceneGraph,
242                ViewCellsManager *viewcells,
243                KdTree *tree);
244
245        virtual ~GlRendererBuffer();
246
247        /** Evaluates render cost of a point sample.
248        @param sample the render cost sample to be evaluated
249        @param useOcclusionQueries if occlusion queries should be used or item buffer
250        @param threshold number of pixels / samples from where an object is considered visible.
251        */
252        virtual void EvalRenderCostSample(RenderCostSample &sample,
253                const bool useOcclusionQueries,
254                const int threshold);
255
256        /** Evaluates render cost of a number of point samples. The point samples
257        are distributed uniformly over the defined view space.
258
259        @param numSamples the number of point samples taken
260        @param samples stores the taken point samples in a container
261        @param useOcclusionQueries if occlusion queries should be used or item buffer
262        @param threshold number of pixels / samples from where an object is considered visible.
263        */
264        virtual void SampleRenderCost(const int numSamples,
265                vector<RenderCostSample> &samples,
266                const bool useOcclusionQueries,
267                const int threshold = 0);
268
269
270        /** Implerment in subclasses.
271        */
272        virtual void EvalPvsStat();
273
274
275        virtual int GetWidth() const = 0;
276        virtual int GetHeight() const  = 0;
277
278        virtual void MakeCurrent() = 0;
279        virtual void DoneCurrent() = 0;
280
281        virtual bool ValidViewPoint();
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.