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

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