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

Revision 1161, 6.4 KB checked in by mattausch, 18 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;
26
27struct VssRayContainer;
28
29struct PvsRenderStatistics {
30 
31  float maxError;
32  float sumError;
33  int sumPvsSize;
34  int frames;
35  int errorFreeFrames;
36
37  PvsRenderStatistics() { Reset(); }
38 
39  void Reset() {
40        maxError = 0.0f;
41        sumError = 0.0f;
42        frames = 0;
43        errorFreeFrames = 0;
44        sumPvsSize = 0;
45  }
46
47  float GetMaxError() { return maxError; }
48  float GetAvgError() { return sumError/frames; }
49  float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
50  float GetAvgPvs() { return sumPvsSize/(float)frames; }
51 
52};
53
54struct RenderCostSample {
55
56  RenderCostSample() {}
57
58  void Reset() {
59        mVisibleObjects = 0;
60        mVisiblePixels = 0;
61  }
62 
63  Vector3 mPosition;
64
65  // visible object from the given point
66  int mVisibleObjects;
67
68  // visible pixels
69  int mVisiblePixels;
70
71  ObjectPvs mPvs;
72 
73};
74
75/** Class encapsulating gl rendering for the scene.
76        There is no gl context binding so the binding is performed in the
77        derived classes
78*/
79class GlRenderer: public Renderer
80{
81
82public:
83
84  GlRenderer(SceneGraph *sceneGraph,
85                         ViewCellsManager *viewcells,
86                         KdTree *tree);
87 
88  GlRenderer() {}
89
90  virtual ~GlRenderer();
91
92
93  void SetupFalseColor(const int id);
94  void RenderIntersectable(Intersectable *);
95  void RenderViewCell(ViewCell *vc);
96  void RenderMeshInstance(MeshInstance *mi);
97  void RenderTransformedMeshInstance(TransformedMeshInstance *mi);
98  void RenderMesh(Mesh *m);
99  void SetupMaterial(Material *m);
100  virtual void SetupCamera();
101 
102  bool
103  RenderScene();
104
105  void
106  _RenderScene();
107
108
109  virtual void
110  SetupProjection(const int w, const int h, const float angle = 70.0f);
111
112 
113 
114
115  void InitGL();
116
117  virtual int GetWidth() const = 0;
118  virtual int GetHeight() const = 0;
119
120  int GetId(int r, int g, int b) const;
121
122  inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
123  inline const string GetSnapPrefix() { return mSnapPrefix; }
124
125  inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
126  inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; }
127
128protected:
129
130
131  vector<OcclusionQuery *> mOcclusionQueries;
132
133  ObjectContainer mObjects;
134   
135  Vector3 mViewPoint;
136  Vector3 mViewDirection;
137
138  int timerId;
139  bool mUseFalseColors;
140  bool mUseForcedColors;
141
142  HaltonSequence halton;
143 
144  int mFrame;
145  bool mWireFrame;
146 
147  bool mDetectEmptyViewSpace;
148  bool mSnapErrorFrames;
149
150  bool mUseGlLists;
151 
152  string mSnapPrefix;
153
154  KdTree *mKdTree;
155
156};
157
158/* Class implementing an OpenGl render buffer.
159*/
160class GlRendererBuffer: public GlRenderer
161{
162
163public:
164
165GlRendererBuffer(SceneGraph *sceneGraph,
166                                 ViewCellsManager *viewcells,
167                                 KdTree *tree);
168
169
170        /** Evaluates render cost of a point sample.
171                @param sample the render cost sample to be evaluated
172                @param useOcclusionQueries if occlusion queries should be used or item buffer
173                @param threshold number of pixels / samples from where an object is considered visible.
174        */
175        void EvalRenderCostSample(RenderCostSample &sample,
176                                                          const bool useOcclusionQueries,
177                                                          const int threshold);
178
179        /** Evaluates render cost of a number of point samples. The point samples
180                are distributed uniformly over the defined view space.
181
182                @param numSamples the number of point samples taken
183                @param samples stores the taken point samples in a container
184                @param useOcclusionQueries if occlusion queries should be used or item buffer
185                @param threshold number of pixels / samples from where an object is considered visible.
186        */
187        void SampleRenderCost(const int numSamples,
188                                                  vector<RenderCostSample> &samples,
189                                                  const bool useOcclusionQueries,
190                                                  const int threshold = 0)
191        {}
192
193        /** Implerment in subclasses.
194        */
195        void EvalPvsStat() {};
196
197        void ClearErrorBuffer();
198 
199
200  virtual int GetWidth() const { return 0; }
201  virtual int GetHeight() const { return 0; }
202
203
204  void RandomViewPoint();
205  void SampleBeamContributions(
206                                                           Intersectable *sourceObject,
207                                                           Beam &beam,
208                                                           const int samples,
209                                                           BeamSampleStatistics &stat
210                                                           );
211
212  void
213  SampleViewpointContributions(
214                                                           Intersectable *sourceObject,
215                                                           const Vector3 viewPoint,
216                                                           Beam &beam,
217                                                           const int desiredSamples,
218                                                           BeamSampleStatistics &stat
219                                                           );
220
221  void InitGL();
222
223  /** Computes rays from information gained with hw sampling-
224  */
225  void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
226
227  int ComputePvs() const;
228
229  float
230  GetPixelError(int &pvsSize);
231
232  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
233
234  PvsRenderStatistics mPvsStat;
235   
236  int mPvsStatFrames;
237  struct PvsErrorEntry {
238          PvsErrorEntry() {}
239          float mError;
240          int mPvsSize;
241          Vector3 mPosition;
242          Vector3 mDirection;
243  };
244 
245  vector<PvsErrorEntry> mPvsErrorBuffer;
246
247 
248protected:
249        unsigned int *mPixelBuffer;
250 
251        static void GenQueries(const int numQueries);
252       
253        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
254                                                                         const Beam &beam,
255
256                                                                         Intersectable *sourceObject);
257
258        /** Evaluates query for one direction using item buffer.
259        */
260        void EvalQueryWithItemBuffer();
261
262        /** Evaluates query for one direction using occlusion queries.
263        */
264        void EvalQueryWithOcclusionQueries();
265
266public:
267        // matt: remove qt dependencies
268 // signals:
269//      void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
270};
271
272
273/** Abstract class for implmenenting a gl render widget.
274*/
275class GlRendererWidget: public GlRenderer
276{
277public:
278       
279        GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
280          GlRenderer(sceneGraph, vcm, kdTree)
281        {}
282
283    GlRendererWidget() {}
284
285    virtual ~GlRendererWidget() {}
286
287        //virtual void Create() {}
288        virtual void Show() {}
289       
290
291protected:
292
293
294        SceneGraph *mSceneGraph;
295        ViewCellsManager *mViewCellsManager;
296        KdTree *mKdTree;
297};
298
299//extern GlRendererWidget *rendererWidget;
300
301};
302
303#endif
Note: See TracBrowser for help on using the repository browser.