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

Revision 2693, 11.6 KB checked in by mattausch, 16 years ago (diff)

started on dynamic object interaction

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