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