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

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

fixed several problems

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       
316
317public slots:
318       
319        /** Replay the view points stored in the view points list.
320        */
321        void ReplayViewPoints();
322        void UpdateDynamicObjects();
323        void UpdateAllPvs();
324        void ComputeVisibility();
325        void StopComputation();
326        void SetRandomViewPoint();
327        void StoreStatistics();
328       
329        void LoadObject();
330
331        void SetRenderErrors(bool b) {
332                mRenderErrors = b;
333                updateGL();
334        }
335
336        void ComputeGVS() {
337                mComputeGVS = true;
338                updateGL();
339        }
340
341        void SetRenderBoxes(bool b) {
342                mRenderBoxes = b;
343                updateGL();
344        }
345
346        void SetRenderFilter(bool b) {
347                mRenderFilter = b;
348                updateGL();
349        }
350
351        void SetRenderVisibilityEstimates(bool b) {
352                mRenderVisibilityEstimates = b;
353                updateGL();
354        }
355
356        void SetUseFilter(bool b) {
357                mUseFilter = b;
358                mPvsCache.Reset();
359                updateGL();
360        }
361
362        void SetUseSpatialFilter(bool b) {
363                mUseSpatialFilter = b;
364                mPvsCache.Reset();
365                updateGL();
366        }
367
368
369        void
370                SetViewCellGranularity(int number);
371
372        void SetTransferFunction(int number)
373        {
374                mTransferFunction = number/1000.0f;
375                updateGL();
376        }
377
378        void SetVisibilityFilterSize(int number);
379
380        void
381                SetSpatialFilterSize(int number);
382
383        void
384                SetSceneCut(int cut);
385
386        void
387                SetTopDistance(int dist);
388
389        void
390                SetTransparency(int dist);
391
392        void
393                SetHidingCost(int dist);
394
395        void SetShowViewCells(bool b) {
396                mRenderViewCells = b;
397                updateGL();
398        }
399
400        void SetShowRays(bool b) {
401                mShowRays = b;
402                updateGL();
403        }
404
405        void SetShowRenderCost(bool b) {
406                mShowRenderCost = b;
407                updateGL();
408        }
409
410        void SetShowPvsSizes(bool b) {
411                mShowPvsSizes = b;
412                updateGL();
413        }
414
415        void SetShowComparison(bool b) {
416                mShowComparison = b;
417                updateGL();
418        }
419
420        void SetShowPiercingRays(bool b) {
421                mShowPiercingRays = b;
422                updateGL();
423        }
424
425        void SetShowWireFrame(bool b) {
426                mUseStandardColors = b;
427                updateGL();
428        }
429       
430
431        void SetShowWeightedRays(bool b) {
432                mShowWeightedRays = b;
433                updateGL();
434        }
435
436        void SetTopView(bool b) {
437                mTopView = b;
438                updateGL();
439        }
440
441        void SetCutViewCells(bool b) {
442                mCutViewCells = b;
443                updateGL();
444        }
445        void SetCutScene(bool b) {
446                mCutScene = b;
447                updateGL();
448        }
449
450        void SetHideByCost(bool b) {
451                mHideByCost = b;
452                updateGL();
453        }
454
455        void SetUseTransparency(bool b) {
456                mUseTransparency = b;
457                updateGL();
458        }
459
460        void SetShowWeightedCost(bool b)
461        {
462                mShowWeightedCost = b;
463                updateGL();
464        }
465
466        void SetShowDistanceWeightedPvs(bool b)
467        {
468                mShowDistanceWeightedPvs = b;
469                updateGL();
470        }
471
472
473        void SetShowDistanceWeightedTriangles(bool b)
474        {
475                mShowDistanceWeightedTriangles = b;
476                updateGL();
477        }
478       
479        void SetShowWeightedTriangles(bool b)
480        {
481                mShowWeightedTriangles = b;
482                updateGL();
483        }
484
485        void UseConstColorForRayViz(bool b)
486        {
487                mRayVisualizationMethod = 0;
488        }
489   
490        void UseRayLengthForRayViz(bool b)
491        {
492                mRayVisualizationMethod = 1;
493        }
494
495        void SetShowContribution(bool b)
496        {
497                mRayVisualizationMethod = 2;
498        }
499   
500        void SetShowDistribution(bool b)
501        {
502                mRayVisualizationMethod = 3;
503        }
504
505        void SetTranslation(bool b)
506        {
507                mTrafoType = 0;
508        }
509
510        void SetScale(bool b)
511        {
512                mTrafoType = 1;
513        }
514       
515        void SetRotation(bool b)
516        {
517                mTrafoType = 2;
518        }
519
520        void SetShowDistribution1(bool b)
521        {
522                if (b)
523                        mShowDistribution |= 1;
524                else
525                        mShowDistribution ^= 1;
526
527                std::cout << "b: "
528                                  << (mShowDistribution & 1) << " "
529                                  << (mShowDistribution & 2) << " "
530                                  << (mShowDistribution & 4) << " "
531                                  << (mShowDistribution & 8) << std::endl;
532        }
533
534       
535        void SetShowDistribution2(bool b)
536        {
537                if (b)
538                        mShowDistribution |= 2;
539                else
540                        mShowDistribution ^= 2;
541        }
542
543       
544        void SetShowDistribution3(bool b)
545        {
546                if (b)
547                        mShowDistribution |= 4;
548                else
549                        mShowDistribution ^= 4;
550        }
551       
552        void SetShowDistribution4(bool b)
553        {
554                if (b)
555                        mShowDistribution |= 8;
556                else
557                        mShowDistribution ^= 8;
558        }
559
560       
561        /** Prepare pvs for rendering.
562        */
563        virtual void PreparePvs(const ObjectPvs &pvs);
564        /** Internal method rendering the pvs if it has been properly prepared.
565        */
566        void _RenderPvs();
567        /** Render pvs using false colors.
568        */
569        void _RenderColoredPvs();
570
571        float ComputeRenderCost(ViewCell *vc);
572
573
574        /////////
575
576signals:
577        void PvsUpdated();
578};
579
580
581class QtGlDebuggerWidget: public QGLWidget
582{
583        Q_OBJECT
584public:
585    QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
586    ~QtGlDebuggerWidget();
587    void initializeGL();
588    void resizeGL(int w, int h);
589    void paintGL();
590    void timerEvent(QTimerEvent *) { update(); }
591    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
592    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
593
594    void initCommon();
595    void initPbuffer();
596
597 
598         QtGlRendererBuffer *mRenderBuffer;
599
600         Beam mBeam;
601         int mSamples;
602         Intersectable *mSourceObject;
603
604private:
605
606    GLuint dynamicTexture;
607    int timerId;
608};
609
610
611extern QtGlDebuggerWidget *debuggerWidget;
612
613};
614
615#endif
Note: See TracBrowser for help on using the repository browser.