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

Revision 1585, 6.7 KB checked in by bittner, 18 years ago (diff)

renderer changes

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