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

Revision 1581, 6.6 KB checked in by bittner, 18 years ago (diff)

Qtglwidget changes - second view + trackball - ray casting seems not functional

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