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

Revision 2002, 7.5 KB checked in by bittner, 17 years ago (diff)

renderer code updates for pixel error measurements

  • 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 
177public:
178
179  int mFrame;
180  bool mWireFrame;
181
182  PvsRenderStatistics mPvsStat;
183 
184  int mPvsStatFrames;
185  struct PvsErrorEntry {
186          PvsErrorEntry() {}
187          float mError;
188          int mPvsSize;
189          Vector3 mPosition;
190          Vector3 mDirection;
191  };
192friend class GlobalLinesRenderer;
193protected:
194
195 
196  vector<PvsErrorEntry> mPvsErrorBuffer;
197
198  PvsCache mPvsCache;
199
200  vector<OcclusionQuery *> mOcclusionQueries;
201
202  ObjectContainer mObjects;
203   
204  Vector3 mViewPoint;
205  Vector3 mViewDirection;
206
207  int timerId;
208  bool mUseFalseColors;
209  bool mUseForcedColors;
210
211  HaltonSequence halton;
212 
213 
214  bool mDetectEmptyViewSpace;
215  bool mSnapErrorFrames;
216
217  bool mRenderBoxes;
218
219  bool mUseGlLists;
220 
221  string mSnapPrefix;
222
223  GLUquadric *mSphere;
224 
225  KdTree *mKdTree;
226
227};
228
229/* Class implementing an OpenGl render buffer.
230*/
231class GlRendererBuffer: public GlRenderer
232{
233
234public:
235
236        GlRendererBuffer(SceneGraph *sceneGraph,
237                ViewCellsManager *viewcells,
238                KdTree *tree);
239
240        virtual ~GlRendererBuffer();
241
242        /** Evaluates render cost of a point sample.
243        @param sample the render cost sample to be evaluated
244        @param useOcclusionQueries if occlusion queries should be used or item buffer
245        @param threshold number of pixels / samples from where an object is considered visible.
246        */
247        virtual void EvalRenderCostSample(RenderCostSample &sample,
248                const bool useOcclusionQueries,
249                const int threshold);
250
251        /** Evaluates render cost of a number of point samples. The point samples
252        are distributed uniformly over the defined view space.
253
254        @param numSamples the number of point samples taken
255        @param samples stores the taken point samples in a container
256        @param useOcclusionQueries if occlusion queries should be used or item buffer
257        @param threshold number of pixels / samples from where an object is considered visible.
258        */
259        virtual void SampleRenderCost(const int numSamples,
260                vector<RenderCostSample> &samples,
261                const bool useOcclusionQueries,
262                const int threshold = 0);
263
264
265        /** Implerment in subclasses.
266        */
267        virtual void EvalPvsStat();
268
269
270        virtual int GetWidth() const = 0;
271        virtual int GetHeight() const  = 0;
272
273        virtual void MakeCurrent() = 0;
274        virtual void DoneCurrent() = 0;
275
276
277        virtual void SampleBeamContributions(
278                Intersectable *sourceObject,
279                Beam &beam,
280                const int samples,
281                BeamSampleStatistics &stat
282                );
283
284        virtual void
285                SampleViewpointContributions(
286                Intersectable *sourceObject,
287                const Vector3 viewPoint,
288                Beam &beam,
289                const int desiredSamples,
290                BeamSampleStatistics &stat
291                );
292
293        virtual void InitGL();
294
295        /** Computes rays from information gained with hw sampling-
296        */
297        virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
298
299        virtual int ComputePvs() const = 0;
300
301        virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
302
303
304protected:
305
306        unsigned int *mPixelBuffer;
307
308        static void GenQueries(const int numQueries);
309
310        virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
311                const Beam &beam,
312
313                Intersectable *sourceObject);
314
315        /** Evaluates query for one direction using item buffer.
316        */
317        virtual void EvalQueryWithItemBuffer();
318
319        /** Evaluates query for one direction using occlusion queries.
320        */
321        virtual void EvalQueryWithOcclusionQueries();
322
323public:
324        // matt: remove qt dependencies
325        // signals:
326        //      void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
327};
328
329
330/** Abstract class for implmenenting a gl render widget.
331*/
332class GlRendererWidget: public GlRenderer
333{
334public:
335
336        GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
337          GlRenderer(sceneGraph, vcm, kdTree)
338          {}
339
340          GlRendererWidget() {}
341
342          virtual ~GlRendererWidget() {}
343
344          //virtual void Create() {}
345          virtual void Show() {}
346
347
348protected:
349
350
351        //      SceneGraph *mSceneGraph;
352        //      ViewCellsManager *mViewCellsManager;
353        //      KdTree *mKdTree;
354};
355
356//extern GlRendererWidget *rendererWidget;
357
358};
359
360#endif
Note: See TracBrowser for help on using the repository browser.