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