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 | #include "RayCaster.h"
|
---|
20 | #include "ObjectPlacer.h"
|
---|
21 |
|
---|
22 | #define TEASER 0
|
---|
23 | #define USE_CG 1
|
---|
24 |
|
---|
25 | #define TEST_PVS_RENDERING 0
|
---|
26 |
|
---|
27 | #if USE_CG
|
---|
28 | #include <Cg/cg.h>
|
---|
29 | #include <Cg/cgGL.h>
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <QVBoxLayout>
|
---|
33 |
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 |
|
---|
37 |
|
---|
38 | namespace GtpVisibilityPreprocessor
|
---|
39 | {
|
---|
40 |
|
---|
41 |
|
---|
42 | class ViewCellsManager;
|
---|
43 |
|
---|
44 | static CGcontext sCgContext = NULL;
|
---|
45 | static CGprogram sCgFragmentProgram = NULL;
|
---|
46 | static CGprofile sCgFragmentProfile;
|
---|
47 |
|
---|
48 |
|
---|
49 | QtGlRendererWidget *rendererWidget = NULL;
|
---|
50 | QtGlDebuggerWidget *debuggerWidget = NULL;
|
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|
54 | static SimpleRayContainer sViewPointsList;
|
---|
55 | static SimpleRayContainer::const_iterator sViewPointsListIt;
|
---|
56 | static int sCurrentSamples = 0;
|
---|
57 | static int sNextSamplesThreshold[] = {10000000, 50000000, 100000000, 250000000};
|
---|
58 | //static int sNextSamplesThreshold[] = {100000000, 200000000};
|
---|
59 | static int sNumReplays = 0;//4;
|
---|
60 | static int sCurrentSamplesThreshold = 0;
|
---|
61 |
|
---|
62 |
|
---|
63 | void processHits (GLint hits, GLuint buffer[])
|
---|
64 | {
|
---|
65 | unsigned int i, j;
|
---|
66 | GLuint names, *ptr;
|
---|
67 |
|
---|
68 | cout << "hits: " << hits << endl;;
|
---|
69 | ptr = (GLuint *) buffer;
|
---|
70 |
|
---|
71 | for (i = 0; i < hits; i++)
|
---|
72 | {
|
---|
73 | /* for each hit */
|
---|
74 | names = *ptr;
|
---|
75 |
|
---|
76 | printf ("number of names for hit: %d\n", names); ptr ++;
|
---|
77 | printf("z1: %g;", (float) *ptr / 0x7fffffff); ptr ++;
|
---|
78 | printf("z2: %g\n", (float) *ptr / 0x7fffffff); ptr ++;
|
---|
79 | printf ("the name is ");
|
---|
80 |
|
---|
81 | // for each name
|
---|
82 | for (j = 0; j < names; j++)
|
---|
83 | printf ("%d ", *ptr); ptr++;
|
---|
84 |
|
---|
85 | printf ("\n");
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
|
---|
91 | {
|
---|
92 | return obj1->mId < obj2->mId;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | inline static bool nearerThan(ViewCell *vc1, ViewCell *vc2)
|
---|
97 | {
|
---|
98 | return vc1->GetDistance() > vc2->GetDistance();
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | #if USE_CG
|
---|
103 | static void handleCgError()
|
---|
104 | {
|
---|
105 | Debug << "Cg error: " << cgGetErrorString(cgGetError()) << endl;
|
---|
106 | exit(1);
|
---|
107 | }
|
---|
108 | #endif
|
---|
109 |
|
---|
110 |
|
---|
111 | void QtGlRendererBuffer::MakeLive()
|
---|
112 | {
|
---|
113 | QGLPixelBuffer::makeCurrent();
|
---|
114 | //makeCurrent();
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | void QtGlRendererBuffer::DoneLive()
|
---|
119 | {
|
---|
120 | QGLPixelBuffer::doneCurrent();
|
---|
121 | //doneCurrent();
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | QtGlRendererBuffer::QtGlRendererBuffer(int w, int h,
|
---|
126 | SceneGraph *sceneGraph,
|
---|
127 | ViewCellsManager *viewcells,
|
---|
128 | KdTree *tree):
|
---|
129 | QGLPixelBuffer(QSize(w, h),
|
---|
130 | QGLFormat(QGL::SampleBuffers)
|
---|
131 | /*,|
|
---|
132 | QGL::StencilBuffer |
|
---|
133 | QGL::DepthBuffer |
|
---|
134 | QGL::DoubleBuffer |
|
---|
135 | QGL::Rgba)
|
---|
136 | */),
|
---|
137 | GlRendererBuffer(sceneGraph, viewcells, tree)
|
---|
138 | {
|
---|
139 | //makeCurrent();
|
---|
140 | MakeLive();
|
---|
141 | glViewport(0, 0, w, h);
|
---|
142 | glMatrixMode(GL_PROJECTION);
|
---|
143 | glLoadIdentity();
|
---|
144 | glOrtho(-1, 1, -1, 1, -99, 99);
|
---|
145 | glMatrixMode(GL_MODELVIEW);
|
---|
146 | glLoadIdentity();
|
---|
147 |
|
---|
148 | InitGL();
|
---|
149 |
|
---|
150 | //doneCurrent();
|
---|
151 | //DoneLive();
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | void QtGlRendererBuffer::RenderPvs(const ObjectPvs &pvs)
|
---|
156 | {
|
---|
157 | EnableDrawArrays();
|
---|
158 |
|
---|
159 | // prepare pvs for rendering
|
---|
160 | PreparePvs(pvs);
|
---|
161 |
|
---|
162 | if (mUseVbos)
|
---|
163 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
|
---|
164 |
|
---|
165 | int offset = (int)mObjects.size() * 3;
|
---|
166 | char *arrayPtr = mUseVbos ? NULL : (char *)mData;
|
---|
167 |
|
---|
168 | glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr);
|
---|
169 | glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
|
---|
170 | glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 | void QtGlRendererBuffer::RenderTrianglePvs()
|
---|
175 | {
|
---|
176 | //Intersectable::NewMail;
|
---|
177 |
|
---|
178 | ObjectContainer::const_iterator oit, oit_end =
|
---|
179 | mViewCellsManager->GetPreprocessor()->mTrianglePvs.end();
|
---|
180 |
|
---|
181 | //int sz = mViewCellsManager->GetPreprocessor()->mDummyBuffer.size();
|
---|
182 |
|
---|
183 | for (oit = mViewCellsManager->GetPreprocessor()->mTrianglePvs.begin();
|
---|
184 | oit != oit_end; ++ oit)
|
---|
185 | {
|
---|
186 | TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(*oit);
|
---|
187 |
|
---|
188 | //int dum = mViewCellsManager->GetPreprocessor()->mDummyBuffer[i];
|
---|
189 | //glColor3f(0, (float)dum / 20.0f, 1);
|
---|
190 | if (mUseFalseColors) SetupFalseColor(triObj->mId);
|
---|
191 |
|
---|
192 | RenderIntersectable(triObj);
|
---|
193 |
|
---|
194 | /*if (!triObj->Mailed())
|
---|
195 | triObj->Mail();
|
---|
196 | else
|
---|
197 | cerr << "böser fehler" << endl;
|
---|
198 | */
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 | // reimplemented here so that we can snap the error windows
|
---|
205 | float QtGlRendererBuffer::GetPixelError(int &pvsSize, int currentPass)
|
---|
206 | {
|
---|
207 | MakeLive();
|
---|
208 |
|
---|
209 | if (0)
|
---|
210 | {
|
---|
211 | cout << "stencil: " << format().stencil() << endl;
|
---|
212 | cout << "depth: " << format().depth() << endl;
|
---|
213 | cout << "rgba: " << format().rgba() << endl;
|
---|
214 | cout << "double: " << format().doubleBuffer() << endl;
|
---|
215 | cout << "depth: " << format().depth() << endl;
|
---|
216 | cout << "gl:" << format().hasOpenGL() << endl;
|
---|
217 | cout << "dir:" << format().directRendering() << endl;
|
---|
218 | }
|
---|
219 |
|
---|
220 | ++ mCurrentFrame;
|
---|
221 |
|
---|
222 | float pErrorPixels = -1.0f;
|
---|
223 |
|
---|
224 | mUseFalseColors = false;
|
---|
225 | unsigned int pixelCount = 0;
|
---|
226 |
|
---|
227 |
|
---|
228 | ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
|
---|
229 |
|
---|
230 | if (viewcell == NULL)
|
---|
231 | return -1.0f;
|
---|
232 |
|
---|
233 | bool evaluateFilter;
|
---|
234 | Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluateFilter", evaluateFilter);
|
---|
235 |
|
---|
236 | ObjectPvs pvs;
|
---|
237 |
|
---|
238 | if (!evaluateFilter)
|
---|
239 | pvs = viewcell->GetPvs();
|
---|
240 | else
|
---|
241 | mViewCellsManager->ApplyFilter2(viewcell, false, mViewCellsManager->GetFilterWidth(), pvs);
|
---|
242 |
|
---|
243 | pvsSize = pvs.GetSize();
|
---|
244 |
|
---|
245 | // hack: assume that view cell empty
|
---|
246 | if (pvsSize == 0)
|
---|
247 | return 0.0f;
|
---|
248 |
|
---|
249 | SetupCamera();
|
---|
250 |
|
---|
251 | // use shading
|
---|
252 | if (mSnapErrorFrames)
|
---|
253 | {
|
---|
254 | glEnable(GL_NORMALIZE);
|
---|
255 |
|
---|
256 | // mat_specular and mat_shininess are NOT default values
|
---|
257 | GLfloat mat_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};
|
---|
258 | GLfloat mat_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
---|
259 | GLfloat mat_specular[] = {0.3f, 0.3f, 0.3f, 1.0f};
|
---|
260 | GLfloat mat_shininess[] = {1.0f};
|
---|
261 |
|
---|
262 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
|
---|
263 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
|
---|
264 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
---|
265 | glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
---|
266 |
|
---|
267 | GLfloat light_ambient[] = {0.3, 0.3, 0.3, 1.0};
|
---|
268 | //GLfloat light_diffuse[] = {0.6, 0.6, 0.6, 1.0};
|
---|
269 | GLfloat light_diffuse[] = {0.6, 0.6, 0.6, 1.0};
|
---|
270 | GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
|
---|
271 |
|
---|
272 | glEnable(GL_LIGHTING);
|
---|
273 | GLfloat light_position[] = {0.f, 0.f, 0.f, 1.0f};
|
---|
274 |
|
---|
275 | // lights in arena
|
---|
276 | glEnable(GL_LIGHT0);
|
---|
277 |
|
---|
278 | // a light
|
---|
279 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
---|
280 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
---|
281 | glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
---|
282 | glLightfv (GL_LIGHT0, GL_POSITION, light_position);
|
---|
283 |
|
---|
284 | glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
---|
285 | glEnable(GL_COLOR_MATERIAL);
|
---|
286 |
|
---|
287 | GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
|
---|
288 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
---|
289 |
|
---|
290 | glShadeModel(GL_SMOOTH);
|
---|
291 | }
|
---|
292 |
|
---|
293 | glDisable(GL_ALPHA_TEST);
|
---|
294 |
|
---|
295 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
296 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
297 |
|
---|
298 | //glColor3f(0.6f, 0.6f, 0.6f);
|
---|
299 | glColor3f(0, 1, 0);
|
---|
300 |
|
---|
301 | glDepthFunc(GL_LESS);
|
---|
302 | glDepthMask(GL_TRUE);
|
---|
303 | glEnable(GL_DEPTH_TEST);
|
---|
304 |
|
---|
305 | glFrontFace(GL_CCW);
|
---|
306 | glCullFace(GL_BACK);
|
---|
307 |
|
---|
308 | glStencilFunc(GL_EQUAL, 0x0, 0x1);
|
---|
309 | glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
---|
310 |
|
---|
311 | KdNode::NewMail2();
|
---|
312 | //Intersectable::NewMail();
|
---|
313 |
|
---|
314 | //mUseFalseColors = true;
|
---|
315 | // hack for gvs
|
---|
316 | RenderTrianglePvs();
|
---|
317 | // render pvs once
|
---|
318 | //RenderPvs(pvs);
|
---|
319 |
|
---|
320 | //glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
|
---|
321 | //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
|
---|
322 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
323 |
|
---|
324 | glEnable(GL_STENCIL_TEST);
|
---|
325 |
|
---|
326 | // errors in red
|
---|
327 | glColor3f(1, 0, 0);
|
---|
328 |
|
---|
329 |
|
---|
330 | // render scene, record differences
|
---|
331 | OcclusionQuery *query = mOcclusionQueries[0];
|
---|
332 |
|
---|
333 | KdNode::NewMail2();
|
---|
334 | //Intersectable::NewMail();
|
---|
335 |
|
---|
336 | query->BeginQuery();
|
---|
337 |
|
---|
338 | // current frame has to be increased at each rendering pass
|
---|
339 | ++ mCurrentFrame;
|
---|
340 |
|
---|
341 | RenderScene();
|
---|
342 |
|
---|
343 | glFlush();
|
---|
344 |
|
---|
345 | query->EndQuery();
|
---|
346 | glDisable(GL_STENCIL_TEST);
|
---|
347 |
|
---|
348 | pixelCount = query->GetQueryResult();
|
---|
349 |
|
---|
350 | pErrorPixels = (float)pixelCount / (GetWidth() * GetHeight());
|
---|
351 |
|
---|
352 | const int pixelThres = 0;
|
---|
353 |
|
---|
354 | // some error happened
|
---|
355 | if (1)//pixelCount > pixelThres)
|
---|
356 | {
|
---|
357 | cout << "f " << mFrame << " id " << viewcell->GetId() << " pvs " << pvsSize
|
---|
358 | << " e " << pixelCount << " vp " << mViewPoint << " vd " << mViewDirection << endl;
|
---|
359 |
|
---|
360 | if (mSnapErrorFrames)
|
---|
361 | {
|
---|
362 | glReadBuffer(GL_BACK);
|
---|
363 | //glReadBuffer(GL_FRONT);
|
---|
364 |
|
---|
365 | //////////////
|
---|
366 | //-- output error visualization
|
---|
367 |
|
---|
368 | char filename[256];
|
---|
369 | //sprintf(filename, "error-frame-%04d-%05d.bmp", pass, mFrame);
|
---|
370 | //sprintf(filename, "error-frame-%05d-%0.5f.png", mFrame, pErrorPixels);
|
---|
371 | sprintf_s(filename, "error-frame-%05d-%05d-%08d.png", viewcell->GetId(), mFrame, pixelCount);
|
---|
372 |
|
---|
373 | QImage im = toImage();
|
---|
374 | string str = mSnapPrefix + filename;
|
---|
375 | QString qstr(str.c_str());
|
---|
376 |
|
---|
377 | im.save(qstr, "PNG");
|
---|
378 |
|
---|
379 | if (1)
|
---|
380 | {
|
---|
381 | ///////////
|
---|
382 | //-- output computed pvs
|
---|
383 |
|
---|
384 | //mUseFalseColors = false;
|
---|
385 | mUseFalseColors = true;
|
---|
386 | glPushAttrib(GL_CURRENT_BIT);
|
---|
387 | glColor3f(0, 1, 0);
|
---|
388 |
|
---|
389 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
390 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
391 |
|
---|
392 | KdNode::NewMail2();
|
---|
393 |
|
---|
394 | ++ mCurrentFrame;
|
---|
395 |
|
---|
396 | // render pvs once
|
---|
397 | //RenderPvs(pvs);
|
---|
398 | EnableDrawArrays();
|
---|
399 |
|
---|
400 | // prepare pvs for rendering
|
---|
401 | PreparePvs(pvs);
|
---|
402 | _RenderColoredPvs(pvs);
|
---|
403 | // hack for gvs visualization
|
---|
404 | //RenderTrianglePvs();
|
---|
405 |
|
---|
406 | glFlush();
|
---|
407 |
|
---|
408 | mUseFalseColors = false;
|
---|
409 |
|
---|
410 | im = toImage();
|
---|
411 | sprintf_s(filename, "error-frame-%05d-%05d-%08d-pvs.png", viewcell->GetId(), mFrame, pixelCount);
|
---|
412 | str = mSnapPrefix + filename;
|
---|
413 | qstr = str.c_str();
|
---|
414 | im.save(qstr, "PNG");
|
---|
415 |
|
---|
416 | glPopAttrib();
|
---|
417 | }
|
---|
418 | }
|
---|
419 | }
|
---|
420 |
|
---|
421 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
422 |
|
---|
423 | //DoneLive();
|
---|
424 |
|
---|
425 | return pErrorPixels;
|
---|
426 | }
|
---|
427 |
|
---|
428 | int
|
---|
429 | QtGlRendererBuffer::ComputePvs(ObjectContainer &objects,
|
---|
430 | ObjectContainer &pvs) const
|
---|
431 | {
|
---|
432 | int pvsSize = 0;
|
---|
433 | QImage image = toImage();
|
---|
434 |
|
---|
435 | Intersectable::NewMail();
|
---|
436 |
|
---|
437 | std::stable_sort(objects.begin(), objects.end(), ilt);
|
---|
438 |
|
---|
439 | MeshInstance dummy(NULL);
|
---|
440 |
|
---|
441 | Intersectable *obj = NULL;
|
---|
442 |
|
---|
443 | for (int x = 0; x < image.width(); ++ x)
|
---|
444 | {
|
---|
445 | for (int y = 0; y < image.height(); ++ y)
|
---|
446 | {
|
---|
447 | QRgb pix = image.pixel(x, y);
|
---|
448 | const int id = GetId(qRed(pix), qGreen(pix), qBlue(pix));
|
---|
449 |
|
---|
450 | dummy.SetId(id);
|
---|
451 |
|
---|
452 | ObjectContainer::iterator oit =
|
---|
453 | lower_bound(objects.begin(), objects.end(), &dummy, ilt);
|
---|
454 |
|
---|
455 | if (//(oit != oit.end()) &&
|
---|
456 | ((*oit)->GetId() == id) &&
|
---|
457 | !obj->Mailed())
|
---|
458 | {
|
---|
459 | obj = *oit;
|
---|
460 | obj->Mail();
|
---|
461 | ++ pvsSize;
|
---|
462 | pvs.push_back(obj);
|
---|
463 | }
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | return pvsSize;
|
---|
468 | }
|
---|
469 |
|
---|
470 |
|
---|
471 | void QtGlRendererWidget::InitGL()
|
---|
472 | {
|
---|
473 | GlRenderer::InitGL();
|
---|
474 |
|
---|
475 | //glEnable(GL_FOG);
|
---|
476 | //glFogi(GL_FOG_MODE, GL_EXP);
|
---|
477 | //glFogf(GL_FOG_DENSITY, .2f);
|
---|
478 | glFogi(GL_FOG_MODE, GL_LINEAR);
|
---|
479 | glFogf(GL_FOG_START, 50.f);
|
---|
480 | glFogf(GL_FOG_END, 500.f);
|
---|
481 |
|
---|
482 |
|
---|
483 | // mat_specular and mat_shininess are NOT default values
|
---|
484 | GLfloat mat_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};
|
---|
485 | GLfloat mat_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
---|
486 | GLfloat mat_specular[] = {0.3f, 0.3f, 0.3f, 1.0f};
|
---|
487 | GLfloat mat_shininess[] = {1.0f};
|
---|
488 |
|
---|
489 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
|
---|
490 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
|
---|
491 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
---|
492 | glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
---|
493 |
|
---|
494 |
|
---|
495 | glEnable(GL_LIGHTING);
|
---|
496 |
|
---|
497 | // a light
|
---|
498 | GLfloat light_ambient[] = {0.3, 0.3, 0.3, 1.0};
|
---|
499 | GLfloat light_diffuse[] = {0.6, 0.6, 0.6, 1.0};
|
---|
500 | GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
|
---|
501 | GLfloat light_position[] = {0.f, .0f, 0.f, 1.0f};
|
---|
502 | //GLfloat light_position[] = {600.0f, 250.0f, -500.f, 1.0f};
|
---|
503 | //GLfloat light_position[] = {278.0f, 548.8f,279.0f, 1.0f};
|
---|
504 |
|
---|
505 |
|
---|
506 |
|
---|
507 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
---|
508 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
---|
509 | glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
---|
510 |
|
---|
511 | glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
---|
512 |
|
---|
513 | //glDisable(GL_LIGHT0);
|
---|
514 | glEnable(GL_LIGHT0);
|
---|
515 |
|
---|
516 | glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
---|
517 | glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
---|
518 | glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
---|
519 |
|
---|
520 | // set position of the light2
|
---|
521 | GLfloat infinite_light2[] = { -0.3, 1.5, 1.0, 0.0 };
|
---|
522 | glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
|
---|
523 | //glEnable(GL_LIGHT1);
|
---|
524 |
|
---|
525 | GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
|
---|
526 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
---|
527 |
|
---|
528 | glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
---|
529 | //glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
|
---|
530 | glEnable(GL_COLOR_MATERIAL);
|
---|
531 |
|
---|
532 | glShadeModel(GL_SMOOTH);
|
---|
533 | }
|
---|
534 |
|
---|
535 |
|
---|
536 | void
|
---|
537 | QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle)
|
---|
538 | {
|
---|
539 | if (!mTopView) {
|
---|
540 | int ww = w;
|
---|
541 | int hh = h;
|
---|
542 | glViewport(0, 0, ww, hh);
|
---|
543 | glMatrixMode(GL_PROJECTION);
|
---|
544 | glLoadIdentity();
|
---|
545 | gluPerspective(angle, ww/(float)hh, 0.1, 2.0 * Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
546 | glMatrixMode(GL_MODELVIEW);
|
---|
547 | } else {
|
---|
548 | int ww = w;
|
---|
549 | int hh = h;
|
---|
550 | glViewport(0, 0, ww, hh);
|
---|
551 | glMatrixMode(GL_PROJECTION);
|
---|
552 | glLoadIdentity();
|
---|
553 | gluPerspective(50.0, ww / (float)hh, 0.1, 20.0 * Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
554 | glMatrixMode(GL_MODELVIEW);
|
---|
555 | }
|
---|
556 | }
|
---|
557 |
|
---|
558 |
|
---|
559 | bool QtGlRendererWidget::PvsChanged(ViewCell *viewCell) const
|
---|
560 | {
|
---|
561 | if (viewCell != mPvsCache.mViewCell)
|
---|
562 | return true;
|
---|
563 |
|
---|
564 | if (viewCell->GetPvs().GetSize() != mPvsCache.mUnfilteredPvsSize)
|
---|
565 | return true;
|
---|
566 |
|
---|
567 | return false;
|
---|
568 | }
|
---|
569 |
|
---|
570 |
|
---|
571 | void QtGlRendererWidget::_RenderPvs()
|
---|
572 | {
|
---|
573 | EnableDrawArrays();
|
---|
574 |
|
---|
575 | if (mUseVbos)
|
---|
576 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
|
---|
577 |
|
---|
578 | mUseFalseColors = false;
|
---|
579 |
|
---|
580 | int offset = (int)mObjects.size() * 3;
|
---|
581 | char *arrayPtr = mUseVbos ? NULL : (char *)mData;
|
---|
582 |
|
---|
583 | glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr);
|
---|
584 | glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
|
---|
585 | glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
|
---|
586 |
|
---|
587 | // handle dynamic objects in pvss
|
---|
588 | DynamicObjectsContainer::const_iterator dit, dit_end = mDynamicPvsObjects.end();
|
---|
589 |
|
---|
590 | //cout << "dynamic objects in pvs " << mDynamicPvsObjects.size() << endl;;
|
---|
591 | #if 0
|
---|
592 | for (dit = mDynamicPvsObjects.begin(); dit != dit_end; ++ dit)
|
---|
593 | {
|
---|
594 | _RenderDynamicObject(*dit);
|
---|
595 | }
|
---|
596 | #endif
|
---|
597 | //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
---|
598 |
|
---|
599 | // show placed dynamic objects as wireframe
|
---|
600 | Preprocessor *p = mViewCellsManager->GetPreprocessor();
|
---|
601 | dit_end = p->mDynamicObjects.end();
|
---|
602 |
|
---|
603 | int i = 0;
|
---|
604 | for (dit = p->mDynamicObjects.begin(); dit != dit_end; ++ dit, ++ i)
|
---|
605 | {
|
---|
606 | if (i == mCurrentDynamicObjectIdx)
|
---|
607 | glColor3f(1, 0, 1);
|
---|
608 | else glColor3f(0.6f, 0.6f, 0.6f);
|
---|
609 |
|
---|
610 | _RenderDynamicObject(*dit);
|
---|
611 | }
|
---|
612 |
|
---|
613 | //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
---|
614 | }
|
---|
615 |
|
---|
616 |
|
---|
617 | void QtGlRendererWidget::PreparePvs(const ObjectPvs &pvs)
|
---|
618 | {
|
---|
619 | int indexBufferSize = 0;
|
---|
620 |
|
---|
621 | // hack: mail not working with multiple threads
|
---|
622 | KdNode::NewMail2();
|
---|
623 |
|
---|
624 | mPvsSize = pvs.GetSize();
|
---|
625 |
|
---|
626 | mDynamicPvsObjects.clear();
|
---|
627 |
|
---|
628 | ObjectPvsIterator it = pvs.GetIterator();
|
---|
629 |
|
---|
630 | while (it.HasMoreEntries())
|
---|
631 | {
|
---|
632 | Intersectable *obj = it.Next();
|
---|
633 |
|
---|
634 | switch (obj->Type())
|
---|
635 | {
|
---|
636 | case Intersectable::KD_INTERSECTABLE:
|
---|
637 | {
|
---|
638 | KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem();
|
---|
639 | _UpdatePvsIndices(node, indexBufferSize);
|
---|
640 | }
|
---|
641 | break;
|
---|
642 |
|
---|
643 | case Intersectable::SCENEGRAPHLEAF_INTERSECTABLE:
|
---|
644 | mDynamicPvsObjects.push_back(static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem());
|
---|
645 | break;
|
---|
646 | default:
|
---|
647 | cerr << "PreparePvs: type " << Intersectable::GetTypeName(obj) << " not handled yet" << endl;
|
---|
648 | }
|
---|
649 | }
|
---|
650 |
|
---|
651 | mIndexBufferSize = indexBufferSize;
|
---|
652 | }
|
---|
653 |
|
---|
654 |
|
---|
655 | void QtGlRendererWidget::VisualizePvs()
|
---|
656 | {
|
---|
657 | if (mUseVbos)
|
---|
658 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
|
---|
659 |
|
---|
660 | ++ mCurrentFrame;
|
---|
661 |
|
---|
662 | EnableDrawArrays();
|
---|
663 |
|
---|
664 | if (mDetectEmptyViewSpace)
|
---|
665 | glEnable(GL_CULL_FACE);
|
---|
666 | else
|
---|
667 | glDisable(GL_CULL_FACE);
|
---|
668 |
|
---|
669 | ViewCell *viewcell = NULL;
|
---|
670 | viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
|
---|
671 |
|
---|
672 | if (viewcell)
|
---|
673 | {
|
---|
674 | // copy the pvs so that it can be filtered ...
|
---|
675 | if (PvsChanged(viewcell))
|
---|
676 | {
|
---|
677 | mPvsCache.Reset();
|
---|
678 | mPvsCache.mViewCell = viewcell;
|
---|
679 | mPvsCache.mUnfilteredPvsSize = viewcell->GetPvs().GetSize();
|
---|
680 |
|
---|
681 | if (mUseSpatialFilter)
|
---|
682 | {
|
---|
683 | //mMutex.lock();
|
---|
684 | // mSpatialFilter size is in range 0.001 - 0.1
|
---|
685 | mViewCellsManager->ApplyFilter2(viewcell,
|
---|
686 | mUseFilter,
|
---|
687 | 100.0f * mSpatialFilterSize,
|
---|
688 | mPvsCache.mPvs,
|
---|
689 | &mPvsCache.filteredBoxes);
|
---|
690 | //mPvsCache.mPvs = pvs;
|
---|
691 | //mMutex.unlock();
|
---|
692 | //cout << "pvs size: " << mPvsCache.mPvs.GetSize() << endl;
|
---|
693 | }
|
---|
694 | else
|
---|
695 | {
|
---|
696 | mPvsCache.mPvs = viewcell->GetPvs();
|
---|
697 | }
|
---|
698 |
|
---|
699 | // update the indices for rendering
|
---|
700 | PreparePvs(mPvsCache.mPvs);
|
---|
701 | emit PvsUpdated();
|
---|
702 |
|
---|
703 | mCurrentPvsCost = mPvsCache.mPvs.EvalPvsCost();
|
---|
704 | }
|
---|
705 |
|
---|
706 | // Render PVS
|
---|
707 | if (mUseSpatialFilter && mRenderBoxes)
|
---|
708 | {
|
---|
709 | for (size_t i=0; i < mPvsCache.filteredBoxes.size(); ++ i)
|
---|
710 | {
|
---|
711 | RenderBox(mPvsCache.filteredBoxes[i]);
|
---|
712 | }
|
---|
713 | }
|
---|
714 | else
|
---|
715 | {
|
---|
716 | if (!mRenderVisibilityEstimates && !mUseRandomColorPerPvsObject)
|
---|
717 | _RenderPvs();
|
---|
718 | else
|
---|
719 | _RenderColoredPvs(mPvsCache.mPvs);
|
---|
720 | }
|
---|
721 |
|
---|
722 | if (mRenderFilter)
|
---|
723 | {
|
---|
724 | mWireFrame = true;
|
---|
725 | RenderIntersectable(viewcell);
|
---|
726 |
|
---|
727 | mWireFrame = false;
|
---|
728 | }
|
---|
729 | }
|
---|
730 | else
|
---|
731 | {
|
---|
732 | RenderScene();
|
---|
733 | }
|
---|
734 |
|
---|
735 | //cout << "vp: " << mViewPoint << " vd: " << mViewDirection << endl;
|
---|
736 | }
|
---|
737 |
|
---|
738 | float
|
---|
739 | QtGlRendererWidget::RenderErrors()
|
---|
740 | {
|
---|
741 | float pErrorPixels = -1.0f;
|
---|
742 |
|
---|
743 | SetupCamera();
|
---|
744 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
745 |
|
---|
746 | glPushAttrib(GL_ENABLE_BIT);
|
---|
747 |
|
---|
748 | glStencilFunc(GL_EQUAL, 0x0, 0x1);
|
---|
749 | glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
---|
750 |
|
---|
751 | #if TEASER
|
---|
752 | glColor3f(0.0f, 0.8f, 0.0f);
|
---|
753 | #else
|
---|
754 | glColor3f(0.6f, 0.6f, 0.6f);
|
---|
755 | #endif
|
---|
756 |
|
---|
757 | // Render PVS
|
---|
758 | VisualizePvs();
|
---|
759 |
|
---|
760 | glEnable(GL_STENCIL_TEST);
|
---|
761 | glDisable(GL_LIGHTING);
|
---|
762 |
|
---|
763 | SetupCamera();
|
---|
764 |
|
---|
765 | mUseForcedColors = true;
|
---|
766 |
|
---|
767 | glColor3f(1.0f, 0.0f, 0.0f);
|
---|
768 |
|
---|
769 | OcclusionQuery *query = mOcclusionQueries[0];
|
---|
770 | query->BeginQuery();
|
---|
771 |
|
---|
772 | RenderScene();
|
---|
773 |
|
---|
774 | mUseForcedColors = false;
|
---|
775 |
|
---|
776 | query->EndQuery();
|
---|
777 |
|
---|
778 | glDisable(GL_STENCIL_TEST);
|
---|
779 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
780 |
|
---|
781 | glPopAttrib();
|
---|
782 |
|
---|
783 | // reenable other state
|
---|
784 | // int wait=0;
|
---|
785 | // while (!query.ResultAvailable()) {
|
---|
786 | // wait++;
|
---|
787 | // }
|
---|
788 |
|
---|
789 | int pixelCount = query->GetQueryResult();
|
---|
790 | pErrorPixels = (float)pixelCount / (GetWidth() * GetHeight());
|
---|
791 |
|
---|
792 | if (0) cout << "error pixels=" << pixelCount << endl;
|
---|
793 |
|
---|
794 | mRenderError = pErrorPixels;
|
---|
795 |
|
---|
796 | return pErrorPixels;
|
---|
797 | }
|
---|
798 |
|
---|
799 |
|
---|
800 | void QtGlRendererWidget::timerEvent(QTimerEvent *timerEvent)
|
---|
801 | {
|
---|
802 | if (mReplayMode && (timerEvent->timerId() == mReplayTimerId))
|
---|
803 | {
|
---|
804 | if (sViewPointsListIt == sViewPointsList.end())
|
---|
805 | {
|
---|
806 | cout << "stopping replay" << endl;
|
---|
807 | mReplayMode = false;
|
---|
808 | GetPreprocessor()->mSynchronize = false;
|
---|
809 | }
|
---|
810 | else
|
---|
811 | {
|
---|
812 | SimpleRay sray = *sViewPointsListIt;
|
---|
813 |
|
---|
814 | mViewPoint = sray.mOrigin;
|
---|
815 | mViewDirection = sray.mDirection;
|
---|
816 |
|
---|
817 | ++ sViewPointsListIt;
|
---|
818 | }
|
---|
819 |
|
---|
820 | updateGL();
|
---|
821 |
|
---|
822 | // output the current frame buffer
|
---|
823 | if (mExportFrameBuffer)
|
---|
824 | {
|
---|
825 | const int dist = sViewPointsListIt - sViewPointsList.begin();
|
---|
826 |
|
---|
827 | char filename[200];
|
---|
828 | sprintf(filename, "error-frame-%04d-%05d.bmp", sCurrentSamples, dist);
|
---|
829 | //QPixmap img = renderPixmap(0, 0, true);
|
---|
830 | QImage im = grabFrameBuffer();
|
---|
831 |
|
---|
832 | string str = mSnapPrefix + filename;
|
---|
833 | QString qstr(str.c_str());
|
---|
834 |
|
---|
835 | //im.save(qstr, "PNG");
|
---|
836 | // use bmp for lossless storage (for video)
|
---|
837 | im.save(qstr, "BMP");
|
---|
838 | }
|
---|
839 | }
|
---|
840 | else if (timerEvent->timerId() == mUpdateTimerId)
|
---|
841 | // update pvss from time to time
|
---|
842 | update();
|
---|
843 |
|
---|
844 | // grab frame buffer after a certain number of samples
|
---|
845 | if (!mReplayMode &&
|
---|
846 | (sCurrentSamplesThreshold < sNumReplays) &&
|
---|
847 | ((GetPreprocessor()->mCurrentSamples > sNextSamplesThreshold[sCurrentSamplesThreshold])))
|
---|
848 | {
|
---|
849 | ++ sCurrentSamplesThreshold;
|
---|
850 | cout << "replaying at total samples: " << GetPreprocessor()->mCurrentSamples << endl;
|
---|
851 | ReplayViewPoints();
|
---|
852 | }
|
---|
853 |
|
---|
854 | }
|
---|
855 |
|
---|
856 |
|
---|
857 | void QtGlRendererWidget::mousePressEvent(QMouseEvent *e)
|
---|
858 | {
|
---|
859 | int x = e->pos().x();
|
---|
860 | int y = e->pos().y();
|
---|
861 |
|
---|
862 | mousePoint.x = x;
|
---|
863 | mousePoint.y = y;
|
---|
864 |
|
---|
865 | if (e->button() == Qt::RightButton)
|
---|
866 | {
|
---|
867 | if (mPlacer->GetCurrentObject())
|
---|
868 | {
|
---|
869 | Vector3 pt = Unproject(x, y);
|
---|
870 |
|
---|
871 | mPlacer->PlaceObject(pt);
|
---|
872 | SceneGraphLeaf *leaf = mPlacer->GetCurrentObject();
|
---|
873 |
|
---|
874 | // hack: should just pass a IntersectableGroup as a whole
|
---|
875 | // instead we duplicate the object container and create a new
|
---|
876 | // leaf
|
---|
877 | SceneGraphLeaf *newObj = new SceneGraphLeaf(*leaf);
|
---|
878 |
|
---|
879 | // make current object
|
---|
880 | // the object is added at the end of the vector
|
---|
881 | mCurrentDynamicObjectIdx = (int)GetPreprocessor()->mDynamicObjects.size();
|
---|
882 |
|
---|
883 | GetPreprocessor()->RegisterDynamicObject(newObj);
|
---|
884 | }
|
---|
885 | }
|
---|
886 | }
|
---|
887 |
|
---|
888 |
|
---|
889 | void QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *e)
|
---|
890 | {
|
---|
891 | int x = e->pos().x();
|
---|
892 | int y = e->pos().y();
|
---|
893 |
|
---|
894 | mousePoint.x = x;
|
---|
895 | mousePoint.y = y;
|
---|
896 |
|
---|
897 | if (e->modifiers() & Qt::ShiftModifier)
|
---|
898 | {
|
---|
899 | const Vector3 pt = Unproject(x, y);
|
---|
900 |
|
---|
901 | int idx = FindDynamicObject(x, y);
|
---|
902 |
|
---|
903 | if (idx >= 0)
|
---|
904 | {
|
---|
905 | mCurrentDynamicObjectIdx = idx;
|
---|
906 | }
|
---|
907 | }
|
---|
908 | }
|
---|
909 |
|
---|
910 | void
|
---|
911 | QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e)
|
---|
912 | {
|
---|
913 | if (mReplayMode)
|
---|
914 | return;
|
---|
915 |
|
---|
916 | float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3;
|
---|
917 | float TURN_SENSITIVITY = 0.1f;
|
---|
918 | float TILT_SENSITIVITY = 32.0 ;
|
---|
919 | float TURN_ANGLE= M_PI / 36.0 ;
|
---|
920 |
|
---|
921 | int x = e->pos().x();
|
---|
922 | int y = e->pos().y();
|
---|
923 |
|
---|
924 | int diffx = -(mousePoint.x - x);
|
---|
925 | int diffy = -(mousePoint.y - y);
|
---|
926 |
|
---|
927 | const float t = 1.0f;
|
---|
928 | if (e->modifiers() & Qt::ControlModifier)
|
---|
929 | {
|
---|
930 | mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY / 2.0;
|
---|
931 | mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY / 2.0;
|
---|
932 | }
|
---|
933 | else if (e->modifiers() & Qt::AltModifier)
|
---|
934 | {
|
---|
935 | if (mCurrentDynamicObjectIdx >= 0)
|
---|
936 | {
|
---|
937 | Matrix4x4 tm;
|
---|
938 |
|
---|
939 | SceneGraphLeaf *l =
|
---|
940 | mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
|
---|
941 |
|
---|
942 | switch (mTrafoType)
|
---|
943 | {
|
---|
944 | case 0:
|
---|
945 | {
|
---|
946 | if (e->modifiers() & Qt::ShiftModifier) {
|
---|
947 | const Vector3 transl(0, diffy, 0);
|
---|
948 | tm = TranslationMatrix(transl);
|
---|
949 |
|
---|
950 | } else {
|
---|
951 | const Vector3 transl(diffx, 0, diffy);
|
---|
952 | tm = TranslationMatrix(transl);
|
---|
953 | }
|
---|
954 | }
|
---|
955 | break;
|
---|
956 | case 1:
|
---|
957 | {
|
---|
958 | float scalef = 1.0f + 0.01f * (diffx + diffy);
|
---|
959 | if (scalef < 0.9) scalef = 0.9f;
|
---|
960 | else if (scalef > 1.1f) scalef = 1.1f;
|
---|
961 | tm = ScaleMatrix(scalef, scalef, scalef);
|
---|
962 | }
|
---|
963 | break;
|
---|
964 | case 2:
|
---|
965 | {
|
---|
966 | // tm = RotationXMatrix(diffx) * RotationYMatrix(diffy);
|
---|
967 | tm = RotationYMatrix(diffx);
|
---|
968 | }
|
---|
969 | break;
|
---|
970 | default:
|
---|
971 | cerr << "not implemented" << endl;
|
---|
972 | }
|
---|
973 |
|
---|
974 | l->ApplyTransform(tm);
|
---|
975 |
|
---|
976 | updateGL();
|
---|
977 | }
|
---|
978 | }
|
---|
979 | else
|
---|
980 | {
|
---|
981 | mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
|
---|
982 | float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
|
---|
983 | float angle = atan2(mViewDirection.x, mViewDirection.z);
|
---|
984 | mViewDirection.x = sin(angle + adiff);
|
---|
985 | mViewDirection.z = cos(angle + adiff);
|
---|
986 | }
|
---|
987 |
|
---|
988 | mousePoint.x = x;
|
---|
989 | mousePoint.y = y;
|
---|
990 |
|
---|
991 | updateGL();
|
---|
992 | }
|
---|
993 |
|
---|
994 |
|
---|
995 | void
|
---|
996 | QtGlRendererWidget::resizeGL(int w, int h)
|
---|
997 | {
|
---|
998 | SetupCameraProjection(w, h);
|
---|
999 | updateGL();
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 |
|
---|
1003 | void QtGlRendererWidget::paintGL()
|
---|
1004 | {
|
---|
1005 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
1006 |
|
---|
1007 | SetupCameraProjection(width(), height());
|
---|
1008 | SetupCamera();
|
---|
1009 |
|
---|
1010 | if (mRenderErrors)
|
---|
1011 | RenderErrors();
|
---|
1012 | else
|
---|
1013 | {
|
---|
1014 | glColor3f(0.6f, 0.6f, 0.6f);
|
---|
1015 | VisualizePvs();
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | if (mShowRays)
|
---|
1019 | RenderRays(mViewCellsManager->mVizBuffer.GetRays(), mRayVisualizationMethod, mShowDistribution, 1);
|
---|
1020 |
|
---|
1021 | RenderInfo();
|
---|
1022 |
|
---|
1023 | ++ mFrame;
|
---|
1024 | // cout<<"vp="<<mViewPoint<<" vd="<<mViewDirection<<endl;
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 |
|
---|
1028 | void
|
---|
1029 | QtGlRendererWidget::SetupCamera()
|
---|
1030 | {
|
---|
1031 | if (!mTopView)
|
---|
1032 | GlRenderer::SetupCamera();
|
---|
1033 | else
|
---|
1034 | {
|
---|
1035 | if (0)
|
---|
1036 | {
|
---|
1037 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05;
|
---|
1038 | Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x,
|
---|
1039 | -1,
|
---|
1040 | mViewDirection.y);
|
---|
1041 |
|
---|
1042 | Vector3 target = mViewPoint + dist*mViewDirection;
|
---|
1043 | Vector3 up(0,1,0);
|
---|
1044 |
|
---|
1045 | glLoadIdentity();
|
---|
1046 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
1047 | target.x, target.y, target.z,
|
---|
1048 | up.x, up.y, up.z);
|
---|
1049 | }
|
---|
1050 | else
|
---|
1051 | {
|
---|
1052 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal()) * mTopDistance;
|
---|
1053 | Vector3 pos = mViewPoint + dist * Vector3(0, 1, 0);
|
---|
1054 |
|
---|
1055 | Vector3 target = mViewPoint;
|
---|
1056 | Vector3 up(mViewDirection.x, 0, mViewDirection.z);
|
---|
1057 |
|
---|
1058 | glLoadIdentity();
|
---|
1059 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
1060 | target.x, target.y, target.z,
|
---|
1061 | up.x, up.y, up.z);
|
---|
1062 |
|
---|
1063 | }
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 |
|
---|
1069 | void
|
---|
1070 | QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
|
---|
1071 | {
|
---|
1072 | switch (e->key())
|
---|
1073 | {
|
---|
1074 | case Qt::Key_E:
|
---|
1075 | mRenderErrors = !mRenderErrors;
|
---|
1076 | updateGL();
|
---|
1077 | break;
|
---|
1078 | case Qt::Key_R:
|
---|
1079 | mUseRandomColorPerPvsObject = !mUseRandomColorPerPvsObject;;
|
---|
1080 | updateGL();
|
---|
1081 | break;
|
---|
1082 | case Qt::Key_T:
|
---|
1083 | mTopView = !mTopView;
|
---|
1084 | SetupCameraProjection(width(), height());
|
---|
1085 | updateGL();
|
---|
1086 | break;
|
---|
1087 | case Qt::Key_V:
|
---|
1088 | mRenderViewCells = !mRenderViewCells;
|
---|
1089 | updateGL();
|
---|
1090 | break;
|
---|
1091 | case Qt::Key_P:
|
---|
1092 | // set random viewpoint
|
---|
1093 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
1094 | updateGL();
|
---|
1095 | break;
|
---|
1096 | case Qt::Key_S: {
|
---|
1097 | // set view poitn and direction
|
---|
1098 | QString text;
|
---|
1099 | bool ok;
|
---|
1100 | text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z);
|
---|
1101 | text = QInputDialog::getText(this,
|
---|
1102 | "Enter a view point",
|
---|
1103 | "",
|
---|
1104 | QLineEdit::Normal,
|
---|
1105 | text,
|
---|
1106 | &ok);
|
---|
1107 | if (!ok)
|
---|
1108 | break;
|
---|
1109 |
|
---|
1110 | if (sscanf_s(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) {
|
---|
1111 | text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z);
|
---|
1112 | text = QInputDialog::getText(this,
|
---|
1113 | "Enter a direction",
|
---|
1114 | "",
|
---|
1115 | QLineEdit::Normal,
|
---|
1116 | text,
|
---|
1117 | &ok);
|
---|
1118 | if (!ok)
|
---|
1119 | break;
|
---|
1120 | if (sscanf_s(text.toAscii(), "%f %f %f", &mViewDirection.x,
|
---|
1121 | &mViewDirection.y, &mViewDirection.z) == 3) {
|
---|
1122 | updateGL();
|
---|
1123 | }
|
---|
1124 | break;
|
---|
1125 | }
|
---|
1126 | }
|
---|
1127 | default:
|
---|
1128 | cerr << "unknown key" << endl;
|
---|
1129 | e->ignore();
|
---|
1130 | break;
|
---|
1131 | }
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 |
|
---|
1135 |
|
---|
1136 | QtGlRendererWidget::QtGlRendererWidget(
|
---|
1137 | SceneGraph *sceneGraph,
|
---|
1138 | ViewCellsManager *viewcells,
|
---|
1139 | KdTree *tree,
|
---|
1140 | QWidget * parent,
|
---|
1141 | const QGLWidget * shareWidget,
|
---|
1142 | Qt::WFlags f):
|
---|
1143 | GlRendererWidget(sceneGraph, viewcells, tree),
|
---|
1144 | QGLWidget(QGLFormat(QGL::SampleBuffers), parent, shareWidget, f)
|
---|
1145 | {
|
---|
1146 | mPreprocessorThread = NULL;
|
---|
1147 | mTopView = false;
|
---|
1148 | mRenderViewCells = false;
|
---|
1149 | mTopDistance = 1.0f;
|
---|
1150 | mCutViewCells = false;
|
---|
1151 | mCutScene = false;
|
---|
1152 | mRenderErrors = false;
|
---|
1153 | mRenderBoxes = false;
|
---|
1154 | mRenderFilter = true;
|
---|
1155 | mRenderVisibilityEstimates = false;
|
---|
1156 | //mRenderVisibilityEstimates = true;
|
---|
1157 |
|
---|
1158 | mComputeGVS = false;
|
---|
1159 | mUseRandomColorPerPvsObject = false;
|
---|
1160 | //mUseRandomColorPerPvsObject = true;
|
---|
1161 |
|
---|
1162 | mHideByCost = false;
|
---|
1163 | mUseTransparency = false;
|
---|
1164 |
|
---|
1165 | mTransferFunction = 1.0f;
|
---|
1166 | mIndexBufferSize = 0;
|
---|
1167 |
|
---|
1168 | const int delay = 250; // in milliseconds
|
---|
1169 | mUpdateTimerId = startTimer(delay);
|
---|
1170 | mReplayTimerId = startTimer(1); // use fastest replay rate
|
---|
1171 |
|
---|
1172 | bool tmp;
|
---|
1173 |
|
---|
1174 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
1175 | mUseFilter = tmp;
|
---|
1176 |
|
---|
1177 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", tmp );
|
---|
1178 | mUseSpatialFilter = tmp;
|
---|
1179 |
|
---|
1180 | mShowRenderCost = false;
|
---|
1181 | mShowPvsSizes = false;
|
---|
1182 | mShowComparison = false;
|
---|
1183 | mShowPiercingRays = false;
|
---|
1184 | mShowWeightedRays = false;
|
---|
1185 | mUseStandardColors = false;
|
---|
1186 | mShowWeightedCost = true;
|
---|
1187 |
|
---|
1188 | mShowDistanceWeightedPvs = true;
|
---|
1189 | mShowDistanceWeightedTriangles = false;
|
---|
1190 | mShowWeightedTriangles = false;
|
---|
1191 | mShowDistribution = 15;
|
---|
1192 |
|
---|
1193 | mSpatialFilterSize = 0.01;
|
---|
1194 | mPvsSize = 0;
|
---|
1195 | mRayVisualizationMethod = 0;
|
---|
1196 | mTrafoType = 0;
|
---|
1197 |
|
---|
1198 | mRenderError = 0.0f;
|
---|
1199 |
|
---|
1200 | mShowRays = false;
|
---|
1201 | mReplayMode = false;
|
---|
1202 |
|
---|
1203 | mPlacer = new ObjectPlacer();
|
---|
1204 |
|
---|
1205 | mCurrentDynamicObjectIdx = -1;
|
---|
1206 |
|
---|
1207 | // export frame buffer during walkthrough
|
---|
1208 | //mExportFrameBuffer = true;
|
---|
1209 | mExportFrameBuffer = false;
|
---|
1210 |
|
---|
1211 | const int sceneCut = 339;
|
---|
1212 | SetSceneCut(sceneCut);
|
---|
1213 | mControlWidget = new QtRendererControlWidget(NULL);
|
---|
1214 |
|
---|
1215 | connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
|
---|
1216 | connect(mControlWidget, SIGNAL(SetTransferFunction(int)), this, SLOT(SetTransferFunction(int)));
|
---|
1217 |
|
---|
1218 | connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs()));
|
---|
1219 | connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility()));
|
---|
1220 | connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation()));
|
---|
1221 | connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this, SLOT(SetRandomViewPoint()));
|
---|
1222 | connect(mControlWidget, SIGNAL(StoreStatistics(void)), this, SLOT(StoreStatistics(void)));
|
---|
1223 | connect(mControlWidget, SIGNAL(ComputeGVS(void)), this, SLOT(ComputeGVS(void)));
|
---|
1224 | connect(mControlWidget, SIGNAL(ReplayViewPoints(void)), this, SLOT(ReplayViewPoints(void)));
|
---|
1225 | connect(mControlWidget, SIGNAL(NextObject(void)), this, SLOT(NextObject(void)));
|
---|
1226 |
|
---|
1227 | connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
|
---|
1228 | connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
|
---|
1229 | connect(mControlWidget, SIGNAL(SetMaxRenderCost(int)), this, SLOT(SetMaxRenderCost(int)));
|
---|
1230 | connect(mControlWidget, SIGNAL(SetTransparency(int)), this, SLOT(SetTransparency(int)));
|
---|
1231 |
|
---|
1232 | connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
|
---|
1233 | connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int)));
|
---|
1234 | connect(mControlWidget, SIGNAL(SetHidingCost(int)), this, SLOT(SetHidingCost(int)));
|
---|
1235 |
|
---|
1236 | connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
|
---|
1237 | connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool)));
|
---|
1238 | connect(mControlWidget, SIGNAL(SetUseTransparency(bool)), this, SLOT(SetUseTransparency(bool)));
|
---|
1239 | connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool)));
|
---|
1240 | connect(mControlWidget, SIGNAL(SetShowComparison(bool)), this, SLOT(SetShowComparison(bool)));
|
---|
1241 | connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
|
---|
1242 | connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
|
---|
1243 | connect(mControlWidget, SIGNAL(SetHideByCost(bool)), this, SLOT(SetHideByCost(bool)));
|
---|
1244 | connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
|
---|
1245 | connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
|
---|
1246 | connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool)));
|
---|
1247 | connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
|
---|
1248 | connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)), this, SLOT(SetRenderVisibilityEstimates(bool)));
|
---|
1249 | connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool)));
|
---|
1250 | connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)), this, SLOT(SetUseSpatialFilter(bool)));
|
---|
1251 | connect(mControlWidget, SIGNAL(SetShowPiercingRays(bool)), this, SLOT(SetShowPiercingRays(bool)));
|
---|
1252 | connect(mControlWidget, SIGNAL(SetShowWireFrame(bool)), this, SLOT(SetShowWireFrame(bool)));
|
---|
1253 | connect(mControlWidget, SIGNAL(SetShowWeightedRays(bool)), this, SLOT(SetShowWeightedRays(bool)));
|
---|
1254 | connect(mControlWidget, SIGNAL(SetShowWeightedCost(bool)), this, SLOT(SetShowWeightedCost(bool)));
|
---|
1255 |
|
---|
1256 | connect(mControlWidget, SIGNAL(SetShowDistanceWeightedTriangles(bool)), this, SLOT(SetShowDistanceWeightedTriangles(bool)));
|
---|
1257 | connect(mControlWidget, SIGNAL(SetShowDistanceWeightedPvs(bool)), this, SLOT(SetShowDistanceWeightedPvs(bool)));
|
---|
1258 | connect(mControlWidget, SIGNAL(SetShowWeightedTriangles(bool)), this, SLOT(SetShowWeightedTriangles(bool)));
|
---|
1259 |
|
---|
1260 | connect(mControlWidget, SIGNAL(UseConstColorForRayViz(bool)), this, SLOT(UseConstColorForRayViz(bool)));
|
---|
1261 | connect(mControlWidget, SIGNAL(UseRayLengthForRayViz(bool)), this, SLOT(UseRayLengthForRayViz(bool)));
|
---|
1262 | connect(mControlWidget, SIGNAL(SetShowContribution(bool)), this, SLOT(SetShowContribution(bool)));
|
---|
1263 | connect(mControlWidget, SIGNAL(SetShowDistribution(bool)), this, SLOT(SetShowDistribution(bool)));
|
---|
1264 |
|
---|
1265 | connect(mControlWidget, SIGNAL(SetShowDistribution1(bool)), this, SLOT(SetShowDistribution1(bool)));
|
---|
1266 | connect(mControlWidget, SIGNAL(SetShowDistribution2(bool)), this, SLOT(SetShowDistribution2(bool)));
|
---|
1267 | connect(mControlWidget, SIGNAL(SetShowDistribution3(bool)), this, SLOT(SetShowDistribution3(bool)));
|
---|
1268 | connect(mControlWidget, SIGNAL(SetShowDistribution4(bool)), this, SLOT(SetShowDistribution4(bool)));
|
---|
1269 |
|
---|
1270 | connect(mControlWidget, SIGNAL(SetShowRays(bool)), this, SLOT(SetShowRays(bool)));
|
---|
1271 |
|
---|
1272 | #if 1
|
---|
1273 | connect(mControlWidget, SIGNAL(SetTranslation(bool)), this, SLOT(SetTranslation(bool)));
|
---|
1274 | connect(mControlWidget, SIGNAL(SetRotation(bool)), this, SLOT(SetRotation(bool)));
|
---|
1275 | connect(mControlWidget, SIGNAL(SetScale(bool)), this, SLOT(SetScale(bool)));
|
---|
1276 | #endif
|
---|
1277 | connect(mControlWidget, SIGNAL(UpdateDynamicObjects()), this, SLOT(UpdateDynamicObjects()));
|
---|
1278 | connect(mControlWidget, SIGNAL(DeleteDynamicObject()), this, SLOT(DeleteDynamicObject()));
|
---|
1279 |
|
---|
1280 | setWindowTitle("PVS Visualization");
|
---|
1281 | // view cell cut: 300
|
---|
1282 | mMaxRenderCost = 500;
|
---|
1283 | mMaxRenderCost = 762;
|
---|
1284 |
|
---|
1285 | // setting the main window size here
|
---|
1286 | //resize(800, 600);
|
---|
1287 | //resize(400, 300);
|
---|
1288 | resize(512, 320);
|
---|
1289 | mControlWidget->show();
|
---|
1290 |
|
---|
1291 | LoadObjects();
|
---|
1292 | }
|
---|
1293 |
|
---|
1294 | void
|
---|
1295 | QtGlRendererWidget::UpdateAllPvs()
|
---|
1296 | {
|
---|
1297 | // $$ does not work so far:(
|
---|
1298 | mViewCellsManager->UpdatePvsForEvaluation();
|
---|
1299 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
1300 | }
|
---|
1301 |
|
---|
1302 | void
|
---|
1303 | QtGlRendererWidget::ComputeVisibility()
|
---|
1304 | {
|
---|
1305 | cerr<<"Compute Visibility called!\n"<<endl;
|
---|
1306 | if (!mPreprocessorThread->isRunning())
|
---|
1307 | mPreprocessorThread->RunThread();
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | void
|
---|
1311 | QtGlRendererWidget::StopComputation()
|
---|
1312 | {
|
---|
1313 | cerr<<"stop computation called!\n"<<endl;
|
---|
1314 | mViewCellsManager->GetPreprocessor()->mStopComputation = true;
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | void
|
---|
1318 | QtGlRendererWidget::SetRandomViewPoint()
|
---|
1319 | {
|
---|
1320 | cerr<<"setting random view point!\n"<<endl;
|
---|
1321 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
1322 | updateGL();
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 |
|
---|
1326 | void QtGlRendererWidget::StoreStatistics()
|
---|
1327 | {
|
---|
1328 | cerr<<"storing statistics!\n"<<endl;
|
---|
1329 | const int currentSamples = mViewCellsManager->GetPreprocessor()->mCurrentSamples;
|
---|
1330 |
|
---|
1331 | cout<<"**********************************************" << endl;
|
---|
1332 | cout << "reached " << currentSamples << " samples " << " => writing file" << endl;
|
---|
1333 |
|
---|
1334 | LogWriter writer;
|
---|
1335 | writer.SetFilename("compare.log");
|
---|
1336 | writer.Write(currentSamples, mViewCellsManager->GetViewCells());
|
---|
1337 | cout << "finished writing file" << endl;
|
---|
1338 | mCompareInfo.clear();
|
---|
1339 | updateGL();
|
---|
1340 | }
|
---|
1341 |
|
---|
1342 |
|
---|
1343 | void QtGlRendererWidget::LoadObjects()
|
---|
1344 | {
|
---|
1345 | AxisAlignedBox3 sceneBox = mViewCellsManager->GetViewSpaceBox();
|
---|
1346 |
|
---|
1347 | //float x = 20.0f; float y = 20.0f; float z = 80.0f;
|
---|
1348 | float x = 20.0f; float y = 20.0f; float z = 20.0f;
|
---|
1349 |
|
---|
1350 | AxisAlignedBox3 box(Vector3(0.5f * x, 0, -0.5f * z), Vector3(-0.5f * x, y, 0.5f * z));
|
---|
1351 | //AxisAlignedBox3 box(Vector3(0.5f * x, 0, 0), Vector3(-0.5f * x, y, z));
|
---|
1352 |
|
---|
1353 | // box.Scale(Vector3(0.02f, 0.1f, 0.1f));
|
---|
1354 |
|
---|
1355 | box.Translate(-box.Min());
|
---|
1356 |
|
---|
1357 | SceneGraphLeaf *leaf = GetPreprocessor()->GenerateBoxGeometry(box);
|
---|
1358 | mPlacer->AddObject(leaf);
|
---|
1359 |
|
---|
1360 | LoadObject("../data/teapot.bn");
|
---|
1361 | LoadObject("../data/bunny.bn");
|
---|
1362 | LoadObject("../data/horse.bn");
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 |
|
---|
1366 | void QtGlRendererWidget::NextObject()
|
---|
1367 | {
|
---|
1368 | mPlacer->NextObject();
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 |
|
---|
1372 | void QtGlRendererWidget::LoadObject(const string &filename)
|
---|
1373 | {
|
---|
1374 | cout << "Loading model " << filename << endl;
|
---|
1375 |
|
---|
1376 | SceneGraphLeaf *leaf =
|
---|
1377 | mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename);
|
---|
1378 |
|
---|
1379 | if (leaf)
|
---|
1380 | {
|
---|
1381 | mPlacer->AddObject(leaf);
|
---|
1382 | cout << "Loading finished" << endl;
|
---|
1383 | }
|
---|
1384 | else
|
---|
1385 | cerr << "Loading failed" << endl;
|
---|
1386 |
|
---|
1387 | //updateGL();
|
---|
1388 | }
|
---|
1389 |
|
---|
1390 |
|
---|
1391 | QtGlRendererWidget::~QtGlRendererWidget()
|
---|
1392 | {
|
---|
1393 | delete mPlacer;
|
---|
1394 | }
|
---|
1395 |
|
---|
1396 |
|
---|
1397 | void
|
---|
1398 | QtGlRendererWidget::RenderRenderCost()
|
---|
1399 | {
|
---|
1400 | static vector<float> costFunction;
|
---|
1401 | static float maxCost = -1;
|
---|
1402 | if (costFunction.size()==0) {
|
---|
1403 | ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree();
|
---|
1404 | if (tree) {
|
---|
1405 | tree->GetCostFunction(costFunction);
|
---|
1406 | maxCost = -1;
|
---|
1407 | for (int i=0; i < costFunction.size(); i++) {
|
---|
1408 | // cout<<i<<":"<<costFunction[i]<<" ";
|
---|
1409 | // update cost function to an absolute value based on the total geometry count
|
---|
1410 | costFunction[i] *= mSceneGraph->GetSize();
|
---|
1411 | if (costFunction[i] > maxCost)
|
---|
1412 | maxCost = costFunction[i];
|
---|
1413 | }
|
---|
1414 | }
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 |
|
---|
1418 | int currentPos = (int)mViewCellsManager->GetViewCells().size();
|
---|
1419 | float currentCost= -1;
|
---|
1420 |
|
---|
1421 | if (currentPos < costFunction.size())
|
---|
1422 | currentCost = costFunction[currentPos];
|
---|
1423 | #if 1
|
---|
1424 | cout<<"costFunction.size()="<<(int)costFunction.size()<<endl;
|
---|
1425 | cout<<"CP="<<currentPos<<endl;
|
---|
1426 | cout<<"MC="<<maxCost<<endl;
|
---|
1427 | cout<<"CC="<<currentCost<<endl;
|
---|
1428 | #endif
|
---|
1429 | if (costFunction.size()) {
|
---|
1430 | float scaley = 1.0f/log10(maxCost);
|
---|
1431 | float scalex = 1.0f/(float)costFunction.size();
|
---|
1432 |
|
---|
1433 | glDisable(GL_DEPTH_TEST);
|
---|
1434 | // init ortographic projection
|
---|
1435 | glMatrixMode(GL_PROJECTION);
|
---|
1436 |
|
---|
1437 | glPushMatrix();
|
---|
1438 |
|
---|
1439 | glLoadIdentity();
|
---|
1440 | gluOrtho2D(0, 1.0f, 0, 1.0f);
|
---|
1441 |
|
---|
1442 | glTranslatef(0.1f, 0.1f, 0.0f);
|
---|
1443 | glScalef(0.8f, 0.8f, 1.0f);
|
---|
1444 | glMatrixMode(GL_MODELVIEW);
|
---|
1445 | glLoadIdentity();
|
---|
1446 |
|
---|
1447 | glColor3f(1.0f,0,0);
|
---|
1448 | glBegin(GL_LINE_STRIP);
|
---|
1449 | // glVertex3f(0,0,0);
|
---|
1450 |
|
---|
1451 | for (int i=0; i < costFunction.size(); i++) {
|
---|
1452 | float x = i*scalex;
|
---|
1453 | float y = log10(costFunction[i])*scaley;
|
---|
1454 | glVertex3f(x,y,0.0f);
|
---|
1455 | }
|
---|
1456 | glEnd();
|
---|
1457 |
|
---|
1458 | glColor3f(1.0f,0,0);
|
---|
1459 | glBegin(GL_LINES);
|
---|
1460 | float x = currentPos*scalex;
|
---|
1461 | glVertex3f(x,0.0,0.0f);
|
---|
1462 | glVertex3f(x,1.0f,0.0f);
|
---|
1463 | glEnd();
|
---|
1464 |
|
---|
1465 | glColor3f(0.0f,0,0);
|
---|
1466 | // show a grid
|
---|
1467 | glBegin(GL_LINE_LOOP);
|
---|
1468 | glVertex3f(0,0,0.0f);
|
---|
1469 | glVertex3f(1,0,0.0f);
|
---|
1470 | glVertex3f(1,1,0.0f);
|
---|
1471 | glVertex3f(0,1,0.0f);
|
---|
1472 | glEnd();
|
---|
1473 |
|
---|
1474 | glBegin(GL_LINES);
|
---|
1475 | for (int i=0; i < costFunction.size(); i += 1000) {
|
---|
1476 | float x = i*scalex;
|
---|
1477 | glVertex3f(x,0.0,0.0f);
|
---|
1478 | glVertex3f(x,1.0f,0.0f);
|
---|
1479 | }
|
---|
1480 |
|
---|
1481 | for (int i=0; pow(10.0f, i) < maxCost; i+=1) {
|
---|
1482 | float y = i*scaley;
|
---|
1483 | // QString s;
|
---|
1484 | // s.sprintf("%d", (int)pow(10,i));
|
---|
1485 | // renderText(width()/2+5, y*height(), s);
|
---|
1486 | glVertex3f(0.0f, y, 0.0f);
|
---|
1487 | glVertex3f(1.0f, y, 0.0f);
|
---|
1488 | }
|
---|
1489 |
|
---|
1490 | glEnd();
|
---|
1491 |
|
---|
1492 |
|
---|
1493 | // restore the projection matrix
|
---|
1494 | glMatrixMode(GL_PROJECTION);
|
---|
1495 | glPopMatrix();
|
---|
1496 | glMatrixMode(GL_MODELVIEW);
|
---|
1497 | glEnable(GL_DEPTH_TEST);
|
---|
1498 |
|
---|
1499 | }
|
---|
1500 |
|
---|
1501 |
|
---|
1502 |
|
---|
1503 | }
|
---|
1504 |
|
---|
1505 | void
|
---|
1506 | QtGlRendererWidget::RenderInfo()
|
---|
1507 | {
|
---|
1508 |
|
---|
1509 | QString s;
|
---|
1510 |
|
---|
1511 | int vc = 0;
|
---|
1512 | if (mViewCellsManager)
|
---|
1513 | vc = (int)mViewCellsManager->GetViewCells().size();
|
---|
1514 |
|
---|
1515 | int filter = 0;
|
---|
1516 | if (mViewCellsManager)
|
---|
1517 | filter = mViewCellsManager->GetMaxFilterSize();
|
---|
1518 |
|
---|
1519 | #if 0 //REMOVE_TEMPORARY
|
---|
1520 | s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)",
|
---|
1521 | mFrame,
|
---|
1522 | mViewPoint.x,
|
---|
1523 | mViewPoint.y,
|
---|
1524 | mViewPoint.z,
|
---|
1525 | mViewDirection.x,
|
---|
1526 | mViewDirection.y,
|
---|
1527 | mViewDirection.z
|
---|
1528 | );
|
---|
1529 |
|
---|
1530 | renderText(20, 20, s);
|
---|
1531 |
|
---|
1532 | s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f %",
|
---|
1533 | vc,
|
---|
1534 | filter,
|
---|
1535 | mPvsSize,
|
---|
1536 | mRenderError * 100.0f);
|
---|
1537 |
|
---|
1538 | renderText(20, 40, s);
|
---|
1539 | #endif
|
---|
1540 |
|
---|
1541 | glDisable(GL_LIGHTING);
|
---|
1542 | //qglColor(QColor(0, 255, 0));
|
---|
1543 | glColor3f(0, 1, 0);
|
---|
1544 | QFont font40; font40.setPointSize(25);
|
---|
1545 | //s.sprintf("PVS: %04d", mPvsSize);
|
---|
1546 | //renderText(20, 40, s, font40);
|
---|
1547 |
|
---|
1548 | //s.sprintf("RAW TRI: %07d", mViewCellsManager->GetPreprocessor()->mGenericStats);
|
---|
1549 | //renderText(290, 40, s, font40);
|
---|
1550 | //s.sprintf("PVS TRI: %07d", mViewCellsManager->GetPreprocessor()->mGenericStats2);
|
---|
1551 | //renderText(290, 70, s, font40);
|
---|
1552 |
|
---|
1553 | s.sprintf("PVS TRI: %08d", (int)mCurrentPvsCost);
|
---|
1554 | //renderText(290, 70, s, font40);
|
---|
1555 | renderText(200, 40, s, font40);
|
---|
1556 | #if 0
|
---|
1557 | s.sprintf("error: %3.3f %", mRenderError * 100.0f);
|
---|
1558 | renderText(20, 40, s, font40);
|
---|
1559 | #endif
|
---|
1560 | //renderText(290, 70, s, font40);
|
---|
1561 | glEnable(GL_LIGHTING);
|
---|
1562 |
|
---|
1563 | }
|
---|
1564 |
|
---|
1565 |
|
---|
1566 | void
|
---|
1567 | QtGlRendererWidget::SetViewCellGranularity(int number)
|
---|
1568 | {
|
---|
1569 | if (mViewCellsManager)
|
---|
1570 | {
|
---|
1571 | // mViewCellsManager->SetMaxFilterSize(number);
|
---|
1572 |
|
---|
1573 | // $$ tmp off
|
---|
1574 | mViewCellsManager->CollectViewCells(number);
|
---|
1575 |
|
---|
1576 | // $$ does not work so far:(
|
---|
1577 | // mViewCellsManager->UpdatePvsForEvaluation();
|
---|
1578 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
1579 | }
|
---|
1580 | updateGL();
|
---|
1581 | }
|
---|
1582 |
|
---|
1583 | void
|
---|
1584 | QtGlRendererWidget::SetVisibilityFilterSize(int number)
|
---|
1585 | {
|
---|
1586 | if (mViewCellsManager)
|
---|
1587 | mViewCellsManager->SetMaxFilterSize(number);
|
---|
1588 |
|
---|
1589 | mPvsCache.Reset();
|
---|
1590 | updateGL();
|
---|
1591 | }
|
---|
1592 |
|
---|
1593 | void
|
---|
1594 | QtGlRendererWidget::SetSpatialFilterSize(int number)
|
---|
1595 | {
|
---|
1596 | mSpatialFilterSize = 1e-3*number;
|
---|
1597 | mPvsCache.Reset();
|
---|
1598 | updateGL();
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 | void
|
---|
1602 | QtGlRendererWidget::SetSceneCut(int number)
|
---|
1603 | {
|
---|
1604 | // assume the cut plane can only be aligned with xz plane
|
---|
1605 | // shift it along y according to number, which is percentage of the bounding
|
---|
1606 | // box position
|
---|
1607 | if (mViewCellsManager)
|
---|
1608 | {
|
---|
1609 | const float f = number / 1000.0f;
|
---|
1610 | AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
|
---|
1611 | Vector3 p = (1.0f - f) * box.Min() + f * box.Max();
|
---|
1612 | mSceneCutPlane.mNormal = Vector3(0, -1, 0);
|
---|
1613 | mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p);
|
---|
1614 |
|
---|
1615 | cout << "cut view cells at " << number << endl;
|
---|
1616 | updateGL();
|
---|
1617 | }
|
---|
1618 | }
|
---|
1619 |
|
---|
1620 | void
|
---|
1621 | QtGlRendererWidget::SetHidingCost(int number)
|
---|
1622 | {
|
---|
1623 | mHidingCost = (float)number / 1000.0f;
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 |
|
---|
1627 | void
|
---|
1628 | QtGlRendererWidget::SetTopDistance(int number)
|
---|
1629 | {
|
---|
1630 | mTopDistance = number / 1000.0f;
|
---|
1631 | updateGL();
|
---|
1632 | }
|
---|
1633 |
|
---|
1634 |
|
---|
1635 | void
|
---|
1636 | QtGlRendererWidget::SetMaxRenderCost(int number)
|
---|
1637 | {
|
---|
1638 | mMaxRenderCost = number * 1000.0f;
|
---|
1639 | cout << "max render cost at " << number << endl;
|
---|
1640 | updateGL();
|
---|
1641 | }
|
---|
1642 |
|
---|
1643 | void QtGlRendererWidget::SetTransparency(int number)
|
---|
1644 | {
|
---|
1645 | mTransparency = number / 1000.0f;
|
---|
1646 | updateGL();
|
---|
1647 | }
|
---|
1648 |
|
---|
1649 |
|
---|
1650 | float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc)
|
---|
1651 | {
|
---|
1652 |
|
---|
1653 | #ifdef USE_VERBOSE_PVS
|
---|
1654 | // $matt temp
|
---|
1655 | return vc->GetPvs().mStats.mWeightedTriangles;
|
---|
1656 |
|
---|
1657 | if (mShowDistanceWeightedPvs)
|
---|
1658 | {
|
---|
1659 | return vc->GetPvs().mStats.mDistanceWeightedPvs;
|
---|
1660 | }
|
---|
1661 | else if (mShowDistanceWeightedTriangles)
|
---|
1662 | {
|
---|
1663 | return vc->GetPvs().mStats.mDistanceWeightedTriangles;
|
---|
1664 | }
|
---|
1665 | else //if (mShowWeightedTriangles)
|
---|
1666 | {
|
---|
1667 | return vc->GetPvs().mStats.mWeightedTriangles;
|
---|
1668 | }
|
---|
1669 | #else
|
---|
1670 | return 0.0f;
|
---|
1671 | #endif
|
---|
1672 | }
|
---|
1673 |
|
---|
1674 |
|
---|
1675 | void QtGlRendererWidget::ComputeMaxValues(const ViewCellContainer &viewCells,
|
---|
1676 | int &maxPvs,
|
---|
1677 | int &maxPiercingRays,
|
---|
1678 | float &maxRelativeRays,
|
---|
1679 | float &maxCost)
|
---|
1680 | {
|
---|
1681 | maxPvs = -1;
|
---|
1682 | maxPiercingRays = 1; // not zero for savety
|
---|
1683 | maxRelativeRays = Limits::Small; // not zero for savety
|
---|
1684 | maxCost = Limits::Small;
|
---|
1685 |
|
---|
1686 | for (size_t i = 0; i < viewCells.size(); ++ i)
|
---|
1687 | {
|
---|
1688 | ViewCell *vc = viewCells[i];
|
---|
1689 |
|
---|
1690 | if (mShowPvsSizes) // pvs size
|
---|
1691 | {
|
---|
1692 | //const int p = vc->GetPvs().CountObjectsInPvs();
|
---|
1693 | const int p = vc->GetPvs().GetSize();
|
---|
1694 | if (p > maxPvs)
|
---|
1695 | maxPvs = p;
|
---|
1696 | }
|
---|
1697 | else if (mShowPiercingRays) // relative number of rays
|
---|
1698 | {
|
---|
1699 | const int piercingRays = vc->GetNumPiercingRays();
|
---|
1700 |
|
---|
1701 | if (piercingRays > maxPiercingRays)
|
---|
1702 | maxPiercingRays = piercingRays;
|
---|
1703 | }
|
---|
1704 | else if (mShowWeightedRays)
|
---|
1705 | {
|
---|
1706 | const int piercingRays = vc->GetNumPiercingRays();
|
---|
1707 |
|
---|
1708 | const float relativeArea =
|
---|
1709 | vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
|
---|
1710 |
|
---|
1711 | if ((float)piercingRays / relativeArea > maxRelativeRays)
|
---|
1712 | maxRelativeRays = (float)piercingRays / relativeArea;
|
---|
1713 | }
|
---|
1714 | else if (mShowWeightedCost)
|
---|
1715 | {
|
---|
1716 | const float rCost = ComputeRenderCost(vc);
|
---|
1717 | mViewCellsManager->UpdateScalarPvsCost(vc, rCost);
|
---|
1718 |
|
---|
1719 | if (rCost > maxCost)
|
---|
1720 | maxCost = rCost;
|
---|
1721 | }
|
---|
1722 | }
|
---|
1723 | }
|
---|
1724 |
|
---|
1725 |
|
---|
1726 | void QtGlRendererWidget::RenderViewCells()
|
---|
1727 | {
|
---|
1728 | mUseFalseColors = true;
|
---|
1729 | //glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
|
---|
1730 |
|
---|
1731 | glEnable(GL_CULL_FACE);
|
---|
1732 | glCullFace(GL_FRONT);
|
---|
1733 | //glDisable(GL_CULL_FACE);
|
---|
1734 |
|
---|
1735 | if (mCutViewCells)
|
---|
1736 | {
|
---|
1737 | double eq[4];
|
---|
1738 | eq[0] = mSceneCutPlane.mNormal.x;
|
---|
1739 | eq[1] = mSceneCutPlane.mNormal.y;
|
---|
1740 | eq[2] = mSceneCutPlane.mNormal.z;
|
---|
1741 | eq[3] = mSceneCutPlane.mD;
|
---|
1742 |
|
---|
1743 | glClipPlane(GL_CLIP_PLANE0, eq);
|
---|
1744 | glEnable(GL_CLIP_PLANE0);
|
---|
1745 | }
|
---|
1746 |
|
---|
1747 | ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
|
---|
1748 |
|
---|
1749 | int maxPvs, maxPiercingRays;
|
---|
1750 | float maxRelativeRays, maxCost;
|
---|
1751 |
|
---|
1752 | ComputeMaxValues(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxCost);
|
---|
1753 | static int currentMaxCost = 0;
|
---|
1754 |
|
---|
1755 | if (maxCost > currentMaxCost + 100000)
|
---|
1756 | {
|
---|
1757 | currentMaxCost = maxCost;
|
---|
1758 | cout << "maxCost: " << maxCost << endl;
|
---|
1759 | }
|
---|
1760 |
|
---|
1761 | // set the max render cost to fixed value
|
---|
1762 | maxCost = mMaxRenderCost;
|
---|
1763 |
|
---|
1764 | // transparency
|
---|
1765 | if (!mUseTransparency)
|
---|
1766 | {
|
---|
1767 | glEnable(GL_DEPTH_TEST);
|
---|
1768 | glDisable(GL_BLEND);
|
---|
1769 | }
|
---|
1770 | else
|
---|
1771 | {
|
---|
1772 | glDisable(GL_DEPTH_TEST);
|
---|
1773 | glEnable(GL_BLEND);
|
---|
1774 |
|
---|
1775 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
---|
1776 | //glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
---|
1777 |
|
---|
1778 | for (int i = 0; i < viewcells.size(); ++ i)
|
---|
1779 | {
|
---|
1780 | ViewCell *vc = viewcells[i];
|
---|
1781 |
|
---|
1782 | const float dist = SqrDistance(mDummyViewPoint, vc->GetBox().Center());
|
---|
1783 | vc->SetDistance(dist);
|
---|
1784 | }
|
---|
1785 |
|
---|
1786 | sort(viewcells.begin(), viewcells.end(), nearerThan);
|
---|
1787 | }
|
---|
1788 |
|
---|
1789 | //mWireFrame = true;
|
---|
1790 |
|
---|
1791 | // normal rendering
|
---|
1792 | //if (!mShowPvsSizes && !mShowPiercingRays && !mShowWeightedRays && !mShowWeightedCost && !mShowComparison)
|
---|
1793 | if (mUseStandardColors)
|
---|
1794 | {
|
---|
1795 | for (int i = 0; i < viewcells.size(); ++ i)
|
---|
1796 | {
|
---|
1797 | ViewCell *vc = viewcells[i];
|
---|
1798 | RgbColor c;
|
---|
1799 |
|
---|
1800 | //if (!mShowPvsSizes && !mShowPiercingRays)
|
---|
1801 | c = vc->GetColor();
|
---|
1802 |
|
---|
1803 | glColor3f(c.r, c.g, c.b);
|
---|
1804 |
|
---|
1805 | if (!mHideByCost || (mHidingCost < (vc->GetNumPiercingRays() / (float)maxPiercingRays)))
|
---|
1806 | {
|
---|
1807 | RenderViewCell(vc);
|
---|
1808 | }
|
---|
1809 | }
|
---|
1810 | }
|
---|
1811 | else // using specialised colors
|
---|
1812 | {
|
---|
1813 | if (!mShowComparison)
|
---|
1814 | AssignImportanceByRelativeValue(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxCost);
|
---|
1815 | else
|
---|
1816 | {
|
---|
1817 | if (mCompareInfo.empty())
|
---|
1818 | {
|
---|
1819 | LogReader reader;
|
---|
1820 | reader.SetFilename("compare.log");
|
---|
1821 | int samples;
|
---|
1822 | reader.Read(samples, mCompareInfo);
|
---|
1823 | }
|
---|
1824 |
|
---|
1825 | AssignColorByComparison(viewcells, mCompareInfo);
|
---|
1826 | }
|
---|
1827 |
|
---|
1828 | glEnable(GL_DEPTH_TEST);
|
---|
1829 | }
|
---|
1830 |
|
---|
1831 | glEnable(GL_CULL_FACE);
|
---|
1832 | glDisable(GL_CULL_FACE);
|
---|
1833 |
|
---|
1834 | glDisable(GL_CLIP_PLANE0);
|
---|
1835 |
|
---|
1836 | mUseFalseColors = false;
|
---|
1837 | mWireFrame = false;
|
---|
1838 |
|
---|
1839 | glPopAttrib();
|
---|
1840 | }
|
---|
1841 |
|
---|
1842 |
|
---|
1843 | void QtGlRendererWidget::AssignImportanceByRelativeValue(const ViewCellContainer &viewCells,
|
---|
1844 | int &maxPvs,
|
---|
1845 | int &maxPiercingRays,
|
---|
1846 | float &maxRelativeRays,
|
---|
1847 | float &maxRcCost)
|
---|
1848 | {
|
---|
1849 | for (size_t i = 0; i < viewCells.size(); ++ i)
|
---|
1850 | {
|
---|
1851 | RgbColor c;
|
---|
1852 | ViewCell *vc = viewCells[i];
|
---|
1853 |
|
---|
1854 | float importance;
|
---|
1855 |
|
---|
1856 | if (mShowPiercingRays)
|
---|
1857 | {
|
---|
1858 | importance = mTransferFunction *
|
---|
1859 | ((float)vc->GetNumPiercingRays() / (float)maxPiercingRays);
|
---|
1860 | }
|
---|
1861 | else if (mShowWeightedRays) // relative number of rays
|
---|
1862 | {
|
---|
1863 | float relativeArea = vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
|
---|
1864 |
|
---|
1865 | if (relativeArea < Limits::Small)
|
---|
1866 | relativeArea = Limits::Small;
|
---|
1867 |
|
---|
1868 | importance = mTransferFunction * ((float)vc->GetNumPiercingRays() / relativeArea) / maxRelativeRays;
|
---|
1869 | }
|
---|
1870 | else if (mShowPvsSizes) // pvs size
|
---|
1871 | {
|
---|
1872 | importance = mTransferFunction *
|
---|
1873 | ((float)vc->GetPvs().GetSize() / (float)maxPvs);
|
---|
1874 | } // weighted render cost
|
---|
1875 | else if (mShowWeightedCost)
|
---|
1876 | {
|
---|
1877 | const float rcCost = mTransferFunction * ComputeRenderCost(vc);
|
---|
1878 | importance = rcCost / maxRcCost;
|
---|
1879 | }
|
---|
1880 |
|
---|
1881 | if (importance > 1.0f) importance = 1.0f;
|
---|
1882 | // c = RgbColor(importance, 1.0f - importance, 0.0f);
|
---|
1883 | c = RainbowColorMapping(importance);
|
---|
1884 |
|
---|
1885 | glColor4f(c.r, c.g, c.b, 1.0f - mTransparency);
|
---|
1886 |
|
---|
1887 | if (!mHideByCost || (mHidingCost < importance))
|
---|
1888 | {
|
---|
1889 | RenderViewCell(vc);
|
---|
1890 | }
|
---|
1891 | }
|
---|
1892 | }
|
---|
1893 |
|
---|
1894 |
|
---|
1895 | void QtGlRendererWidget::AssignColorByComparison(const ViewCellContainer &viewcells,
|
---|
1896 | //const ViewCellInfoContainer &infos1,
|
---|
1897 | const ViewCellInfoContainer &compareInfo)
|
---|
1898 | {
|
---|
1899 | if (viewcells.size() > compareInfo.size())
|
---|
1900 | {
|
---|
1901 | cerr << "loaded size (" << (int)compareInfo.size()
|
---|
1902 | << ") does not fit to view cells size (" << (int)viewcells.size() << ")" << endl;
|
---|
1903 | return;
|
---|
1904 | }
|
---|
1905 |
|
---|
1906 | //const float maxRatio = 1.0f;
|
---|
1907 | const float maxRatio = 2.0f;
|
---|
1908 | const float minRatio = 0.0f;
|
---|
1909 |
|
---|
1910 | const float scale = 1.0f / (maxRatio - minRatio);
|
---|
1911 |
|
---|
1912 | for (size_t i = 0; i < viewcells.size(); ++ i)
|
---|
1913 | {
|
---|
1914 | RgbColor c;
|
---|
1915 | ViewCell *vc = viewcells[i];
|
---|
1916 |
|
---|
1917 | //ViewCellInfo vc1Info = infos1[i];
|
---|
1918 | ViewCellInfo vc2Info = compareInfo[i];
|
---|
1919 |
|
---|
1920 | //const float vcRatio = vc->GetNumPiercingRays() / vc2Info.mPiercingRays + Limits::Small;
|
---|
1921 | float vcRatio = 1.0f;//maxRatio;
|
---|
1922 |
|
---|
1923 | if (vc2Info.mPvsSize > Limits::Small)
|
---|
1924 | vcRatio = (float)vc->GetPvs().GetSize() / vc2Info.mPvsSize;
|
---|
1925 |
|
---|
1926 | // truncate here
|
---|
1927 | if (vcRatio > maxRatio) vcRatio = 1.0f;
|
---|
1928 |
|
---|
1929 | const float importance = (vcRatio - minRatio) * scale;
|
---|
1930 |
|
---|
1931 | if (0 && (i < 20))
|
---|
1932 | {
|
---|
1933 | cout << "pvs1: " << vc->GetPvs().GetSize() << " pvs2: "
|
---|
1934 | << compareInfo[i].mPvsSize << " importance: " << importance << endl;
|
---|
1935 | }
|
---|
1936 |
|
---|
1937 | // c = RgbColor(importance, 1.0f - importance, 0.0f);
|
---|
1938 | c = RainbowColorMapping(importance);
|
---|
1939 |
|
---|
1940 | glColor4f(c.r, c.g, c.b, 1.0f);
|
---|
1941 |
|
---|
1942 | if (1)//!mHideByCost || (mHidingCost < importance))
|
---|
1943 | {
|
---|
1944 | RenderViewCell(vc);
|
---|
1945 | }
|
---|
1946 | }
|
---|
1947 | }
|
---|
1948 |
|
---|
1949 |
|
---|
1950 |
|
---|
1951 | /**********************************************************************/
|
---|
1952 | /* QtRendererControlWidget implementation */
|
---|
1953 | /**********************************************************************/
|
---|
1954 |
|
---|
1955 |
|
---|
1956 | QGroupBox *QtRendererControlWidget::CreateVisualizationPanel(QWidget *parent)
|
---|
1957 | {
|
---|
1958 | QRadioButton *rb1, *rb2, *rb3, *rb4, *rb5;
|
---|
1959 |
|
---|
1960 | rb1 = new QRadioButton("random colors", parent);
|
---|
1961 | rb1->setText("random");
|
---|
1962 | connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowWireFrame(bool)));
|
---|
1963 |
|
---|
1964 | // Create a check box to be in the group box
|
---|
1965 | rb2 = new QRadioButton("piercing rays", parent);
|
---|
1966 | rb2->setText("piercing rays");
|
---|
1967 | //vl->addWidget(rb1);
|
---|
1968 | connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetShowPiercingRays(bool)));
|
---|
1969 |
|
---|
1970 | rb3 = new QRadioButton("pvs size", parent);
|
---|
1971 | rb3->setText("pvs size");
|
---|
1972 | connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
|
---|
1973 |
|
---|
1974 | rb4 = new QRadioButton("weighted rays", parent);
|
---|
1975 | rb4->setText("weighted rays");
|
---|
1976 | connect(rb4, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedRays(bool)));
|
---|
1977 |
|
---|
1978 | rb5 = new QRadioButton("pvs cost", parent);
|
---|
1979 | rb5->setText("pvs cost");
|
---|
1980 | connect(rb5, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedCost(bool)));
|
---|
1981 |
|
---|
1982 | QGroupBox *groupBox = new QGroupBox("PVS Visualization");
|
---|
1983 |
|
---|
1984 | QVBoxLayout *vbox2 = new QVBoxLayout;
|
---|
1985 |
|
---|
1986 | vbox2->addWidget(rb1);
|
---|
1987 | vbox2->addWidget(rb2);
|
---|
1988 | vbox2->addWidget(rb3);
|
---|
1989 | vbox2->addWidget(rb4);
|
---|
1990 | vbox2->addWidget(rb5);
|
---|
1991 |
|
---|
1992 | rb5->setChecked(true);
|
---|
1993 |
|
---|
1994 | vbox2->addStretch(1);
|
---|
1995 | groupBox->setLayout(vbox2);
|
---|
1996 |
|
---|
1997 | return groupBox;
|
---|
1998 | }
|
---|
1999 |
|
---|
2000 |
|
---|
2001 | QGroupBox *QtRendererControlWidget::CreateTrafoPanel(QWidget *parent)
|
---|
2002 | {
|
---|
2003 | QRadioButton *rb1, *rb2, *rb3;
|
---|
2004 |
|
---|
2005 | rb1 = new QRadioButton("translation", parent);
|
---|
2006 | rb1->setText("translation");
|
---|
2007 | connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetTranslation(bool)));
|
---|
2008 |
|
---|
2009 | // Create a check box to be in the group box
|
---|
2010 | rb2 = new QRadioButton("scale", parent);
|
---|
2011 | rb2->setText("scale");
|
---|
2012 | //vl->addWidget(rb1);
|
---|
2013 | connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetScale(bool)));
|
---|
2014 |
|
---|
2015 | rb3 = new QRadioButton("rotation", parent);
|
---|
2016 | rb3->setText("rotation");
|
---|
2017 | connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetRotation(bool)));
|
---|
2018 |
|
---|
2019 | QVBoxLayout *vbox2 = new QVBoxLayout;
|
---|
2020 | QGroupBox *groupBox = new QGroupBox("Dynamic Obojects");
|
---|
2021 |
|
---|
2022 | vbox2->addWidget(rb1);
|
---|
2023 | vbox2->addWidget(rb2);
|
---|
2024 | vbox2->addWidget(rb3);
|
---|
2025 |
|
---|
2026 | rb1->setChecked(true);
|
---|
2027 |
|
---|
2028 | vbox2->addStretch(1);
|
---|
2029 |
|
---|
2030 |
|
---|
2031 | QPushButton *button = new QPushButton("Update", groupBox);
|
---|
2032 | vbox2->addWidget(button);
|
---|
2033 | connect(button, SIGNAL(clicked()), SIGNAL(UpdateDynamicObjects()));
|
---|
2034 |
|
---|
2035 | button = new QPushButton("Delete", groupBox);
|
---|
2036 | vbox2->addWidget(button);
|
---|
2037 | connect(button, SIGNAL(clicked()), SIGNAL(DeleteDynamicObject()));
|
---|
2038 |
|
---|
2039 | button = new QPushButton("Next object", groupBox);
|
---|
2040 | vbox2->layout()->addWidget(button);
|
---|
2041 | connect(button, SIGNAL(clicked()), SIGNAL(NextObject()));
|
---|
2042 |
|
---|
2043 | groupBox->setLayout(vbox2);
|
---|
2044 |
|
---|
2045 | return groupBox;
|
---|
2046 | }
|
---|
2047 |
|
---|
2048 |
|
---|
2049 | QGroupBox *QtRendererControlWidget::CreateRenderCostPanel(QWidget *parent)
|
---|
2050 | {
|
---|
2051 | QRadioButton *rb1, *rb2, *rb3;
|
---|
2052 |
|
---|
2053 | // Create a check box to be in the group box
|
---|
2054 | rb1 = new QRadioButton("triangles", parent);
|
---|
2055 | rb1->setText("triangles");
|
---|
2056 | connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowWeightedTriangles(bool)));
|
---|
2057 |
|
---|
2058 | rb2 = new QRadioButton("distance weighted pvs", parent);
|
---|
2059 | rb2->setText("distance weighted");
|
---|
2060 | connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetShowDistanceWeightedPvs(bool)));
|
---|
2061 |
|
---|
2062 | rb3 = new QRadioButton("distance weighted triangles", parent);
|
---|
2063 | rb3->setText("distance weighted triangles");
|
---|
2064 | connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowDistanceWeightedTriangles(bool)));
|
---|
2065 |
|
---|
2066 | QGroupBox *groupBox = new QGroupBox("Render cost options");
|
---|
2067 | QVBoxLayout *vbox2 = new QVBoxLayout;
|
---|
2068 |
|
---|
2069 | vbox2->addWidget(rb1);
|
---|
2070 | vbox2->addWidget(rb2);
|
---|
2071 | vbox2->addWidget(rb3);
|
---|
2072 |
|
---|
2073 | rb1->setChecked(true);
|
---|
2074 |
|
---|
2075 | vbox2->addStretch(1);
|
---|
2076 | groupBox->setLayout(vbox2);
|
---|
2077 |
|
---|
2078 | return groupBox;
|
---|
2079 | }
|
---|
2080 |
|
---|
2081 |
|
---|
2082 | QGroupBox *QtRendererControlWidget::CreateRayVisualizationPanel(QWidget *parent)
|
---|
2083 | {
|
---|
2084 | QRadioButton *rb1, *rb2, *rb3, *rb4;
|
---|
2085 |
|
---|
2086 | // Create a check box to be in the group box
|
---|
2087 | rb1 = new QRadioButton("const color", parent);
|
---|
2088 | rb1->setText("const color");
|
---|
2089 | //vl->addWidget(rb1);
|
---|
2090 | connect(rb1, SIGNAL(toggled(bool)), SIGNAL(UseConstColorForRayViz(bool)));
|
---|
2091 |
|
---|
2092 | rb2 = new QRadioButton("ray length", parent);
|
---|
2093 | rb2->setText("ray length");
|
---|
2094 | connect(rb2, SIGNAL(toggled(bool)), SIGNAL(UseRayLengthForRayViz(bool)));
|
---|
2095 |
|
---|
2096 | rb3 = new QRadioButton("contribution", parent);
|
---|
2097 | rb3->setText("contribution");
|
---|
2098 | connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetShowContribution(bool)));
|
---|
2099 |
|
---|
2100 | rb4 = new QRadioButton("distribution", parent);
|
---|
2101 | rb4->setText("distribution");
|
---|
2102 | connect(rb4, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution(bool)));
|
---|
2103 |
|
---|
2104 |
|
---|
2105 | ///////////////////////////
|
---|
2106 |
|
---|
2107 | QGroupBox *groupBox = new QGroupBox("Ray visualization");
|
---|
2108 | QVBoxLayout *vbox2 = new QVBoxLayout;
|
---|
2109 |
|
---|
2110 | vbox2->addWidget(rb1);
|
---|
2111 | vbox2->addWidget(rb2);
|
---|
2112 | vbox2->addWidget(rb3);
|
---|
2113 | vbox2->addWidget(rb4);
|
---|
2114 |
|
---|
2115 | rb1->setChecked(true);
|
---|
2116 |
|
---|
2117 |
|
---|
2118 | QCheckBox *cb = new QCheckBox("Distribution 1", parent);
|
---|
2119 | vbox2->addWidget(cb);
|
---|
2120 | cb->setChecked(true);
|
---|
2121 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution1(bool)));
|
---|
2122 |
|
---|
2123 | cb = new QCheckBox("Distribution 2", parent);
|
---|
2124 | vbox2->addWidget(cb);
|
---|
2125 | cb->setChecked(true);
|
---|
2126 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution2(bool)));
|
---|
2127 |
|
---|
2128 | cb = new QCheckBox("Distribution 3", parent);
|
---|
2129 | vbox2->addWidget(cb);
|
---|
2130 | cb->setChecked(true);
|
---|
2131 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution3(bool)));
|
---|
2132 |
|
---|
2133 | cb = new QCheckBox("Distribution 4", parent);
|
---|
2134 | vbox2->addWidget(cb);
|
---|
2135 | cb->setChecked(true);
|
---|
2136 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowDistribution4(bool)));
|
---|
2137 |
|
---|
2138 | vbox2->addStretch(1);
|
---|
2139 | groupBox->setLayout(vbox2);
|
---|
2140 |
|
---|
2141 | return groupBox;
|
---|
2142 | }
|
---|
2143 |
|
---|
2144 |
|
---|
2145 | QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f):
|
---|
2146 | QWidget(parent, f)
|
---|
2147 | {
|
---|
2148 |
|
---|
2149 | QVBoxLayout *vl = new QVBoxLayout;
|
---|
2150 | setLayout(vl);
|
---|
2151 |
|
---|
2152 | //QWidget *vbox;
|
---|
2153 |
|
---|
2154 | //vbox = new QGroupBox("Render Controls", this);
|
---|
2155 | //layout()->addWidget(vbox);
|
---|
2156 | //vl = new QVBoxLayout;
|
---|
2157 | //vbox->setLayout(vl);
|
---|
2158 |
|
---|
2159 | QLabel *label;
|
---|
2160 | QSlider *slider;
|
---|
2161 | QPushButton *button;
|
---|
2162 |
|
---|
2163 | #if 0//REMOVE_TEMPORARY
|
---|
2164 |
|
---|
2165 | label = new QLabel("Granularity");
|
---|
2166 | //vbox->layout()->addWidget(label);
|
---|
2167 | vl->addWidget(label);
|
---|
2168 |
|
---|
2169 | slider = new QSlider(Qt::Horizontal);
|
---|
2170 | vl->addWidget(slider);
|
---|
2171 | slider->show();
|
---|
2172 | slider->setRange(1, 10000);
|
---|
2173 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2174 | slider->setValue(200);
|
---|
2175 |
|
---|
2176 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
|
---|
2177 |
|
---|
2178 | ///////////////////////////
|
---|
2179 |
|
---|
2180 | label = new QLabel("Transfer function");
|
---|
2181 | vl->addWidget(label);
|
---|
2182 |
|
---|
2183 | slider = new QSlider(Qt::Horizontal);
|
---|
2184 | vl->addWidget(slider);
|
---|
2185 | slider->show();
|
---|
2186 | slider->setRange(1, 10000);
|
---|
2187 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2188 | slider->setValue(100);
|
---|
2189 |
|
---|
2190 |
|
---|
2191 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int)));
|
---|
2192 |
|
---|
2193 | ////////////////////////////////////////7
|
---|
2194 |
|
---|
2195 | button = new QPushButton("Update all PVSs");
|
---|
2196 | vl->addWidget(button);
|
---|
2197 | connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs()));
|
---|
2198 |
|
---|
2199 | ////////////////////////////////////////77777
|
---|
2200 |
|
---|
2201 | label = new QLabel("Filter size");
|
---|
2202 | vl->addWidget(label);
|
---|
2203 |
|
---|
2204 | slider = new QSlider(Qt::Horizontal);
|
---|
2205 | vl->addWidget(slider);
|
---|
2206 | slider->show();
|
---|
2207 | slider->setRange(1, 100);
|
---|
2208 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2209 | slider->setValue(3);
|
---|
2210 |
|
---|
2211 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int)));
|
---|
2212 |
|
---|
2213 | #endif
|
---|
2214 |
|
---|
2215 |
|
---|
2216 |
|
---|
2217 | ///////////////////////////////////
|
---|
2218 |
|
---|
2219 |
|
---|
2220 | QWidget *hbox = new QWidget();
|
---|
2221 | vl->addWidget(hbox);
|
---|
2222 | QHBoxLayout *hlayout = new QHBoxLayout;
|
---|
2223 | hbox->setLayout(hlayout);
|
---|
2224 |
|
---|
2225 | QCheckBox *cb = new QCheckBox("Show viewcells", hbox);
|
---|
2226 | hlayout->addWidget(cb);
|
---|
2227 | cb->setChecked(false);
|
---|
2228 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool)));
|
---|
2229 |
|
---|
2230 | cb = new QCheckBox("Render errors", hbox);
|
---|
2231 | hlayout->layout()->addWidget(cb);
|
---|
2232 | cb->setChecked(false);
|
---|
2233 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
|
---|
2234 |
|
---|
2235 | #if 0
|
---|
2236 | cb = new QCheckBox("Render cost curve", hbox);
|
---|
2237 | hlayout->addWidget(cb);
|
---|
2238 | cb->setChecked(false);
|
---|
2239 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool)));
|
---|
2240 | #endif
|
---|
2241 | cb = new QCheckBox("Show rays", hbox);
|
---|
2242 | hlayout->addWidget(cb);
|
---|
2243 | cb->setChecked(false);
|
---|
2244 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
|
---|
2245 | #if 0
|
---|
2246 | cb = new QCheckBox("Show Comparison", hbox);
|
---|
2247 | hlayout->addWidget(cb);
|
---|
2248 | cb->setChecked(false);
|
---|
2249 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowComparison(bool)));
|
---|
2250 | #endif
|
---|
2251 |
|
---|
2252 | //////////////////
|
---|
2253 |
|
---|
2254 | QHBoxLayout *vh = new QHBoxLayout;
|
---|
2255 |
|
---|
2256 | QGroupBox *myBox = new QGroupBox("Visualization");
|
---|
2257 |
|
---|
2258 | myBox->setLayout(vh);
|
---|
2259 | vl->addWidget(myBox, 0, 0);
|
---|
2260 |
|
---|
2261 | QGroupBox *groupBox = CreateVisualizationPanel(hbox);
|
---|
2262 | vh->addWidget(groupBox, 0, 0);
|
---|
2263 |
|
---|
2264 |
|
---|
2265 | QGroupBox *groupBox2 = CreateRenderCostPanel(hbox);
|
---|
2266 | vh->addWidget(groupBox2, 0, 0);
|
---|
2267 | #if 0
|
---|
2268 | QGroupBox *groupBox3 = CreateRayVisualizationPanel(hbox);
|
---|
2269 | vh->addWidget(groupBox3, 0, 0);
|
---|
2270 | #endif
|
---|
2271 |
|
---|
2272 | #if 1
|
---|
2273 | QGroupBox *groupBox4 = CreateTrafoPanel(hbox);
|
---|
2274 | vh->addWidget(groupBox4, 0, 0);
|
---|
2275 | #endif
|
---|
2276 |
|
---|
2277 | //////////////////////////////////
|
---|
2278 |
|
---|
2279 | bool tmp = false;
|
---|
2280 | const int range = 1000;
|
---|
2281 |
|
---|
2282 | //vbox->resize(800,150);
|
---|
2283 | QWidget *vbox;
|
---|
2284 |
|
---|
2285 | vbox = new QGroupBox("Rendering", this);
|
---|
2286 | layout()->addWidget(vbox);
|
---|
2287 |
|
---|
2288 | vl = new QVBoxLayout;
|
---|
2289 | vbox->setLayout(vl);
|
---|
2290 |
|
---|
2291 |
|
---|
2292 | cb = new QCheckBox("Cut view cells", vbox);
|
---|
2293 | vbox->layout()->addWidget(cb);
|
---|
2294 | cb->setChecked(false);
|
---|
2295 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool)));
|
---|
2296 |
|
---|
2297 |
|
---|
2298 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
2299 | vbox->layout()->addWidget(slider);
|
---|
2300 | slider->show();
|
---|
2301 | slider->setRange(0, 1000);
|
---|
2302 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2303 | slider->setValue(1000);
|
---|
2304 |
|
---|
2305 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int)));
|
---|
2306 |
|
---|
2307 | #if 0
|
---|
2308 | cb = new QCheckBox("Use spatial filter", vbox);
|
---|
2309 | vbox->layout()->addWidget(cb);
|
---|
2310 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter", tmp);
|
---|
2311 | cb->setChecked(tmp);
|
---|
2312 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool)));
|
---|
2313 |
|
---|
2314 |
|
---|
2315 | label = new QLabel("Spatial Filter size");
|
---|
2316 | vbox->layout()->addWidget(label);
|
---|
2317 |
|
---|
2318 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
2319 | vbox->layout()->addWidget(slider);
|
---|
2320 | slider->show();
|
---|
2321 | slider->setRange(1, 100);
|
---|
2322 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2323 | slider->setValue(10);
|
---|
2324 |
|
---|
2325 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int)));
|
---|
2326 | #endif
|
---|
2327 | ////////////////////////////
|
---|
2328 |
|
---|
2329 |
|
---|
2330 | cb = new QCheckBox("Hide view cells by render cost ", vbox);
|
---|
2331 | vbox->layout()->addWidget(cb);
|
---|
2332 | cb->setChecked(false);
|
---|
2333 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetHideByCost(bool)));
|
---|
2334 |
|
---|
2335 | label = new QLabel("Hide by cost");
|
---|
2336 | vbox->layout()->addWidget(label);
|
---|
2337 |
|
---|
2338 | // the render cost visualization
|
---|
2339 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
2340 | vbox->layout()->addWidget(slider);
|
---|
2341 | slider->show();
|
---|
2342 | slider->setRange(0, range);
|
---|
2343 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2344 | slider->setValue(0);
|
---|
2345 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetHidingCost(int)));
|
---|
2346 |
|
---|
2347 | ///////////////////////////////////////////
|
---|
2348 | #if 0
|
---|
2349 | cb = new QCheckBox("Top View", vbox);
|
---|
2350 | vbox->layout()->addWidget(cb);
|
---|
2351 | cb->setChecked(false);
|
---|
2352 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
|
---|
2353 |
|
---|
2354 |
|
---|
2355 | label = new QLabel("Top distance");
|
---|
2356 | vbox->layout()->addWidget(label);
|
---|
2357 |
|
---|
2358 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
2359 | vbox->layout()->addWidget(slider);
|
---|
2360 | slider->show();
|
---|
2361 | slider->setRange(1, 1000);
|
---|
2362 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2363 | slider->setValue(500);
|
---|
2364 |
|
---|
2365 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
|
---|
2366 |
|
---|
2367 | #endif
|
---|
2368 | label = new QLabel("Max render cost");
|
---|
2369 | vbox->layout()->addWidget(label);
|
---|
2370 |
|
---|
2371 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
2372 | vbox->layout()->addWidget(slider);
|
---|
2373 | slider->show();
|
---|
2374 | slider->setRange(1, 1000);
|
---|
2375 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2376 |
|
---|
2377 | slider->setValue(500);
|
---|
2378 |
|
---|
2379 |
|
---|
2380 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetMaxRenderCost(int)));
|
---|
2381 |
|
---|
2382 |
|
---|
2383 |
|
---|
2384 | ///////////////////////////////////////////
|
---|
2385 | #if REMOVE_TEMPORARY
|
---|
2386 | cb = new QCheckBox("Transparency", vbox);
|
---|
2387 | vbox->layout()->addWidget(cb);
|
---|
2388 | cb->setChecked(false);
|
---|
2389 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseTransparency(bool)));
|
---|
2390 |
|
---|
2391 | label = new QLabel("Use transparency");
|
---|
2392 | vbox->layout()->addWidget(label);
|
---|
2393 |
|
---|
2394 | // the render cost visualization
|
---|
2395 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
2396 | vbox->layout()->addWidget(slider);
|
---|
2397 | slider->show();
|
---|
2398 | slider->setRange(0, range);
|
---|
2399 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
2400 | slider->setValue(0);
|
---|
2401 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransparency(int)));
|
---|
2402 | #endif
|
---|
2403 |
|
---|
2404 |
|
---|
2405 | //////////////////////////////
|
---|
2406 |
|
---|
2407 | #if REMOVE_TEMPORARY
|
---|
2408 |
|
---|
2409 | cb = new QCheckBox("Cut scene", vbox);
|
---|
2410 | vbox->layout()->addWidget(cb);
|
---|
2411 | cb->setChecked(false);
|
---|
2412 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool)));
|
---|
2413 |
|
---|
2414 | cb = new QCheckBox("Render boxes", vbox);
|
---|
2415 | vbox->layout()->addWidget(cb);
|
---|
2416 | cb->setChecked(false);
|
---|
2417 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool)));
|
---|
2418 |
|
---|
2419 | cb = new QCheckBox("Render visibility estimates", vbox);
|
---|
2420 | vbox->layout()->addWidget(cb);
|
---|
2421 | cb->setChecked(false);
|
---|
2422 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool)));
|
---|
2423 | #endif
|
---|
2424 |
|
---|
2425 | #if REMOVE_TEMPORARY
|
---|
2426 |
|
---|
2427 | cb = new QCheckBox("Use filter", vbox);
|
---|
2428 | vbox->layout()->addWidget(cb);
|
---|
2429 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp);
|
---|
2430 | cb->setChecked(tmp);
|
---|
2431 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool)));
|
---|
2432 | #endif
|
---|
2433 |
|
---|
2434 | #if REMOVE_TEMPORARY
|
---|
2435 |
|
---|
2436 | cb = new QCheckBox("Render filter", vbox);
|
---|
2437 | vbox->layout()->addWidget(cb);
|
---|
2438 | cb->setChecked(true);
|
---|
2439 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
|
---|
2440 |
|
---|
2441 | /*vbox = new QGroupBox("PVS Errors", this);
|
---|
2442 | layout()->addWidget(vbox);
|
---|
2443 |
|
---|
2444 | vl = new QVBoxLayout;
|
---|
2445 | vbox->setLayout(vl);
|
---|
2446 |
|
---|
2447 | button = new QPushButton("Compute Visibility", vbox);
|
---|
2448 | vbox->layout()->addWidget(button);
|
---|
2449 | connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility()));
|
---|
2450 |
|
---|
2451 | button = new QPushButton("Stop Computation", vbox);
|
---|
2452 | vbox->layout()->addWidget(button);
|
---|
2453 | connect(button, SIGNAL(clicked()), SLOT(StopComputation()));
|
---|
2454 |
|
---|
2455 | button = new QPushButton("Set Random View Point", vbox);
|
---|
2456 | vbox->layout()->addWidget(button);
|
---|
2457 | connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint()));*/
|
---|
2458 |
|
---|
2459 | button = new QPushButton("Store statistics", vbox);
|
---|
2460 | vbox->layout()->addWidget(button);
|
---|
2461 | connect(button, SIGNAL(clicked()), SIGNAL(StoreStatistics()));
|
---|
2462 |
|
---|
2463 | #endif
|
---|
2464 |
|
---|
2465 | #if 0
|
---|
2466 |
|
---|
2467 | button = new QPushButton("Compute GVS", vbox);
|
---|
2468 | vbox->layout()->addWidget(button);
|
---|
2469 | connect(button, SIGNAL(clicked()), SIGNAL(ComputeGVS()));
|
---|
2470 | #endif
|
---|
2471 |
|
---|
2472 | button = new QPushButton("Replay view points", vbox);
|
---|
2473 | vbox->layout()->addWidget(button);
|
---|
2474 | connect(button, SIGNAL(clicked()), SIGNAL(ReplayViewPoints()));
|
---|
2475 |
|
---|
2476 |
|
---|
2477 | /*cb = new QCheckBox("Stats", vbox);
|
---|
2478 | vbox->layout()->addWidget(cb);
|
---|
2479 | cb->setChecked(false);
|
---|
2480 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics()));*/
|
---|
2481 |
|
---|
2482 | if (0)
|
---|
2483 | {
|
---|
2484 | vbox = new QGroupBox("PVS Errors", this);
|
---|
2485 | layout()->addWidget(vbox);
|
---|
2486 |
|
---|
2487 | vl = new QVBoxLayout;
|
---|
2488 | vbox->setLayout(vl);
|
---|
2489 |
|
---|
2490 | mPvsErrorWidget = new QListWidget(vbox);
|
---|
2491 | vbox->layout()->addWidget(mPvsErrorWidget);
|
---|
2492 |
|
---|
2493 | connect(mPvsErrorWidget,
|
---|
2494 | SIGNAL(doubleClicked(const QModelIndex &)),
|
---|
2495 | this,
|
---|
2496 | SLOT(PvsErrorClicked(const QModelIndex &)));
|
---|
2497 |
|
---|
2498 | button = new QPushButton("Next Error Frame", vbox);
|
---|
2499 | vbox->layout()->addWidget(button);
|
---|
2500 | connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
|
---|
2501 | }
|
---|
2502 |
|
---|
2503 | //connect(button, SIGNAL(clicked(void)), SLOT(StoreStatistics(void)));
|
---|
2504 |
|
---|
2505 | //////////////////////////////////////////
|
---|
2506 |
|
---|
2507 |
|
---|
2508 | setWindowTitle("Preprocessor Control Widget");
|
---|
2509 | adjustSize();
|
---|
2510 | }
|
---|
2511 |
|
---|
2512 |
|
---|
2513 |
|
---|
2514 |
|
---|
2515 | void
|
---|
2516 | QtRendererControlWidget::FocusNextPvsErrorFrame(void)
|
---|
2517 | {}
|
---|
2518 |
|
---|
2519 | void
|
---|
2520 | QtRendererControlWidget::UpdatePvsErrorItem(int row,
|
---|
2521 | GlRendererBuffer::PvsErrorEntry &pvsErrorEntry)
|
---|
2522 | {
|
---|
2523 | #if 0
|
---|
2524 | QListWidgetItem *i = mPvsErrorWidget->item(row);
|
---|
2525 | QString s;
|
---|
2526 | s.sprintf("%5.5f", pvsErrorEntry.mError);
|
---|
2527 | if (i) {
|
---|
2528 | i->setText(s);
|
---|
2529 | } else {
|
---|
2530 | new QListWidgetItem(s, mPvsErrorWidget);
|
---|
2531 | }
|
---|
2532 | mPvsErrorWidget->update();
|
---|
2533 | #endif
|
---|
2534 | }
|
---|
2535 |
|
---|
2536 |
|
---|
2537 |
|
---|
2538 |
|
---|
2539 | /*********************************************************************/
|
---|
2540 | /* QtGlDebuggerWidget implementation */
|
---|
2541 | /*********************************************************************/
|
---|
2542 |
|
---|
2543 |
|
---|
2544 | QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
|
---|
2545 | : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
|
---|
2546 | {
|
---|
2547 | // create the pbuffer
|
---|
2548 | //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
|
---|
2549 | //mUpdateTimerId = startTimer(20);
|
---|
2550 | setWindowTitle(("OpenGL pbuffers"));
|
---|
2551 | }
|
---|
2552 |
|
---|
2553 |
|
---|
2554 | QtGlDebuggerWidget::~QtGlDebuggerWidget()
|
---|
2555 | {
|
---|
2556 | mRenderBuffer->releaseFromDynamicTexture();
|
---|
2557 | glDeleteTextures(1, &dynamicTexture);
|
---|
2558 |
|
---|
2559 | DEL_PTR(mRenderBuffer);
|
---|
2560 | }
|
---|
2561 |
|
---|
2562 |
|
---|
2563 | void QtGlDebuggerWidget::initializeGL()
|
---|
2564 | {
|
---|
2565 | glMatrixMode(GL_PROJECTION);
|
---|
2566 | glLoadIdentity();
|
---|
2567 |
|
---|
2568 | glFrustum(-1, 1, -1, 1, 10, 100);
|
---|
2569 | glTranslatef(-0.5f, -0.5f, -0.5f);
|
---|
2570 | glTranslatef(0.0f, 0.0f, -15.0f);
|
---|
2571 | glMatrixMode(GL_MODELVIEW);
|
---|
2572 |
|
---|
2573 | glEnable(GL_CULL_FACE);
|
---|
2574 | initCommon();
|
---|
2575 | initPbuffer();
|
---|
2576 |
|
---|
2577 | }
|
---|
2578 |
|
---|
2579 |
|
---|
2580 | void QtGlDebuggerWidget::resizeGL(int w, int h)
|
---|
2581 | {
|
---|
2582 | glViewport(0, 0, w, h);
|
---|
2583 | }
|
---|
2584 |
|
---|
2585 |
|
---|
2586 | void QtGlDebuggerWidget::paintGL()
|
---|
2587 | {
|
---|
2588 | // draw a spinning cube into the pbuffer..
|
---|
2589 | mRenderBuffer->makeCurrent();
|
---|
2590 |
|
---|
2591 | BeamSampleStatistics stats;
|
---|
2592 | mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats);
|
---|
2593 |
|
---|
2594 | glFlush();
|
---|
2595 |
|
---|
2596 | // rendering directly to a texture is not supported on X11, unfortunately
|
---|
2597 | mRenderBuffer->updateDynamicTexture(dynamicTexture);
|
---|
2598 |
|
---|
2599 | // and use the pbuffer contents as a texture when rendering the
|
---|
2600 | // background and the bouncing cubes
|
---|
2601 | makeCurrent();
|
---|
2602 | glBindTexture(GL_TEXTURE_2D, dynamicTexture);
|
---|
2603 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
2604 |
|
---|
2605 | // draw the background
|
---|
2606 | glMatrixMode(GL_MODELVIEW);
|
---|
2607 | glPushMatrix();
|
---|
2608 | glLoadIdentity();
|
---|
2609 | glMatrixMode(GL_PROJECTION);
|
---|
2610 | glPushMatrix();
|
---|
2611 | glLoadIdentity();
|
---|
2612 |
|
---|
2613 | glPopMatrix();
|
---|
2614 | glMatrixMode(GL_MODELVIEW);
|
---|
2615 | glPopMatrix();
|
---|
2616 | }
|
---|
2617 |
|
---|
2618 |
|
---|
2619 | void QtGlDebuggerWidget::initPbuffer()
|
---|
2620 | {
|
---|
2621 | // set up the pbuffer context
|
---|
2622 | mRenderBuffer->makeCurrent();
|
---|
2623 | // generate a texture that has the same size/format as the pbuffer
|
---|
2624 | dynamicTexture = mRenderBuffer->generateDynamicTexture();
|
---|
2625 | // bind the dynamic texture to the pbuffer - this is a no-op under X11
|
---|
2626 | mRenderBuffer->bindToDynamicTexture(dynamicTexture);
|
---|
2627 | //makeCurrent();
|
---|
2628 | }
|
---|
2629 |
|
---|
2630 |
|
---|
2631 | void QtGlDebuggerWidget::initCommon()
|
---|
2632 | {
|
---|
2633 | glEnable(GL_TEXTURE_2D);
|
---|
2634 | glEnable(GL_DEPTH_TEST);
|
---|
2635 |
|
---|
2636 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
---|
2637 | }
|
---|
2638 |
|
---|
2639 |
|
---|
2640 |
|
---|
2641 | void QtGlRendererWidget::UpdateDynamicObjects()
|
---|
2642 | {
|
---|
2643 | preprocessor->ScheduleUpdateDynamicObjects();
|
---|
2644 | }
|
---|
2645 |
|
---|
2646 |
|
---|
2647 | void QtGlRendererWidget::ReplayViewPoints()
|
---|
2648 | {
|
---|
2649 | ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList();
|
---|
2650 |
|
---|
2651 | ViewCellPointsList::const_iterator vit, vit_end = vcPoints->end();
|
---|
2652 |
|
---|
2653 | sViewPointsList.clear();
|
---|
2654 |
|
---|
2655 | for (vit = vcPoints->begin(); vit != vit_end; ++ vit)
|
---|
2656 | {
|
---|
2657 | ViewCellPoints *vp = *vit;
|
---|
2658 |
|
---|
2659 | SimpleRayContainer::const_iterator rit, rit_end = vp->second.end();
|
---|
2660 |
|
---|
2661 | for (rit = vp->second.begin(); rit != rit_end; ++ rit)
|
---|
2662 | {
|
---|
2663 | sViewPointsList.push_back(*rit);
|
---|
2664 | }
|
---|
2665 | }
|
---|
2666 |
|
---|
2667 | if (!sViewPointsList.empty())
|
---|
2668 | {
|
---|
2669 | cout << "replaying " << (int)sViewPointsList.size() << " view points " << endl;
|
---|
2670 |
|
---|
2671 | mReplayMode = true;
|
---|
2672 |
|
---|
2673 | if (mExportFrameBuffer)
|
---|
2674 | GetPreprocessor()->mSynchronize = true;
|
---|
2675 |
|
---|
2676 | sCurrentSamples = GetPreprocessor()->mCurrentSamples;
|
---|
2677 | sViewPointsListIt = sViewPointsList.begin();
|
---|
2678 | }
|
---|
2679 | else
|
---|
2680 | cerr << "view points list empty" << endl;
|
---|
2681 |
|
---|
2682 | }
|
---|
2683 |
|
---|
2684 |
|
---|
2685 |
|
---|
2686 | Vector3 QtGlRendererWidget::Unproject(int x, int y)
|
---|
2687 | {
|
---|
2688 | // swap y coordinate
|
---|
2689 | y = GetHeight() - y;
|
---|
2690 |
|
---|
2691 | // HACK: should come from camera!
|
---|
2692 | double projection[16];
|
---|
2693 | glGetDoublev(GL_PROJECTION_MATRIX, projection);
|
---|
2694 | double modelview[16];
|
---|
2695 | glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
|
---|
2696 |
|
---|
2697 | const int viewport[4] = {0,0, GetWidth(), GetHeight()};
|
---|
2698 |
|
---|
2699 | RenderScene();
|
---|
2700 |
|
---|
2701 | float z;
|
---|
2702 | glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
|
---|
2703 |
|
---|
2704 | GLdouble rx, ry, rz;
|
---|
2705 | gluUnProject(x, y, z, modelview, projection, viewport, &rx, &ry, &rz);
|
---|
2706 |
|
---|
2707 | return Vector3(rx, ry, rz);
|
---|
2708 | }
|
---|
2709 |
|
---|
2710 |
|
---|
2711 | int QtGlRendererWidget::FindDynamicObject(float x, float y)
|
---|
2712 | {
|
---|
2713 |
|
---|
2714 | if (GetPreprocessor()->mDynamicObjects.empty())
|
---|
2715 | return -1;
|
---|
2716 |
|
---|
2717 | makeCurrent();
|
---|
2718 |
|
---|
2719 | // this is the same as in every OpenGL picking example
|
---|
2720 | const int maxSize = 512;
|
---|
2721 |
|
---|
2722 | // see below for an explanation on the buffer content
|
---|
2723 | GLuint buffer[maxSize];
|
---|
2724 | glSelectBuffer(maxSize, buffer);
|
---|
2725 |
|
---|
2726 | // enter select mode
|
---|
2727 | glRenderMode(GL_SELECT);
|
---|
2728 | glInitNames();
|
---|
2729 | glPushName(0);
|
---|
2730 |
|
---|
2731 | glMatrixMode(GL_PROJECTION);
|
---|
2732 | glPushMatrix();
|
---|
2733 | glLoadIdentity();
|
---|
2734 |
|
---|
2735 | glViewport(0, 0, width(), height());
|
---|
2736 |
|
---|
2737 | GLint viewport[4];
|
---|
2738 | glGetIntegerv(GL_VIEWPORT, viewport);
|
---|
2739 |
|
---|
2740 | const float w = 1.0f;
|
---|
2741 |
|
---|
2742 | //gluPickMatrix(x, y, 1000.0, 1000.0, viewport);
|
---|
2743 | gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3] - y), w, w, viewport);
|
---|
2744 |
|
---|
2745 | GLfloat aspect = (GLfloat) width() / height();
|
---|
2746 | gluPerspective(70.0f, aspect, 0.1f, 2.0f * Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
2747 |
|
---|
2748 | glMatrixMode(GL_MODELVIEW);
|
---|
2749 | glPushMatrix();
|
---|
2750 | glLoadIdentity();
|
---|
2751 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
2752 |
|
---|
2753 |
|
---|
2754 | SetupCamera();
|
---|
2755 |
|
---|
2756 | for (GLuint i = 0; i < GetPreprocessor()->mDynamicObjects.size(); ++ i)
|
---|
2757 | {
|
---|
2758 | glLoadName(i);
|
---|
2759 | _RenderDynamicObject(GetPreprocessor()->mDynamicObjects[i]);
|
---|
2760 | }
|
---|
2761 |
|
---|
2762 | glFlush();
|
---|
2763 | glPopMatrix();
|
---|
2764 |
|
---|
2765 | glMatrixMode(GL_PROJECTION);
|
---|
2766 | glPopMatrix();
|
---|
2767 |
|
---|
2768 | int hits = glRenderMode(GL_RENDER);
|
---|
2769 |
|
---|
2770 | // finally release the rendering context again
|
---|
2771 | if (!hits)
|
---|
2772 | {
|
---|
2773 | cout << "no object picked" << endl;
|
---|
2774 | return -1;
|
---|
2775 | }
|
---|
2776 |
|
---|
2777 | //processHits(hits, buffer);
|
---|
2778 |
|
---|
2779 | // Each hit takes 4 items in the buffer.
|
---|
2780 | // The first item is the number of names on the name stack when the hit occured.
|
---|
2781 | // The second item is the minimum z value of all the verticies that intersected
|
---|
2782 | // the viewing area at the time of the hit. The third item is the maximum z value
|
---|
2783 | // of all the vertices that intersected the viewing area at the time of the hit
|
---|
2784 | // and the last item is the content of the name stack at the time of the hit
|
---|
2785 | // (name of the object). We are only interested in the object name
|
---|
2786 | // (number of the surface).
|
---|
2787 | // return the name of the clicked surface
|
---|
2788 | return buffer[3];
|
---|
2789 | }
|
---|
2790 |
|
---|
2791 |
|
---|
2792 | void QtGlRendererWidget::DeleteDynamicObject()
|
---|
2793 | {
|
---|
2794 | Preprocessor *p = GetPreprocessor();
|
---|
2795 |
|
---|
2796 | if ((mCurrentDynamicObjectIdx < 0) ||
|
---|
2797 | (mCurrentDynamicObjectIdx >= p->mDynamicObjects.size()))
|
---|
2798 | return;
|
---|
2799 |
|
---|
2800 | cout << "deleting object" << endl;
|
---|
2801 |
|
---|
2802 | SceneGraphLeaf *l = p->mDynamicObjects[mCurrentDynamicObjectIdx];
|
---|
2803 |
|
---|
2804 | // tell the preprocessor that an object was deleted
|
---|
2805 | p->ObjectRemoved(l);
|
---|
2806 |
|
---|
2807 | swap(p->mDynamicObjects[mCurrentDynamicObjectIdx], p->mDynamicObjects.back());
|
---|
2808 | p->mDynamicObjects.pop_back();
|
---|
2809 |
|
---|
2810 | delete l;
|
---|
2811 |
|
---|
2812 | mCurrentDynamicObjectIdx = -1;
|
---|
2813 | }
|
---|
2814 |
|
---|
2815 | }
|
---|