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