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

Revision 2621, 11.2 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#include "Material.h"
17#include "common.h"
18
19
20class QWidget;
21
22
23
24namespace GtpVisibilityPreprocessor {
25
26
27class SceneGraph;
28class ViewCellsManager;
29class Mesh;
30class MeshInstance;
31class Intersectable;
32class Material;
33class Beam;
34class KdTree;
35class GlRendererBuffer;
36class BeamSampleStatistics;
37class OcclusionQuery;
38class TransformedMeshInstance;
39
40
41struct VssRayContainer;
42struct PvsRenderStatistics;
43struct RenderCostSample;
44
45//class LogWriter;
46
47
48
49class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer
50{
51        Q_OBJECT
52public:
53        QtGlRendererBuffer(const int w,
54                const int h,
55                SceneGraph *sceneGraph,
56                ViewCellsManager *viewcells,
57                KdTree *tree);
58
59  ~QtGlRendererBuffer() {}
60
61  virtual void MakeCurrent();
62  virtual void DoneCurrent();
63
64  virtual int GetWidth() const { return width(); }
65  virtual int GetHeight() const { return height(); }
66
67  int ComputePvs() const { return 0; }
68
69  void
70  RenderPvs(const ObjectPvs &pvs);
71
72  float
73  GetPixelError(int &pvsSize);
74 
75  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
76     
77 
78 
79 
80public:
81  signals:
82  void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
83};
84
85
86class QtRendererControlWidget : public QWidget
87{
88  Q_OBJECT
89public:
90
91  QListWidget *mPvsErrorWidget;
92
93  QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
94
95  QGroupBox *CreateVisualizationPanel(QWidget *parent);
96  QGroupBox *CreateTrafoPanel(QWidget *parent);
97
98  public slots:
99
100  void FocusNextPvsErrorFrame();
101  void UpdatePvsErrorItem(int i,
102                                                  GlRendererBuffer::PvsErrorEntry &);
103
104 
105  QGroupBox *CreateRenderCostPanel(QWidget *parent);
106  QGroupBox *CreateRayVisualizationPanel(QWidget *parent);
107
108
109  signals:
110
111  void ComputeVisibility();
112  void StopComputation();
113  void SetRandomViewPoint();
114  void StoreStatistics();
115  void LoadObject();
116  void UpdateAllPvs();
117  void SetViewCellGranularity(int);
118  void SetTransferFunction(int);
119  void SetSceneCut(int);
120  void SetTopDistance(int);
121  void SetHidingCost(int);
122  void SetVisibilityFilterSize(int);
123  void SetSpatialFilterSize(int);
124  void SetTransparency(int);
125
126  void SetShowRays(bool);
127  void SetRenderFilter(bool);
128  void SetRenderVisibilityEstimates(bool);
129  void SetUseFilter(bool);
130  void SetUseSpatialFilter(bool);
131  void SetRenderErrors(bool);
132  void SetRenderBoxes(bool);
133  void SetShowViewCells(bool);
134  void SetShowRenderCost(bool);
135  void SetShowPvsSizes(bool);
136  void SetShowWireFrame(bool);
137  void SetShowPiercingRays(bool);
138  void SetShowWeightedRays(bool);
139  void SetShowComparison(bool);
140  void SetShowWeightedCost(bool);
141 
142  void SetTopView(bool);
143  void SetCutViewCells(bool);
144  void SetCutScene(bool);
145
146  void SetHideByCost(bool);
147  void SetUseTransparency(bool);
148
149  void SetShowDistanceWeightedTriangles(bool);
150  void SetShowWeightedTriangles(bool);
151  void SetShowDistanceWeightedPvs(bool);
152
153  void UseConstColorForRayViz(bool);
154  void UseRayLengthForRayViz(bool);
155  void SetShowContribution(bool);
156  void SetShowDistribution(bool);
157
158  void SetShowDistribution1(bool);
159  void SetShowDistribution2(bool);
160  void SetShowDistribution3(bool);
161  void SetShowDistribution4(bool);
162
163  void SetTranslation(bool);
164  void SetRotation(bool);
165  void SetScale(bool);
166};
167
168
169class QtGlRendererWidget: public QGLWidget, public GlRendererWidget
170{
171        Q_OBJECT
172public:
173
174        // point of the last mouse click used for movement in the scene
175        Vector3 mousePoint;
176
177        bool mTopView;
178        bool mRenderViewCells;
179        bool mCutViewCells;
180        bool mCutScene;
181        bool mHideByCost;
182        bool mRenderErrors;
183        bool mRenderFilter;
184        bool mRenderVisibilityEstimates;
185        bool mUseFilter;
186        bool mUseSpatialFilter;
187        bool mShowRenderCost;
188        bool mShowPiercingRays;
189        bool mShowWeightedRays;
190        bool mUseStandardColors;
191        bool mShowRays;
192
193        bool mShowPvsSizes;
194        bool mShowComparison;
195        float mSpatialFilterSize;
196
197        //LogWriter *mLogWriter;
198        Plane3 mSceneCutPlane;
199        float mHidingCost;
200
201        float mTopDistance;
202
203        float mTransparency;
204        bool mUseTransparency;
205
206        bool mShowWeightedCost;
207
208        bool mShowDistanceWeightedTriangles;
209        bool mShowDistanceWeightedPvs;
210        bool mShowWeightedTriangles;
211       
212        int mShowDistribution;
213
214        int mCurrentDynamicObjectIdx;
215
216        // some statistics
217        int mPvsSize;
218        float mRenderError;
219        float mTransferFunction;
220
221
222        Vector3 mDummyViewPoint;
223
224        int mRayVisualizationMethod;
225        int mTrafoType;
226
227        QtRendererControlWidget *mControlWidget;
228
229        QtPreprocessorThread *mPreprocessorThread;
230
231        ViewCellInfoContainer mCompareInfo;
232
233        vector<RgbColor> mColors;
234
235        bool mUseRandomColorPerPvsObject;
236#if DYNAMIC_OBJECTS_HACK
237        DynamicObjectsContainer mDynamicObjects;
238#endif
239        QtGlRendererWidget(SceneGraph *sceneGraph,
240                               ViewCellsManager *viewcells,
241                                           KdTree *tree,
242                                           QWidget * parent = 0,
243                                           const QGLWidget *shareWidget = 0,
244                                           Qt::WFlags f = 0);
245
246        QtGlRendererWidget() {};
247
248        void SetThread(QtPreprocessorThread *t)
249        {
250                mPreprocessorThread = t;
251        }
252        void RenderRenderCost();
253
254        virtual void SetupCamera();
255
256        void initializeGL() {
257                InitGL();
258        }
259
260        virtual void InitGL();
261
262        void resizeGL(int w, int h);
263        void paintGL();
264        void timerEvent(QTimerEvent *event);
265        void mousePressEvent(QMouseEvent *);
266        void mouseReleaseEvent(QMouseEvent *);
267        void mouseMoveEvent(QMouseEvent *);
268
269        void keyPressEvent(QKeyEvent * e);
270
271        void RenderPvs();
272
273        float RenderErrors();
274        void RenderInfo();
275
276        virtual int GetWidth() const { return width(); }
277        virtual int GetHeight() const { return height(); }
278
279        virtual void
280                SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
281
282        void RenderViewCells();
283
284        virtual void Show() { show(); }
285
286        bool PvsChanged(ViewCell *viewcell) const;
287
288        void ComputeMaxValues(const ViewCellContainer &viewCells,
289                                                  int &maxPvs,
290                                                  int &maxPiercingRays,
291                                                  float &maxRelativeRays,
292                                                  float &maxRcCost);
293
294        void AssignImportanceByRelativeValue(const ViewCellContainer &viewCells,
295                                                                                 int &maxPvs,
296                                                                                 int &maxPiercingRays,
297                                                                                 float &maxRelativeRays,
298                                                                                 float &maxRcCost);
299
300        void AssignColorByComparison(const ViewCellContainer &viewcells,
301                                                                 //const ViewCellInfoContainer &info1,
302                                                                 const ViewCellInfoContainer &compareInfo);
303
304        void WriteViewCellInfos();
305
306
307        /////////
308        //QMutex mMutex;
309
310
311public slots:
312
313        void UpdateAllPvs();
314        void ComputeVisibility();
315        void StopComputation();
316        void SetRandomViewPoint();
317        void StoreStatistics();
318        void LoadObject();
319
320        void SetRenderErrors(bool b) {
321                mRenderErrors = b;
322                updateGL();
323        }
324
325        void SetRenderBoxes(bool b) {
326                mRenderBoxes = b;
327                updateGL();
328        }
329
330        void SetRenderFilter(bool b) {
331                mRenderFilter = b;
332                updateGL();
333        }
334
335        void SetRenderVisibilityEstimates(bool b) {
336                mRenderVisibilityEstimates = b;
337                updateGL();
338        }
339
340        void SetUseFilter(bool b) {
341                mUseFilter = b;
342                mPvsCache.Reset();
343                updateGL();
344        }
345
346        void SetUseSpatialFilter(bool b) {
347                mUseSpatialFilter = b;
348                mPvsCache.Reset();
349                updateGL();
350        }
351
352
353        void
354                SetViewCellGranularity(int number);
355
356        void SetTransferFunction(int number)
357        {
358                mTransferFunction = number/1000.0f;
359                updateGL();
360        }
361
362        void SetVisibilityFilterSize(int number);
363
364        void
365                SetSpatialFilterSize(int number);
366
367        void
368                SetSceneCut(int cut);
369
370        void
371                SetTopDistance(int dist);
372
373        void
374                SetTransparency(int dist);
375
376        void
377                SetHidingCost(int dist);
378
379        void SetShowViewCells(bool b) {
380                mRenderViewCells = b;
381                updateGL();
382        }
383
384        void SetShowRays(bool b) {
385                mShowRays = b;
386                updateGL();
387        }
388
389        void SetShowRenderCost(bool b) {
390                mShowRenderCost = b;
391                updateGL();
392        }
393
394        void SetShowPvsSizes(bool b) {
395                mShowPvsSizes = b;
396                updateGL();
397        }
398
399        void SetShowComparison(bool b) {
400                mShowComparison = b;
401                updateGL();
402        }
403
404        void SetShowPiercingRays(bool b) {
405                mShowPiercingRays = b;
406                updateGL();
407        }
408
409        void SetShowWireFrame(bool b) {
410                mUseStandardColors = b;
411                updateGL();
412        }
413       
414
415        void SetShowWeightedRays(bool b) {
416                mShowWeightedRays = b;
417                updateGL();
418        }
419
420        void SetTopView(bool b) {
421                mTopView = b;
422                updateGL();
423        }
424
425        void SetCutViewCells(bool b) {
426                mCutViewCells = b;
427                updateGL();
428        }
429        void SetCutScene(bool b) {
430                mCutScene = b;
431                updateGL();
432        }
433
434        void SetHideByCost(bool b) {
435                mHideByCost = b;
436                updateGL();
437        }
438
439        void SetUseTransparency(bool b) {
440                mUseTransparency = b;
441                updateGL();
442        }
443
444        void SetShowWeightedCost(bool b)
445        {
446                mShowWeightedCost = b;
447                updateGL();
448        }
449
450        void SetShowDistanceWeightedPvs(bool b)
451        {
452                mShowDistanceWeightedPvs = b;
453                updateGL();
454        }
455
456
457        void SetShowDistanceWeightedTriangles(bool b)
458        {
459                mShowDistanceWeightedTriangles = b;
460                updateGL();
461        }
462       
463        void SetShowWeightedTriangles(bool b)
464        {
465                mShowWeightedTriangles = b;
466                updateGL();
467        }
468
469        void UseConstColorForRayViz(bool b)
470        {
471                mRayVisualizationMethod = 0;
472        }
473   
474        void UseRayLengthForRayViz(bool b)
475        {
476                mRayVisualizationMethod = 1;
477        }
478
479        void SetShowContribution(bool b)
480        {
481                mRayVisualizationMethod = 2;
482        }
483   
484        void SetShowDistribution(bool b)
485        {
486                mRayVisualizationMethod = 3;
487        }
488
489        void SetTranslation(bool b)
490        {
491                mTrafoType = 0;
492        }
493
494        void SetScale(bool b)
495        {
496                mTrafoType = 1;
497        }
498       
499        void SetRotation(bool b)
500        {
501                mTrafoType = 2;
502        }
503
504        void SetShowDistribution1(bool b)
505        {
506                if (b)
507                        mShowDistribution |= 1;
508                else
509                        mShowDistribution ^= 1;
510
511                std::cout << "b: " << (mShowDistribution & 1) << " " << (mShowDistribution & 2) << " " << (mShowDistribution & 4) << " " << (mShowDistribution & 8) << std::endl;
512        }
513
514       
515        void SetShowDistribution2(bool b)
516        {
517                if (b)
518                        mShowDistribution |= 2;
519                else
520                        mShowDistribution ^= 2;
521        }
522
523       
524        void SetShowDistribution3(bool b)
525        {
526                if (b)
527                        mShowDistribution |= 4;
528                else
529                        mShowDistribution ^= 4;
530        }
531       
532        void SetShowDistribution4(bool b)
533        {
534                if (b)
535                        mShowDistribution |= 8;
536                else
537                        mShowDistribution ^= 8;
538        }
539
540        void PreparePvs();
541
542        void _RenderPvs();
543        /** Render pvs using false colors.
544        */
545        void _RenderColoredPvs();
546
547  //    void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
548
549        float ComputeRenderCost(ViewCell *vc);
550
551
552
553        /////////
554
555signals:
556        void PvsUpdated();
557};
558
559
560class QtGlDebuggerWidget: public QGLWidget
561{
562        Q_OBJECT
563public:
564    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
565    ~QtGlDebuggerWidget();
566    void initializeGL();
567    void resizeGL(int w, int h);
568    void paintGL();
569    void timerEvent(QTimerEvent *) { update(); }
570    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
571    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
572
573    void initCommon();
574    void initPbuffer();
575
576 
577         QtGlRendererBuffer *mRenderBuffer;
578
579         Beam mBeam;
580         int mSamples;
581         Intersectable *mSourceObject;
582
583private:
584
585    GLuint dynamicTexture;
586    int timerId;
587};
588
589
590extern QtGlDebuggerWidget *debuggerWidget;
591
592};
593
594#endif
Note: See TracBrowser for help on using the repository browser.