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

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

redoing stuff from submission

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