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

Revision 1694, 8.3 KB checked in by bittner, 18 years ago (diff)

obj exporter, vienna.obj + kdf added

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