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

Revision 2703, 12.0 KB checked in by mattausch, 16 years ago (diff)

worked on dynamic objects

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