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

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

global lines support

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