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

Revision 2643, 11.4 KB checked in by mattausch, 16 years ago (diff)

compiling under release internal

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