source: GTP/trunk/Lib/Vis/Preprocessing/src/CHCRenderer.h @ 2562

Revision 2562, 8.0 KB checked in by mattausch, 17 years ago (diff)

worked on visualization

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