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

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

implemented dynamic object placement / removal

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 LoadObject();
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        int mCurrentDynamicObjectIdx;
220
221        bool mReplayMode;
222
223        // some statistics
224        int mPvsSize;
225        float mRenderError;
226        float mTransferFunction;
227
228        Vector3 mDummyViewPoint;
229
230        int mRayVisualizationMethod;
231        int mTrafoType;
232
233        QtRendererControlWidget *mControlWidget;
234
235        QtPreprocessorThread *mPreprocessorThread;
236
237        ViewCellInfoContainer mCompareInfo;
238
239        int mCurrentPvsCost;
240
241        vector<RgbColor> mColors;
242
243        bool mUseRandomColorPerPvsObject;
244
245        int mUpdateTimerId;
246        int mReplayTimerId;
247
248        ObjectPlacer *mPlacer;
249
250        //DynamicObjectsContainer mPendingDynamicObjects;
251        DynamicObjectsContainer mDynamicPvsObjects;
252
253        QtGlRendererWidget(SceneGraph *sceneGraph,
254                               ViewCellsManager *viewcells,
255                                           KdTree *tree,
256                                           QWidget * parent = 0,
257                                           const QGLWidget *shareWidget = 0,
258                                           Qt::WFlags f = 0);
259
260        QtGlRendererWidget() {};
261
262        ~QtGlRendererWidget();
263
264        void SetThread(QtPreprocessorThread *t)
265        {
266                mPreprocessorThread = t;
267        }
268
269        void RenderRenderCost();
270
271        virtual void SetupCamera();
272
273        void initializeGL()
274        {
275                InitGL();
276        }
277
278        virtual void InitGL();
279
280        void resizeGL(int w, int h);
281        void paintGL();
282        void timerEvent(QTimerEvent *event);
283        void mousePressEvent(QMouseEvent *);
284        void mouseReleaseEvent(QMouseEvent *);
285        void mouseMoveEvent(QMouseEvent *);
286
287        void keyPressEvent(QKeyEvent * e);
288
289        void VisualizePvs();
290
291        float RenderErrors();
292        void RenderInfo();
293
294        virtual int GetWidth() const { return width(); }
295        virtual int GetHeight() const { return height(); }
296
297        virtual void SetupCameraProjection(const int w,
298                                                                           const int h,
299                                                                           const float angle = 70.0f);
300
301        void RenderViewCells();
302
303        virtual void Show() { show(); }
304
305        bool PvsChanged(ViewCell *viewcell) const;
306
307        void ComputeMaxValues(const ViewCellContainer &viewCells,
308                                                  int &maxPvs,
309                                                  int &maxPiercingRays,
310                                                  float &maxRelativeRays,
311                                                  float &maxRcCost);
312
313        void AssignImportanceByRelativeValue(const ViewCellContainer &viewCells,
314                                                                                 int &maxPvs,
315                                                                                 int &maxPiercingRays,
316                                                                                 float &maxRelativeRays,
317                                                                                 float &maxRcCost);
318
319        void AssignColorByComparison(const ViewCellContainer &viewcells,
320                                                                 const ViewCellInfoContainer &compareInfo);
321
322        void WriteViewCellInfos();
323        /** Unproject x/y screen coordinates.
324        */
325        Vector3 Unproject(int x, int y);
326       
327        int FindDynamicObject(float x, float y);
328
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
344        void SetRenderErrors(bool b) {
345                mRenderErrors = b;
346                updateGL();
347        }
348
349        void ComputeGVS() {
350                mComputeGVS = true;
351                updateGL();
352        }
353
354        void SetRenderBoxes(bool b) {
355                mRenderBoxes = b;
356                updateGL();
357        }
358
359        void SetRenderFilter(bool b) {
360                mRenderFilter = b;
361                updateGL();
362        }
363
364        void SetRenderVisibilityEstimates(bool b) {
365                mRenderVisibilityEstimates = b;
366                updateGL();
367        }
368
369        void SetUseFilter(bool b) {
370                mUseFilter = b;
371                mPvsCache.Reset();
372                updateGL();
373        }
374
375        void SetUseSpatialFilter(bool b) {
376                mUseSpatialFilter = b;
377                mPvsCache.Reset();
378                updateGL();
379        }
380
381
382        void
383                SetViewCellGranularity(int number);
384
385        void SetTransferFunction(int number)
386        {
387                mTransferFunction = number/1000.0f;
388                updateGL();
389        }
390
391        void SetVisibilityFilterSize(int number);
392
393        void
394                SetSpatialFilterSize(int number);
395
396        void
397                SetSceneCut(int cut);
398
399        void
400                SetTopDistance(int dist);
401
402        void
403                SetTransparency(int dist);
404
405        void
406                SetHidingCost(int dist);
407
408        void SetShowViewCells(bool b) {
409                mRenderViewCells = b;
410                updateGL();
411        }
412
413        void SetShowRays(bool b) {
414                mShowRays = b;
415                updateGL();
416        }
417
418        void SetShowRenderCost(bool b) {
419                mShowRenderCost = b;
420                updateGL();
421        }
422
423        void SetShowPvsSizes(bool b) {
424                mShowPvsSizes = b;
425                updateGL();
426        }
427
428        void SetShowComparison(bool b) {
429                mShowComparison = b;
430                updateGL();
431        }
432
433        void SetShowPiercingRays(bool b) {
434                mShowPiercingRays = b;
435                updateGL();
436        }
437
438        void SetShowWireFrame(bool b) {
439                mUseStandardColors = b;
440                updateGL();
441        }
442       
443
444        void SetShowWeightedRays(bool b) {
445                mShowWeightedRays = b;
446                updateGL();
447        }
448
449        void SetTopView(bool b) {
450                mTopView = b;
451                updateGL();
452        }
453
454        void SetCutViewCells(bool b) {
455                mCutViewCells = b;
456                updateGL();
457        }
458        void SetCutScene(bool b) {
459                mCutScene = b;
460                updateGL();
461        }
462
463        void SetHideByCost(bool b) {
464                mHideByCost = b;
465                updateGL();
466        }
467
468        void SetUseTransparency(bool b) {
469                mUseTransparency = b;
470                updateGL();
471        }
472
473        void SetShowWeightedCost(bool b)
474        {
475                mShowWeightedCost = b;
476                updateGL();
477        }
478
479        void SetShowDistanceWeightedPvs(bool b)
480        {
481                mShowDistanceWeightedPvs = b;
482                updateGL();
483        }
484
485
486        void SetShowDistanceWeightedTriangles(bool b)
487        {
488                mShowDistanceWeightedTriangles = b;
489                updateGL();
490        }
491       
492        void SetShowWeightedTriangles(bool b)
493        {
494                mShowWeightedTriangles = b;
495                updateGL();
496        }
497
498        void UseConstColorForRayViz(bool b)
499        {
500                mRayVisualizationMethod = 0;
501        }
502   
503        void UseRayLengthForRayViz(bool b)
504        {
505                mRayVisualizationMethod = 1;
506        }
507
508        void SetShowContribution(bool b)
509        {
510                mRayVisualizationMethod = 2;
511        }
512   
513        void SetShowDistribution(bool b)
514        {
515                mRayVisualizationMethod = 3;
516        }
517
518        void SetTranslation(bool b)
519        {
520                mTrafoType = 0;
521        }
522
523        void SetScale(bool b)
524        {
525                mTrafoType = 1;
526        }
527       
528        void SetRotation(bool b)
529        {
530                mTrafoType = 2;
531        }
532
533        void SetShowDistribution1(bool b)
534        {
535                if (b)
536                        mShowDistribution |= 1;
537                else
538                        mShowDistribution ^= 1;
539
540                std::cout << "b: "
541                                  << (mShowDistribution & 1) << " "
542                                  << (mShowDistribution & 2) << " "
543                                  << (mShowDistribution & 4) << " "
544                                  << (mShowDistribution & 8) << std::endl;
545        }
546
547       
548        void SetShowDistribution2(bool b)
549        {
550                if (b)
551                        mShowDistribution |= 2;
552                else
553                        mShowDistribution ^= 2;
554        }
555
556       
557        void SetShowDistribution3(bool b)
558        {
559                if (b)
560                        mShowDistribution |= 4;
561                else
562                        mShowDistribution ^= 4;
563        }
564       
565        void SetShowDistribution4(bool b)
566        {
567                if (b)
568                        mShowDistribution |= 8;
569                else
570                        mShowDistribution ^= 8;
571        }
572
573       
574        /** Prepare pvs for rendering.
575        */
576        virtual void PreparePvs(const ObjectPvs &pvs);
577        /** Internal method rendering the pvs if it has been properly prepared.
578        */
579        void _RenderPvs();
580        /** Render pvs using false colors.
581        */
582        void _RenderColoredPvs();
583
584        float ComputeRenderCost(ViewCell *vc);
585
586
587        /////////
588
589signals:
590        void PvsUpdated();
591};
592
593
594class QtGlDebuggerWidget: public QGLWidget
595{
596        Q_OBJECT
597public:
598    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
599    ~QtGlDebuggerWidget();
600    void initializeGL();
601    void resizeGL(int w, int h);
602    void paintGL();
603    void timerEvent(QTimerEvent *) { update(); }
604    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
605    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
606
607    void initCommon();
608    void initPbuffer();
609
610 
611         QtGlRendererBuffer *mRenderBuffer;
612
613         Beam mBeam;
614         int mSamples;
615         Intersectable *mSourceObject;
616
617private:
618
619    GLuint dynamicTexture;
620    int timerId;
621};
622
623
624extern QtGlDebuggerWidget *debuggerWidget;
625
626};
627
628#endif
Note: See TracBrowser for help on using the repository browser.