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

Revision 2591, 10.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  QGroupBox *CreateRayVisualizationPanel(QWidget *parent);
101
102
103  signals:
104
105  void ComputeVisibility();
106  void StopComputation();
107  void SetRandomViewPoint();
108  void StoreStatistics();
109  void UpdateAllPvs();
110  void SetViewCellGranularity(int);
111  void SetTransferFunction(int);
112  void SetSceneCut(int);
113  void SetTopDistance(int);
114  void SetHidingCost(int);
115  void SetVisibilityFilterSize(int);
116  void SetSpatialFilterSize(int);
117  void SetTransparency(int);
118
119  void SetShowRays(bool);
120  void SetRenderFilter(bool);
121  void SetRenderVisibilityEstimates(bool);
122  void SetUseFilter(bool);
123  void SetUseSpatialFilter(bool);
124  void SetRenderErrors(bool);
125  void SetRenderBoxes(bool);
126  void SetShowViewCells(bool);
127  void SetShowRenderCost(bool);
128  void SetShowPvsSizes(bool);
129  void SetShowPiercingRays(bool);
130  void SetShowWeightedRays(bool);
131   void SetShowComparison(bool);
132  void SetShowWeightedCost(bool);
133 
134  void SetTopView(bool);
135  void SetCutViewCells(bool);
136  void SetCutScene(bool);
137
138  void SetHideByCost(bool);
139  void SetUseTransparency(bool);
140
141  void SetShowDistanceWeightedTriangles(bool);
142  void SetShowWeightedTriangles(bool);
143  void SetShowDistanceWeightedPvs(bool);
144
145  void UseConstColorForRayViz(bool);
146  void UseRayLengthForRayViz(bool);
147  void SetShowContribution(bool);
148  void SetShowDistribution(bool);
149
150  void SetShowDistribution1(bool);
151  void SetShowDistribution2(bool);
152  void SetShowDistribution3(bool);
153  void SetShowDistribution4(bool);
154};
155
156
157class QtGlRendererWidget: public QGLWidget, public GlRendererWidget
158{
159        Q_OBJECT
160public:
161
162        // point of the last mouse click used for movement in the scene
163        Vector3 mousePoint;
164
165        bool mTopView;
166        bool mRenderViewCells;
167        bool mCutViewCells;
168        bool mCutScene;
169        bool mHideByCost;
170        bool mRenderErrors;
171        bool mRenderFilter;
172        bool mRenderVisibilityEstimates;
173        bool mUseFilter;
174        bool mUseSpatialFilter;
175        bool mShowRenderCost;
176        bool mShowPiercingRays;
177        bool mShowWeightedRays;
178        bool mShowRays;
179
180        bool mShowPvsSizes;
181        bool mShowComparison;
182        float mSpatialFilterSize;
183
184        //LogWriter *mLogWriter;
185        Plane3 mSceneCutPlane;
186        float mHidingCost;
187
188        float mTopDistance;
189
190        float mTransparency;
191        bool mUseTransparency;
192
193        bool mShowWeightedCost;
194
195        bool mShowDistanceWeightedTriangles;
196        bool mShowDistanceWeightedPvs;
197        bool mShowWeightedTriangles;
198       
199        int mShowDistribution;
200
201        // some statistics
202        int mPvsSize;
203        float mRenderError;
204        float mTransferFunction;
205
206        unsigned int mIndexBufferSize;
207
208        Vector3 mDummyViewPoint;
209
210        int mRayVisualizationMethod;
211
212        QtRendererControlWidget *mControlWidget;
213
214        QtPreprocessorThread *mPreprocessorThread;
215
216        ViewCellInfoContainer mCompareInfo;
217
218        QtGlRendererWidget(SceneGraph *sceneGraph,
219                               ViewCellsManager *viewcells,
220                                           KdTree *tree,
221                                           QWidget * parent = 0,
222                                           const QGLWidget *shareWidget = 0,
223                                           Qt::WFlags f = 0);
224
225        QtGlRendererWidget() {};
226
227        void SetThread(QtPreprocessorThread *t)
228        {
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        void WriteViewCellInfos();
291
292
293        /////////
294
295        //QMutex mMutex;
296
297
298public slots:
299
300        void UpdateAllPvs();
301        void ComputeVisibility();
302        void StopComputation();
303        void SetRandomViewPoint();
304        void StoreStatistics();
305
306        void SetRenderErrors(bool b) {
307                mRenderErrors = b;
308                updateGL();
309        }
310
311        void SetRenderBoxes(bool b) {
312                mRenderBoxes = b;
313                updateGL();
314        }
315
316        void SetRenderFilter(bool b) {
317                mRenderFilter = b;
318                updateGL();
319        }
320
321        void SetRenderVisibilityEstimates(bool b) {
322                mRenderVisibilityEstimates = b;
323                updateGL();
324        }
325
326        void SetUseFilter(bool b) {
327                mUseFilter = b;
328                mPvsCache.Reset();
329                updateGL();
330        }
331
332        void SetUseSpatialFilter(bool b) {
333                mUseSpatialFilter = b;
334                mPvsCache.Reset();
335                updateGL();
336        }
337
338
339        void
340                SetViewCellGranularity(int number);
341
342        void SetTransferFunction(int number)
343        {
344                mTransferFunction = number/1000.0f;
345                updateGL();
346        }
347
348        void SetVisibilityFilterSize(int number);
349
350        void
351                SetSpatialFilterSize(int number);
352
353        void
354                SetSceneCut(int cut);
355
356        void
357                SetTopDistance(int dist);
358
359        void
360                SetTransparency(int dist);
361
362        void
363                SetHidingCost(int dist);
364
365        void SetShowViewCells(bool b) {
366                mRenderViewCells = b;
367                updateGL();
368        }
369
370        void SetShowRays(bool b) {
371                mShowRays = b;
372                updateGL();
373        }
374
375        void SetShowRenderCost(bool b) {
376                mShowRenderCost = b;
377                updateGL();
378        }
379
380        void SetShowPvsSizes(bool b) {
381                mShowPvsSizes = b;
382                updateGL();
383        }
384
385        void SetShowComparison(bool b) {
386                mShowComparison = b;
387                updateGL();
388        }
389
390        void SetShowPiercingRays(bool b) {
391                mShowPiercingRays = b;
392                updateGL();
393        }
394
395        void SetShowWeightedRays(bool b) {
396                mShowWeightedRays = b;
397                updateGL();
398        }
399
400        void SetTopView(bool b) {
401                mTopView = b;
402                updateGL();
403        }
404
405        void SetCutViewCells(bool b) {
406                mCutViewCells = b;
407                updateGL();
408        }
409        void SetCutScene(bool b) {
410                mCutScene = b;
411                updateGL();
412        }
413
414        void SetHideByCost(bool b) {
415                mHideByCost = b;
416                updateGL();
417        }
418
419        void SetUseTransparency(bool b) {
420                mUseTransparency = b;
421                updateGL();
422        }
423
424        void SetShowWeightedCost(bool b)
425        {
426                mShowWeightedCost = b;
427                updateGL();
428        }
429
430        void SetShowDistanceWeightedPvs(bool b)
431        {
432                mShowDistanceWeightedPvs = b;
433                updateGL();
434        }
435
436
437        void SetShowDistanceWeightedTriangles(bool b)
438        {
439                mShowDistanceWeightedTriangles = b;
440                updateGL();
441        }
442       
443        void SetShowWeightedTriangles(bool b)
444        {
445                mShowWeightedTriangles = b;
446                updateGL();
447        }
448
449        void UseConstColorForRayViz(bool b)
450        {
451                mRayVisualizationMethod = 0;
452        }
453   
454        void UseRayLengthForRayViz(bool b)
455        {
456                mRayVisualizationMethod = 1;
457        }
458
459        void SetShowContribution(bool b)
460        {
461                mRayVisualizationMethod = 2;
462        }
463   
464        void SetShowDistribution(bool b)
465        {
466                mRayVisualizationMethod = 3;
467        }
468       
469        void SetShowDistribution1(bool b)
470        {
471                if (b)
472                        mShowDistribution |= 1;
473                else
474                        mShowDistribution ^= 1;
475
476                std::cout << "b: " << (mShowDistribution & 1) << " " << (mShowDistribution & 2) << " " << (mShowDistribution & 4) << " " << (mShowDistribution & 8) << std::endl;
477        }
478
479       
480        void SetShowDistribution2(bool b)
481        {
482                if (b)
483                        mShowDistribution |= 2;
484                else
485                        mShowDistribution ^= 2;
486        }
487
488       
489        void SetShowDistribution3(bool b)
490        {
491                if (b)
492                        mShowDistribution |= 4;
493                else
494                        mShowDistribution ^= 4;
495        }
496       
497        void SetShowDistribution4(bool b)
498        {
499                if (b)
500                        mShowDistribution |= 8;
501                else
502                        mShowDistribution ^= 8;
503        }
504
505        void _RenderPvs();
506
507        void _UpdatePvsIndices();
508
509        void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
510
511        float ComputeRenderCost(ViewCell *vc);
512
513
514
515        /////////
516
517signals:
518        void PvsUpdated();
519};
520
521
522class QtGlDebuggerWidget: public QGLWidget
523{
524        Q_OBJECT
525public:
526    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
527    ~QtGlDebuggerWidget();
528    void initializeGL();
529    void resizeGL(int w, int h);
530    void paintGL();
531    void timerEvent(QTimerEvent *) { update(); }
532    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
533    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
534
535    void initCommon();
536    void initPbuffer();
537
538 
539         QtGlRendererBuffer *mRenderBuffer;
540
541         Beam mBeam;
542         int mSamples;
543         Intersectable *mSourceObject;
544
545private:
546
547    GLuint dynamicTexture;
548    int timerId;
549};
550
551
552extern QtGlDebuggerWidget *debuggerWidget;
553
554};
555
556#endif
557
Note: See TracBrowser for help on using the repository browser.