1 | #include "Mesh.h"
|
---|
2 | #include "glInterface.h"
|
---|
3 | #include "OcclusionQuery.h"
|
---|
4 | #include "QtGlRenderer.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 |
|
---|
18 | #define USE_CG 1
|
---|
19 |
|
---|
20 |
|
---|
21 | #if USE_CG
|
---|
22 | #include <Cg/cg.h>
|
---|
23 | #include <Cg/cgGL.h>
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | #include <QVBoxLayout>
|
---|
27 |
|
---|
28 | namespace GtpVisibilityPreprocessor {
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 | class ViewCellsManager;
|
---|
33 |
|
---|
34 | static CGcontext sCgContext = NULL;
|
---|
35 | static CGprogram sCgFragmentProgram = NULL;
|
---|
36 | static CGprofile sCgFragmentProfile;
|
---|
37 |
|
---|
38 |
|
---|
39 | //static vector<OcclusionQuery *> sQueries;
|
---|
40 |
|
---|
41 | QtGlRendererWidget *rendererWidget = NULL;
|
---|
42 | QtGlDebuggerWidget *debuggerWidget = NULL;
|
---|
43 |
|
---|
44 |
|
---|
45 | static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
|
---|
46 | {
|
---|
47 | return obj1->mId < obj2->mId;
|
---|
48 | }
|
---|
49 |
|
---|
50 | #if USE_CG
|
---|
51 | static void handleCgError()
|
---|
52 | {
|
---|
53 | Debug << "Cg error: " << cgGetErrorString(cgGetError()) << endl;
|
---|
54 | exit(1);
|
---|
55 | }
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | void
|
---|
59 | QtGlRendererBuffer::MakeCurrent()
|
---|
60 | {
|
---|
61 | makeCurrent();
|
---|
62 | }
|
---|
63 |
|
---|
64 | void
|
---|
65 | QtGlRendererBuffer::DoneCurrent()
|
---|
66 | {
|
---|
67 | doneCurrent();
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | QtGlRendererBuffer::QtGlRendererBuffer(const int w,
|
---|
72 | const int h,
|
---|
73 | SceneGraph *sceneGraph,
|
---|
74 | ViewCellsManager *viewcells,
|
---|
75 | KdTree *tree):
|
---|
76 | QGLPixelBuffer(QSize(w, h)),
|
---|
77 | //QGLWidget(NULL, w, h),
|
---|
78 | GlRendererBuffer(sceneGraph, viewcells, tree)
|
---|
79 | {
|
---|
80 | MakeCurrent();
|
---|
81 | InitGL();
|
---|
82 | DoneCurrent();
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | // reimplemented here so that we can snap the error windows
|
---|
87 | float
|
---|
88 | QtGlRendererBuffer::GetPixelError(int &pvsSize)
|
---|
89 | {
|
---|
90 | float pErrorPixels = -1.0f;
|
---|
91 |
|
---|
92 |
|
---|
93 | mUseFalseColors = false;
|
---|
94 | unsigned int pixelCount;
|
---|
95 |
|
---|
96 |
|
---|
97 | ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
|
---|
98 | // cout<<"View cell"<<viewcell<<endl;
|
---|
99 | if (viewcell == NULL)
|
---|
100 | return 0.0f;
|
---|
101 |
|
---|
102 | // ViewCell *viewcell = NULL;
|
---|
103 |
|
---|
104 | // PrVs prvs;
|
---|
105 |
|
---|
106 | // mViewCellsManager->SetMaxFilterSize(0);
|
---|
107 | // mViewCellsManager->GetPrVS(mViewPoint, prvs, mViewCellsManager->GetFilterWidth());
|
---|
108 | // viewcell = prvs.mViewCell;
|
---|
109 |
|
---|
110 | ObjectPvs pvs;
|
---|
111 | if (1) {
|
---|
112 | pvs = viewcell->GetPvs();
|
---|
113 | } else {
|
---|
114 | mViewCellsManager->ApplyFilter2(viewcell,
|
---|
115 | false,
|
---|
116 | 1.0f,
|
---|
117 | pvs);
|
---|
118 | }
|
---|
119 |
|
---|
120 | // cout<<"pvs size"<<pvs.GetSize()<<endl<<flush;
|
---|
121 |
|
---|
122 | SetupCamera();
|
---|
123 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
124 | glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
|
---|
125 |
|
---|
126 |
|
---|
127 | glStencilFunc(GL_EQUAL, 0x0, 0x1);
|
---|
128 | glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
---|
129 |
|
---|
130 | // // Render PVS
|
---|
131 | ObjectPvsIterator it = pvs.GetIterator();
|
---|
132 |
|
---|
133 | pvsSize = pvs.GetSize();
|
---|
134 | Intersectable::NewMail();
|
---|
135 | for (; it.HasMoreEntries(); ) {
|
---|
136 | RenderIntersectable(it.Next());
|
---|
137 | }
|
---|
138 |
|
---|
139 |
|
---|
140 | // glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
|
---|
141 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
142 | glEnable(GL_STENCIL_TEST);
|
---|
143 |
|
---|
144 | mUseFalseColors = true;
|
---|
145 |
|
---|
146 | OcclusionQuery *query = mOcclusionQueries[0];
|
---|
147 |
|
---|
148 |
|
---|
149 | query->BeginQuery();
|
---|
150 |
|
---|
151 | SetupCamera();
|
---|
152 |
|
---|
153 | RenderScene();
|
---|
154 |
|
---|
155 | query->EndQuery();
|
---|
156 | glDisable(GL_STENCIL_TEST);
|
---|
157 | // reenable other state
|
---|
158 | // int wait=0;
|
---|
159 | // while (!query.ResultAvailable()) {
|
---|
160 | // wait++;
|
---|
161 | // }
|
---|
162 |
|
---|
163 |
|
---|
164 | pixelCount = query->GetQueryResult();
|
---|
165 |
|
---|
166 | pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
|
---|
167 |
|
---|
168 |
|
---|
169 | if (mSnapErrorFrames && pErrorPixels >= 0.01f) {
|
---|
170 | glReadBuffer(GL_BACK);
|
---|
171 |
|
---|
172 | char filename[256];
|
---|
173 | sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels);
|
---|
174 | QImage im = toImage();
|
---|
175 | string str = mSnapPrefix + filename;
|
---|
176 | QString qstr(str.c_str());
|
---|
177 |
|
---|
178 | im.save(qstr, "PNG");
|
---|
179 | if (1) { //0 && mFrame == 1543) {
|
---|
180 | int x,y;
|
---|
181 | int lastIndex = -1;
|
---|
182 | for (y=0; y < im.height(); y++)
|
---|
183 | for (x=0; x < im.width(); x++) {
|
---|
184 | QRgb p = im.pixel(x,y);
|
---|
185 | int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16);
|
---|
186 | if (qGreen(p) != 255 && index!=0) {
|
---|
187 | if (index != lastIndex) {
|
---|
188 | // Debug<<"ei="<<index<<" ";
|
---|
189 | lastIndex = index;
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 | }
|
---|
194 |
|
---|
195 |
|
---|
196 | mUseFalseColors = false;
|
---|
197 | glPushAttrib(GL_CURRENT_BIT);
|
---|
198 | glColor3f(0,1,0);
|
---|
199 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
200 | SetupCamera();
|
---|
201 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
202 |
|
---|
203 | // Render PVS
|
---|
204 | Intersectable::NewMail();
|
---|
205 |
|
---|
206 | ObjectPvsIterator it = pvs.GetIterator();
|
---|
207 | for (; it.HasMoreEntries(); ) {
|
---|
208 | RenderIntersectable(it.Next());
|
---|
209 | }
|
---|
210 |
|
---|
211 | im = toImage();
|
---|
212 | sprintf(filename, "error-frame-%04d-%0.5f-pvs.png", mFrame, pErrorPixels);
|
---|
213 | str = mSnapPrefix + filename;
|
---|
214 | qstr = str.c_str();
|
---|
215 | im.save(qstr, "PNG");
|
---|
216 | glPopAttrib();
|
---|
217 | }
|
---|
218 |
|
---|
219 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
220 |
|
---|
221 | return pErrorPixels;
|
---|
222 | }
|
---|
223 |
|
---|
224 | int
|
---|
225 | QtGlRendererBuffer::ComputePvs(ObjectContainer &objects,
|
---|
226 | ObjectContainer &pvs) const
|
---|
227 | {
|
---|
228 | int pvsSize = 0;
|
---|
229 | QImage image = toImage();
|
---|
230 | Intersectable::NewMail();
|
---|
231 |
|
---|
232 | std::stable_sort(objects.begin(), objects.end(), ilt);
|
---|
233 |
|
---|
234 | MeshInstance dummy(NULL);
|
---|
235 |
|
---|
236 | Intersectable *obj = NULL;
|
---|
237 |
|
---|
238 | for (int x = 0; x < image.width(); ++ x)
|
---|
239 | {
|
---|
240 | for (int y = 0; y < image.height(); ++ y)
|
---|
241 | {
|
---|
242 | QRgb pix = image.pixel(x, y);
|
---|
243 | const int id = GetId(qRed(pix), qGreen(pix), qBlue(pix));
|
---|
244 |
|
---|
245 | dummy.SetId(id);
|
---|
246 |
|
---|
247 | ObjectContainer::iterator oit =
|
---|
248 | lower_bound(objects.begin(), objects.end(), &dummy, ilt);
|
---|
249 |
|
---|
250 |
|
---|
251 | if (//(oit != oit.end()) &&
|
---|
252 | ((*oit)->GetId() == id) &&
|
---|
253 | !obj->Mailed())
|
---|
254 | {
|
---|
255 | obj = *oit;
|
---|
256 | obj->Mail();
|
---|
257 | ++ pvsSize;
|
---|
258 | pvs.push_back(obj);
|
---|
259 | }
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 | return pvsSize;
|
---|
264 | }
|
---|
265 |
|
---|
266 | ///////////////////////////////////////////////////////////////
|
---|
267 | ///////////////////////////////////////////////////////////////
|
---|
268 | ///////////////////////////////////////////////////////////////
|
---|
269 | ///////////////////////////////////////////////////////////////
|
---|
270 |
|
---|
271 |
|
---|
272 | void
|
---|
273 | QtGlRendererWidget::InitGL()
|
---|
274 | {
|
---|
275 | GlRenderer::InitGL();
|
---|
276 |
|
---|
277 | GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
|
---|
278 | /* mat_specular and mat_shininess are NOT default values */
|
---|
279 | GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
---|
280 | GLfloat mat_specular[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
281 | GLfloat mat_shininess[] = { 1.0 };
|
---|
282 |
|
---|
283 | GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
|
---|
284 | GLfloat light_diffuse[] = { 0.4, 0.4, 0.4, 1.0 };
|
---|
285 | GLfloat light_specular[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
286 |
|
---|
287 | GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
288 |
|
---|
289 |
|
---|
290 | // default Material
|
---|
291 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
|
---|
292 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
|
---|
293 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
---|
294 | glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
---|
295 |
|
---|
296 | // a light
|
---|
297 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
---|
298 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
---|
299 | glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
---|
300 |
|
---|
301 | glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
---|
302 | glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
---|
303 | glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
---|
304 |
|
---|
305 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
---|
306 |
|
---|
307 | glEnable(GL_LIGHTING);
|
---|
308 | glEnable(GL_LIGHT0);
|
---|
309 | glEnable(GL_LIGHT1);
|
---|
310 |
|
---|
311 |
|
---|
312 | // set position of the light
|
---|
313 | GLfloat infinite_light[] = { 1.0, 0.8, 1.0, 0.0 };
|
---|
314 | glLightfv (GL_LIGHT0, GL_POSITION, infinite_light);
|
---|
315 |
|
---|
316 | // set position of the light2
|
---|
317 | GLfloat infinite_light2[] = { -0.3, 1.5, 1.0, 0.0 };
|
---|
318 | glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
|
---|
319 |
|
---|
320 | glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
---|
321 | // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR);
|
---|
322 | glEnable(GL_COLOR_MATERIAL);
|
---|
323 |
|
---|
324 | glShadeModel( GL_FLAT );
|
---|
325 | }
|
---|
326 |
|
---|
327 |
|
---|
328 | void
|
---|
329 | QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle)
|
---|
330 | {
|
---|
331 | if (!mTopView) {
|
---|
332 | int ww = w;
|
---|
333 | int hh = h;
|
---|
334 | glViewport(0, 0, ww, hh);
|
---|
335 | glMatrixMode(GL_PROJECTION);
|
---|
336 | glLoadIdentity();
|
---|
337 | gluPerspective(angle, ww/(float)hh, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
338 | glMatrixMode(GL_MODELVIEW);
|
---|
339 | } else {
|
---|
340 | int ww = w;
|
---|
341 | int hh = h;
|
---|
342 | glViewport(0, 0, ww, hh);
|
---|
343 | glMatrixMode(GL_PROJECTION);
|
---|
344 | glLoadIdentity();
|
---|
345 | gluPerspective(50.0, ww/(float)hh, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
346 | glMatrixMode(GL_MODELVIEW);
|
---|
347 | }
|
---|
348 | }
|
---|
349 |
|
---|
350 |
|
---|
351 |
|
---|
352 | void
|
---|
353 | QtGlRendererWidget::RenderPvs()
|
---|
354 | {
|
---|
355 |
|
---|
356 | Intersectable::NewMail();
|
---|
357 |
|
---|
358 | ViewCell *viewcell = NULL;
|
---|
359 |
|
---|
360 | if (mDetectEmptyViewSpace)
|
---|
361 | glEnable( GL_CULL_FACE );
|
---|
362 | else
|
---|
363 | glDisable( GL_CULL_FACE );
|
---|
364 |
|
---|
365 | viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
|
---|
366 |
|
---|
367 | if (viewcell) {
|
---|
368 | // copy the pvs so that it can be filtered...
|
---|
369 |
|
---|
370 | // mPvsCache.mPvs;
|
---|
371 |
|
---|
372 | if (mPvsCache.mViewCell != viewcell) {
|
---|
373 | mPvsCache.Reset();
|
---|
374 | mPvsCache.mViewCell = viewcell;
|
---|
375 |
|
---|
376 | if (mUseSpatialFilter) {
|
---|
377 | // 9.11. 2006 -> experiment with new spatial filter
|
---|
378 | #if 0
|
---|
379 | mViewCellsManager->ApplySpatialFilter(mKdTree,
|
---|
380 | mSpatialFilterSize*
|
---|
381 | Magnitude(mViewCellsManager->GetViewSpaceBox().Size()),
|
---|
382 | mPvsCache.mPvs);
|
---|
383 | #else
|
---|
384 | // mSpatialFilter size is in range 0.001 - 0.1
|
---|
385 | mViewCellsManager->ApplyFilter2(viewcell,
|
---|
386 | mUseFilter,
|
---|
387 | 100*mSpatialFilterSize,
|
---|
388 | mPvsCache.mPvs,
|
---|
389 | &mPvsCache.filteredBoxes
|
---|
390 | );
|
---|
391 | #endif
|
---|
392 | } else
|
---|
393 | mPvsCache.mPvs = viewcell->GetPvs();
|
---|
394 |
|
---|
395 | emit PvsUpdated();
|
---|
396 | }
|
---|
397 |
|
---|
398 | Intersectable::NewMail();
|
---|
399 |
|
---|
400 | PvsData pvsData;
|
---|
401 |
|
---|
402 | // Render PVS
|
---|
403 | if (mUseSpatialFilter && mRenderBoxes) {
|
---|
404 | for (int i=0; i < mPvsCache.filteredBoxes.size(); i++)
|
---|
405 | RenderBox(mPvsCache.filteredBoxes[i]);
|
---|
406 | } else {
|
---|
407 | ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
|
---|
408 |
|
---|
409 | mPvsSize = mPvsCache.mPvs.GetSize();
|
---|
410 | for (; it.HasMoreEntries(); ) {
|
---|
411 | Intersectable *object = it.Next(pvsData);
|
---|
412 |
|
---|
413 | if (mRenderVisibilityEstimates) {
|
---|
414 | //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f
|
---|
415 | // glColor3f(visibility, 0.0f, 0.0f);
|
---|
416 | //cerr << "sumpdf: " << pvsData.mSumPdf << endl;
|
---|
417 | RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1));
|
---|
418 | glColor3f(color.r, color.g, color.b);
|
---|
419 |
|
---|
420 | mUseForcedColors = true;
|
---|
421 | RenderIntersectable(object);
|
---|
422 | mUseForcedColors = false;
|
---|
423 | } else {
|
---|
424 | mUseForcedColors = false;
|
---|
425 | RenderIntersectable(object);
|
---|
426 | }
|
---|
427 | }
|
---|
428 | }
|
---|
429 |
|
---|
430 | if (mRenderFilter) {
|
---|
431 | mWireFrame = true;
|
---|
432 | RenderIntersectable(viewcell);
|
---|
433 | glPushMatrix();
|
---|
434 | glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z);
|
---|
435 | glScalef(5.0f,5.0f,5.0f);
|
---|
436 | glPushAttrib(GL_CURRENT_BIT);
|
---|
437 | glColor3f(1.0f, 0.0f, 0.0f);
|
---|
438 | // gluSphere((::GLUquadric *)mSphere,
|
---|
439 | // 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6);
|
---|
440 | glPopAttrib();
|
---|
441 | glPopMatrix();
|
---|
442 | mWireFrame = false;
|
---|
443 | }
|
---|
444 | } else {
|
---|
445 | ObjectContainer::const_iterator oi = mObjects.begin();
|
---|
446 | for (; oi != mObjects.end(); oi++)
|
---|
447 | RenderIntersectable(*oi);
|
---|
448 | }
|
---|
449 | }
|
---|
450 |
|
---|
451 | float
|
---|
452 | QtGlRendererWidget::RenderErrors()
|
---|
453 | {
|
---|
454 | float pErrorPixels = -1.0f;
|
---|
455 |
|
---|
456 | SetupCamera();
|
---|
457 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
458 |
|
---|
459 | glPushAttrib(GL_ENABLE_BIT);
|
---|
460 |
|
---|
461 | glStencilFunc(GL_EQUAL, 0x0, 0x1);
|
---|
462 | glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
---|
463 |
|
---|
464 | mUseForcedColors = true;
|
---|
465 |
|
---|
466 | glColor3f(0.0f, 0.8f, 0.2f);
|
---|
467 |
|
---|
468 | // // Render PVS
|
---|
469 | RenderPvs();
|
---|
470 |
|
---|
471 | glEnable(GL_STENCIL_TEST);
|
---|
472 |
|
---|
473 | // mUseFalseColors = true;
|
---|
474 |
|
---|
475 | glDisable(GL_LIGHTING);
|
---|
476 |
|
---|
477 | OcclusionQuery *query = mOcclusionQueries[0];
|
---|
478 | query->BeginQuery();
|
---|
479 |
|
---|
480 | SetupCamera();
|
---|
481 |
|
---|
482 | glColor3f(1.0f, 0.0f, 0.0f);
|
---|
483 |
|
---|
484 | RenderScene();
|
---|
485 |
|
---|
486 | mUseForcedColors = false;
|
---|
487 |
|
---|
488 | query->EndQuery();
|
---|
489 |
|
---|
490 | glDisable(GL_STENCIL_TEST);
|
---|
491 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
492 |
|
---|
493 | glPopAttrib();
|
---|
494 |
|
---|
495 | // reenable other state
|
---|
496 | // int wait=0;
|
---|
497 | // while (!query.ResultAvailable()) {
|
---|
498 | // wait++;
|
---|
499 | // }
|
---|
500 |
|
---|
501 | int pixelCount = query->GetQueryResult();
|
---|
502 | pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
|
---|
503 | cout<<"error pixels="<<pixelCount<<endl;
|
---|
504 |
|
---|
505 | mRenderError = pErrorPixels;
|
---|
506 |
|
---|
507 | return pErrorPixels;
|
---|
508 | }
|
---|
509 |
|
---|
510 |
|
---|
511 | void
|
---|
512 | QtGlRendererWidget::mousePressEvent(QMouseEvent *e)
|
---|
513 | {
|
---|
514 | int x = e->pos().x();
|
---|
515 | int y = e->pos().y();
|
---|
516 |
|
---|
517 | mousePoint.x = x;
|
---|
518 | mousePoint.y = y;
|
---|
519 |
|
---|
520 | }
|
---|
521 |
|
---|
522 | void
|
---|
523 | QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e)
|
---|
524 | {
|
---|
525 | float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3;
|
---|
526 | float TURN_SENSITIVITY=0.1f;
|
---|
527 | float TILT_SENSITIVITY=32.0 ;
|
---|
528 | float TURN_ANGLE= M_PI/36.0 ;
|
---|
529 |
|
---|
530 | int x = e->pos().x();
|
---|
531 | int y = e->pos().y();
|
---|
532 |
|
---|
533 | int diffx = -(mousePoint.x - x);
|
---|
534 | int diffy = -(mousePoint.y - y);
|
---|
535 |
|
---|
536 | if (e->modifiers() & Qt::ControlModifier) {
|
---|
537 | mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0;
|
---|
538 | mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0;
|
---|
539 | } else {
|
---|
540 | mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
|
---|
541 | float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
|
---|
542 | float angle = atan2(mViewDirection.x, mViewDirection.z);
|
---|
543 | mViewDirection.x = sin(angle+adiff);
|
---|
544 | mViewDirection.z = cos(angle+adiff);
|
---|
545 | }
|
---|
546 |
|
---|
547 | mousePoint.x = x;
|
---|
548 | mousePoint.y = y;
|
---|
549 |
|
---|
550 | updateGL();
|
---|
551 | }
|
---|
552 |
|
---|
553 | void
|
---|
554 | QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *)
|
---|
555 | {
|
---|
556 |
|
---|
557 |
|
---|
558 | }
|
---|
559 |
|
---|
560 | void
|
---|
561 | QtGlRendererWidget::resizeGL(int w, int h)
|
---|
562 | {
|
---|
563 | SetupCameraProjection(w, h);
|
---|
564 | updateGL();
|
---|
565 | }
|
---|
566 |
|
---|
567 | void
|
---|
568 | QtGlRendererWidget::paintGL()
|
---|
569 | {
|
---|
570 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
571 |
|
---|
572 | if (1) {
|
---|
573 | SetupCameraProjection(width(), height());
|
---|
574 | SetupCamera();
|
---|
575 |
|
---|
576 | if (mRenderErrors) {
|
---|
577 | RenderErrors();
|
---|
578 | } else {
|
---|
579 | glColor3f(0.6f, 0.6f, 0.6f);
|
---|
580 | RenderPvs();
|
---|
581 | }
|
---|
582 | }
|
---|
583 |
|
---|
584 | RenderInfo();
|
---|
585 |
|
---|
586 | mFrame++;
|
---|
587 |
|
---|
588 | }
|
---|
589 |
|
---|
590 |
|
---|
591 | void
|
---|
592 | QtGlRendererWidget::SetupCamera()
|
---|
593 | {
|
---|
594 | if (!mTopView)
|
---|
595 | GlRenderer::SetupCamera();
|
---|
596 | else {
|
---|
597 | if (0) {
|
---|
598 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05;
|
---|
599 | Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x,
|
---|
600 | -1,
|
---|
601 | mViewDirection.y);
|
---|
602 |
|
---|
603 | Vector3 target = mViewPoint + dist*mViewDirection;
|
---|
604 | Vector3 up(0,1,0);
|
---|
605 |
|
---|
606 | glLoadIdentity();
|
---|
607 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
608 | target.x, target.y, target.z,
|
---|
609 | up.x, up.y, up.z);
|
---|
610 | } else {
|
---|
611 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*mTopDistance;
|
---|
612 | Vector3 pos = mViewPoint + dist*Vector3(0,
|
---|
613 | 1,
|
---|
614 | 0);
|
---|
615 |
|
---|
616 | Vector3 target = mViewPoint;
|
---|
617 | Vector3 up(mViewDirection.x, 0, mViewDirection.z);
|
---|
618 |
|
---|
619 | glLoadIdentity();
|
---|
620 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
621 | target.x, target.y, target.z,
|
---|
622 | up.x, up.y, up.z);
|
---|
623 |
|
---|
624 | }
|
---|
625 | }
|
---|
626 |
|
---|
627 | }
|
---|
628 |
|
---|
629 |
|
---|
630 | void
|
---|
631 | QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
|
---|
632 | {
|
---|
633 | switch (e->key()) {
|
---|
634 | case Qt::Key_T:
|
---|
635 | mTopView = !mTopView;
|
---|
636 | SetupCameraProjection(width(), height());
|
---|
637 | updateGL();
|
---|
638 | break;
|
---|
639 | case Qt::Key_V:
|
---|
640 | mRenderViewCells = !mRenderViewCells;
|
---|
641 | updateGL();
|
---|
642 | break;
|
---|
643 | case Qt::Key_P:
|
---|
644 | // set random viewpoint
|
---|
645 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
646 | updateGL();
|
---|
647 | break;
|
---|
648 | case Qt::Key_S: {
|
---|
649 | // set view poitn and direction
|
---|
650 | QString text;
|
---|
651 | bool ok;
|
---|
652 | text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z);
|
---|
653 | text = QInputDialog::getText(this,
|
---|
654 | "Enter a view point",
|
---|
655 | "",
|
---|
656 | QLineEdit::Normal,
|
---|
657 | text,
|
---|
658 | &ok);
|
---|
659 | if (!ok)
|
---|
660 | break;
|
---|
661 |
|
---|
662 | if (sscanf(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) {
|
---|
663 | text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z);
|
---|
664 | text = QInputDialog::getText(this,
|
---|
665 | "Enter a direction",
|
---|
666 | "",
|
---|
667 | QLineEdit::Normal,
|
---|
668 | text,
|
---|
669 | &ok);
|
---|
670 | if (!ok)
|
---|
671 | break;
|
---|
672 | if (sscanf(text.toAscii(), "%f %f %f", &mViewDirection.x,
|
---|
673 | &mViewDirection.y, &mViewDirection.z) == 3) {
|
---|
674 | updateGL();
|
---|
675 | }
|
---|
676 | break;
|
---|
677 | }
|
---|
678 | }
|
---|
679 | default:
|
---|
680 | e->ignore();
|
---|
681 | break;
|
---|
682 | }
|
---|
683 | }
|
---|
684 |
|
---|
685 |
|
---|
686 |
|
---|
687 | QtGlRendererWidget::QtGlRendererWidget(
|
---|
688 | SceneGraph *sceneGraph,
|
---|
689 | ViewCellsManager *viewcells,
|
---|
690 | KdTree *tree,
|
---|
691 | QWidget * parent,
|
---|
692 | const QGLWidget * shareWidget,
|
---|
693 | Qt::WFlags f
|
---|
694 | )
|
---|
695 | :
|
---|
696 | GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
|
---|
697 | {
|
---|
698 | mPreprocessorThread = NULL;
|
---|
699 | mTopView = false;
|
---|
700 | mRenderViewCells = false;
|
---|
701 | mTopDistance = 1.0f;
|
---|
702 | mCutViewCells = false;
|
---|
703 | mCutScene = false;
|
---|
704 | mRenderErrors = false;
|
---|
705 | mRenderBoxes = false;
|
---|
706 | mRenderFilter = true;
|
---|
707 | mRenderVisibilityEstimates = false;
|
---|
708 | mTransferFunction = 0.2f;
|
---|
709 |
|
---|
710 | bool tmp;
|
---|
711 |
|
---|
712 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
713 | mUseFilter = tmp;
|
---|
714 |
|
---|
715 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
|
---|
716 | tmp );
|
---|
717 | mUseSpatialFilter = tmp;
|
---|
718 |
|
---|
719 | mShowRenderCost = false;
|
---|
720 | mShowPvsSizes = false;
|
---|
721 | mSpatialFilterSize = 0.01;
|
---|
722 | mPvsSize = 0;
|
---|
723 | mRenderError = 0.0f;
|
---|
724 | mShowRays = false;
|
---|
725 |
|
---|
726 | mControlWidget = new QtRendererControlWidget(NULL);
|
---|
727 |
|
---|
728 | connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
|
---|
729 | connect(mControlWidget,
|
---|
730 | SIGNAL(SetTransferFunction(int)),
|
---|
731 | this,
|
---|
732 | SLOT(SetTransferFunction(int)));
|
---|
733 | connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs()));
|
---|
734 | connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility()));
|
---|
735 | connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation()));
|
---|
736 | connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this,
|
---|
737 | SLOT(SetRandomViewPoint()));
|
---|
738 |
|
---|
739 | connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
|
---|
740 | connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
|
---|
741 |
|
---|
742 | connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
|
---|
743 | connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int)));
|
---|
744 |
|
---|
745 | connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
|
---|
746 | connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool)));
|
---|
747 | connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool)));
|
---|
748 | connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
|
---|
749 | connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
|
---|
750 | connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
|
---|
751 | connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
|
---|
752 | connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool)));
|
---|
753 | connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
|
---|
754 | connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)),
|
---|
755 | this, SLOT(SetRenderVisibilityEstimates(bool)));
|
---|
756 | connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool)));
|
---|
757 | connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)),
|
---|
758 | this, SLOT(SetUseSpatialFilter(bool)));
|
---|
759 |
|
---|
760 | connect(mControlWidget,
|
---|
761 | SIGNAL(SetShowRays(bool)),
|
---|
762 | this,
|
---|
763 | SLOT(SetShowRays(bool)));
|
---|
764 |
|
---|
765 | resize(1000, 500);
|
---|
766 | mControlWidget->show();
|
---|
767 | }
|
---|
768 |
|
---|
769 | void
|
---|
770 | QtGlRendererWidget::UpdateAllPvs()
|
---|
771 | {
|
---|
772 | // $$ does not work so far:(
|
---|
773 | mViewCellsManager->UpdatePvsForEvaluation();
|
---|
774 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
775 | }
|
---|
776 |
|
---|
777 | void
|
---|
778 | QtGlRendererWidget::ComputeVisibility()
|
---|
779 | {
|
---|
780 | cerr<<"Compute Visibility called!\n"<<endl;
|
---|
781 | if (!mPreprocessorThread->isRunning())
|
---|
782 | mPreprocessorThread->RunThread();
|
---|
783 | }
|
---|
784 |
|
---|
785 | void
|
---|
786 | QtGlRendererWidget::StopComputation()
|
---|
787 | {
|
---|
788 | cerr<<"stop computation called!\n"<<endl;
|
---|
789 | mViewCellsManager->GetPreprocessor()->mStopComputation = true;
|
---|
790 | }
|
---|
791 |
|
---|
792 | void
|
---|
793 | QtGlRendererWidget::SetRandomViewPoint()
|
---|
794 | {
|
---|
795 | cerr<<"stop computation called!\n"<<endl;
|
---|
796 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
797 | updateGL();
|
---|
798 | }
|
---|
799 |
|
---|
800 | void
|
---|
801 | QtGlRendererWidget::RenderRenderCost()
|
---|
802 | {
|
---|
803 | static vector<float> costFunction;
|
---|
804 | static float maxCost = -1;
|
---|
805 | if (costFunction.size()==0) {
|
---|
806 | ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree();
|
---|
807 | if (tree) {
|
---|
808 | tree->GetCostFunction(costFunction);
|
---|
809 | maxCost = -1;
|
---|
810 | for (int i=0; i < costFunction.size(); i++) {
|
---|
811 | // cout<<i<<":"<<costFunction[i]<<" ";
|
---|
812 | // update cost function to an absolute value based on the total geometry count
|
---|
813 | costFunction[i]*=mSceneGraph->GetRoot()->mGeometry.size();
|
---|
814 | if (costFunction[i] > maxCost)
|
---|
815 | maxCost = costFunction[i];
|
---|
816 | }
|
---|
817 | }
|
---|
818 | }
|
---|
819 |
|
---|
820 |
|
---|
821 | int currentPos = (int)mViewCellsManager->GetViewCells().size();
|
---|
822 | float currentCost= -1;
|
---|
823 |
|
---|
824 | if (currentPos < costFunction.size())
|
---|
825 | currentCost = costFunction[currentPos];
|
---|
826 | #if 1
|
---|
827 | cout<<"costFunction.size()="<<costFunction.size()<<endl;
|
---|
828 | cout<<"CP="<<currentPos<<endl;
|
---|
829 | cout<<"MC="<<maxCost<<endl;
|
---|
830 | cout<<"CC="<<currentCost<<endl;
|
---|
831 | #endif
|
---|
832 | if (costFunction.size()) {
|
---|
833 | float scaley = 1.0f/log10(maxCost);
|
---|
834 | float scalex = 1.0f/(float)costFunction.size();
|
---|
835 |
|
---|
836 | glDisable(GL_DEPTH_TEST);
|
---|
837 | // init ortographic projection
|
---|
838 | glMatrixMode(GL_PROJECTION);
|
---|
839 |
|
---|
840 | glPushMatrix();
|
---|
841 |
|
---|
842 | glLoadIdentity();
|
---|
843 | gluOrtho2D(0, 1.0f, 0, 1.0f);
|
---|
844 |
|
---|
845 | glTranslatef(0.1f, 0.1f, 0.0f);
|
---|
846 | glScalef(0.8f, 0.8f, 1.0f);
|
---|
847 | glMatrixMode(GL_MODELVIEW);
|
---|
848 | glLoadIdentity();
|
---|
849 |
|
---|
850 | glColor3f(1.0f,0,0);
|
---|
851 | glBegin(GL_LINE_STRIP);
|
---|
852 | // glVertex3f(0,0,0);
|
---|
853 |
|
---|
854 | for (int i=0; i < costFunction.size(); i++) {
|
---|
855 | float x = i*scalex;
|
---|
856 | float y = log10(costFunction[i])*scaley;
|
---|
857 | glVertex3f(x,y,0.0f);
|
---|
858 | }
|
---|
859 | glEnd();
|
---|
860 |
|
---|
861 | glColor3f(1.0f,0,0);
|
---|
862 | glBegin(GL_LINES);
|
---|
863 | float x = currentPos*scalex;
|
---|
864 | glVertex3f(x,0.0,0.0f);
|
---|
865 | glVertex3f(x,1.0f,0.0f);
|
---|
866 | glEnd();
|
---|
867 |
|
---|
868 | glColor3f(0.0f,0,0);
|
---|
869 | // show a grid
|
---|
870 | glBegin(GL_LINE_LOOP);
|
---|
871 | glVertex3f(0,0,0.0f);
|
---|
872 | glVertex3f(1,0,0.0f);
|
---|
873 | glVertex3f(1,1,0.0f);
|
---|
874 | glVertex3f(0,1,0.0f);
|
---|
875 | glEnd();
|
---|
876 |
|
---|
877 | glBegin(GL_LINES);
|
---|
878 | for (int i=0; i < costFunction.size(); i += 1000) {
|
---|
879 | float x = i*scalex;
|
---|
880 | glVertex3f(x,0.0,0.0f);
|
---|
881 | glVertex3f(x,1.0f,0.0f);
|
---|
882 | }
|
---|
883 |
|
---|
884 | for (int i=0; pow(10.0f, i) < maxCost; i+=1) {
|
---|
885 | float y = i*scaley;
|
---|
886 | // QString s;
|
---|
887 | // s.sprintf("%d", (int)pow(10,i));
|
---|
888 | // renderText(width()/2+5, y*height(), s);
|
---|
889 | glVertex3f(0.0f, y, 0.0f);
|
---|
890 | glVertex3f(1.0f, y, 0.0f);
|
---|
891 | }
|
---|
892 |
|
---|
893 | glEnd();
|
---|
894 |
|
---|
895 |
|
---|
896 | // restore the projection matrix
|
---|
897 | glMatrixMode(GL_PROJECTION);
|
---|
898 | glPopMatrix();
|
---|
899 | glMatrixMode(GL_MODELVIEW);
|
---|
900 | glEnable(GL_DEPTH_TEST);
|
---|
901 |
|
---|
902 | }
|
---|
903 |
|
---|
904 |
|
---|
905 |
|
---|
906 | }
|
---|
907 |
|
---|
908 | void
|
---|
909 | QtGlRendererWidget::RenderInfo()
|
---|
910 | {
|
---|
911 |
|
---|
912 | QString s;
|
---|
913 | int vc = 0;
|
---|
914 | if (mViewCellsManager)
|
---|
915 | vc = mViewCellsManager->GetViewCells().size();
|
---|
916 |
|
---|
917 | int filter = 0;
|
---|
918 | if (mViewCellsManager)
|
---|
919 | filter = mViewCellsManager->GetMaxFilterSize();
|
---|
920 |
|
---|
921 | glColor3f(1.0f,1.0f,1.0f);
|
---|
922 |
|
---|
923 | s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)",
|
---|
924 | mFrame,
|
---|
925 | mViewPoint.x,
|
---|
926 | mViewPoint.y,
|
---|
927 | mViewPoint.z,
|
---|
928 | mViewDirection.x,
|
---|
929 | mViewDirection.y,
|
---|
930 | mViewDirection.z
|
---|
931 | );
|
---|
932 |
|
---|
933 | renderText(20,20,s);
|
---|
934 |
|
---|
935 | s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f\%",
|
---|
936 | vc,
|
---|
937 | filter,
|
---|
938 | mPvsSize,
|
---|
939 | mRenderError*100.0f);
|
---|
940 |
|
---|
941 |
|
---|
942 | renderText(20,40,s);
|
---|
943 |
|
---|
944 |
|
---|
945 |
|
---|
946 |
|
---|
947 | }
|
---|
948 |
|
---|
949 |
|
---|
950 | void
|
---|
951 | QtGlRendererWidget::SetViewCellGranularity(int number)
|
---|
952 | {
|
---|
953 | if (mViewCellsManager) {
|
---|
954 | // mViewCellsManager->SetMaxFilterSize(number);
|
---|
955 |
|
---|
956 | // $$ tmp off
|
---|
957 | mViewCellsManager->CollectViewCells(number);
|
---|
958 |
|
---|
959 | // $$ does not work so far:(
|
---|
960 | // mViewCellsManager->UpdatePvsForEvaluation();
|
---|
961 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
962 | }
|
---|
963 | updateGL();
|
---|
964 | }
|
---|
965 |
|
---|
966 | void
|
---|
967 | QtGlRendererWidget::SetVisibilityFilterSize(int number)
|
---|
968 | {
|
---|
969 | if (mViewCellsManager)
|
---|
970 | mViewCellsManager->SetMaxFilterSize(number);
|
---|
971 | mPvsCache.Reset();
|
---|
972 | updateGL();
|
---|
973 | }
|
---|
974 |
|
---|
975 | void
|
---|
976 | QtGlRendererWidget::SetSpatialFilterSize(int number)
|
---|
977 | {
|
---|
978 | mSpatialFilterSize = 1e-3*number;
|
---|
979 | mPvsCache.Reset();
|
---|
980 | updateGL();
|
---|
981 | }
|
---|
982 |
|
---|
983 | void
|
---|
984 | QtGlRendererWidget::SetSceneCut(int number)
|
---|
985 | {
|
---|
986 | // assume the cut plane can only be aligned with xz plane
|
---|
987 | // shift it along y according to number, which is percentage of the bounding
|
---|
988 | // box position
|
---|
989 | if (mViewCellsManager) {
|
---|
990 | AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
|
---|
991 | Vector3 p = box.Min() + (number/1000.0f)*box.Max();
|
---|
992 | mSceneCutPlane.mNormal = Vector3(0,-1,0);
|
---|
993 | mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p);
|
---|
994 | updateGL();
|
---|
995 | }
|
---|
996 | }
|
---|
997 |
|
---|
998 | void
|
---|
999 | QtGlRendererWidget::SetTopDistance(int number)
|
---|
1000 | {
|
---|
1001 | mTopDistance = number/1000.0f;
|
---|
1002 | updateGL();
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | void
|
---|
1006 | QtGlRendererWidget::RenderViewCells()
|
---|
1007 | {
|
---|
1008 | mUseFalseColors = true;
|
---|
1009 |
|
---|
1010 | glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
|
---|
1011 |
|
---|
1012 | glEnable(GL_CULL_FACE);
|
---|
1013 | glCullFace(GL_FRONT);
|
---|
1014 |
|
---|
1015 | glDisable(GL_CULL_FACE);
|
---|
1016 | double eq[4];
|
---|
1017 | eq[0] = mSceneCutPlane.mNormal.x;
|
---|
1018 | eq[1] = mSceneCutPlane.mNormal.y;
|
---|
1019 | eq[2] = mSceneCutPlane.mNormal.z;
|
---|
1020 | eq[3] = mSceneCutPlane.mD;
|
---|
1021 |
|
---|
1022 | if (mCutViewCells) {
|
---|
1023 | glClipPlane(GL_CLIP_PLANE0, eq);
|
---|
1024 | glEnable(GL_CLIP_PLANE0);
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | int i;
|
---|
1028 | ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
|
---|
1029 | int maxPvs = -1;
|
---|
1030 | for (i=0; i < viewcells.size(); i++)
|
---|
1031 | {
|
---|
1032 | ViewCell *vc = viewcells[i];
|
---|
1033 |
|
---|
1034 | //const int p = vc->GetPvs().CountObjectsInPvs();
|
---|
1035 | const int p = vc->GetPvs().GetSize();
|
---|
1036 | if (p > maxPvs)
|
---|
1037 | maxPvs = p;
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 |
|
---|
1041 | for (i=0; i < viewcells.size(); i++) {
|
---|
1042 | ViewCell *vc = viewcells[i];
|
---|
1043 | // Mesh *m = vc->GetMesh();
|
---|
1044 |
|
---|
1045 | RgbColor c;
|
---|
1046 |
|
---|
1047 | if (!mShowPvsSizes) {
|
---|
1048 | mWireFrame = true;
|
---|
1049 | c = vc->GetColor();
|
---|
1050 | } else {
|
---|
1051 | // const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs);
|
---|
1052 | const float importance = 5.0f*mTransferFunction *
|
---|
1053 | ((float)vc->GetPvs().GetSize() / (float)maxPvs);
|
---|
1054 | // c = RgbColor(importance, 1.0f - importance, 0.0f);
|
---|
1055 | c = RainbowColorMapping(importance);
|
---|
1056 |
|
---|
1057 | }
|
---|
1058 | glColor3f(c.r, c.g, c.b);
|
---|
1059 |
|
---|
1060 | RenderViewCell(vc);
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | mUseFalseColors = false;
|
---|
1064 | mWireFrame = false;
|
---|
1065 |
|
---|
1066 | glPopAttrib();
|
---|
1067 |
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 |
|
---|
1071 |
|
---|
1072 |
|
---|
1073 |
|
---|
1074 | /***********************************************************************/
|
---|
1075 | /* QtGlDebuggerWidget implementation */
|
---|
1076 | /***********************************************************************/
|
---|
1077 |
|
---|
1078 |
|
---|
1079 | QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
|
---|
1080 | : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
|
---|
1081 | {
|
---|
1082 | // create the pbuffer
|
---|
1083 | //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
|
---|
1084 | timerId = startTimer(20);
|
---|
1085 | setWindowTitle(("OpenGL pbuffers"));
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 |
|
---|
1089 | QtGlDebuggerWidget::~QtGlDebuggerWidget()
|
---|
1090 | {
|
---|
1091 | mRenderBuffer->releaseFromDynamicTexture();
|
---|
1092 | glDeleteTextures(1, &dynamicTexture);
|
---|
1093 |
|
---|
1094 | DEL_PTR(mRenderBuffer);
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 |
|
---|
1098 |
|
---|
1099 | QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f):
|
---|
1100 | QWidget(parent, f)
|
---|
1101 | {
|
---|
1102 |
|
---|
1103 | QVBoxLayout *vl = new QVBoxLayout;
|
---|
1104 | setLayout(vl);
|
---|
1105 |
|
---|
1106 | QWidget *vbox = new QGroupBox("ViewCells", this);
|
---|
1107 | layout()->addWidget(vbox);
|
---|
1108 |
|
---|
1109 | vl = new QVBoxLayout;
|
---|
1110 | vbox->setLayout(vl);
|
---|
1111 |
|
---|
1112 | QLabel *label = new QLabel("Granularity");
|
---|
1113 | vbox->layout()->addWidget(label);
|
---|
1114 |
|
---|
1115 | QSlider *slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1116 | vl->addWidget(slider);
|
---|
1117 | slider->show();
|
---|
1118 | slider->setRange(1, 10000);
|
---|
1119 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1120 | slider->setValue(200);
|
---|
1121 |
|
---|
1122 |
|
---|
1123 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
|
---|
1124 |
|
---|
1125 | label = new QLabel("Transfer function");
|
---|
1126 | vbox->layout()->addWidget(label);
|
---|
1127 |
|
---|
1128 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1129 | vl->addWidget(slider);
|
---|
1130 | slider->show();
|
---|
1131 | slider->setRange(1, 10000);
|
---|
1132 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1133 | slider->setValue(100);
|
---|
1134 |
|
---|
1135 |
|
---|
1136 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int)));
|
---|
1137 |
|
---|
1138 | {
|
---|
1139 | QPushButton *button = new QPushButton("Update all PVSs", vbox);
|
---|
1140 | vbox->layout()->addWidget(button);
|
---|
1141 | connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs()));
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 |
|
---|
1145 | label = new QLabel("Filter size");
|
---|
1146 | vbox->layout()->addWidget(label);
|
---|
1147 |
|
---|
1148 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1149 | vbox->layout()->addWidget(slider);
|
---|
1150 | slider->show();
|
---|
1151 | slider->setRange(1, 100);
|
---|
1152 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1153 | slider->setValue(3);
|
---|
1154 |
|
---|
1155 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int)));
|
---|
1156 |
|
---|
1157 |
|
---|
1158 | label = new QLabel("Spatial Filter size");
|
---|
1159 | vbox->layout()->addWidget(label);
|
---|
1160 |
|
---|
1161 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1162 | vbox->layout()->addWidget(slider);
|
---|
1163 | slider->show();
|
---|
1164 | slider->setRange(1, 100);
|
---|
1165 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1166 | slider->setValue(10);
|
---|
1167 |
|
---|
1168 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int)));
|
---|
1169 |
|
---|
1170 |
|
---|
1171 |
|
---|
1172 | QWidget *hbox = new QWidget(vbox);
|
---|
1173 | vl->addWidget(hbox);
|
---|
1174 | QHBoxLayout *hlayout = new QHBoxLayout;
|
---|
1175 | hbox->setLayout(hlayout);
|
---|
1176 |
|
---|
1177 | QCheckBox *cb = new QCheckBox("Show viewcells", hbox);
|
---|
1178 | hlayout->addWidget(cb);
|
---|
1179 | cb->setChecked(false);
|
---|
1180 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool)));
|
---|
1181 |
|
---|
1182 | cb = new QCheckBox("Render cost curve", hbox);
|
---|
1183 | hlayout->addWidget(cb);
|
---|
1184 | cb->setChecked(false);
|
---|
1185 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool)));
|
---|
1186 |
|
---|
1187 | cb = new QCheckBox("Show render cost", hbox);
|
---|
1188 | hlayout->addWidget(cb);
|
---|
1189 | cb->setChecked(false);
|
---|
1190 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
|
---|
1191 |
|
---|
1192 | cb = new QCheckBox("Show rays", hbox);
|
---|
1193 | hlayout->addWidget(cb);
|
---|
1194 | cb->setChecked(false);
|
---|
1195 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
|
---|
1196 |
|
---|
1197 | vbox->resize(800,100);
|
---|
1198 |
|
---|
1199 |
|
---|
1200 | vbox = new QGroupBox("Rendering", this);
|
---|
1201 | layout()->addWidget(vbox);
|
---|
1202 |
|
---|
1203 | vl = new QVBoxLayout;
|
---|
1204 | vbox->setLayout(vl);
|
---|
1205 |
|
---|
1206 |
|
---|
1207 |
|
---|
1208 | cb = new QCheckBox("Cut view cells", vbox);
|
---|
1209 | vbox->layout()->addWidget(cb);
|
---|
1210 | cb->setChecked(false);
|
---|
1211 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool)));
|
---|
1212 |
|
---|
1213 |
|
---|
1214 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1215 | vbox->layout()->addWidget(slider);
|
---|
1216 | slider->show();
|
---|
1217 | slider->setRange(0, 1000);
|
---|
1218 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1219 | slider->setValue(1000);
|
---|
1220 |
|
---|
1221 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int)));
|
---|
1222 |
|
---|
1223 |
|
---|
1224 | cb = new QCheckBox("Cut scene", vbox);
|
---|
1225 | vbox->layout()->addWidget(cb);
|
---|
1226 | cb->setChecked(false);
|
---|
1227 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool)));
|
---|
1228 |
|
---|
1229 | cb = new QCheckBox("Render boxes", vbox);
|
---|
1230 | vbox->layout()->addWidget(cb);
|
---|
1231 | cb->setChecked(false);
|
---|
1232 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool)));
|
---|
1233 |
|
---|
1234 | cb = new QCheckBox("Render visibility estimates", vbox);
|
---|
1235 | vbox->layout()->addWidget(cb);
|
---|
1236 | cb->setChecked(false);
|
---|
1237 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool)));
|
---|
1238 |
|
---|
1239 |
|
---|
1240 | cb = new QCheckBox("Render errors", vbox);
|
---|
1241 | vbox->layout()->addWidget(cb);
|
---|
1242 | cb->setChecked(false);
|
---|
1243 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
|
---|
1244 |
|
---|
1245 |
|
---|
1246 | bool tmp;
|
---|
1247 |
|
---|
1248 | cb = new QCheckBox("Use filter", vbox);
|
---|
1249 | vbox->layout()->addWidget(cb);
|
---|
1250 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
1251 | cb->setChecked(tmp);
|
---|
1252 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool)));
|
---|
1253 |
|
---|
1254 |
|
---|
1255 | cb = new QCheckBox("Use spatial filter", vbox);
|
---|
1256 | vbox->layout()->addWidget(cb);
|
---|
1257 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
|
---|
1258 | tmp );
|
---|
1259 | cb->setChecked(tmp);
|
---|
1260 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool)));
|
---|
1261 |
|
---|
1262 | cb = new QCheckBox("Render filter", vbox);
|
---|
1263 | vbox->layout()->addWidget(cb);
|
---|
1264 | cb->setChecked(true);
|
---|
1265 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
|
---|
1266 |
|
---|
1267 |
|
---|
1268 |
|
---|
1269 |
|
---|
1270 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1271 | vbox->layout()->addWidget(slider);
|
---|
1272 | slider->show();
|
---|
1273 | slider->setRange(1, 1000);
|
---|
1274 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1275 | slider->setValue(500);
|
---|
1276 |
|
---|
1277 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
|
---|
1278 |
|
---|
1279 | cb = new QCheckBox("Top View", vbox);
|
---|
1280 | vbox->layout()->addWidget(cb);
|
---|
1281 | cb->setChecked(false);
|
---|
1282 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
|
---|
1283 |
|
---|
1284 |
|
---|
1285 |
|
---|
1286 | vbox = new QGroupBox("PVS Errors", this);
|
---|
1287 | layout()->addWidget(vbox);
|
---|
1288 |
|
---|
1289 | vl = new QVBoxLayout;
|
---|
1290 | vbox->setLayout(vl);
|
---|
1291 |
|
---|
1292 | QPushButton *button = new QPushButton("Compute Visibility", vbox);
|
---|
1293 | vbox->layout()->addWidget(button);
|
---|
1294 | connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility()));
|
---|
1295 |
|
---|
1296 | button = new QPushButton("Stop Computation", vbox);
|
---|
1297 | vbox->layout()->addWidget(button);
|
---|
1298 | connect(button, SIGNAL(clicked()), SLOT(StopComputation()));
|
---|
1299 |
|
---|
1300 | button = new QPushButton("Set Random View Point", vbox);
|
---|
1301 | vbox->layout()->addWidget(button);
|
---|
1302 | connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint()));
|
---|
1303 |
|
---|
1304 |
|
---|
1305 | if (0) {
|
---|
1306 | vbox = new QGroupBox("PVS Errors", this);
|
---|
1307 | layout()->addWidget(vbox);
|
---|
1308 |
|
---|
1309 | vl = new QVBoxLayout;
|
---|
1310 | vbox->setLayout(vl);
|
---|
1311 |
|
---|
1312 | mPvsErrorWidget = new QListWidget(vbox);
|
---|
1313 | vbox->layout()->addWidget(mPvsErrorWidget);
|
---|
1314 |
|
---|
1315 | connect(mPvsErrorWidget,
|
---|
1316 | SIGNAL(doubleClicked(const QModelIndex &)),
|
---|
1317 | this,
|
---|
1318 | SLOT(PvsErrorClicked(const QModelIndex &)));
|
---|
1319 |
|
---|
1320 | QPushButton *button = new QPushButton("Next Error Frame", vbox);
|
---|
1321 | vbox->layout()->addWidget(button);
|
---|
1322 | connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | setWindowTitle("Preprocessor Control Widget");
|
---|
1326 | adjustSize();
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 |
|
---|
1330 |
|
---|
1331 |
|
---|
1332 | void
|
---|
1333 | QtRendererControlWidget::FocusNextPvsErrorFrame(void)
|
---|
1334 | {
|
---|
1335 |
|
---|
1336 |
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | void
|
---|
1340 | QtRendererControlWidget::UpdatePvsErrorItem(int row,
|
---|
1341 | GlRendererBuffer::PvsErrorEntry &pvsErrorEntry)
|
---|
1342 | {
|
---|
1343 |
|
---|
1344 | QListWidgetItem *i = mPvsErrorWidget->item(row);
|
---|
1345 | QString s;
|
---|
1346 | s.sprintf("%5.5f", pvsErrorEntry.mError);
|
---|
1347 | if (i) {
|
---|
1348 | i->setText(s);
|
---|
1349 | } else {
|
---|
1350 | new QListWidgetItem(s, mPvsErrorWidget);
|
---|
1351 | }
|
---|
1352 | mPvsErrorWidget->update();
|
---|
1353 | }
|
---|
1354 |
|
---|
1355 |
|
---|
1356 | void QtGlDebuggerWidget::initializeGL()
|
---|
1357 | {
|
---|
1358 | glMatrixMode(GL_PROJECTION);
|
---|
1359 | glLoadIdentity();
|
---|
1360 |
|
---|
1361 | glFrustum(-1, 1, -1, 1, 10, 100);
|
---|
1362 | glTranslatef(-0.5f, -0.5f, -0.5f);
|
---|
1363 | glTranslatef(0.0f, 0.0f, -15.0f);
|
---|
1364 | glMatrixMode(GL_MODELVIEW);
|
---|
1365 |
|
---|
1366 | glEnable(GL_CULL_FACE);
|
---|
1367 | initCommon();
|
---|
1368 | initPbuffer();
|
---|
1369 |
|
---|
1370 | }
|
---|
1371 |
|
---|
1372 |
|
---|
1373 | void QtGlDebuggerWidget::resizeGL(int w, int h)
|
---|
1374 | {
|
---|
1375 | glViewport(0, 0, w, h);
|
---|
1376 | }
|
---|
1377 |
|
---|
1378 |
|
---|
1379 | void QtGlDebuggerWidget::paintGL()
|
---|
1380 | {
|
---|
1381 | // draw a spinning cube into the pbuffer..
|
---|
1382 | mRenderBuffer->makeCurrent();
|
---|
1383 |
|
---|
1384 | BeamSampleStatistics stats;
|
---|
1385 | mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats);
|
---|
1386 |
|
---|
1387 | glFlush();
|
---|
1388 |
|
---|
1389 | // rendering directly to a texture is not supported on X11, unfortunately
|
---|
1390 | mRenderBuffer->updateDynamicTexture(dynamicTexture);
|
---|
1391 |
|
---|
1392 | // and use the pbuffer contents as a texture when rendering the
|
---|
1393 | // background and the bouncing cubes
|
---|
1394 | makeCurrent();
|
---|
1395 | glBindTexture(GL_TEXTURE_2D, dynamicTexture);
|
---|
1396 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
1397 |
|
---|
1398 | // draw the background
|
---|
1399 | glMatrixMode(GL_MODELVIEW);
|
---|
1400 | glPushMatrix();
|
---|
1401 | glLoadIdentity();
|
---|
1402 | glMatrixMode(GL_PROJECTION);
|
---|
1403 | glPushMatrix();
|
---|
1404 | glLoadIdentity();
|
---|
1405 |
|
---|
1406 | glPopMatrix();
|
---|
1407 | glMatrixMode(GL_MODELVIEW);
|
---|
1408 | glPopMatrix();
|
---|
1409 | }
|
---|
1410 |
|
---|
1411 |
|
---|
1412 | void QtGlDebuggerWidget::initPbuffer()
|
---|
1413 | {
|
---|
1414 | // set up the pbuffer context
|
---|
1415 | mRenderBuffer->makeCurrent();
|
---|
1416 | /*mRenderBuffer->InitGL();
|
---|
1417 |
|
---|
1418 | glViewport(0, 0, mRenderBuffer->size().width(), mRenderBuffer->size().height());
|
---|
1419 | glMatrixMode(GL_PROJECTION);
|
---|
1420 | glLoadIdentity();
|
---|
1421 | glOrtho(-1, 1, -1, 1, -99, 99);
|
---|
1422 | glTranslatef(-0.5f, -0.5f, 0.0f);
|
---|
1423 | glMatrixMode(GL_MODELVIEW);
|
---|
1424 | glLoadIdentity();
|
---|
1425 |
|
---|
1426 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/
|
---|
1427 |
|
---|
1428 | // generate a texture that has the same size/format as the pbuffer
|
---|
1429 | dynamicTexture = mRenderBuffer->generateDynamicTexture();
|
---|
1430 |
|
---|
1431 | // bind the dynamic texture to the pbuffer - this is a no-op under X11
|
---|
1432 | mRenderBuffer->bindToDynamicTexture(dynamicTexture);
|
---|
1433 | makeCurrent();
|
---|
1434 | }
|
---|
1435 |
|
---|
1436 | void QtGlDebuggerWidget::initCommon()
|
---|
1437 | {
|
---|
1438 | glEnable(GL_TEXTURE_2D);
|
---|
1439 | glEnable(GL_DEPTH_TEST);
|
---|
1440 |
|
---|
1441 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
---|
1442 | }
|
---|
1443 |
|
---|
1444 |
|
---|
1445 |
|
---|
1446 | }
|
---|