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

Revision 1581, 7.5 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 __QTGLRENDERER_H
2#define __QTGLRENDERER_H
3
4#include <QtOpenGL>
5#include <QWaitCondition>
6
7//#include <QGLPixelBuffer>
8
9#include "Vector3.h"
10#include "Containers.h"
11#include "Halton.h"
12#include "Renderer.h"
13#include "GlRenderer.h"
14#include "Beam.h"
15
16class QWidget;
17
18namespace GtpVisibilityPreprocessor {
19
20class SceneGraph;
21class ViewCellsManager;
22class Mesh;
23class MeshInstance;
24class Intersectable;
25class Material;
26class Beam;
27class KdTree;
28class GlRendererBuffer;
29class BeamSampleStatistics;
30class OcclusionQuery;
31class TransformedMeshInstance;
32
33
34struct VssRayContainer;
35struct PvsRenderStatistics;
36struct RenderCostSample;
37
38
39class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer
40{
41        Q_OBJECT
42public:
43        QtGlRendererBuffer(const int w,
44                const int h,
45                SceneGraph *sceneGraph,
46                ViewCellsManager *viewcells,
47                KdTree *tree);
48
49        ~QtGlRendererBuffer();
50
51        /** Evaluates render cost of a point sample.
52        @param sample the render cost sample to be evaluated
53        @param useOcclusionQueries if occlusion queries should be used or item buffer
54        @param threshold number of pixels / samples from where an object is considered visible.
55        */
56        void EvalRenderCostSample(RenderCostSample &sample,
57                const bool useOcclusionQueries,
58                const int threshold);
59
60        /** Evaluates render cost of a number of point samples. The point samples
61        are distributed uniformly over the defined view space.
62
63        @param numSamples the number of point samples taken
64        @param samples stores the taken point samples in a container
65        @param useOcclusionQueries if occlusion queries should be used or item buffer
66        @param threshold number of pixels / samples from where an object is considered visible.
67        */
68        void SampleRenderCost(const int numSamples,
69                vector<RenderCostSample> &samples,
70                const bool useOcclusionQueries,
71                const int threshold = 0);
72
73
74  void
75  EvalPvsStat();
76
77  void
78  ClearErrorBuffer();
79 
80
81  virtual int GetWidth() const { return width(); }
82  virtual int GetHeight() const { return height(); }
83
84
85 
86  void SampleBeamContributions(
87                                                           Intersectable *sourceObject,
88                                                           Beam &beam,
89                                                           const int samples,
90                                                           BeamSampleStatistics &stat
91                                                           );
92
93  void
94  SampleViewpointContributions(
95                                                           Intersectable *sourceObject,
96                                                           const Vector3 viewPoint,
97                                                           Beam &beam,
98                                                           const int desiredSamples,
99                                                           BeamSampleStatistics &stat
100                                                           );
101
102  void InitGL();
103
104  /** Computes rays from information gained with hw sampling-
105  */
106  void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
107
108  int ComputePvs() const;
109
110  float
111  GetPixelError(int &pvsSize);
112
113  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
114     
115   
116private:
117       
118        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
119                                                                         const Beam &beam,
120                                                                         Intersectable *sourceObject);
121
122
123public:
124  signals:
125        void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
126};
127
128
129class QtRendererControlWidget : public QWidget
130{
131  Q_OBJECT
132public:
133
134  QListWidget *mPvsErrorWidget;
135
136  QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
137
138  public slots:
139
140  void FocusNextPvsErrorFrame();
141  void UpdatePvsErrorItem(int i,
142                                                  GlRendererBuffer::PvsErrorEntry &);
143
144  signals:
145 
146  void SetViewCellGranularity(int);
147  void SetSceneCut(int);
148  void SetTopDistance(int);
149  void SetVisibilityFilterSize(int);
150  void SetSpatialFilterSize(int);
151
152  void SetShowRays(bool);
153  void SetRenderFilter(bool);
154  void SetUseFilter(bool);
155  void SetUseSpatialFilter(bool);
156  void SetRenderErrors(bool);
157  void SetShowViewCells(bool);
158  void SetShowRenderCost(bool);
159  void SetShowPvsSizes(bool);
160  void SetTopView(bool);
161  void SetCutViewCells(bool);
162  void SetCutScene(bool);
163
164 
165};
166
167class QtGlRendererWidget : public QGLWidget, public GlRendererWidget
168{
169  Q_OBJECT
170public:
171
172  // point of the last mouse click used for movement in the scene
173  Vector3 mousePoint;
174
175  bool mTopView;
176  bool mRenderViewCells;
177  bool mCutViewCells;
178  bool mCutScene;
179  bool mRenderErrors;
180  bool mRenderFilter;
181  bool mUseFilter;
182  bool mUseSpatialFilter;
183  bool mShowRenderCost;
184  bool mShowRays;
185
186  bool mShowPvsSizes;
187  float mSpatialFilterSize;
188 
189  Plane3 mSceneCutPlane;
190  float mTopDistance;
191
192  // some statistics
193  int mPvsSize;
194  float mRenderError;
195
196
197  float mManipulatorLastQuat[4];
198  float mManipulatorScale;
199 
200  QtRendererControlWidget *mControlWidget;
201 
202  QtGlRendererWidget(SceneGraph *sceneGraph,
203                                         ViewCellsManager *viewcells,
204                                         KdTree *tree,
205                                         QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
206                                         );
207 
208  QtGlRendererWidget() {};
209
210  virtual void SetupCamera();
211  // setup a transformation for manipulator
212  void
213  SetupManipulator();
214
215  void initializeGL() {
216        InitGL();
217  }
218  void resizeGL(int w, int h);
219  void paintGL();
220  void timerEvent(QTimerEvent *) {
221          update();
222  }
223
224  void mousePressEvent(QMouseEvent *);
225  void mouseReleaseEvent(QMouseEvent *);
226  void mouseMoveEvent(QMouseEvent *);
227
228  void keyPressEvent ( QKeyEvent * e ) ;
229
230  void
231  RenderPvs();
232
233  float
234  RenderErrors();
235  void
236  RenderInfo();
237
238  virtual int GetWidth() const { return width(); }
239  virtual int GetHeight() const { return height(); }
240
241  // virtual void
242  //  SetupProjection(const int w, const int h, const float angle = 70.0f);
243
244  virtual void
245  SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
246
247  virtual void
248  SetupManipulatorProjection(const int w, const int h, const float angle = 70.0f);
249
250  void
251  RenderViewCells();
252
253
254  virtual void Show() {
255        show();
256  }
257
258 public slots:
259
260 void SetRenderErrors(bool b) {
261   mRenderErrors = b;
262   updateGL();
263 }
264
265 void SetRenderFilter(bool b) {
266   mRenderFilter = b;
267   updateGL();
268 }
269
270  void SetUseFilter(bool b) {
271   mUseFilter = b;
272   updateGL();
273 }
274
275  void SetUseSpatialFilter(bool b) {
276        mUseSpatialFilter = b;
277        updateGL();
278  }
279
280 
281  void
282  SetViewCellGranularity(int number);
283 
284  void
285  SetVisibilityFilterSize(int number);
286
287  void
288  SetSpatialFilterSize(int number);
289 
290  void
291  SetSceneCut(int cut);
292 
293  void
294  SetTopDistance(int dist);
295 
296  void SetShowViewCells(bool b) {
297        mRenderViewCells = b;
298        updateGL();
299  }
300
301  void SetShowRays(bool b) {
302        mShowRays = b;
303        updateGL();
304  }
305
306  void SetShowRenderCost(bool b) {
307        mShowRenderCost = b;
308        updateGL();
309  }
310
311  void SetShowPvsSizes(bool b) {
312        mShowPvsSizes = b;
313        updateGL();
314  }
315
316  void SetTopView(bool b) {
317        mTopView = b;
318        updateGL();
319  }
320
321  void SetCutViewCells(bool b) {
322        mCutViewCells = b;
323        updateGL();
324  }
325  void SetCutScene(bool b) {
326        mCutScene = b;
327        updateGL();
328  }
329
330
331};
332
333
334class QtGlDebuggerWidget : public QGLWidget
335{
336        Q_OBJECT
337public:
338    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
339    ~QtGlDebuggerWidget();
340    void initializeGL();
341    void resizeGL(int w, int h);
342    void paintGL();
343    void timerEvent(QTimerEvent *) { update(); }
344    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
345    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
346
347    void initCommon();
348    void initPbuffer();
349
350 
351         QtGlRendererBuffer *mRenderBuffer;
352
353         Beam mBeam;
354         int mSamples;
355         Intersectable *mSourceObject;
356
357private:
358    GLuint dynamicTexture;
359    int timerId;
360};
361
362extern QtGlDebuggerWidget *debuggerWidget;
363
364};
365
366#endif
367
Note: See TracBrowser for help on using the repository browser.