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

Revision 1832, 7.3 KB checked in by bittner, 18 years ago (diff)

gl render updates - separate gl viewer widget

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