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

Revision 1146, 6.1 KB checked in by mattausch, 18 years ago (diff)

use qt renderer as dll
changed vsp render heuristics sweep
capsulated thread

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