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

Revision 1387, 6.4 KB checked in by bittner, 18 years ago (diff)

updates to make qt version running again

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