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

Revision 2725, 12.1 KB checked in by mattausch, 16 years ago (diff)

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