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

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