1 | #include "glInterface.h"
|
---|
2 | #include "QtGlRenderer.h"
|
---|
3 | #include "Mesh.h"
|
---|
4 | #include "OcclusionQuery.h"
|
---|
5 | #include "ViewCellsManager.h"
|
---|
6 | #include "SceneGraph.h"
|
---|
7 | #include "Pvs.h"
|
---|
8 | #include "Viewcell.h"
|
---|
9 | #include "Beam.h"
|
---|
10 | #include "KdTree.h"
|
---|
11 | #include "Environment.h"
|
---|
12 | #include "RssPreprocessor.h"
|
---|
13 | #include "RssTree.h"
|
---|
14 | #include "Trackball.h"
|
---|
15 | #include "QtPreprocessorThread.h"
|
---|
16 | #include "Material.h"
|
---|
17 | #include "IntersectableWrapper.h"
|
---|
18 | #include "LogWriter.h"
|
---|
19 |
|
---|
20 |
|
---|
21 | #define USE_CG 1
|
---|
22 |
|
---|
23 | #define TEST_PVS_RENDERING 0
|
---|
24 |
|
---|
25 | #if USE_CG
|
---|
26 | #include <Cg/cg.h>
|
---|
27 | #include <Cg/cgGL.h>
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | #include <QVBoxLayout>
|
---|
31 |
|
---|
32 | namespace GtpVisibilityPreprocessor {
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | class ViewCellsManager;
|
---|
37 |
|
---|
38 | static CGcontext sCgContext = NULL;
|
---|
39 | static CGprogram sCgFragmentProgram = NULL;
|
---|
40 | static CGprofile sCgFragmentProfile;
|
---|
41 |
|
---|
42 |
|
---|
43 | //static vector<OcclusionQuery *> sQueries;
|
---|
44 |
|
---|
45 | QtGlRendererWidget *rendererWidget = NULL;
|
---|
46 | QtGlDebuggerWidget *debuggerWidget = NULL;
|
---|
47 |
|
---|
48 | const static int SAMPLES_INCR = 2000000;
|
---|
49 |
|
---|
50 |
|
---|
51 |
|
---|
52 | static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
|
---|
53 | {
|
---|
54 | return obj1->mId < obj2->mId;
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | inline static bool nearerThan(ViewCell *vc1, ViewCell *vc2)
|
---|
59 | {
|
---|
60 | return vc1->GetDistance() > vc2->GetDistance();
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | #if USE_CG
|
---|
65 | static void handleCgError()
|
---|
66 | {
|
---|
67 | Debug << "Cg error: " << cgGetErrorString(cgGetError()) << endl;
|
---|
68 | exit(1);
|
---|
69 | }
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | void
|
---|
73 | QtGlRendererBuffer::MakeCurrent()
|
---|
74 | {
|
---|
75 | makeCurrent();
|
---|
76 | }
|
---|
77 |
|
---|
78 | void
|
---|
79 | QtGlRendererBuffer::DoneCurrent()
|
---|
80 | {
|
---|
81 | doneCurrent();
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | QtGlRendererBuffer::QtGlRendererBuffer(const int w,
|
---|
86 | const int h,
|
---|
87 | SceneGraph *sceneGraph,
|
---|
88 | ViewCellsManager *viewcells,
|
---|
89 | KdTree *tree):
|
---|
90 | QGLPixelBuffer(QSize(w, h)),
|
---|
91 | GlRendererBuffer(sceneGraph, viewcells, tree)
|
---|
92 | {
|
---|
93 | mUseVbos = false;
|
---|
94 | MakeCurrent();
|
---|
95 | InitGL();
|
---|
96 | DoneCurrent();
|
---|
97 | }
|
---|
98 |
|
---|
99 | void
|
---|
100 | QtGlRendererBuffer::RenderPvs(const ObjectPvs &pvs)
|
---|
101 | {
|
---|
102 | #if TEST_PVS_RENDERING
|
---|
103 |
|
---|
104 | // Render PVS
|
---|
105 | ObjectPvsIterator it = pvs.GetIterator();
|
---|
106 |
|
---|
107 | Intersectable::NewMail();
|
---|
108 | mCurrentFrame++;
|
---|
109 | while (it.HasMoreEntries())
|
---|
110 | {
|
---|
111 | RenderIntersectable(it.Next());
|
---|
112 | }
|
---|
113 |
|
---|
114 | #else
|
---|
115 |
|
---|
116 | PreparePvs(pvs);
|
---|
117 |
|
---|
118 | int offset = (int)mObjects.size() * 3;
|
---|
119 | char *arrayPtr = mUseVbos ? NULL : (char *)mData;
|
---|
120 |
|
---|
121 | glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr);
|
---|
122 | glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
|
---|
123 | glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
|
---|
124 |
|
---|
125 | #endif
|
---|
126 | }
|
---|
127 |
|
---|
128 | // reimplemented here so that we can snap the error windows
|
---|
129 | float
|
---|
130 | QtGlRendererBuffer::GetPixelError(int &pvsSize)
|
---|
131 | {
|
---|
132 |
|
---|
133 | MakeCurrent();
|
---|
134 |
|
---|
135 | float pErrorPixels = -1.0f;
|
---|
136 |
|
---|
137 |
|
---|
138 | mUseFalseColors = false;
|
---|
139 | unsigned int pixelCount;
|
---|
140 |
|
---|
141 |
|
---|
142 | ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
|
---|
143 | if (viewcell == NULL)
|
---|
144 | return 0.0f;
|
---|
145 |
|
---|
146 | ObjectPvs pvs;
|
---|
147 |
|
---|
148 | if (1)
|
---|
149 | pvs = viewcell->GetPvs();
|
---|
150 | else
|
---|
151 | mViewCellsManager->ApplyFilter2(viewcell, false, 1.0f, pvs);
|
---|
152 |
|
---|
153 | mUseForcedColors = true;
|
---|
154 |
|
---|
155 | SetupCamera();
|
---|
156 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
157 | glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
|
---|
158 | glColor3f(0,1,0);
|
---|
159 |
|
---|
160 |
|
---|
161 | glStencilFunc(GL_EQUAL, 0x0, 0x1);
|
---|
162 | glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
---|
163 |
|
---|
164 |
|
---|
165 | pvsSize = pvs.GetSize();
|
---|
166 | cout<<pvsSize<<endl;
|
---|
167 |
|
---|
168 | RenderPvs(pvs);
|
---|
169 |
|
---|
170 | //glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
|
---|
171 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
172 | glEnable(GL_STENCIL_TEST);
|
---|
173 | glColor3f(1,0,0);
|
---|
174 |
|
---|
175 |
|
---|
176 | OcclusionQuery *query = mOcclusionQueries[0];
|
---|
177 |
|
---|
178 | // SetupCamera();
|
---|
179 |
|
---|
180 | Intersectable::NewMail();
|
---|
181 |
|
---|
182 | query->BeginQuery();
|
---|
183 |
|
---|
184 | RenderScene();
|
---|
185 |
|
---|
186 | query->EndQuery();
|
---|
187 | glDisable(GL_STENCIL_TEST);
|
---|
188 |
|
---|
189 | // reenable other state
|
---|
190 | // int wait=0;
|
---|
191 | // while (!query.ResultAvailable()) {
|
---|
192 | // wait++;
|
---|
193 | // }
|
---|
194 |
|
---|
195 |
|
---|
196 | pixelCount = query->GetQueryResult();
|
---|
197 | // cout<<"pc="<<pixelCount<<endl;
|
---|
198 |
|
---|
199 | pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
|
---|
200 |
|
---|
201 |
|
---|
202 | if (mSnapErrorFrames && (pErrorPixels >= 0.01f)) {
|
---|
203 | glReadBuffer(GL_BACK);
|
---|
204 | //glReadBuffer(GL_FRONT);
|
---|
205 |
|
---|
206 | char filename[256];
|
---|
207 | sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels);
|
---|
208 | QImage im = toImage();
|
---|
209 | string str = mSnapPrefix + filename;
|
---|
210 | QString qstr(str.c_str());
|
---|
211 |
|
---|
212 | im.save(qstr, "PNG");
|
---|
213 | if (0) { //0 && mFrame == 1543) {
|
---|
214 | int x,y;
|
---|
215 | int lastIndex = -1;
|
---|
216 | for (y=0; y < im.height(); y++)
|
---|
217 | for (x=0; x < im.width(); x++) {
|
---|
218 | QRgb p = im.pixel(x,y);
|
---|
219 | int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16);
|
---|
220 | if (qGreen(p) != 255 && index!=0) {
|
---|
221 | if (index != lastIndex) {
|
---|
222 | // Debug<<"ei="<<index<<" ";
|
---|
223 | lastIndex = index;
|
---|
224 | }
|
---|
225 | }
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | mUseFalseColors = false;
|
---|
230 | glPushAttrib(GL_CURRENT_BIT);
|
---|
231 | glColor3f(0,1,0);
|
---|
232 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
233 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
234 |
|
---|
235 | RenderPvs(pvs);
|
---|
236 |
|
---|
237 | mUseForcedColors = false;
|
---|
238 | im = toImage();
|
---|
239 | sprintf(filename, "error-frame-%04d-%0.5f-pvs.png", mFrame, pErrorPixels);
|
---|
240 | str = mSnapPrefix + filename;
|
---|
241 | qstr = str.c_str();
|
---|
242 | im.save(qstr, "PNG");
|
---|
243 | glPopAttrib();
|
---|
244 | }
|
---|
245 |
|
---|
246 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
247 |
|
---|
248 | DoneCurrent();
|
---|
249 |
|
---|
250 | return pErrorPixels;
|
---|
251 | }
|
---|
252 |
|
---|
253 | int
|
---|
254 | QtGlRendererBuffer::ComputePvs(ObjectContainer &objects,
|
---|
255 | ObjectContainer &pvs) const
|
---|
256 | {
|
---|
257 | int pvsSize = 0;
|
---|
258 | QImage image = toImage();
|
---|
259 | Intersectable::NewMail();
|
---|
260 |
|
---|
261 | std::stable_sort(objects.begin(), objects.end(), ilt);
|
---|
262 |
|
---|
263 | MeshInstance dummy(NULL);
|
---|
264 |
|
---|
265 | Intersectable *obj = NULL;
|
---|
266 |
|
---|
267 | for (int x = 0; x < image.width(); ++ x)
|
---|
268 | {
|
---|
269 | for (int y = 0; y < image.height(); ++ y)
|
---|
270 | {
|
---|
271 | QRgb pix = image.pixel(x, y);
|
---|
272 | const int id = GetId(qRed(pix), qGreen(pix), qBlue(pix));
|
---|
273 |
|
---|
274 | dummy.SetId(id);
|
---|
275 |
|
---|
276 | ObjectContainer::iterator oit =
|
---|
277 | lower_bound(objects.begin(), objects.end(), &dummy, ilt);
|
---|
278 |
|
---|
279 |
|
---|
280 | if (//(oit != oit.end()) &&
|
---|
281 | ((*oit)->GetId() == id) &&
|
---|
282 | !obj->Mailed())
|
---|
283 | {
|
---|
284 | obj = *oit;
|
---|
285 | obj->Mail();
|
---|
286 | ++ pvsSize;
|
---|
287 | pvs.push_back(obj);
|
---|
288 | }
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 | return pvsSize;
|
---|
293 | }
|
---|
294 |
|
---|
295 |
|
---|
296 | void QtGlRendererWidget::InitGL()
|
---|
297 | {
|
---|
298 | GlRenderer::InitGL();
|
---|
299 |
|
---|
300 | GLfloat mat_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};
|
---|
301 |
|
---|
302 | // mat_specular and mat_shininess are NOT default values
|
---|
303 | GLfloat mat_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
---|
304 | GLfloat mat_specular[] = {0.3f, 0.3f, 0.3f, 1.0f};
|
---|
305 | GLfloat mat_shininess[] = {1.0f};
|
---|
306 |
|
---|
307 | GLfloat light_ambient[] = {0.2f, 0.2f, 0.2f, 1.0f};
|
---|
308 | GLfloat light_diffuse[] = {0.4f, 0.4f, 0.4f, 1.0f};
|
---|
309 | GLfloat light_specular[] = {0.3f, 0.3f, 0.3f, 1.0f};
|
---|
310 |
|
---|
311 | GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
|
---|
312 |
|
---|
313 |
|
---|
314 | // default Material
|
---|
315 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
|
---|
316 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
|
---|
317 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
---|
318 | glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
---|
319 |
|
---|
320 | // a light
|
---|
321 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
---|
322 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
---|
323 | glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
---|
324 |
|
---|
325 | glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
---|
326 | glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
---|
327 | glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
---|
328 |
|
---|
329 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
---|
330 |
|
---|
331 | glEnable(GL_LIGHTING);
|
---|
332 | glEnable(GL_LIGHT0);
|
---|
333 | glEnable(GL_LIGHT1);
|
---|
334 |
|
---|
335 | // set position of the light
|
---|
336 | GLfloat infinite_light[] = { 1.0, 0.8, 1.0, 0.0 };
|
---|
337 | glLightfv (GL_LIGHT0, GL_POSITION, infinite_light);
|
---|
338 |
|
---|
339 | // set position of the light2
|
---|
340 | GLfloat infinite_light2[] = { -0.3, 1.5, 1.0, 0.0 };
|
---|
341 | glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
|
---|
342 |
|
---|
343 | glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
---|
344 | // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR);
|
---|
345 | glEnable(GL_COLOR_MATERIAL);
|
---|
346 |
|
---|
347 | glShadeModel(GL_FLAT);
|
---|
348 | }
|
---|
349 |
|
---|
350 |
|
---|
351 | void
|
---|
352 | QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle)
|
---|
353 | {
|
---|
354 | if (!mTopView) {
|
---|
355 | int ww = w;
|
---|
356 | int hh = h;
|
---|
357 | glViewport(0, 0, ww, hh);
|
---|
358 | glMatrixMode(GL_PROJECTION);
|
---|
359 | glLoadIdentity();
|
---|
360 | gluPerspective(angle, ww/(float)hh, 0.1, 2.0 * Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
361 | glMatrixMode(GL_MODELVIEW);
|
---|
362 | } else {
|
---|
363 | int ww = w;
|
---|
364 | int hh = h;
|
---|
365 | glViewport(0, 0, ww, hh);
|
---|
366 | glMatrixMode(GL_PROJECTION);
|
---|
367 | glLoadIdentity();
|
---|
368 | gluPerspective(50.0, ww / (float)hh, 0.1, 20.0 * Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
369 | glMatrixMode(GL_MODELVIEW);
|
---|
370 | }
|
---|
371 | }
|
---|
372 |
|
---|
373 |
|
---|
374 | bool QtGlRendererWidget::PvsChanged(ViewCell *viewCell) const
|
---|
375 | {
|
---|
376 | if (viewCell != mPvsCache.mViewCell)
|
---|
377 | return true;
|
---|
378 |
|
---|
379 | if (viewCell->GetPvs().GetSize() != mPvsCache.mUnfilteredPvsSize)
|
---|
380 | return true;
|
---|
381 |
|
---|
382 | return false;
|
---|
383 | }
|
---|
384 |
|
---|
385 |
|
---|
386 | void QtGlRendererWidget::_RenderPvs()
|
---|
387 | {
|
---|
388 |
|
---|
389 | #if TEST_PVS_RENDERING
|
---|
390 |
|
---|
391 | ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
|
---|
392 |
|
---|
393 | int pvsSize = mPvsCache.mPvs.GetSize();
|
---|
394 |
|
---|
395 | Intersectable::NewMail();
|
---|
396 | mCurrentFrame++;
|
---|
397 | while (it.HasMoreEntries())
|
---|
398 | {
|
---|
399 | RenderIntersectable(it.Next());
|
---|
400 | }
|
---|
401 |
|
---|
402 |
|
---|
403 | return;
|
---|
404 | #endif
|
---|
405 |
|
---|
406 | mUseFalseColors = false;
|
---|
407 |
|
---|
408 | int offset = (int)mObjects.size() * 3;
|
---|
409 | char *arrayPtr = mUseVbos ? NULL : (char *)mData;
|
---|
410 |
|
---|
411 | glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr);
|
---|
412 | glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
|
---|
413 | glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
|
---|
414 | #if DYNAMIC_OBJECTS_HACK
|
---|
415 | // handle dynamic objects
|
---|
416 | DynamicObjectsContainer::const_iterator dit, dit_end = mDynamicObjects.end();
|
---|
417 |
|
---|
418 |
|
---|
419 | for (dit = mDynamicObjects.begin(); dit != dit_end; ++ dit)
|
---|
420 | {
|
---|
421 | #if USE_TRANSFORMED_MESH_INSTANCE_HACK
|
---|
422 | //cerr << "here45\n****"<<endl;
|
---|
423 | RenderIntersectable(*dit);
|
---|
424 | #else
|
---|
425 | _RenderDynamicObject(*dit);
|
---|
426 | #endif
|
---|
427 | }
|
---|
428 | #endif
|
---|
429 | }
|
---|
430 |
|
---|
431 |
|
---|
432 | void QtGlRendererWidget::PreparePvs()
|
---|
433 | {
|
---|
434 | int indexBufferSize = 0;
|
---|
435 |
|
---|
436 | KdNode::NewMail();
|
---|
437 | //Intersectable::NewMail();
|
---|
438 |
|
---|
439 | mPvsSize = mPvsCache.mPvs.GetSize();
|
---|
440 | #if DYNAMIC_OBJECTS_HACK
|
---|
441 | mDynamicObjects.clear();
|
---|
442 | #endif
|
---|
443 | ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
|
---|
444 |
|
---|
445 | while (it.HasMoreEntries())
|
---|
446 | {
|
---|
447 | Intersectable *obj = it.Next();
|
---|
448 | switch (obj->Type())
|
---|
449 | {
|
---|
450 | case Intersectable::KD_INTERSECTABLE:
|
---|
451 | {
|
---|
452 | KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem();
|
---|
453 | _UpdatePvsIndices(node, indexBufferSize);
|
---|
454 | }
|
---|
455 | break;
|
---|
456 | #if DYNAMIC_OBJECTS_HACK
|
---|
457 | #if USE_TRANSFORMED_MESH_INSTANCE_HACK
|
---|
458 |
|
---|
459 | case Intersectable::TRANSFORMED_MESH_INSTANCE:
|
---|
460 | mDynamicObjects.push_back(static_cast<TransformedMeshInstance *>(obj));
|
---|
461 | break;
|
---|
462 |
|
---|
463 | #else
|
---|
464 | case Intersectable::SCENEGRAPHLEAF_INTERSECTABLE:
|
---|
465 | mDynamicObjects.push_back(static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem());
|
---|
466 | break;
|
---|
467 | #endif
|
---|
468 | #endif
|
---|
469 | default:
|
---|
470 | cerr << "PreparePvs: type " << Intersectable::GetTypeName(obj) << " not handled yet" << endl;
|
---|
471 | }
|
---|
472 | }
|
---|
473 |
|
---|
474 | mIndexBufferSize = indexBufferSize;
|
---|
475 | }
|
---|
476 |
|
---|
477 |
|
---|
478 |
|
---|
479 |
|
---|
480 | void QtGlRendererWidget::RenderPvs()
|
---|
481 | {
|
---|
482 | if (mUseVbos)
|
---|
483 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
|
---|
484 |
|
---|
485 | ++ mCurrentFrame;
|
---|
486 |
|
---|
487 | EnableDrawArrays();
|
---|
488 |
|
---|
489 | //Intersectable::NewMail();
|
---|
490 |
|
---|
491 | if (mDetectEmptyViewSpace)
|
---|
492 | glEnable(GL_CULL_FACE);
|
---|
493 | else
|
---|
494 | glDisable(GL_CULL_FACE);
|
---|
495 |
|
---|
496 | ViewCell *viewcell = NULL;
|
---|
497 | viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
|
---|
498 |
|
---|
499 | if (viewcell)
|
---|
500 | {
|
---|
501 | // copy the pvs so that it can be filtered ...
|
---|
502 | if (PvsChanged(viewcell))
|
---|
503 | {
|
---|
504 | mPvsCache.Reset();
|
---|
505 | mPvsCache.mViewCell = viewcell;
|
---|
506 | mPvsCache.mUnfilteredPvsSize = viewcell->GetPvs().GetSize();
|
---|
507 |
|
---|
508 | if (mUseSpatialFilter)
|
---|
509 | {
|
---|
510 | //mMutex.lock();
|
---|
511 | // mSpatialFilter size is in range 0.001 - 0.1
|
---|
512 | mViewCellsManager->ApplyFilter2(viewcell,
|
---|
513 | mUseFilter,
|
---|
514 | 100.0f * mSpatialFilterSize,
|
---|
515 | //pvs,
|
---|
516 | mPvsCache.mPvs,
|
---|
517 | &mPvsCache.filteredBoxes);
|
---|
518 | //mPvsCache.mPvs = pvs;
|
---|
519 | //mMutex.unlock();
|
---|
520 | cout << "pvs size: " << mPvsCache.mPvs.GetSize() << endl;
|
---|
521 | }
|
---|
522 | else
|
---|
523 | {
|
---|
524 | mPvsCache.mPvs = viewcell->GetPvs();
|
---|
525 | }
|
---|
526 |
|
---|
527 | /// update the indices for rendering
|
---|
528 | PreparePvs();
|
---|
529 |
|
---|
530 | emit PvsUpdated();
|
---|
531 | }
|
---|
532 |
|
---|
533 |
|
---|
534 | // Render PVS
|
---|
535 | if (mUseSpatialFilter && mRenderBoxes)
|
---|
536 | {
|
---|
537 | for (int i=0; i < mPvsCache.filteredBoxes.size(); ++ i)
|
---|
538 | {
|
---|
539 | RenderBox(mPvsCache.filteredBoxes[i]);
|
---|
540 | }
|
---|
541 | }
|
---|
542 | else
|
---|
543 | {
|
---|
544 | if (!mRenderVisibilityEstimates && !mUseRandomColorPerPvsObject)
|
---|
545 | _RenderPvs();
|
---|
546 | else
|
---|
547 | _RenderColoredPvs();
|
---|
548 | }
|
---|
549 |
|
---|
550 | if (mRenderFilter)
|
---|
551 | {
|
---|
552 | mWireFrame = true;
|
---|
553 | RenderIntersectable(viewcell);
|
---|
554 |
|
---|
555 | /*glPushMatrix();
|
---|
556 | glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z);
|
---|
557 | glScalef(5.0f,5.0f,5.0f);
|
---|
558 | glPushAttrib(GL_CURRENT_BIT);
|
---|
559 | glColor3f(1.0f, 0.0f, 0.0f);
|
---|
560 | // gluSphere((::GLUquadric *)mSphere,
|
---|
561 | // 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6);
|
---|
562 | glPopAttrib();
|
---|
563 | glPopMatrix();
|
---|
564 | */
|
---|
565 | mWireFrame = false;
|
---|
566 | }
|
---|
567 | }
|
---|
568 | else
|
---|
569 | {
|
---|
570 | //ObjectContainer::const_iterator oi = mObjects.begin();
|
---|
571 | //for (; oi != mObjects.end(); oi++)
|
---|
572 | // RenderIntersectable(*oi);
|
---|
573 | RenderScene();
|
---|
574 | }
|
---|
575 | }
|
---|
576 |
|
---|
577 | float
|
---|
578 | QtGlRendererWidget::RenderErrors()
|
---|
579 | {
|
---|
580 | float pErrorPixels = -1.0f;
|
---|
581 |
|
---|
582 | SetupCamera();
|
---|
583 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
584 |
|
---|
585 | glPushAttrib(GL_ENABLE_BIT);
|
---|
586 |
|
---|
587 | glStencilFunc(GL_EQUAL, 0x0, 0x1);
|
---|
588 | glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
---|
589 |
|
---|
590 | mUseForcedColors = true;
|
---|
591 |
|
---|
592 | glColor3f(0.0f, 0.8f, 0.2f);
|
---|
593 |
|
---|
594 | // Render PVS
|
---|
595 | RenderPvs();
|
---|
596 |
|
---|
597 | glEnable(GL_STENCIL_TEST);
|
---|
598 |
|
---|
599 | //mUseFalseColors = true;
|
---|
600 |
|
---|
601 | glDisable(GL_LIGHTING);
|
---|
602 |
|
---|
603 | OcclusionQuery *query = mOcclusionQueries[0];
|
---|
604 | query->BeginQuery();
|
---|
605 |
|
---|
606 | SetupCamera();
|
---|
607 |
|
---|
608 | glColor3f(1.0f, 0.0f, 0.0f);
|
---|
609 |
|
---|
610 | RenderScene();
|
---|
611 |
|
---|
612 | mUseForcedColors = false;
|
---|
613 |
|
---|
614 | query->EndQuery();
|
---|
615 |
|
---|
616 | glDisable(GL_STENCIL_TEST);
|
---|
617 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
618 |
|
---|
619 | glPopAttrib();
|
---|
620 |
|
---|
621 | // reenable other state
|
---|
622 | // int wait=0;
|
---|
623 | // while (!query.ResultAvailable()) {
|
---|
624 | // wait++;
|
---|
625 | // }
|
---|
626 |
|
---|
627 | int pixelCount = query->GetQueryResult();
|
---|
628 | pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
|
---|
629 | if (0) cout<<"error pixels="<<pixelCount<<endl;
|
---|
630 |
|
---|
631 | mRenderError = pErrorPixels;
|
---|
632 |
|
---|
633 | return pErrorPixels;
|
---|
634 | }
|
---|
635 |
|
---|
636 |
|
---|
637 | void QtGlRendererWidget::timerEvent(QTimerEvent *event)
|
---|
638 | {
|
---|
639 | //std::cout << "Timer ID:" << event->timerId();
|
---|
640 | update();
|
---|
641 | }
|
---|
642 |
|
---|
643 |
|
---|
644 | void QtGlRendererWidget::mousePressEvent(QMouseEvent *e)
|
---|
645 | {
|
---|
646 | int x = e->pos().x();
|
---|
647 | int y = e->pos().y();
|
---|
648 |
|
---|
649 | mousePoint.x = x;
|
---|
650 | mousePoint.y = y;
|
---|
651 |
|
---|
652 | }
|
---|
653 |
|
---|
654 | void
|
---|
655 | QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e)
|
---|
656 | {
|
---|
657 | float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3;
|
---|
658 | float TURN_SENSITIVITY = 0.1f;
|
---|
659 | float TILT_SENSITIVITY = 32.0 ;
|
---|
660 | float TURN_ANGLE= M_PI /36.0 ;
|
---|
661 |
|
---|
662 | int x = e->pos().x();
|
---|
663 | int y = e->pos().y();
|
---|
664 |
|
---|
665 | int diffx = -(mousePoint.x - x);
|
---|
666 | int diffy = -(mousePoint.y - y);
|
---|
667 |
|
---|
668 | const float t = 1.0f;
|
---|
669 |
|
---|
670 | if (e->modifiers() & Qt::ControlModifier)
|
---|
671 | {
|
---|
672 | mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY / 2.0;
|
---|
673 | mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY / 2.0;
|
---|
674 | }
|
---|
675 | #if DYNAMIC_OBJECTS_HACK
|
---|
676 | else if (e->modifiers() & Qt::AltModifier)
|
---|
677 | {
|
---|
678 | if (mCurrentDynamicObjectIdx >= 0)
|
---|
679 | {
|
---|
680 | Matrix4x4 tm;
|
---|
681 |
|
---|
682 | switch (mTrafoType)
|
---|
683 | {
|
---|
684 | case 0:
|
---|
685 | {
|
---|
686 | const Vector3 transl(diffx, 0, diffy);
|
---|
687 |
|
---|
688 | tm = TranslationMatrix(transl);
|
---|
689 | }
|
---|
690 | break;
|
---|
691 | case 1:
|
---|
692 | {
|
---|
693 | float scalef = 1.0f + 0.01f * (diffx + diffy);
|
---|
694 | if (scalef < 0.9) scalef = 0.9f;
|
---|
695 | else if (scalef > 1.1f) scalef = 1.1f;
|
---|
696 | tm = ScaleMatrix(scalef, scalef, scalef);
|
---|
697 | }
|
---|
698 | break;
|
---|
699 | case 2:
|
---|
700 | {
|
---|
701 | tm = RotationXMatrix(diffx) * RotationYMatrix(diffy);
|
---|
702 | }
|
---|
703 | break;
|
---|
704 | default:
|
---|
705 | cerr << "not implemented" << endl;
|
---|
706 | }
|
---|
707 |
|
---|
708 | #if USE_TRANSFORMED_MESH_INSTANCE_HACK
|
---|
709 | TransformedMeshInstance *tmi = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
|
---|
710 | tmi->ApplyWorldTransform(tm);
|
---|
711 | #else
|
---|
712 | SceneGraphLeaf *l = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
|
---|
713 | l->ApplyTransform(tm);
|
---|
714 | #endif
|
---|
715 | updateGL();
|
---|
716 | }
|
---|
717 | }
|
---|
718 | #endif
|
---|
719 | else
|
---|
720 | {
|
---|
721 | mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
|
---|
722 | float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
|
---|
723 | float angle = atan2(mViewDirection.x, mViewDirection.z);
|
---|
724 | mViewDirection.x = sin(angle + adiff);
|
---|
725 | mViewDirection.z = cos(angle + adiff);
|
---|
726 | }
|
---|
727 |
|
---|
728 | mousePoint.x = x;
|
---|
729 | mousePoint.y = y;
|
---|
730 |
|
---|
731 | updateGL();
|
---|
732 | }
|
---|
733 |
|
---|
734 | void
|
---|
735 | QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *)
|
---|
736 | {
|
---|
737 | }
|
---|
738 |
|
---|
739 | void
|
---|
740 | QtGlRendererWidget::resizeGL(int w, int h)
|
---|
741 | {
|
---|
742 | SetupCameraProjection(w, h);
|
---|
743 | updateGL();
|
---|
744 | }
|
---|
745 |
|
---|
746 | void
|
---|
747 | QtGlRendererWidget::paintGL()
|
---|
748 | {
|
---|
749 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
750 |
|
---|
751 | if (1)
|
---|
752 | {
|
---|
753 | SetupCameraProjection(width(), height());
|
---|
754 | SetupCamera();
|
---|
755 |
|
---|
756 | if (mRenderErrors)
|
---|
757 | {
|
---|
758 | RenderErrors();
|
---|
759 | }
|
---|
760 | else
|
---|
761 | {
|
---|
762 | glColor3f(0.6f, 0.6f, 0.6f);
|
---|
763 | RenderPvs();
|
---|
764 | }
|
---|
765 |
|
---|
766 | if (1 && mShowRays)
|
---|
767 | {
|
---|
768 | RenderRays(mViewCellsManager->mVizBuffer.GetRays(), mRayVisualizationMethod, mShowDistribution, 1);
|
---|
769 | }
|
---|
770 | }
|
---|
771 |
|
---|
772 | RenderInfo();
|
---|
773 | mFrame ++;
|
---|
774 | }
|
---|
775 |
|
---|
776 |
|
---|
777 | void
|
---|
778 | QtGlRendererWidget::SetupCamera()
|
---|
779 | {
|
---|
780 | if (!mTopView)
|
---|
781 | GlRenderer::SetupCamera();
|
---|
782 | else
|
---|
783 | {
|
---|
784 | if (0)
|
---|
785 | {
|
---|
786 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05;
|
---|
787 | Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x,
|
---|
788 | -1,
|
---|
789 | mViewDirection.y);
|
---|
790 |
|
---|
791 | Vector3 target = mViewPoint + dist*mViewDirection;
|
---|
792 | Vector3 up(0,1,0);
|
---|
793 |
|
---|
794 | glLoadIdentity();
|
---|
795 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
796 | target.x, target.y, target.z,
|
---|
797 | up.x, up.y, up.z);
|
---|
798 | }
|
---|
799 | else
|
---|
800 | {
|
---|
801 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal()) * mTopDistance;
|
---|
802 | Vector3 pos = mViewPoint + dist*Vector3(0,
|
---|
803 | 1,
|
---|
804 | 0);
|
---|
805 |
|
---|
806 | Vector3 target = mViewPoint;
|
---|
807 | Vector3 up(mViewDirection.x, 0, mViewDirection.z);
|
---|
808 |
|
---|
809 | glLoadIdentity();
|
---|
810 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
811 | target.x, target.y, target.z,
|
---|
812 | up.x, up.y, up.z);
|
---|
813 |
|
---|
814 | }
|
---|
815 | }
|
---|
816 |
|
---|
817 | }
|
---|
818 |
|
---|
819 |
|
---|
820 | void
|
---|
821 | QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
|
---|
822 | {
|
---|
823 | switch (e->key())
|
---|
824 | {
|
---|
825 | case Qt::Key_E:
|
---|
826 | mRenderErrors = !mRenderErrors;
|
---|
827 | updateGL();
|
---|
828 | break;
|
---|
829 | case Qt::Key_R:
|
---|
830 | mUseRandomColorPerPvsObject = !mUseRandomColorPerPvsObject;;
|
---|
831 | updateGL();
|
---|
832 | break;
|
---|
833 | case Qt::Key_T:
|
---|
834 | mTopView = !mTopView;
|
---|
835 | SetupCameraProjection(width(), height());
|
---|
836 | updateGL();
|
---|
837 | break;
|
---|
838 | case Qt::Key_V:
|
---|
839 | mRenderViewCells = !mRenderViewCells;
|
---|
840 | updateGL();
|
---|
841 | break;
|
---|
842 | case Qt::Key_P:
|
---|
843 | // set random viewpoint
|
---|
844 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
845 | updateGL();
|
---|
846 | break;
|
---|
847 | case Qt::Key_S: {
|
---|
848 | // set view poitn and direction
|
---|
849 | QString text;
|
---|
850 | bool ok;
|
---|
851 | text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z);
|
---|
852 | text = QInputDialog::getText(this,
|
---|
853 | "Enter a view point",
|
---|
854 | "",
|
---|
855 | QLineEdit::Normal,
|
---|
856 | text,
|
---|
857 | &ok);
|
---|
858 | if (!ok)
|
---|
859 | break;
|
---|
860 |
|
---|
861 | if (sscanf(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) {
|
---|
862 | text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z);
|
---|
863 | text = QInputDialog::getText(this,
|
---|
864 | "Enter a direction",
|
---|
865 | "",
|
---|
866 | QLineEdit::Normal,
|
---|
867 | text,
|
---|
868 | &ok);
|
---|
869 | if (!ok)
|
---|
870 | break;
|
---|
871 | if (sscanf(text.toAscii(), "%f %f %f", &mViewDirection.x,
|
---|
872 | &mViewDirection.y, &mViewDirection.z) == 3) {
|
---|
873 | updateGL();
|
---|
874 | }
|
---|
875 | break;
|
---|
876 | }
|
---|
877 | }
|
---|
878 | default:
|
---|
879 | cerr << "unknown key" << endl;
|
---|
880 | e->ignore();
|
---|
881 | break;
|
---|
882 | }
|
---|
883 | }
|
---|
884 |
|
---|
885 |
|
---|
886 |
|
---|
887 | QtGlRendererWidget::QtGlRendererWidget(
|
---|
888 | SceneGraph *sceneGraph,
|
---|
889 | ViewCellsManager *viewcells,
|
---|
890 | KdTree *tree,
|
---|
891 | QWidget * parent,
|
---|
892 | const QGLWidget * shareWidget,
|
---|
893 | Qt::WFlags f
|
---|
894 | )
|
---|
895 | :
|
---|
896 | GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
|
---|
897 | {
|
---|
898 | mPreprocessorThread = NULL;
|
---|
899 | mTopView = false;
|
---|
900 | mRenderViewCells = false;
|
---|
901 | mTopDistance = 1.0f;
|
---|
902 | mCutViewCells = false;
|
---|
903 | mCutScene = false;
|
---|
904 | mRenderErrors = false;
|
---|
905 | mRenderBoxes = false;
|
---|
906 | mRenderFilter = true;
|
---|
907 | mRenderVisibilityEstimates = false;
|
---|
908 |
|
---|
909 | mUseRandomColorPerPvsObject = false;
|
---|
910 |
|
---|
911 | mHideByCost = false;
|
---|
912 | mUseTransparency = false;
|
---|
913 |
|
---|
914 | mTransferFunction = 1.0f;
|
---|
915 | mIndexBufferSize = 0;
|
---|
916 |
|
---|
917 | //mCurrentFrame = 0;
|
---|
918 |
|
---|
919 | const int delay = 250; // in milliseconds
|
---|
920 | timerId = startTimer(delay);
|
---|
921 |
|
---|
922 | bool tmp;
|
---|
923 |
|
---|
924 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
925 | mUseFilter = tmp;
|
---|
926 |
|
---|
927 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", tmp );
|
---|
928 | mUseSpatialFilter = tmp;
|
---|
929 |
|
---|
930 | //mLogWriter = new LogWriter("myfile.out");
|
---|
931 |
|
---|
932 | mShowRenderCost = false;
|
---|
933 | mShowPvsSizes = false;
|
---|
934 | mShowComparison = false;
|
---|
935 | mShowPiercingRays = false;
|
---|
936 | mShowWeightedRays = false;
|
---|
937 | mUseStandardColors = false;
|
---|
938 | mShowWeightedCost = true;
|
---|
939 |
|
---|
940 | mShowDistanceWeightedPvs = true;
|
---|
941 | mShowDistanceWeightedTriangles = false;
|
---|
942 | mShowWeightedTriangles = false;
|
---|
943 | mShowDistribution = 15;
|
---|
944 | mCurrentDynamicObjectIdx = -1;
|
---|
945 |
|
---|
946 | mSpatialFilterSize = 0.01;
|
---|
947 | mPvsSize = 0;
|
---|
948 | mRayVisualizationMethod = 0;
|
---|
949 | mTrafoType = 0;
|
---|
950 |
|
---|
951 | mRenderError = 0.0f;
|
---|
952 | mShowRays = false;
|
---|
953 |
|
---|
954 | mControlWidget = new QtRendererControlWidget(NULL);
|
---|
955 |
|
---|
956 | connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
|
---|
957 | connect(mControlWidget, SIGNAL(SetTransferFunction(int)), this, SLOT(SetTransferFunction(int)));
|
---|
958 |
|
---|
959 | connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs()));
|
---|
960 | connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility()));
|
---|
961 | connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation()));
|
---|
962 | connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this, SLOT(SetRandomViewPoint()));
|
---|
963 | connect(mControlWidget, SIGNAL(StoreStatistics(void)), this, SLOT(StoreStatistics(void)));
|
---|
964 | connect(mControlWidget, SIGNAL(LoadObject(void)), this, SLOT(LoadObject(void)));
|
---|
965 |
|
---|
966 | connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
|
---|
967 | connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
|
---|
968 | connect(mControlWidget, SIGNAL(SetTransparency(int)), this, SLOT(SetTransparency(int)));
|
---|
969 |
|
---|
970 | connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
|
---|
971 | connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int)));
|
---|
972 | connect(mControlWidget, SIGNAL(SetHidingCost(int)), this, SLOT(SetHidingCost(int)));
|
---|
973 |
|
---|
974 | connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
|
---|
975 | connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool)));
|
---|
976 | connect(mControlWidget, SIGNAL(SetUseTransparency(bool)), this, SLOT(SetUseTransparency(bool)));
|
---|
977 | connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool)));
|
---|
978 | connect(mControlWidget, SIGNAL(SetShowComparison(bool)), this, SLOT(SetShowComparison(bool)));
|
---|
979 | connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
|
---|
980 | connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
|
---|
981 | connect(mControlWidget, SIGNAL(SetHideByCost(bool)), this, SLOT(SetHideByCost(bool)));
|
---|
982 | connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
|
---|
983 | connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
|
---|
984 | connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool)));
|
---|
985 | connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
|
---|
986 | connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)), this, SLOT(SetRenderVisibilityEstimates(bool)));
|
---|
987 | connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool)));
|
---|
988 | connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)), this, SLOT(SetUseSpatialFilter(bool)));
|
---|
989 | connect(mControlWidget, SIGNAL(SetShowPiercingRays(bool)), this, SLOT(SetShowPiercingRays(bool)));
|
---|
990 | connect(mControlWidget, SIGNAL(SetShowWireFrame(bool)), this, SLOT(SetShowWireFrame(bool)));
|
---|
991 | connect(mControlWidget, SIGNAL(SetShowWeightedRays(bool)), this, SLOT(SetShowWeightedRays(bool)));
|
---|
992 | connect(mControlWidget, SIGNAL(SetShowWeightedCost(bool)), this, SLOT(SetShowWeightedCost(bool)));
|
---|
993 |
|
---|
994 | connect(mControlWidget, SIGNAL(SetShowDistanceWeightedTriangles(bool)), this, SLOT(SetShowDistanceWeightedTriangles(bool)));
|
---|
995 | connect(mControlWidget, SIGNAL(SetShowDistanceWeightedPvs(bool)), this, SLOT(SetShowDistanceWeightedPvs(bool)));
|
---|
996 | connect(mControlWidget, SIGNAL(SetShowWeightedTriangles(bool)), this, SLOT(SetShowWeightedTriangles(bool)));
|
---|
997 |
|
---|
998 | connect(mControlWidget, SIGNAL(UseConstColorForRayViz(bool)), this, SLOT(UseConstColorForRayViz(bool)));
|
---|
999 | connect(mControlWidget, SIGNAL(UseRayLengthForRayViz(bool)), this, SLOT(UseRayLengthForRayViz(bool)));
|
---|
1000 | connect(mControlWidget, SIGNAL(SetShowContribution(bool)), this, SLOT(SetShowContribution(bool)));
|
---|
1001 | connect(mControlWidget, SIGNAL(SetShowDistribution(bool)), this, SLOT(SetShowDistribution(bool)));
|
---|
1002 |
|
---|
1003 | connect(mControlWidget, SIGNAL(SetShowDistribution1(bool)), this, SLOT(SetShowDistribution1(bool)));
|
---|
1004 | connect(mControlWidget, SIGNAL(SetShowDistribution2(bool)), this, SLOT(SetShowDistribution2(bool)));
|
---|
1005 | connect(mControlWidget, SIGNAL(SetShowDistribution3(bool)), this, SLOT(SetShowDistribution3(bool)));
|
---|
1006 | connect(mControlWidget, SIGNAL(SetShowDistribution4(bool)), this, SLOT(SetShowDistribution4(bool)));
|
---|
1007 |
|
---|
1008 | connect(mControlWidget, SIGNAL(SetShowRays(bool)), this, SLOT(SetShowRays(bool)));
|
---|
1009 |
|
---|
1010 | connect(mControlWidget, SIGNAL(SetTranslation(bool)), this, SLOT(SetTranslation(bool)));
|
---|
1011 | connect(mControlWidget, SIGNAL(SetRotation(bool)), this, SLOT(SetRotation(bool)));
|
---|
1012 | connect(mControlWidget, SIGNAL(SetScale(bool)), this, SLOT(SetScale(bool)));
|
---|
1013 |
|
---|
1014 | setWindowTitle("PVS Visualization");
|
---|
1015 |
|
---|
1016 | // setting the main window size here
|
---|
1017 | //resize(800, 600);
|
---|
1018 | //resize(640, 480);
|
---|
1019 | //resize(512, 384);
|
---|
1020 | //resize(512, 320);
|
---|
1021 | resize(640, 400);
|
---|
1022 |
|
---|
1023 | mControlWidget->show();
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | void
|
---|
1027 | QtGlRendererWidget::UpdateAllPvs()
|
---|
1028 | {
|
---|
1029 | // $$ does not work so far:(
|
---|
1030 | mViewCellsManager->UpdatePvsForEvaluation();
|
---|
1031 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | void
|
---|
1035 | QtGlRendererWidget::ComputeVisibility()
|
---|
1036 | {
|
---|
1037 | cerr<<"Compute Visibility called!\n"<<endl;
|
---|
1038 | if (!mPreprocessorThread->isRunning())
|
---|
1039 | mPreprocessorThread->RunThread();
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | void
|
---|
1043 | QtGlRendererWidget::StopComputation()
|
---|
1044 | {
|
---|
1045 | cerr<<"stop computation called!\n"<<endl;
|
---|
1046 | mViewCellsManager->GetPreprocessor()->mStopComputation = true;
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 | void
|
---|
1050 | QtGlRendererWidget::SetRandomViewPoint()
|
---|
1051 | {
|
---|
1052 | cerr<<"setting random view point!\n"<<endl;
|
---|
1053 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
1054 | updateGL();
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 |
|
---|
1058 | void QtGlRendererWidget::StoreStatistics()
|
---|
1059 | {
|
---|
1060 | cerr<<"storing statistics!\n"<<endl;
|
---|
1061 | const int currentSamples = mViewCellsManager->GetPreprocessor()->mCurrentSamples;
|
---|
1062 |
|
---|
1063 | cout<<"**********************************************" << endl;
|
---|
1064 | cout << "reached " << currentSamples << " samples " << " => writing file" << endl;
|
---|
1065 |
|
---|
1066 | LogWriter writer;
|
---|
1067 | writer.SetFilename("compare.log");
|
---|
1068 | writer.Write(currentSamples, mViewCellsManager->GetViewCells());
|
---|
1069 | cout << "finished writing file" << endl;
|
---|
1070 | mCompareInfo.clear();
|
---|
1071 | updateGL();
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 |
|
---|
1075 | void QtGlRendererWidget::LoadObject()
|
---|
1076 | {
|
---|
1077 | string filename("../data/teapot.bn");
|
---|
1078 |
|
---|
1079 | cout << "Loading model << " << filename << endl;
|
---|
1080 |
|
---|
1081 | ++ mCurrentDynamicObjectIdx;
|
---|
1082 |
|
---|
1083 | if (mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename))
|
---|
1084 | cout << "Loading finished" << endl;
|
---|
1085 | else
|
---|
1086 | cerr << "Loading failed" << endl;
|
---|
1087 |
|
---|
1088 | updateGL();
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | void
|
---|
1092 | QtGlRendererWidget::RenderRenderCost()
|
---|
1093 | {
|
---|
1094 | static vector<float> costFunction;
|
---|
1095 | static float maxCost = -1;
|
---|
1096 | if (costFunction.size()==0) {
|
---|
1097 | ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree();
|
---|
1098 | if (tree) {
|
---|
1099 | tree->GetCostFunction(costFunction);
|
---|
1100 | maxCost = -1;
|
---|
1101 | for (int i=0; i < costFunction.size(); i++) {
|
---|
1102 | // cout<<i<<":"<<costFunction[i]<<" ";
|
---|
1103 | // update cost function to an absolute value based on the total geometry count
|
---|
1104 | costFunction[i] *= mSceneGraph->GetSize();
|
---|
1105 | if (costFunction[i] > maxCost)
|
---|
1106 | maxCost = costFunction[i];
|
---|
1107 | }
|
---|
1108 | }
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 |
|
---|
1112 | int currentPos = (int)mViewCellsManager->GetViewCells().size();
|
---|
1113 | float currentCost= -1;
|
---|
1114 |
|
---|
1115 | if (currentPos < costFunction.size())
|
---|
1116 | currentCost = costFunction[currentPos];
|
---|
1117 | #if 1
|
---|
1118 | cout<<"costFunction.size()="<<(int)costFunction.size()<<endl;
|
---|
1119 | cout<<"CP="<<currentPos<<endl;
|
---|
1120 | cout<<"MC="<<maxCost<<endl;
|
---|
1121 | cout<<"CC="<<currentCost<<endl;
|
---|
1122 | #endif
|
---|
1123 | if (costFunction.size()) {
|
---|
1124 | float scaley = 1.0f/log10(maxCost);
|
---|
1125 | float scalex = 1.0f/(float)costFunction.size();
|
---|
1126 |
|
---|
1127 | glDisable(GL_DEPTH_TEST);
|
---|
1128 | // init ortographic projection
|
---|
1129 | glMatrixMode(GL_PROJECTION);
|
---|
1130 |
|
---|
1131 | glPushMatrix();
|
---|
1132 |
|
---|
1133 | glLoadIdentity();
|
---|
1134 | gluOrtho2D(0, 1.0f, 0, 1.0f);
|
---|
1135 |
|
---|
1136 | glTranslatef(0.1f, 0.1f, 0.0f);
|
---|
1137 | glScalef(0.8f, 0.8f, 1.0f);
|
---|
1138 | glMatrixMode(GL_MODELVIEW);
|
---|
1139 | glLoadIdentity();
|
---|
1140 |
|
---|
1141 | glColor3f(1.0f,0,0);
|
---|
1142 | glBegin(GL_LINE_STRIP);
|
---|
1143 | // glVertex3f(0,0,0);
|
---|
1144 |
|
---|
1145 | for (int i=0; i < costFunction.size(); i++) {
|
---|
1146 | float x = i*scalex;
|
---|
1147 | float y = log10(costFunction[i])*scaley;
|
---|
1148 | glVertex3f(x,y,0.0f);
|
---|
1149 | }
|
---|
1150 | glEnd();
|
---|
1151 |
|
---|
1152 | glColor3f(1.0f,0,0);
|
---|
1153 | glBegin(GL_LINES);
|
---|
1154 | float x = currentPos*scalex;
|
---|
1155 | glVertex3f(x,0.0,0.0f);
|
---|
1156 | glVertex3f(x,1.0f,0.0f);
|
---|
1157 | glEnd();
|
---|
1158 |
|
---|
1159 | glColor3f(0.0f,0,0);
|
---|
1160 | // show a grid
|
---|
1161 | glBegin(GL_LINE_LOOP);
|
---|
1162 | glVertex3f(0,0,0.0f);
|
---|
1163 | glVertex3f(1,0,0.0f);
|
---|
1164 | glVertex3f(1,1,0.0f);
|
---|
1165 | glVertex3f(0,1,0.0f);
|
---|
1166 | glEnd();
|
---|
1167 |
|
---|
1168 | glBegin(GL_LINES);
|
---|
1169 | for (int i=0; i < costFunction.size(); i += 1000) {
|
---|
1170 | float x = i*scalex;
|
---|
1171 | glVertex3f(x,0.0,0.0f);
|
---|
1172 | glVertex3f(x,1.0f,0.0f);
|
---|
1173 | }
|
---|
1174 |
|
---|
1175 | for (int i=0; pow(10.0f, i) < maxCost; i+=1) {
|
---|
1176 | float y = i*scaley;
|
---|
1177 | // QString s;
|
---|
1178 | // s.sprintf("%d", (int)pow(10,i));
|
---|
1179 | // renderText(width()/2+5, y*height(), s);
|
---|
1180 | glVertex3f(0.0f, y, 0.0f);
|
---|
1181 | glVertex3f(1.0f, y, 0.0f);
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | glEnd();
|
---|
1185 |
|
---|
1186 |
|
---|
1187 | // restore the projection matrix
|
---|
1188 | glMatrixMode(GL_PROJECTION);
|
---|
1189 | glPopMatrix();
|
---|
1190 | glMatrixMode(GL_MODELVIEW);
|
---|
1191 | glEnable(GL_DEPTH_TEST);
|
---|
1192 |
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 |
|
---|
1196 |
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | void
|
---|
1200 | QtGlRendererWidget::RenderInfo()
|
---|
1201 | {
|
---|
1202 |
|
---|
1203 | QString s;
|
---|
1204 |
|
---|
1205 | int vc = 0;
|
---|
1206 | if (mViewCellsManager)
|
---|
1207 | vc = (int)mViewCellsManager->GetViewCells().size();
|
---|
1208 |
|
---|
1209 | int filter = 0;
|
---|
1210 | if (mViewCellsManager)
|
---|
1211 | filter = mViewCellsManager->GetMaxFilterSize();
|
---|
1212 |
|
---|
1213 | glColor3f(0.0f, 0.0f, 1.0f);
|
---|
1214 |
|
---|
1215 | #if REMOVE_TEMPORARY
|
---|
1216 | s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)",
|
---|
1217 | mFrame,
|
---|
1218 | mViewPoint.x,
|
---|
1219 | mViewPoint.y,
|
---|
1220 | mViewPoint.z,
|
---|
1221 | mViewDirection.x,
|
---|
1222 | mViewDirection.y,
|
---|
1223 | mViewDirection.z
|
---|
1224 | );
|
---|
1225 |
|
---|
1226 | renderText(20, 20, s);
|
---|
1227 |
|
---|
1228 | s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f %",
|
---|
1229 | vc,
|
---|
1230 | filter,
|
---|
1231 | mPvsSize,
|
---|
1232 | mRenderError*100.0f);
|
---|
1233 |
|
---|
1234 | renderText(20, 40, s);
|
---|
1235 | #endif
|
---|
1236 |
|
---|
1237 | QFont font40; font40.setPointSize(30);
|
---|
1238 | s.sprintf("PVS: %04d", mPvsSize);
|
---|
1239 | renderText(20, 40, s, font40);
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 |
|
---|
1243 | void
|
---|
1244 | QtGlRendererWidget::SetViewCellGranularity(int number)
|
---|
1245 | {
|
---|
1246 | if (mViewCellsManager) {
|
---|
1247 | // mViewCellsManager->SetMaxFilterSize(number);
|
---|
1248 |
|
---|
1249 | // $$ tmp off
|
---|
1250 | mViewCellsManager->CollectViewCells(number);
|
---|
1251 |
|
---|
1252 | // $$ does not work so far:(
|
---|
1253 | // mViewCellsManager->UpdatePvsForEvaluation();
|
---|
1254 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
1255 | }
|
---|
1256 | updateGL();
|
---|
1257 | }
|
---|
1258 |
|
---|
1259 | void
|
---|
1260 | QtGlRendererWidget::SetVisibilityFilterSize(int number)
|
---|
1261 | {
|
---|
1262 | if (mViewCellsManager)
|
---|
1263 | mViewCellsManager->SetMaxFilterSize(number);
|
---|
1264 | mPvsCache.Reset();
|
---|
1265 | updateGL();
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | void
|
---|
1269 | QtGlRendererWidget::SetSpatialFilterSize(int number)
|
---|
1270 | {
|
---|
1271 | mSpatialFilterSize = 1e-3*number;
|
---|
1272 | mPvsCache.Reset();
|
---|
1273 | updateGL();
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | void
|
---|
1277 | QtGlRendererWidget::SetSceneCut(int number)
|
---|
1278 | {
|
---|
1279 | // assume the cut plane can only be aligned with xz plane
|
---|
1280 | // shift it along y according to number, which is percentage of the bounding
|
---|
1281 | // box position
|
---|
1282 | if (mViewCellsManager)
|
---|
1283 | {
|
---|
1284 | const float f = number / 1000.0f;
|
---|
1285 | AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
|
---|
1286 | Vector3 p = (1.0f - f) * box.Min() + f * box.Max();
|
---|
1287 | mSceneCutPlane.mNormal = Vector3(0,-1,0);
|
---|
1288 | mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p);
|
---|
1289 |
|
---|
1290 | updateGL();
|
---|
1291 | }
|
---|
1292 | }
|
---|
1293 |
|
---|
1294 | void
|
---|
1295 | QtGlRendererWidget::SetHidingCost(int number)
|
---|
1296 | {
|
---|
1297 | mHidingCost = (float)number / 1000.0f;
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 |
|
---|
1301 | void
|
---|
1302 | QtGlRendererWidget::SetTopDistance(int number)
|
---|
1303 | {
|
---|
1304 | mTopDistance = number / 1000.0f;
|
---|
1305 | updateGL();
|
---|
1306 | }
|
---|
1307 |
|
---|
1308 | void QtGlRendererWidget::SetTransparency(int number)
|
---|
1309 | {
|
---|
1310 | mTransparency = number / 1000.0f;
|
---|
1311 | updateGL();
|
---|
1312 | }
|
---|
1313 |
|
---|
1314 | #if 0
|
---|
1315 | float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc)
|
---|
1316 | {
|
---|
1317 | ObjectPvs basePvs;
|
---|
1318 |
|
---|
1319 | basePvs = vc->CopyPvs();
|
---|
1320 | ObjectPvsIterator pit = basePvs.GetIterator();
|
---|
1321 |
|
---|
1322 | float renderCost = 0;
|
---|
1323 |
|
---|
1324 | //cout << "cost vis: " << mShowDistanceWeightedPvs << " " << " " << mShowDistanceWeightedTriangles << " " << mShowWeightedTriangles << endl;
|
---|
1325 |
|
---|
1326 | // first mark all objects from this pvs
|
---|
1327 | while (pit.HasMoreEntries())
|
---|
1328 | {
|
---|
1329 | KdIntersectable *kdObj = static_cast<KdIntersectable *>(pit.Next());
|
---|
1330 |
|
---|
1331 | if (mShowDistanceWeightedPvs)
|
---|
1332 | {
|
---|
1333 | const AxisAlignedBox3 box = kdObj->GetBox();
|
---|
1334 |
|
---|
1335 | const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
|
---|
1336 | renderCost += 1.0f / dist;
|
---|
1337 | }
|
---|
1338 | else if (mShowDistanceWeightedTriangles)
|
---|
1339 | {
|
---|
1340 | const AxisAlignedBox3 box = kdObj->GetBox();
|
---|
1341 |
|
---|
1342 | const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
|
---|
1343 | renderCost += kdObj->ComputeNumTriangles() / dist;
|
---|
1344 | }
|
---|
1345 | else //if (mShowWeightedTriangles)
|
---|
1346 | {
|
---|
1347 | renderCost += kdObj->ComputeNumTriangles();
|
---|
1348 | }
|
---|
1349 | //if (pit.Next()->Mail();
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 | return renderCost;
|
---|
1353 | }
|
---|
1354 | #else
|
---|
1355 |
|
---|
1356 | float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc)
|
---|
1357 | {
|
---|
1358 | float renderCost = 0;
|
---|
1359 |
|
---|
1360 | #ifndef USE_BIT_PVS
|
---|
1361 | if (mShowDistanceWeightedPvs)
|
---|
1362 | {
|
---|
1363 | return vc->GetPvs().mStats.mDistanceWeightedPvs;
|
---|
1364 | }
|
---|
1365 | else if (mShowDistanceWeightedTriangles)
|
---|
1366 | {
|
---|
1367 | return vc->GetPvs().mStats.mDistanceWeightedTriangles;
|
---|
1368 | }
|
---|
1369 | else //if (mShowWeightedTriangles)
|
---|
1370 | {
|
---|
1371 | return vc->GetPvs().mStats.mWeightedTriangles;
|
---|
1372 | }
|
---|
1373 | #else
|
---|
1374 | return 0.0f;
|
---|
1375 | #endif
|
---|
1376 | }
|
---|
1377 | #endif
|
---|
1378 |
|
---|
1379 |
|
---|
1380 |
|
---|
1381 | void QtGlRendererWidget::ComputeMaxValues(const ViewCellContainer &viewCells,
|
---|
1382 | int &maxPvs,
|
---|
1383 | int &maxPiercingRays,
|
---|
1384 | float &maxRelativeRays,
|
---|
1385 | float &maxRcCost)
|
---|
1386 | {
|
---|
1387 | maxPvs = -1;
|
---|
1388 | maxPiercingRays = 1; // not zero for savety
|
---|
1389 | maxRelativeRays = Limits::Small; // not zero for savety
|
---|
1390 | maxRcCost = Limits::Small;
|
---|
1391 |
|
---|
1392 | for (size_t i = 0; i < viewCells.size(); ++ i)
|
---|
1393 | {
|
---|
1394 | ViewCell *vc = viewCells[i];
|
---|
1395 |
|
---|
1396 | if (mShowPvsSizes) // pvs size
|
---|
1397 | {
|
---|
1398 | //const int p = vc->GetPvs().CountObjectsInPvs();
|
---|
1399 | const int p = vc->GetPvs().GetSize();
|
---|
1400 | if (p > maxPvs)
|
---|
1401 | maxPvs = p;
|
---|
1402 | }
|
---|
1403 | else if (mShowPiercingRays) // relative number of rays
|
---|
1404 | {
|
---|
1405 | const int piercingRays = vc->GetNumPiercingRays();
|
---|
1406 |
|
---|
1407 | if (piercingRays > maxPiercingRays)
|
---|
1408 | maxPiercingRays = piercingRays;
|
---|
1409 | }
|
---|
1410 | else if (mShowWeightedRays)
|
---|
1411 | {
|
---|
1412 | const int piercingRays = vc->GetNumPiercingRays();
|
---|
1413 |
|
---|
1414 | const float relativeArea =
|
---|
1415 | vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
|
---|
1416 |
|
---|
1417 | if ((float)piercingRays / relativeArea > maxRelativeRays)
|
---|
1418 | maxRelativeRays = (float)piercingRays / relativeArea;
|
---|
1419 | }
|
---|
1420 | else if (mShowWeightedCost)
|
---|
1421 | {
|
---|
1422 | const float rcCost = ComputeRenderCost(vc);
|
---|
1423 | mViewCellsManager->UpdateScalarPvsCost(vc, rcCost);
|
---|
1424 |
|
---|
1425 | if (rcCost > maxRcCost)
|
---|
1426 | maxRcCost = rcCost;
|
---|
1427 | }
|
---|
1428 | }
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 |
|
---|
1432 | void QtGlRendererWidget::RenderViewCells()
|
---|
1433 | {
|
---|
1434 | mUseFalseColors = true;
|
---|
1435 | //glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
|
---|
1436 |
|
---|
1437 | glEnable(GL_CULL_FACE);
|
---|
1438 | glCullFace(GL_FRONT);
|
---|
1439 | //glDisable(GL_CULL_FACE);
|
---|
1440 |
|
---|
1441 | if (mCutViewCells)
|
---|
1442 | {
|
---|
1443 | double eq[4];
|
---|
1444 | eq[0] = mSceneCutPlane.mNormal.x;
|
---|
1445 | eq[1] = mSceneCutPlane.mNormal.y;
|
---|
1446 | eq[2] = mSceneCutPlane.mNormal.z;
|
---|
1447 | eq[3] = mSceneCutPlane.mD;
|
---|
1448 |
|
---|
1449 | glClipPlane(GL_CLIP_PLANE0, eq);
|
---|
1450 | glEnable(GL_CLIP_PLANE0);
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
|
---|
1454 |
|
---|
1455 | int maxPvs, maxPiercingRays;
|
---|
1456 | float maxRelativeRays, maxRcCost;
|
---|
1457 |
|
---|
1458 | ComputeMaxValues(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost);
|
---|
1459 | // matt: temp hack
|
---|
1460 | maxRcCost = 200.0f;
|
---|
1461 | //cout << "maxRcCost: " << maxRcCost << endl;
|
---|
1462 | int i;
|
---|
1463 |
|
---|
1464 | // transparency
|
---|
1465 | if (!mUseTransparency)
|
---|
1466 | {
|
---|
1467 | glEnable(GL_DEPTH_TEST);
|
---|
1468 | glDisable(GL_BLEND);
|
---|
1469 | }
|
---|
1470 | else
|
---|
1471 | {
|
---|
1472 | glDisable(GL_DEPTH_TEST);
|
---|
1473 | glEnable(GL_BLEND);
|
---|
1474 |
|
---|
1475 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
---|
1476 | //glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
---|
1477 |
|
---|
1478 | for (i = 0; i < viewcells.size(); ++ i)
|
---|
1479 | {
|
---|
1480 | ViewCell *vc = viewcells[i];
|
---|
1481 |
|
---|
1482 | const float dist = SqrDistance(mDummyViewPoint, vc->GetBox().Center());
|
---|
1483 | vc->SetDistance(dist);
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 | sort(viewcells.begin(), viewcells.end(), nearerThan);
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | //mWireFrame = true;
|
---|
1490 |
|
---|
1491 | // normal rendering
|
---|
1492 | //if (!mShowPvsSizes && !mShowPiercingRays && !mShowWeightedRays && !mShowWeightedCost && !mShowComparison)
|
---|
1493 | if (mUseStandardColors)
|
---|
1494 | {
|
---|
1495 | for (i = 0; i < viewcells.size(); ++ i)
|
---|
1496 | {
|
---|
1497 | ViewCell *vc = viewcells[i];
|
---|
1498 | RgbColor c;
|
---|
1499 |
|
---|
1500 | //if (!mShowPvsSizes && !mShowPiercingRays)
|
---|
1501 | c = vc->GetColor();
|
---|
1502 |
|
---|
1503 | glColor3f(c.r, c.g, c.b);
|
---|
1504 |
|
---|
1505 | if (!mHideByCost || (mHidingCost < (vc->GetNumPiercingRays() / (float)maxPiercingRays)))
|
---|
1506 | {
|
---|
1507 | RenderViewCell(vc);
|
---|
1508 | }
|
---|
1509 | }
|
---|
1510 | }
|
---|
1511 | else // using specialised colors
|
---|
1512 | {
|
---|
1513 | if (!mShowComparison)
|
---|
1514 | AssignImportanceByRelativeValue(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost);
|
---|
1515 | else
|
---|
1516 | {
|
---|
1517 | if (mCompareInfo.empty())
|
---|
1518 | {
|
---|
1519 | LogReader reader;
|
---|
1520 | reader.SetFilename("compare.log");
|
---|
1521 | int samples;
|
---|
1522 | reader.Read(samples, mCompareInfo);
|
---|
1523 | }
|
---|
1524 |
|
---|
1525 | AssignColorByComparison(viewcells, mCompareInfo);
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 | glEnable(GL_DEPTH_TEST);
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | glEnable(GL_CULL_FACE);
|
---|
1532 | glDisable(GL_CULL_FACE);
|
---|
1533 |
|
---|
1534 | glDisable(GL_CLIP_PLANE0);
|
---|
1535 |
|
---|
1536 | mUseFalseColors = false;
|
---|
1537 | mWireFrame = false;
|
---|
1538 |
|
---|
1539 | glPopAttrib();
|
---|
1540 | }
|
---|
1541 |
|
---|
1542 |
|
---|
1543 | void QtGlRendererWidget::AssignImportanceByRelativeValue(const ViewCellContainer &viewCells,
|
---|
1544 | int &maxPvs,
|
---|
1545 | int &maxPiercingRays,
|
---|
1546 | float &maxRelativeRays,
|
---|
1547 | float &maxRcCost)
|
---|
1548 | {
|
---|
1549 | for (size_t i = 0; i < viewCells.size(); ++ i)
|
---|
1550 | {
|
---|
1551 | RgbColor c;
|
---|
1552 | ViewCell *vc = viewCells[i];
|
---|
1553 |
|
---|
1554 | float importance;
|
---|
1555 |
|
---|
1556 | if (mShowPiercingRays)
|
---|
1557 | {
|
---|
1558 | importance = mTransferFunction *
|
---|
1559 | ((float)vc->GetNumPiercingRays() / (float)maxPiercingRays);
|
---|
1560 | }
|
---|
1561 | else if (mShowWeightedRays) // relative number of rays
|
---|
1562 | {
|
---|
1563 | float relativeArea = vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
|
---|
1564 |
|
---|
1565 | if (relativeArea < Limits::Small)
|
---|
1566 | relativeArea = Limits::Small;
|
---|
1567 |
|
---|
1568 | importance = mTransferFunction * ((float)vc->GetNumPiercingRays() / relativeArea) / maxRelativeRays;
|
---|
1569 | }
|
---|
1570 | else if (mShowPvsSizes) // pvs size
|
---|
1571 | {
|
---|
1572 | importance = mTransferFunction *
|
---|
1573 | ((float)vc->GetPvs().GetSize() / (float)maxPvs);
|
---|
1574 | } // weighted render cost
|
---|
1575 | else if (mShowWeightedCost)
|
---|
1576 | {
|
---|
1577 | const float rcCost = mTransferFunction * ComputeRenderCost(vc);
|
---|
1578 | importance = rcCost / maxRcCost;
|
---|
1579 | }
|
---|
1580 | if (importance > 1.0f) importance = 1.0f;
|
---|
1581 | // c = RgbColor(importance, 1.0f - importance, 0.0f);
|
---|
1582 | c = RainbowColorMapping(importance);
|
---|
1583 |
|
---|
1584 | glColor4f(c.r, c.g, c.b, 1.0f - mTransparency);
|
---|
1585 |
|
---|
1586 | if (!mHideByCost || (mHidingCost < importance))
|
---|
1587 | {
|
---|
1588 | RenderViewCell(vc);
|
---|
1589 | }
|
---|
1590 | }
|
---|
1591 | }
|
---|
1592 |
|
---|
1593 |
|
---|
1594 | void QtGlRendererWidget::AssignColorByComparison(const ViewCellContainer &viewcells,
|
---|
1595 | //const ViewCellInfoContainer &infos1,
|
---|
1596 | const ViewCellInfoContainer &compareInfo)
|
---|
1597 | {
|
---|
1598 | //cout << "comparing " << viewcells.size() << " view cells to " << compareInfo.size() << " values" << endl;
|
---|
1599 |
|
---|
1600 | if (viewcells.size() > compareInfo.size())
|
---|
1601 | {
|
---|
1602 | cerr << "loaded size (" << (int)compareInfo.size() << ") does not fit to view cells size (" << (int)viewcells.size() << ")" << endl;
|
---|
1603 | return;
|
---|
1604 | }
|
---|
1605 |
|
---|
1606 | //const float maxRatio = 1.0f;
|
---|
1607 | const float maxRatio = 2.0f;
|
---|
1608 | const float minRatio = 0.0f;
|
---|
1609 |
|
---|
1610 | const float scale = 1.0f / (maxRatio - minRatio);
|
---|
1611 |
|
---|
1612 | for (size_t i = 0; i < viewcells.size(); ++ i)
|
---|
1613 | {
|
---|
1614 | RgbColor c;
|
---|
1615 | ViewCell *vc = viewcells[i];
|
---|
1616 |
|
---|
1617 | //ViewCellInfo vc1Info = infos1[i];
|
---|
1618 | ViewCellInfo vc2Info = compareInfo[i];
|
---|
1619 |
|
---|
1620 | //const float vcRatio = vc->GetNumPiercingRays() / vc2Info.mPiercingRays + Limits::Small;
|
---|
1621 | float vcRatio = 1.0f;//maxRatio;
|
---|
1622 |
|
---|
1623 | if (vc2Info.mPvsSize > Limits::Small)
|
---|
1624 | vcRatio = (float)vc->GetPvs().GetSize() / vc2Info.mPvsSize;
|
---|
1625 |
|
---|
1626 | // truncate here
|
---|
1627 | if (vcRatio > maxRatio) vcRatio = 1.0f;
|
---|
1628 |
|
---|
1629 | const float importance = (vcRatio - minRatio) * scale;
|
---|
1630 |
|
---|
1631 | if (0 && (i < 20))
|
---|
1632 | {
|
---|
1633 | cout << "pvs1: " << vc->GetPvs().GetSize() << " pvs2: " << compareInfo[i].mPvsSize << " importance: " << importance << endl;
|
---|
1634 | }
|
---|
1635 |
|
---|
1636 | // c = RgbColor(importance, 1.0f - importance, 0.0f);
|
---|
1637 | c = RainbowColorMapping(importance);
|
---|
1638 |
|
---|
1639 | glColor4f(c.r, c.g, c.b, 1.0f);
|
---|
1640 |
|
---|
1641 | if (1)//!mHideByCost || (mHidingCost < importance))
|
---|
1642 | {
|
---|
1643 | RenderViewCell(vc);
|
---|
1644 | }
|
---|
1645 | }
|
---|
1646 | }
|
---|
1647 |
|
---|
1648 |
|
---|
1649 |
|
---|
1650 | /**********************************************************************/
|
---|
1651 | /* QtRendererControlWidget implementation */
|
---|
1652 | /**********************************************************************/
|
---|
1653 |
|
---|
1654 |
|
---|
1655 | QGroupBox *QtRendererControlWidget::CreateVisualizationPanel(QWidget *parent)
|
---|
1656 | {
|
---|
1657 | QRadioButton *rb1, *rb2, *rb3, *rb4, *rb5;
|
---|
1658 |
|
---|
1659 | rb1 = new QRadioButton("random colors", parent);
|
---|
1660 | rb1->setText("random");
|
---|
1661 | connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowWireFrame(bool)));
|
---|
1662 |
|
---|
1663 | // Create a check box to be in the group box
|
---|
1664 | rb2 = new QRadioButton("piercing rays", parent);
|
---|
1665 | rb2->setText("piercing rays");
|
---|
1666 | //vl->addWidget(rb1);
|
---|
1667 | connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetShowPiercingRays(bool)));
|
---|
1668 |
|
---|
1669 | rb3 = new QRadioButton("pvs size", parent);
|
---|
1670 | rb3->setText("pvs size");
|
---|
1671 | connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
|
---|
1672 |
|
---|
1673 | rb4 = new QRadioButton("weighted rays", parent);
|
---|
1674 | rb4->setText("weighted rays");
|
---|
1675 | connect(rb4, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedRays(bool)));
|
---|
1676 |
|
---|
1677 | rb5 = new QRadioButton("pvs cost", parent);
|
---|
1678 | rb5->setText("pvs cost");
|
---|
1679 | connect(rb5, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedCost(bool)));
|
---|
1680 |
|
---|
1681 | QGroupBox *groupBox = new QGroupBox("PVS Visualization");
|
---|
1682 |
|
---|
1683 | QVBoxLayout *vbox2 = new QVBoxLayout;
|
---|
1684 |
|
---|
1685 | vbox2->addWidget(rb1);
|
---|
1686 | vbox2->addWidget(rb2);
|
---|
1687 | vbox2->addWidget(rb3);
|
---|
1688 | vbox2->addWidget(rb4);
|
---|
1689 | vbox2->addWidget(rb5);
|
---|
1690 |
|
---|
1691 | rb5->setChecked(true);
|
---|
1692 |
|
---|
1693 | vbox2->addStretch(1);
|
---|
1694 | groupBox->setLayout(vbox2);
|
---|
1695 |
|
---|
1696 | return groupBox;
|
---|
1697 | }
|
---|
1698 |
|
---|
1699 |
|
---|
1700 | QGroupBox *QtRendererControlWidget::CreateTrafoPanel(QWidget *parent)
|
---|
1701 | {
|
---|
1702 | QRadioButton *rb1, *rb2, *rb3;
|
---|
1703 |
|
---|
1704 | rb1 = new QRadioButton("translation", parent);
|
---|
1705 | rb1->setText("translation");
|
---|
1706 | connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetTranslation(bool)));
|
---|
1707 |
|
---|
1708 | // Create a check box to be in the group box
|
---|
1709 | rb2 = new QRadioButton("scale", parent);
|
---|
1710 | rb2->setText("scale");
|
---|
1711 | //vl->addWidget(rb1);
|
---|
1712 | connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetScale(bool)));
|
---|
1713 |
|
---|
1714 | rb3 = new QRadioButton("rotation", parent);
|
---|
1715 | rb3->setText("rotation");
|
---|
1716 | connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetRotation(bool)));
|
---|
1717 |
|
---|
1718 | QVBoxLayout *vbox2 = new QVBoxLayout;
|
---|
1719 | QGroupBox *groupBox = new QGroupBox("Trafo types");
|
---|
1720 |
|
---|
1721 | vbox2->addWidget(rb1);
|
---|
1722 | vbox2->addWidget(rb2);
|
---|
1723 | vbox2->addWidget(rb3);
|
---|
1724 |
|
---|
1725 | rb1->setChecked(true);
|
---|
1726 |
|
---|
1727 | vbox2->addStretch(1);
|
---|
1728 | groupBox->setLayout(vbox2);
|
---|
1729 |
|
---|
1730 | return groupBox;
|
---|
1731 | }
|
---|
1732 |
|
---|
1733 |
|
---|
1734 |
|
---|
1735 | QGroupBox *QtRendererControlWidget::CreateRenderCostPanel(QWidget *parent)
|
---|
1736 | {
|
---|
1737 | QRadioButton *rb1, *rb2, *rb3;
|
---|
1738 |
|
---|
1739 | // Create a check box to be in the group box
|
---|
1740 | rb1 = new QRadioButton("triangles", parent);
|
---|
1741 | rb1->setText("triangles");
|
---|
1742 | connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedTriangles(bool)));
|
---|
1743 |
|
---|
1744 | rb2 = new QRadioButton("distance weighted pvs", parent);
|
---|
1745 | rb2->setText("distance weighted");
|
---|
1746 | connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetShowDistanceWeightedPvs(bool)));
|
---|
1747 |
|
---|
1748 | rb3 = new QRadioButton("distance weighted triangles", parent);
|
---|
1749 | rb3->setText("distance weighted triangles");
|
---|
1750 | connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowDistanceWeightedTriangles(bool)));
|
---|
1751 |
|
---|
1752 | QGroupBox *groupBox = new QGroupBox("Render cost options");
|
---|
1753 | QVBoxLayout *vbox2 = new QVBoxLayout;
|
---|
1754 |
|
---|
1755 | vbox2->addWidget(rb1);
|
---|
1756 | vbox2->addWidget(rb2);
|
---|
1757 | vbox2->addWidget(rb3);
|
---|
1758 |
|
---|
1759 | rb1->setChecked(true);
|
---|
1760 |
|
---|
1761 | vbox2->addStretch(1);
|
---|
1762 | groupBox->setLayout(vbox2);
|
---|
1763 |
|
---|
1764 | return groupBox;
|
---|
1765 | }
|
---|
1766 |
|
---|
1767 |
|
---|
1768 | QGroupBox *QtRendererControlWidget::CreateRayVisualizationPanel(QWidget *parent)
|
---|
1769 | {
|
---|
1770 | QRadioButton *rb1, *rb2, *rb3, *rb4;
|
---|
1771 |
|
---|
1772 | // Create a check box to be in the group box
|
---|
1773 | rb1 = new QRadioButton("const color", parent);
|
---|
1774 | rb1->setText("const color");
|
---|
1775 | //vl->addWidget(rb1);
|
---|
1776 | connect(rb1, SIGNAL(toggled(bool)), SIGNAL(UseConstColorForRayViz(bool)));
|
---|
1777 |
|
---|
1778 | rb2 = new QRadioButton("ray length", parent);
|
---|
1779 | rb2->setText("ray length");
|
---|
1780 | connect(rb2, SIGNAL(toggled(bool)), SIGNAL(UseRayLengthForRayViz(bool)));
|
---|
1781 |
|
---|
1782 | rb3 = new QRadioButton("contribution", parent);
|
---|
1783 | rb3->setText("contribution");
|
---|
1784 | connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowContribution(bool)));
|
---|
1785 |
|
---|
1786 | rb4 = new QRadioButton("distribution", parent);
|
---|
1787 | rb4->setText("distribution");
|
---|
1788 | connect(rb4, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution(bool)));
|
---|
1789 |
|
---|
1790 |
|
---|
1791 | ///////////////////////////
|
---|
1792 |
|
---|
1793 |
|
---|
1794 | QGroupBox *groupBox = new QGroupBox("Ray visualization");
|
---|
1795 | QVBoxLayout *vbox2 = new QVBoxLayout;
|
---|
1796 |
|
---|
1797 | vbox2->addWidget(rb1);
|
---|
1798 | vbox2->addWidget(rb2);
|
---|
1799 | vbox2->addWidget(rb3);
|
---|
1800 | vbox2->addWidget(rb4);
|
---|
1801 |
|
---|
1802 | rb1->setChecked(true);
|
---|
1803 |
|
---|
1804 |
|
---|
1805 | QCheckBox *cb = new QCheckBox("Distribution 1", parent);
|
---|
1806 | vbox2->addWidget(cb);
|
---|
1807 | cb->setChecked(true);
|
---|
1808 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution1(bool)));
|
---|
1809 |
|
---|
1810 | cb = new QCheckBox("Distribution 2", parent);
|
---|
1811 | vbox2->addWidget(cb);
|
---|
1812 | cb->setChecked(true);
|
---|
1813 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution2(bool)));
|
---|
1814 |
|
---|
1815 | cb = new QCheckBox("Distribution 3", parent);
|
---|
1816 | vbox2->addWidget(cb);
|
---|
1817 | cb->setChecked(true);
|
---|
1818 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution3(bool)));
|
---|
1819 |
|
---|
1820 | cb = new QCheckBox("Distribution 4", parent);
|
---|
1821 | vbox2->addWidget(cb);
|
---|
1822 | cb->setChecked(true);
|
---|
1823 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution4(bool)));
|
---|
1824 |
|
---|
1825 |
|
---|
1826 | vbox2->addStretch(1);
|
---|
1827 | groupBox->setLayout(vbox2);
|
---|
1828 |
|
---|
1829 | return groupBox;
|
---|
1830 | }
|
---|
1831 |
|
---|
1832 |
|
---|
1833 | QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f):
|
---|
1834 | QWidget(parent, f)
|
---|
1835 | {
|
---|
1836 |
|
---|
1837 | QVBoxLayout *vl = new QVBoxLayout;
|
---|
1838 | setLayout(vl);
|
---|
1839 |
|
---|
1840 | //QWidget *vbox;
|
---|
1841 |
|
---|
1842 | //vbox = new QGroupBox("Render Controls", this);
|
---|
1843 | //layout()->addWidget(vbox);
|
---|
1844 | //vl = new QVBoxLayout;
|
---|
1845 | //vbox->setLayout(vl);
|
---|
1846 |
|
---|
1847 | QLabel *label;
|
---|
1848 | QSlider *slider;
|
---|
1849 | QPushButton *button;
|
---|
1850 |
|
---|
1851 | #if REMOVE_TEMPORARY
|
---|
1852 |
|
---|
1853 | label = new QLabel("Granularity");
|
---|
1854 | //vbox->layout()->addWidget(label);
|
---|
1855 | vl->addWidget(label);
|
---|
1856 |
|
---|
1857 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1858 | vl->addWidget(slider);
|
---|
1859 | slider->show();
|
---|
1860 | slider->setRange(1, 10000);
|
---|
1861 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1862 | slider->setValue(200);
|
---|
1863 |
|
---|
1864 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
|
---|
1865 |
|
---|
1866 | ///////////////////////////
|
---|
1867 |
|
---|
1868 | label = new QLabel("Transfer function");
|
---|
1869 | vl->addWidget(label);
|
---|
1870 |
|
---|
1871 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1872 | vl->addWidget(slider);
|
---|
1873 | slider->show();
|
---|
1874 | slider->setRange(1, 10000);
|
---|
1875 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1876 | slider->setValue(100);
|
---|
1877 |
|
---|
1878 |
|
---|
1879 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int)));
|
---|
1880 |
|
---|
1881 | ////////////////////////////////////////7
|
---|
1882 |
|
---|
1883 | button = new QPushButton("Update all PVSs", vbox);
|
---|
1884 | vl->addWidget(button);
|
---|
1885 | connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs()));
|
---|
1886 |
|
---|
1887 | ////////////////////////////////////////77777
|
---|
1888 |
|
---|
1889 | label = new QLabel("Filter size");
|
---|
1890 | vl->addWidget(label);
|
---|
1891 |
|
---|
1892 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1893 | vl->addWidget(slider);
|
---|
1894 | slider->show();
|
---|
1895 | slider->setRange(1, 100);
|
---|
1896 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1897 | slider->setValue(3);
|
---|
1898 |
|
---|
1899 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int)));
|
---|
1900 |
|
---|
1901 | #endif
|
---|
1902 |
|
---|
1903 |
|
---|
1904 |
|
---|
1905 | ///////////////////////////////////
|
---|
1906 |
|
---|
1907 |
|
---|
1908 | QWidget *hbox = new QWidget();//vbox);
|
---|
1909 | vl->addWidget(hbox);
|
---|
1910 | QHBoxLayout *hlayout = new QHBoxLayout;
|
---|
1911 | hbox->setLayout(hlayout);
|
---|
1912 |
|
---|
1913 | QCheckBox *cb = new QCheckBox("Show viewcells", hbox);
|
---|
1914 | hlayout->addWidget(cb);
|
---|
1915 | cb->setChecked(false);
|
---|
1916 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool)));
|
---|
1917 |
|
---|
1918 | cb = new QCheckBox("Render errors", hbox);
|
---|
1919 | hlayout->layout()->addWidget(cb);
|
---|
1920 | cb->setChecked(false);
|
---|
1921 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
|
---|
1922 |
|
---|
1923 | #if REMOVE_TEMPORARY
|
---|
1924 | cb = new QCheckBox("Render cost curve", hbox);
|
---|
1925 | hlayout->addWidget(cb);
|
---|
1926 | cb->setChecked(false);
|
---|
1927 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool)));
|
---|
1928 | #endif
|
---|
1929 | cb = new QCheckBox("Show rays", hbox);
|
---|
1930 | hlayout->addWidget(cb);
|
---|
1931 | cb->setChecked(false);
|
---|
1932 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
|
---|
1933 | #if REMOVE_TEMPORARY
|
---|
1934 | cb = new QCheckBox("Show Comparison", hbox);
|
---|
1935 | hlayout->addWidget(cb);
|
---|
1936 | cb->setChecked(false);
|
---|
1937 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowComparison(bool)));
|
---|
1938 | #endif
|
---|
1939 |
|
---|
1940 | //////////////////
|
---|
1941 |
|
---|
1942 | QHBoxLayout *vh = new QHBoxLayout;
|
---|
1943 |
|
---|
1944 | QGroupBox *myBox = new QGroupBox("Visualization");
|
---|
1945 |
|
---|
1946 | myBox->setLayout(vh);
|
---|
1947 | vl->addWidget(myBox, 0, 0);
|
---|
1948 |
|
---|
1949 | QGroupBox *groupBox = CreateVisualizationPanel(hbox);
|
---|
1950 | vh->addWidget(groupBox, 0, 0);
|
---|
1951 | #if REMOVE_TEMPORARY
|
---|
1952 | QGroupBox *groupBox2 = CreateRenderCostPanel(hbox);
|
---|
1953 | vh->addWidget(groupBox2, 0, 0);
|
---|
1954 | #endif
|
---|
1955 | QGroupBox *groupBox3 = CreateRayVisualizationPanel(hbox);
|
---|
1956 | vh->addWidget(groupBox3, 0, 0);
|
---|
1957 |
|
---|
1958 | QGroupBox *groupBox4 = CreateTrafoPanel(hbox);
|
---|
1959 | vh->addWidget(groupBox4, 0, 0);
|
---|
1960 |
|
---|
1961 | //////////////////////////////////
|
---|
1962 |
|
---|
1963 |
|
---|
1964 | /*cb = new QRadiobox("Top View", vbox);
|
---|
1965 | vl->addWidget(cb);
|
---|
1966 | cb->setChecked(false);
|
---|
1967 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
|
---|
1968 | */
|
---|
1969 |
|
---|
1970 | //vbox->resize(800,150);
|
---|
1971 | QWidget *vbox;
|
---|
1972 |
|
---|
1973 | vbox = new QGroupBox("Rendering", this);
|
---|
1974 | layout()->addWidget(vbox);
|
---|
1975 |
|
---|
1976 | vl = new QVBoxLayout;
|
---|
1977 | vbox->setLayout(vl);
|
---|
1978 |
|
---|
1979 |
|
---|
1980 |
|
---|
1981 | cb = new QCheckBox("Cut view cells", vbox);
|
---|
1982 | vbox->layout()->addWidget(cb);
|
---|
1983 | cb->setChecked(false);
|
---|
1984 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool)));
|
---|
1985 |
|
---|
1986 |
|
---|
1987 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1988 | vbox->layout()->addWidget(slider);
|
---|
1989 | slider->show();
|
---|
1990 | slider->setRange(0, 1000);
|
---|
1991 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1992 | slider->setValue(1000);
|
---|
1993 |
|
---|
1994 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int)));
|
---|
1995 |
|
---|
1996 |
|
---|
1997 | cb = new QCheckBox("Hide view cells by render cost ", vbox);
|
---|
1998 | vbox->layout()->addWidget(cb);
|
---|
1999 | cb->setChecked(false);
|
---|
2000 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetHideByCost(bool)));
|
---|
2001 |
|
---|
2002 | ////////////////////////////
|
---|
2003 |
|
---|
2004 | const int range = 1000;
|
---|
2005 |
|
---|
2006 | label = new QLabel("Hide by cost");
|
---|
2007 | vbox->layout()->addWidget(label);
|
---|
2008 |
|
---|
2009 | // the render cost visualization
|
---|
2010 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
2011 | vbox->layout()->addWidget(slider);
|
---|
2012 | slider->show();
|
---|
2013 | slider->setRange(0, range);
|
---|
2014 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2015 | slider->setValue(0);
|
---|
2016 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetHidingCost(int)));
|
---|
2017 |
|
---|
2018 | ///////////////////////////////////////////
|
---|
2019 |
|
---|
2020 | cb = new QCheckBox("Top View", vbox);
|
---|
2021 | vbox->layout()->addWidget(cb);
|
---|
2022 | cb->setChecked(false);
|
---|
2023 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
|
---|
2024 |
|
---|
2025 |
|
---|
2026 | label = new QLabel("Top distance");
|
---|
2027 | vbox->layout()->addWidget(label);
|
---|
2028 |
|
---|
2029 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
2030 | vbox->layout()->addWidget(slider);
|
---|
2031 | slider->show();
|
---|
2032 | slider->setRange(1, 1000);
|
---|
2033 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2034 | slider->setValue(500);
|
---|
2035 |
|
---|
2036 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
|
---|
2037 |
|
---|
2038 |
|
---|
2039 | ///////////////////////////////////////////
|
---|
2040 | #if REMOVE_TEMPORARY
|
---|
2041 | cb = new QCheckBox("Transparency", vbox);
|
---|
2042 | vbox->layout()->addWidget(cb);
|
---|
2043 | cb->setChecked(false);
|
---|
2044 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseTransparency(bool)));
|
---|
2045 |
|
---|
2046 | label = new QLabel("Use transparency");
|
---|
2047 | vbox->layout()->addWidget(label);
|
---|
2048 |
|
---|
2049 | // the render cost visualization
|
---|
2050 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
2051 | vbox->layout()->addWidget(slider);
|
---|
2052 | slider->show();
|
---|
2053 | slider->setRange(0, range);
|
---|
2054 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2055 | slider->setValue(0);
|
---|
2056 | #endif
|
---|
2057 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransparency(int)));
|
---|
2058 |
|
---|
2059 | //////////////////////////////
|
---|
2060 |
|
---|
2061 | #if REMOVE_TEMPORARY
|
---|
2062 | cb = new QCheckBox("Cut scene", vbox);
|
---|
2063 | vbox->layout()->addWidget(cb);
|
---|
2064 | cb->setChecked(false);
|
---|
2065 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool)));
|
---|
2066 |
|
---|
2067 | cb = new QCheckBox("Render boxes", vbox);
|
---|
2068 | vbox->layout()->addWidget(cb);
|
---|
2069 | cb->setChecked(false);
|
---|
2070 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool)));
|
---|
2071 |
|
---|
2072 | cb = new QCheckBox("Render visibility estimates", vbox);
|
---|
2073 | vbox->layout()->addWidget(cb);
|
---|
2074 | cb->setChecked(false);
|
---|
2075 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool)));
|
---|
2076 | #endif
|
---|
2077 |
|
---|
2078 | bool tmp;
|
---|
2079 | #if REMOVE_TEMPORARY
|
---|
2080 |
|
---|
2081 | cb = new QCheckBox("Use filter", vbox);
|
---|
2082 | vbox->layout()->addWidget(cb);
|
---|
2083 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
2084 | cb->setChecked(tmp);
|
---|
2085 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool)));
|
---|
2086 | #endif
|
---|
2087 |
|
---|
2088 | cb = new QCheckBox("Use spatial filter", vbox);
|
---|
2089 | vbox->layout()->addWidget(cb);
|
---|
2090 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
|
---|
2091 | tmp );
|
---|
2092 | cb->setChecked(tmp);
|
---|
2093 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool)));
|
---|
2094 | #if REMOVE_TEMPORARY
|
---|
2095 | cb = new QCheckBox("Render filter", vbox);
|
---|
2096 | vbox->layout()->addWidget(cb);
|
---|
2097 | cb->setChecked(true);
|
---|
2098 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
|
---|
2099 |
|
---|
2100 |
|
---|
2101 | /*vbox = new QGroupBox("PVS Errors", this);
|
---|
2102 | layout()->addWidget(vbox);
|
---|
2103 |
|
---|
2104 | vl = new QVBoxLayout;
|
---|
2105 | vbox->setLayout(vl);
|
---|
2106 |
|
---|
2107 | button = new QPushButton("Compute Visibility", vbox);
|
---|
2108 | vbox->layout()->addWidget(button);
|
---|
2109 | connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility()));
|
---|
2110 |
|
---|
2111 | button = new QPushButton("Stop Computation", vbox);
|
---|
2112 | vbox->layout()->addWidget(button);
|
---|
2113 | connect(button, SIGNAL(clicked()), SLOT(StopComputation()));
|
---|
2114 |
|
---|
2115 | button = new QPushButton("Set Random View Point", vbox);
|
---|
2116 | vbox->layout()->addWidget(button);
|
---|
2117 | connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint()));*/
|
---|
2118 |
|
---|
2119 | button = new QPushButton("Store statistics", vbox);
|
---|
2120 | vbox->layout()->addWidget(button);
|
---|
2121 | connect(button, SIGNAL(clicked()), SIGNAL(StoreStatistics()));
|
---|
2122 | #endif
|
---|
2123 |
|
---|
2124 | #if DYNAMIC_OBJECTS_HACK
|
---|
2125 |
|
---|
2126 | button = new QPushButton("Load object", vbox);
|
---|
2127 | vbox->layout()->addWidget(button);
|
---|
2128 | connect(button, SIGNAL(clicked()), SIGNAL(LoadObject()));
|
---|
2129 | #endif
|
---|
2130 |
|
---|
2131 | /*cb = new QCheckBox("Stats", vbox);
|
---|
2132 | vbox->layout()->addWidget(cb);
|
---|
2133 | cb->setChecked(false);
|
---|
2134 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics()));*/
|
---|
2135 |
|
---|
2136 | if (0)
|
---|
2137 | {
|
---|
2138 | vbox = new QGroupBox("PVS Errors", this);
|
---|
2139 | layout()->addWidget(vbox);
|
---|
2140 |
|
---|
2141 | vl = new QVBoxLayout;
|
---|
2142 | vbox->setLayout(vl);
|
---|
2143 |
|
---|
2144 | mPvsErrorWidget = new QListWidget(vbox);
|
---|
2145 | vbox->layout()->addWidget(mPvsErrorWidget);
|
---|
2146 |
|
---|
2147 | connect(mPvsErrorWidget,
|
---|
2148 | SIGNAL(doubleClicked(const QModelIndex &)),
|
---|
2149 | this,
|
---|
2150 | SLOT(PvsErrorClicked(const QModelIndex &)));
|
---|
2151 |
|
---|
2152 | button = new QPushButton("Next Error Frame", vbox);
|
---|
2153 | vbox->layout()->addWidget(button);
|
---|
2154 | connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
|
---|
2155 | }
|
---|
2156 |
|
---|
2157 | //connect(button, SIGNAL(clicked(void)), SLOT(StoreStatistics(void)));
|
---|
2158 | //mHidingCost = 0.1f;
|
---|
2159 | //////////////////////////////////////////
|
---|
2160 |
|
---|
2161 | label = new QLabel("Spatial Filter size");
|
---|
2162 | vbox->layout()->addWidget(label);
|
---|
2163 |
|
---|
2164 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
2165 | vbox->layout()->addWidget(slider);
|
---|
2166 | slider->show();
|
---|
2167 | slider->setRange(1, 100);
|
---|
2168 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2169 | slider->setValue(10);
|
---|
2170 |
|
---|
2171 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int)));
|
---|
2172 |
|
---|
2173 |
|
---|
2174 | setWindowTitle("Preprocessor Control Widget");
|
---|
2175 | adjustSize();
|
---|
2176 | }
|
---|
2177 |
|
---|
2178 |
|
---|
2179 |
|
---|
2180 |
|
---|
2181 | void
|
---|
2182 | QtRendererControlWidget::FocusNextPvsErrorFrame(void)
|
---|
2183 | {}
|
---|
2184 |
|
---|
2185 | void
|
---|
2186 | QtRendererControlWidget::UpdatePvsErrorItem(int row,
|
---|
2187 | GlRendererBuffer::PvsErrorEntry &pvsErrorEntry)
|
---|
2188 | {
|
---|
2189 |
|
---|
2190 | QListWidgetItem *i = mPvsErrorWidget->item(row);
|
---|
2191 | QString s;
|
---|
2192 | s.sprintf("%5.5f", pvsErrorEntry.mError);
|
---|
2193 | if (i) {
|
---|
2194 | i->setText(s);
|
---|
2195 | } else {
|
---|
2196 | new QListWidgetItem(s, mPvsErrorWidget);
|
---|
2197 | }
|
---|
2198 | mPvsErrorWidget->update();
|
---|
2199 | }
|
---|
2200 |
|
---|
2201 |
|
---|
2202 |
|
---|
2203 |
|
---|
2204 | /*********************************************************************/
|
---|
2205 | /* QtGlDebuggerWidget implementation */
|
---|
2206 | /*********************************************************************/
|
---|
2207 |
|
---|
2208 |
|
---|
2209 | QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
|
---|
2210 | : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
|
---|
2211 | {
|
---|
2212 | // create the pbuffer
|
---|
2213 | //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
|
---|
2214 | timerId = startTimer(20);
|
---|
2215 | setWindowTitle(("OpenGL pbuffers"));
|
---|
2216 | }
|
---|
2217 |
|
---|
2218 |
|
---|
2219 | QtGlDebuggerWidget::~QtGlDebuggerWidget()
|
---|
2220 | {
|
---|
2221 | mRenderBuffer->releaseFromDynamicTexture();
|
---|
2222 | glDeleteTextures(1, &dynamicTexture);
|
---|
2223 |
|
---|
2224 | DEL_PTR(mRenderBuffer);
|
---|
2225 | }
|
---|
2226 |
|
---|
2227 |
|
---|
2228 | void QtGlDebuggerWidget::initializeGL()
|
---|
2229 | {
|
---|
2230 | glMatrixMode(GL_PROJECTION);
|
---|
2231 | glLoadIdentity();
|
---|
2232 |
|
---|
2233 | glFrustum(-1, 1, -1, 1, 10, 100);
|
---|
2234 | glTranslatef(-0.5f, -0.5f, -0.5f);
|
---|
2235 | glTranslatef(0.0f, 0.0f, -15.0f);
|
---|
2236 | glMatrixMode(GL_MODELVIEW);
|
---|
2237 |
|
---|
2238 | glEnable(GL_CULL_FACE);
|
---|
2239 | initCommon();
|
---|
2240 | initPbuffer();
|
---|
2241 |
|
---|
2242 | }
|
---|
2243 |
|
---|
2244 |
|
---|
2245 | void QtGlDebuggerWidget::resizeGL(int w, int h)
|
---|
2246 | {
|
---|
2247 | glViewport(0, 0, w, h);
|
---|
2248 | }
|
---|
2249 |
|
---|
2250 |
|
---|
2251 | void QtGlDebuggerWidget::paintGL()
|
---|
2252 | {
|
---|
2253 | // draw a spinning cube into the pbuffer..
|
---|
2254 | mRenderBuffer->makeCurrent();
|
---|
2255 |
|
---|
2256 | BeamSampleStatistics stats;
|
---|
2257 | mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats);
|
---|
2258 |
|
---|
2259 | glFlush();
|
---|
2260 |
|
---|
2261 | // rendering directly to a texture is not supported on X11, unfortunately
|
---|
2262 | mRenderBuffer->updateDynamicTexture(dynamicTexture);
|
---|
2263 |
|
---|
2264 | // and use the pbuffer contents as a texture when rendering the
|
---|
2265 | // background and the bouncing cubes
|
---|
2266 | makeCurrent();
|
---|
2267 | glBindTexture(GL_TEXTURE_2D, dynamicTexture);
|
---|
2268 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
2269 |
|
---|
2270 | // draw the background
|
---|
2271 | glMatrixMode(GL_MODELVIEW);
|
---|
2272 | glPushMatrix();
|
---|
2273 | glLoadIdentity();
|
---|
2274 | glMatrixMode(GL_PROJECTION);
|
---|
2275 | glPushMatrix();
|
---|
2276 | glLoadIdentity();
|
---|
2277 |
|
---|
2278 | glPopMatrix();
|
---|
2279 | glMatrixMode(GL_MODELVIEW);
|
---|
2280 | glPopMatrix();
|
---|
2281 | }
|
---|
2282 |
|
---|
2283 |
|
---|
2284 | void QtGlDebuggerWidget::initPbuffer()
|
---|
2285 | {
|
---|
2286 | // set up the pbuffer context
|
---|
2287 | mRenderBuffer->makeCurrent();
|
---|
2288 | /*mRenderBuffer->InitGL();
|
---|
2289 |
|
---|
2290 | glViewport(0, 0, mRenderBuffer->size().width(), mRenderBuffer->size().height());
|
---|
2291 | glMatrixMode(GL_PROJECTION);
|
---|
2292 | glLoadIdentity();
|
---|
2293 | glOrtho(-1, 1, -1, 1, -99, 99);
|
---|
2294 | glTranslatef(-0.5f, -0.5f, 0.0f);
|
---|
2295 | glMatrixMode(GL_MODELVIEW);
|
---|
2296 | glLoadIdentity();
|
---|
2297 |
|
---|
2298 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/
|
---|
2299 |
|
---|
2300 | // generate a texture that has the same size/format as the pbuffer
|
---|
2301 | dynamicTexture = mRenderBuffer->generateDynamicTexture();
|
---|
2302 |
|
---|
2303 | // bind the dynamic texture to the pbuffer - this is a no-op under X11
|
---|
2304 | mRenderBuffer->bindToDynamicTexture(dynamicTexture);
|
---|
2305 | makeCurrent();
|
---|
2306 | }
|
---|
2307 |
|
---|
2308 |
|
---|
2309 | void QtGlDebuggerWidget::initCommon()
|
---|
2310 | {
|
---|
2311 | glEnable(GL_TEXTURE_2D);
|
---|
2312 | glEnable(GL_DEPTH_TEST);
|
---|
2313 |
|
---|
2314 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
---|
2315 | }
|
---|
2316 |
|
---|
2317 |
|
---|
2318 | void QtGlRendererWidget::_RenderColoredPvs()
|
---|
2319 | {
|
---|
2320 | // note: could be done more efficiently using color buffers
|
---|
2321 | mPvsSize = mPvsCache.mPvs.GetSize();
|
---|
2322 |
|
---|
2323 | ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
|
---|
2324 |
|
---|
2325 | PvsData pvsData;
|
---|
2326 |
|
---|
2327 | while (it.HasMoreEntries())
|
---|
2328 | {
|
---|
2329 | Intersectable *object = it.Next(pvsData);
|
---|
2330 |
|
---|
2331 | RgbColor color;
|
---|
2332 |
|
---|
2333 | //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f
|
---|
2334 | // glColor3f(visibility, 0.0f, 0.0f);
|
---|
2335 | //cerr << "sumpdf: " << pvsData.mSumPdf << endl;
|
---|
2336 | if (mUseRandomColorPerPvsObject)
|
---|
2337 | {
|
---|
2338 | KdIntersectable *kdint = static_cast<KdIntersectable *>(object);
|
---|
2339 |
|
---|
2340 | if (kdint->mGenericIdx == -1)
|
---|
2341 | {
|
---|
2342 | kdint->mGenericIdx = (int)mColors.size();
|
---|
2343 | mColors.push_back(RandomColor());
|
---|
2344 | }
|
---|
2345 | color = mColors[kdint->mGenericIdx];
|
---|
2346 | }
|
---|
2347 | else
|
---|
2348 | {
|
---|
2349 | color = RainbowColorMapping(mTransferFunction * log10(pvsData.mSumPdf + 1));
|
---|
2350 | }
|
---|
2351 |
|
---|
2352 | glColor3f(color.r, color.g, color.b);
|
---|
2353 |
|
---|
2354 | mUseForcedColors = true;
|
---|
2355 | RenderIntersectable(object);
|
---|
2356 | mUseForcedColors = false;
|
---|
2357 | }
|
---|
2358 | }
|
---|
2359 |
|
---|
2360 | }
|
---|