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