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