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 *
RevLine 
[865]1#ifndef __GLRENDERER_H
2#define __GLRENDERER_H
[492]3
4#include "Vector3.h"
5#include "Containers.h"
6#include "Halton.h"
[497]7#include "Renderer.h"
[540]8#include "Beam.h"
[1161]9#include "Pvs.h"
[492]10
[863]11
[860]12namespace GtpVisibilityPreprocessor {
13
[492]14class SceneGraph;
15class ViewCellsManager;
16class Mesh;
17class MeshInstance;
18class Intersectable;
19class Material;
[512]20class Beam;
[532]21class KdTree;
[538]22class GlRendererBuffer;
[531]23class BeamSampleStatistics;
[1001]24class OcclusionQuery;
25class TransformedMeshInstance;
[1581]26class TriangleIntersectable;
[1585]27  class BvhNode;
28 
[540]29struct VssRayContainer;
30
[492]31struct PvsRenderStatistics {
32 
33  float maxError;
34  float sumError;
[713]35  int sumPvsSize;
[492]36  int frames;
37  int errorFreeFrames;
[502]38
[492]39  PvsRenderStatistics() { Reset(); }
40 
[498]41  void Reset() {
[492]42        maxError = 0.0f;
43        sumError = 0.0f;
44        frames = 0;
45        errorFreeFrames = 0;
[713]46        sumPvsSize = 0;
[492]47  }
48
49  float GetMaxError() { return maxError; }
50  float GetAvgError() { return sumError/frames; }
51  float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
[713]52  float GetAvgPvs() { return sumPvsSize/(float)frames; }
[492]53 
54};
55
[811]56struct RenderCostSample {
[496]57
[811]58  RenderCostSample() {}
59
60  void Reset() {
61        mVisibleObjects = 0;
62        mVisiblePixels = 0;
63  }
64 
[991]65  Vector3 mPosition;
66
[811]67  // visible object from the given point
68  int mVisibleObjects;
69
70  // visible pixels
71  int mVisiblePixels;
[1161]72
73  ObjectPvs mPvs;
[811]74 
75};
76
[496]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*/
[497]81class GlRenderer: public Renderer
[492]82{
[496]83
[492]84public:
85
86  GlRenderer(SceneGraph *sceneGraph,
[532]87                         ViewCellsManager *viewcells,
88                         KdTree *tree);
[496]89 
[1151]90  GlRenderer() {}
91
[1145]92  virtual ~GlRenderer();
[492]93
[496]94
[492]95  void SetupFalseColor(const int id);
96  void RenderIntersectable(Intersectable *);
[535]97  void RenderViewCell(ViewCell *vc);
[492]98  void RenderMeshInstance(MeshInstance *mi);
[1001]99  void RenderTransformedMeshInstance(TransformedMeshInstance *mi);
[492]100  void RenderMesh(Mesh *m);
101  void SetupMaterial(Material *m);
[502]102  virtual void SetupCamera();
[1581]103
104  void
105  RenderRays(const VssRayContainer &rays);
106
107  void
108  RenderTriangle(TriangleIntersectable *object);
109
[1585]110  void
111  RenderBox(const AxisAlignedBox3 &box);
112
113  void
114  RenderBvhNode(BvhNode *node);
115       
[497]116  bool
[496]117  RenderScene();
[492]118
[811]119  void
120  _RenderScene();
[589]121
[811]122
[608]123  virtual void
[811]124  SetupProjection(const int w, const int h, const float angle = 70.0f);
[496]125
126 
127 
128
129  void InitGL();
130
131  virtual int GetWidth() const = 0;
132  virtual int GetHeight() const = 0;
[540]133
134  int GetId(int r, int g, int b) const;
[1151]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
[496]170};
171
[1146]172/* Class implementing an OpenGl render buffer.
173*/
[1145]174class GlRendererBuffer: public GlRenderer
[496]175{
[1145]176
[496]177public:
[1151]178
[1145]179GlRendererBuffer(SceneGraph *sceneGraph,
[811]180                                 ViewCellsManager *viewcells,
181                                 KdTree *tree);
[589]182
[811]183
[1001]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);
[811]192
[1001]193        /** Evaluates render cost of a number of point samples. The point samples
194                are distributed uniformly over the defined view space.
[811]195
[1001]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,
[1145]204                                                  const int threshold = 0)
205        {}
[811]206
[1145]207        /** Implerment in subclasses.
208        */
209        void EvalPvsStat() {};
[1001]210
[1145]211        void ClearErrorBuffer();
[496]212 
213
[1145]214  virtual int GetWidth() const { return 0; }
215  virtual int GetHeight() const { return 0; }
[496]216
[507]217
[563]218  void RandomViewPoint();
[507]219  void SampleBeamContributions(
220                                                           Intersectable *sourceObject,
[512]221                                                           Beam &beam,
[507]222                                                           const int samples,
223                                                           BeamSampleStatistics &stat
224                                                           );
225
226  void
227  SampleViewpointContributions(
228                                                           Intersectable *sourceObject,
[514]229                                                           const Vector3 viewPoint,
[512]230                                                           Beam &beam,
[507]231                                                           const int desiredSamples,
232                                                           BeamSampleStatistics &stat
233                                                           );
234
[540]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
[576]243  float
[713]244  GetPixelError(int &pvsSize);
[540]245
246  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
247
248  PvsRenderStatistics mPvsStat;
[532]249   
[540]250  int mPvsStatFrames;
[713]251  struct PvsErrorEntry {
[1145]252          PvsErrorEntry() {}
253          float mError;
254          int mPvsSize;
255          Vector3 mPosition;
256          Vector3 mDirection;
[713]257  };
258 
259  vector<PvsErrorEntry> mPvsErrorBuffer;
260
[997]261 
[1145]262protected:
263        unsigned int *mPixelBuffer;
[811]264 
[513]265        static void GenQueries(const int numQueries);
[589]266       
267        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
268                                                                         const Beam &beam,
[746]269
[525]270                                                                         Intersectable *sourceObject);
[746]271
[1001]272        /** Evaluates query for one direction using item buffer.
273        */
[997]274        void EvalQueryWithItemBuffer();
[1146]275
[1001]276        /** Evaluates query for one direction using occlusion queries.
277        */
[997]278        void EvalQueryWithOcclusionQueries();
279
[746]280public:
[1145]281        // matt: remove qt dependencies
282 // signals:
283//      void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
[496]284};
285
[1146]286
287/** Abstract class for implmenenting a gl render widget.
288*/
[1151]289class GlRendererWidget: public GlRenderer
[1146]290{
291public:
292       
[1151]293        GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
294          GlRenderer(sceneGraph, vcm, kdTree)
295        {}
[1146]296
[1151]297    GlRendererWidget() {}
[1146]298
[1151]299    virtual ~GlRendererWidget() {}
[1146]300
301        //virtual void Create() {}
302        virtual void Show() {}
303       
304
305protected:
306
307
[1387]308  //    SceneGraph *mSceneGraph;
309  //    ViewCellsManager *mViewCellsManager;
310  //    KdTree *mKdTree;
[608]311};
312
[1151]313//extern GlRendererWidget *rendererWidget;
314
[1146]315};
[492]316
[1387]317#endif
Note: See TracBrowser for help on using the repository browser.