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