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

Revision 1983, 7.3 KB checked in by bittner, 17 years ago (diff)

merge

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