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

Revision 2581, 9.5 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef __QTGLRENDERER_H
2#define __QTGLRENDERER_H
3
4#include <QtOpenGL>
5#include <QWaitCondition>
6#include <QMutex>
7
8#include "Vector3.h"
9#include "Containers.h"
10#include "Halton.h"
11#include "Renderer.h"
12#include "GlRenderer.h"
13#include "Beam.h"
14#include "QtPreprocessorThread.h"
15#include "LogReader.h"
16
17
18class QWidget;
19
20
21
22namespace GtpVisibilityPreprocessor {
23
24
25class SceneGraph;
26class ViewCellsManager;
27class Mesh;
28class MeshInstance;
29class Intersectable;
30class Material;
31class Beam;
32class KdTree;
33class GlRendererBuffer;
34class BeamSampleStatistics;
35class OcclusionQuery;
36class TransformedMeshInstance;
37
38
39struct VssRayContainer;
40struct PvsRenderStatistics;
41struct RenderCostSample;
42
43//class LogWriter;
44
45
46
47class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer
48{
49        Q_OBJECT
50public:
51        QtGlRendererBuffer(const int w,
52                const int h,
53                SceneGraph *sceneGraph,
54                ViewCellsManager *viewcells,
55                KdTree *tree);
56
57  ~QtGlRendererBuffer() {}
58
59  virtual void MakeCurrent();
60  virtual void DoneCurrent();
61
62  virtual int GetWidth() const { return width(); }
63  virtual int GetHeight() const { return height(); }
64
65  int ComputePvs() const { return 0; }
66 
67  float
68  GetPixelError(int &pvsSize);
69 
70  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
71     
72 
73 
74 
75public:
76  signals:
77  void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
78};
79
80
81class QtRendererControlWidget : public QWidget
82{
83  Q_OBJECT
84public:
85
86  QListWidget *mPvsErrorWidget;
87
88  QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
89
90  QGroupBox *CreateVisualizationPanel(QWidget *parent);
91
92  public slots:
93
94  void FocusNextPvsErrorFrame();
95  void UpdatePvsErrorItem(int i,
96                                                  GlRendererBuffer::PvsErrorEntry &);
97
98 
99  QGroupBox *CreateRenderCostPanel(QWidget *parent);
100
101
102  signals:
103
104  void ComputeVisibility();
105  void StopComputation();
106  void SetRandomViewPoint();
107  void UpdateAllPvs();
108  void SetViewCellGranularity(int);
109  void SetTransferFunction(int);
110  void SetSceneCut(int);
111  void SetTopDistance(int);
112  void SetHidingCost(int);
113  void SetVisibilityFilterSize(int);
114  void SetSpatialFilterSize(int);
115  void SetTransparency(int);
116
117  void SetShowRays(bool);
118  void SetRenderFilter(bool);
119  void SetRenderVisibilityEstimates(bool);
120  void SetUseFilter(bool);
121  void SetUseSpatialFilter(bool);
122  void SetRenderErrors(bool);
123  void SetRenderBoxes(bool);
124  void SetShowViewCells(bool);
125  void SetShowRenderCost(bool);
126  void SetShowPvsSizes(bool);
127  void SetShowPiercingRays(bool);
128  void SetShowWeightedRays(bool);
129   void SetShowComparison(bool);
130  void SetShowWeightedCost(bool);
131 
132  void SetTopView(bool);
133  void SetCutViewCells(bool);
134  void SetCutScene(bool);
135
136  void SetHideByCost(bool);
137  void SetUseTransparency(bool);
138
139  void SetShowDistanceWeightedTriangles(bool);
140  void SetShowWeightedTriangles(bool);
141  void SetShowDistanceWeightedPvs(bool);
142};
143
144
145class QtGlRendererWidget: public QGLWidget, public GlRendererWidget
146{
147        Q_OBJECT
148public:
149
150        // point of the last mouse click used for movement in the scene
151        Vector3 mousePoint;
152
153        bool mTopView;
154        bool mRenderViewCells;
155        bool mCutViewCells;
156        bool mCutScene;
157        bool mHideByCost;
158        bool mRenderErrors;
159        bool mRenderFilter;
160        bool mRenderVisibilityEstimates;
161        bool mUseFilter;
162        bool mUseSpatialFilter;
163        bool mShowRenderCost;
164        bool mShowPiercingRays;
165        bool mShowWeightedRays;
166        bool mShowRays;
167
168        bool mShowPvsSizes;
169        bool mShowComparison;
170        float mSpatialFilterSize;
171
172        //LogWriter *mLogWriter;
173        Plane3 mSceneCutPlane;
174        float mHidingCost;
175
176        float mTopDistance;
177
178        float mTransparency;
179        bool mUseTransparency;
180
181        bool mShowWeightedCost;
182
183        bool mShowDistanceWeightedTriangles;
184        bool mShowDistanceWeightedPvs;
185        bool mShowWeightedTriangles;
186
187        /// the current number of samples
188        //int mCurrentSamples;
189        /// the next number of samples where we record the data
190        int mNextSamples;
191        bool mHistRecorded;
192
193        // some statistics
194        int mPvsSize;
195        float mRenderError;
196        float mTransferFunction;
197
198        unsigned int mIndexBufferSize;
199
200        //bool mAssignImportanceByRelativeValue;
201
202        Vector3 mDummyViewPoint;
203
204        QtRendererControlWidget *mControlWidget;
205
206        QtPreprocessorThread *mPreprocessorThread;
207
208        int mCurrentSamples;
209
210        //ViewCellHistoryContainer mCurrentHist;
211        //ViewCellHistoryContainer mCompareHist;
212
213        ViewCellInfoContainer mCurrentInfo;
214        ViewCellInfoContainer mCompareInfo;
215
216        QtGlRendererWidget(SceneGraph *sceneGraph,
217                               ViewCellsManager *viewcells,
218                                           KdTree *tree,
219                                           QWidget * parent = 0,
220                                           const QGLWidget *shareWidget = 0,
221                                           Qt::WFlags f = 0);
222
223        QtGlRendererWidget() {};
224
225        void FillNewContainer(const ViewCellContainer &viewCells, ViewCellInfoContainer &infos);
226
227
228        void SetThread(QtPreprocessorThread *t) {
229                mPreprocessorThread = t;
230        }
231        void RenderRenderCost();
232
233        virtual void SetupCamera();
234
235        void initializeGL() {
236                InitGL();
237        }
238
239        virtual void InitGL();
240
241        void resizeGL(int w, int h);
242        void paintGL();
243        void timerEvent(QTimerEvent *event);
244        void mousePressEvent(QMouseEvent *);
245        void mouseReleaseEvent(QMouseEvent *);
246        void mouseMoveEvent(QMouseEvent *);
247
248        void keyPressEvent(QKeyEvent * e);
249
250        void RenderPvs();
251
252        float RenderErrors();
253        void RenderInfo();
254
255        virtual int GetWidth() const { return width(); }
256        virtual int GetHeight() const { return height(); }
257
258        // virtual void
259        //  SetupProjection(const int w, const int h, const float angle = 70.0f);
260
261        virtual void
262                SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
263
264        void
265                RenderViewCells();
266
267
268        virtual void Show() {
269                show();
270        }
271
272        bool PvsChanged(ViewCell *viewcell) const;
273
274        void ComputeMaxValues(const ViewCellContainer &viewCells,
275                                                  int &maxPvs,
276                                                  int &maxPiercingRays,
277                                                  float &maxRelativeRays,
278                                                  float &maxRcCost);
279
280        void AssignImportanceByRelativeValue(const ViewCellContainer &viewCells,
281                                                                                 int &maxPvs,
282                                                                                 int &maxPiercingRays,
283                                                                                 float &maxRelativeRays,
284                                                                                 float &maxRcCost);
285
286        void AssignColorByComparison(const ViewCellContainer &viewcells,
287                                                                 //const ViewCellInfoContainer &info1,
288                                                                 const ViewCellInfoContainer &compareInfo);
289
290
291        /////////
292
293        //QMutex mMutex;
294
295
296public slots:
297
298        void UpdateAllPvs();
299        void ComputeVisibility();
300        void StopComputation();
301        void SetRandomViewPoint();
302
303        void SetRenderErrors(bool b) {
304                mRenderErrors = b;
305                updateGL();
306        }
307
308        void SetRenderBoxes(bool b) {
309                mRenderBoxes = b;
310                updateGL();
311        }
312
313        void SetRenderFilter(bool b) {
314                mRenderFilter = b;
315                updateGL();
316        }
317
318        void SetRenderVisibilityEstimates(bool b) {
319                mRenderVisibilityEstimates = b;
320                updateGL();
321        }
322
323        void SetUseFilter(bool b) {
324                mUseFilter = b;
325                mPvsCache.Reset();
326                updateGL();
327        }
328
329        void SetUseSpatialFilter(bool b) {
330                mUseSpatialFilter = b;
331                mPvsCache.Reset();
332                updateGL();
333        }
334
335
336        void
337                SetViewCellGranularity(int number);
338
339        void SetTransferFunction(int number)
340        {
341                mTransferFunction = number/1000.0f;
342                updateGL();
343        }
344
345        void SetVisibilityFilterSize(int number);
346
347        void
348                SetSpatialFilterSize(int number);
349
350        void
351                SetSceneCut(int cut);
352
353        void
354                SetTopDistance(int dist);
355
356        void
357                SetTransparency(int dist);
358
359        void
360                SetHidingCost(int dist);
361
362        void SetShowViewCells(bool b) {
363                mRenderViewCells = b;
364                updateGL();
365        }
366
367        void SetShowRays(bool b) {
368                mShowRays = b;
369                updateGL();
370        }
371
372        void SetShowRenderCost(bool b) {
373                mShowRenderCost = b;
374                updateGL();
375        }
376
377        void SetShowPvsSizes(bool b) {
378                mShowPvsSizes = b;
379                updateGL();
380        }
381
382        void SetShowComparison(bool b) {
383                mShowComparison = b;
384                updateGL();
385        }
386
387        void SetShowPiercingRays(bool b) {
388                mShowPiercingRays = b;
389                updateGL();
390        }
391
392        void SetShowWeightedRays(bool b) {
393                mShowWeightedRays = b;
394                updateGL();
395        }
396
397        void SetTopView(bool b) {
398                mTopView = b;
399                updateGL();
400        }
401
402        void SetCutViewCells(bool b) {
403                mCutViewCells = b;
404                updateGL();
405        }
406        void SetCutScene(bool b) {
407                mCutScene = b;
408                updateGL();
409        }
410
411        void SetHideByCost(bool b) {
412                mHideByCost = b;
413                updateGL();
414        }
415
416        void SetUseTransparency(bool b) {
417                mUseTransparency = b;
418                updateGL();
419        }
420
421        void SetShowWeightedCost(bool b)
422        {
423                mShowWeightedCost = b;
424                updateGL();
425        }
426
427        void SetShowDistanceWeightedPvs(bool b)
428        {
429                mShowDistanceWeightedPvs = b;
430                updateGL();
431        }
432
433
434        void SetShowDistanceWeightedTriangles(bool b)
435        {
436                mShowDistanceWeightedTriangles = b;
437                updateGL();
438        }
439       
440        void SetShowWeightedTriangles(bool b)
441        {
442                mShowWeightedTriangles = b;
443                updateGL();
444        }
445
446
447        void _RenderPvs();
448
449        void _UpdatePvsIndices();
450
451        void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
452
453        float ComputeRenderCost(ViewCell *vc);
454
455        /////////
456
457signals:
458        void PvsUpdated();
459};
460
461
462class QtGlDebuggerWidget: public QGLWidget
463{
464        Q_OBJECT
465public:
466    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
467    ~QtGlDebuggerWidget();
468    void initializeGL();
469    void resizeGL(int w, int h);
470    void paintGL();
471    void timerEvent(QTimerEvent *) { update(); }
472    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
473    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
474
475    void initCommon();
476    void initPbuffer();
477
478 
479         QtGlRendererBuffer *mRenderBuffer;
480
481         Beam mBeam;
482         int mSamples;
483         Intersectable *mSourceObject;
484
485private:
486
487    GLuint dynamicTexture;
488    int timerId;
489};
490
491
492extern QtGlDebuggerWidget *debuggerWidget;
493
494};
495
496#endif
497
Note: See TracBrowser for help on using the repository browser.