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