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

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