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

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

sheduling dynamic object only when necessary

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