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

Revision 2704, 11.9 KB checked in by mattausch, 16 years ago (diff)

repaired city scene

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