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

Revision 1151, 6.4 KB checked in by mattausch, 18 years ago (diff)

worded on dll loading

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