source: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h @ 511

Revision 511, 4.3 KB checked in by mattausch, 19 years ago (diff)
  • Property svn:executable set to *
RevLine 
[492]1#ifndef __RENDERER_H
2#define __RENDERER_H
3
4#include <QtOpenGL>
5#include <QWaitCondition>
[500]6//#include <QGLPixelBuffer>
[492]7
8#include "Vector3.h"
9#include "Containers.h"
10#include "Halton.h"
[497]11#include "Renderer.h"
[492]12
13class SceneGraph;
14class ViewCellsManager;
15class Mesh;
16class MeshInstance;
17class Intersectable;
18class Material;
[511]19class MyBeam;
[492]20
21struct PvsRenderStatistics {
22 
23  float maxError;
24  float sumError;
25  int frames;
26  int errorFreeFrames;
[502]27
[492]28  PvsRenderStatistics() { Reset(); }
29 
[498]30  void Reset() {
[492]31        maxError = 0.0f;
32        sumError = 0.0f;
33        frames = 0;
34        errorFreeFrames = 0;
35  }
36
37  float GetMaxError() { return maxError; }
38  float GetAvgError() { return sumError/frames; }
39  float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
40 
41};
42
[496]43
44/** Class encapsulating gl rendering for the scene.
45        There is no gl context binding so the binding is performed in the
46        derived classes
47*/
48
[497]49class GlRenderer: public Renderer
[492]50{
[496]51
[492]52public:
53  ObjectContainer mObjects;
[498]54   
[492]55  Vector3 mViewPoint;
56  Vector3 mViewDirection;
57
58  int timerId;
59  bool mUseFalseColors;
60
61  HaltonSequence halton;
62 
63  int mFrame;
[502]64  bool mWireFrame;
65
[492]66  QWaitCondition mRenderingFinished;
67 
68 
69  GlRenderer(SceneGraph *sceneGraph,
[496]70                         ViewCellsManager *viewcells);
71 
[492]72  ~GlRenderer();
73
[496]74
[492]75  void SetupFalseColor(const int id);
76  void RenderIntersectable(Intersectable *);
77  void RenderMeshInstance(MeshInstance *mi);
78  void RenderMesh(Mesh *m);
79  void SetupMaterial(Material *m);
[502]80  virtual void SetupCamera();
[492]81  void RandomViewPoint();
[496]82 
[497]83  bool
[496]84  RenderScene();
[492]85
[496]86  void
87  SetupProjection(const int w, const int h);
88
89 
90 
91  float
92  GetPixelError();
93
94  void InitGL();
95
96  virtual int GetWidth() const = 0;
97  virtual int GetHeight() const = 0;
98};
99
100
101class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
102{
103
104public:
105  int mPvsStatFrames;
106  vector<float> mPvsErrorBuffer;
107 
108  PvsRenderStatistics mPvsStat;
109
110
111  GlRendererBuffer(const int w,
112                                   const int h,
113                                   SceneGraph *sceneGraph,
114                                   ViewCellsManager *viewcells):
115        QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells) {
116
117        mPvsStatFrames = 10000;
118        mPvsErrorBuffer.resize(mPvsStatFrames);
119        ClearErrorBuffer();
120
121        makeCurrent();
122        InitGL();
[502]123        doneCurrent();
124
[496]125  }
126 
127  void
128  EvalPvsStat();
129
130  void
131  ClearErrorBuffer();
132 
133
134  virtual int GetWidth() const { return width(); }
135  virtual int GetHeight() const { return height(); }
136
[507]137
138
139  // the values need for rss tree update computed already inside the glrendererbuffer
140  // not all of them need to be computed
141  struct BeamSampleStatistics {
142
143        enum {COMPUTE_PVS_SIZE, COMPUTE_RAY_CONTRIBUTIONS, COMPUTE_PVS_ENTROPY};
144        int flags;
145
146        BeamSampleStatistics():flags(COMPUTE_RAY_CONTRIBUTIONS) {}
147       
148        float pvsSize;
149        float rays;
150        float rayContributions;
151        float pvsEntropy;
152        float rayLengthEntropy;
153        float importance;
154       
155        float weightedRayContribution;
156  };
157 
158
159  void SampleBeamContributions(
160                                                           Intersectable *sourceObject,
[511]161                                                           MyBeam &beam,
[507]162                                                           const int samples,
163                                                           BeamSampleStatistics &stat
164                                                           );
165
166  void
167  SampleViewpointContributions(
168                                                           Intersectable *sourceObject,
[511]169                                                           MyBeam &beam,
[507]170                                                           const int desiredSamples,
171                                                           BeamSampleStatistics &stat
172                                                           );
173
[496]174};
175
176
177
178class GlRendererWidget : public QGLWidget, public GlRenderer
179{
180  Q_OBJECT
181public:
182
[502]183  // point of the last mouse click used for movement in the scene
184  Vector3 mousePoint;
185
186  bool mTopView;
187 
[496]188  GlRendererWidget(SceneGraph *sceneGraph,
189                                   ViewCellsManager *viewcells,
190                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
191                                   ):
192        GlRenderer(sceneGraph, viewcells), QGLWidget(parent, shareWidget, f)
[502]193  {
194        mTopView = false;
195  }
[496]196
[502]197  virtual void SetupCamera();
198
[496]199  void initializeGL() {
200        InitGL();
201  }
[492]202  void resizeGL(int w, int h);
203  void paintGL();
204  void timerEvent(QTimerEvent *) {
205          update();
206  }
207
208  void mousePressEvent(QMouseEvent *);
209  void mouseReleaseEvent(QMouseEvent *);
210  void mouseMoveEvent(QMouseEvent *);
211
[504]212  void keyPressEvent ( QKeyEvent * e ) ;
213 
[492]214  float
[496]215  RenderErrors();
[492]216
[496]217  virtual int GetWidth() const { return width(); }
218  virtual int GetHeight() const { return height(); }
[492]219
220};
221
222
[496]223extern GlRendererWidget *rendererWidget;
[492]224
225#endif
226
Note: See TracBrowser for help on using the repository browser.