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 | #include "IntersectableWrapper.h"
|
---|
18 |
|
---|
19 |
|
---|
20 | #define USE_CG 1
|
---|
21 |
|
---|
22 |
|
---|
23 | #if USE_CG
|
---|
24 | #include <Cg/cg.h>
|
---|
25 | #include <Cg/cgGL.h>
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | #include <QVBoxLayout>
|
---|
29 |
|
---|
30 | namespace GtpVisibilityPreprocessor {
|
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 | class ViewCellsManager;
|
---|
35 |
|
---|
36 | static CGcontext sCgContext = NULL;
|
---|
37 | static CGprogram sCgFragmentProgram = NULL;
|
---|
38 | static CGprofile sCgFragmentProfile;
|
---|
39 |
|
---|
40 |
|
---|
41 | //static vector<OcclusionQuery *> sQueries;
|
---|
42 |
|
---|
43 | QtGlRendererWidget *rendererWidget = NULL;
|
---|
44 | QtGlDebuggerWidget *debuggerWidget = NULL;
|
---|
45 |
|
---|
46 |
|
---|
47 | static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
|
---|
48 | {
|
---|
49 | return obj1->mId < obj2->mId;
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | inline static bool nearerThan(ViewCell *vc1, ViewCell *vc2)
|
---|
54 | {
|
---|
55 | return vc1->GetDistance() > vc2->GetDistance();
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | #if USE_CG
|
---|
60 | static void handleCgError()
|
---|
61 | {
|
---|
62 | Debug << "Cg error: " << cgGetErrorString(cgGetError()) << endl;
|
---|
63 | exit(1);
|
---|
64 | }
|
---|
65 | #endif
|
---|
66 |
|
---|
67 | void
|
---|
68 | QtGlRendererBuffer::MakeCurrent()
|
---|
69 | {
|
---|
70 | makeCurrent();
|
---|
71 | }
|
---|
72 |
|
---|
73 | void
|
---|
74 | QtGlRendererBuffer::DoneCurrent()
|
---|
75 | {
|
---|
76 | doneCurrent();
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | QtGlRendererBuffer::QtGlRendererBuffer(const int w,
|
---|
81 | const int h,
|
---|
82 | SceneGraph *sceneGraph,
|
---|
83 | ViewCellsManager *viewcells,
|
---|
84 | KdTree *tree):
|
---|
85 | QGLPixelBuffer(QSize(w, h)),
|
---|
86 | //QGLWidget(NULL, w, h),
|
---|
87 | GlRendererBuffer(sceneGraph, viewcells, tree)
|
---|
88 | {
|
---|
89 | MakeCurrent();
|
---|
90 | InitGL();
|
---|
91 | DoneCurrent();
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | // reimplemented here so that we can snap the error windows
|
---|
96 | float
|
---|
97 | QtGlRendererBuffer::GetPixelError(int &pvsSize)
|
---|
98 | {
|
---|
99 | float pErrorPixels = -1.0f;
|
---|
100 |
|
---|
101 |
|
---|
102 | mUseFalseColors = false;
|
---|
103 | unsigned int pixelCount;
|
---|
104 |
|
---|
105 |
|
---|
106 | ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
|
---|
107 | // cout<<"View cell"<<viewcell<<endl;
|
---|
108 | if (viewcell == NULL)
|
---|
109 | return 0.0f;
|
---|
110 |
|
---|
111 |
|
---|
112 | ObjectPvs pvs;
|
---|
113 |
|
---|
114 | if (1)
|
---|
115 | pvs = viewcell->GetPvs();
|
---|
116 | else
|
---|
117 | mViewCellsManager->ApplyFilter2(viewcell, false, 1.0f, pvs);
|
---|
118 |
|
---|
119 | SetupCamera();
|
---|
120 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
121 | glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
|
---|
122 |
|
---|
123 |
|
---|
124 | glStencilFunc(GL_EQUAL, 0x0, 0x1);
|
---|
125 | glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
---|
126 |
|
---|
127 | // Render PVS
|
---|
128 | ObjectPvsIterator it = pvs.GetIterator();
|
---|
129 |
|
---|
130 | pvsSize = pvs.GetSize();
|
---|
131 |
|
---|
132 | Intersectable::NewMail();
|
---|
133 | while (it.HasMoreEntries())
|
---|
134 | {
|
---|
135 | RenderIntersectable(it.Next());
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | // glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
|
---|
140 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
141 | glEnable(GL_STENCIL_TEST);
|
---|
142 |
|
---|
143 | mUseFalseColors = true;
|
---|
144 |
|
---|
145 | OcclusionQuery *query = mOcclusionQueries[0];
|
---|
146 |
|
---|
147 |
|
---|
148 | query->BeginQuery();
|
---|
149 |
|
---|
150 | SetupCamera();
|
---|
151 |
|
---|
152 | RenderScene();
|
---|
153 |
|
---|
154 | query->EndQuery();
|
---|
155 | glDisable(GL_STENCIL_TEST);
|
---|
156 | // reenable other state
|
---|
157 | // int wait=0;
|
---|
158 | // while (!query.ResultAvailable()) {
|
---|
159 | // wait++;
|
---|
160 | // }
|
---|
161 |
|
---|
162 |
|
---|
163 | pixelCount = query->GetQueryResult();
|
---|
164 |
|
---|
165 | pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
|
---|
166 |
|
---|
167 |
|
---|
168 | if (mSnapErrorFrames && pErrorPixels >= 0.01f) {
|
---|
169 | glReadBuffer(GL_BACK);
|
---|
170 |
|
---|
171 | char filename[256];
|
---|
172 | sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels);
|
---|
173 | QImage im = toImage();
|
---|
174 | string str = mSnapPrefix + filename;
|
---|
175 | QString qstr(str.c_str());
|
---|
176 |
|
---|
177 | im.save(qstr, "PNG");
|
---|
178 | if (1) { //0 && mFrame == 1543) {
|
---|
179 | int x,y;
|
---|
180 | int lastIndex = -1;
|
---|
181 | for (y=0; y < im.height(); y++)
|
---|
182 | for (x=0; x < im.width(); x++) {
|
---|
183 | QRgb p = im.pixel(x,y);
|
---|
184 | int index = qRed(p) + (qGreen(p)<<8) + (qBlue(p)<<16);
|
---|
185 | if (qGreen(p) != 255 && index!=0) {
|
---|
186 | if (index != lastIndex) {
|
---|
187 | // Debug<<"ei="<<index<<" ";
|
---|
188 | lastIndex = index;
|
---|
189 | }
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 |
|
---|
195 | mUseFalseColors = false;
|
---|
196 | glPushAttrib(GL_CURRENT_BIT);
|
---|
197 | glColor3f(0,1,0);
|
---|
198 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
199 | SetupCamera();
|
---|
200 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
201 |
|
---|
202 | // Render PVS
|
---|
203 | Intersectable::NewMail();
|
---|
204 |
|
---|
205 | ObjectPvsIterator it = pvs.GetIterator();
|
---|
206 | for (; it.HasMoreEntries(); )
|
---|
207 | {
|
---|
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 | void QtGlRendererWidget::InitGL()
|
---|
268 | {
|
---|
269 | GlRenderer::InitGL();
|
---|
270 |
|
---|
271 | GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
|
---|
272 | /* mat_specular and mat_shininess are NOT default values */
|
---|
273 | GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
|
---|
274 | GLfloat mat_specular[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
275 | GLfloat mat_shininess[] = { 1.0 };
|
---|
276 |
|
---|
277 | GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
|
---|
278 | GLfloat light_diffuse[] = { 0.4, 0.4, 0.4, 1.0 };
|
---|
279 | GLfloat light_specular[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
280 |
|
---|
281 | GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
|
---|
282 |
|
---|
283 |
|
---|
284 | // default Material
|
---|
285 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
|
---|
286 | glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
|
---|
287 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
---|
288 | glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
---|
289 |
|
---|
290 | // a light
|
---|
291 | glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
---|
292 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
---|
293 | glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
---|
294 |
|
---|
295 | glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
---|
296 | glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
---|
297 | glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
---|
298 |
|
---|
299 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
---|
300 |
|
---|
301 | glEnable(GL_LIGHTING);
|
---|
302 | glEnable(GL_LIGHT0);
|
---|
303 | glEnable(GL_LIGHT1);
|
---|
304 |
|
---|
305 |
|
---|
306 | // set position of the light
|
---|
307 | GLfloat infinite_light[] = { 1.0, 0.8, 1.0, 0.0 };
|
---|
308 | glLightfv (GL_LIGHT0, GL_POSITION, infinite_light);
|
---|
309 |
|
---|
310 | // set position of the light2
|
---|
311 | GLfloat infinite_light2[] = { -0.3, 1.5, 1.0, 0.0 };
|
---|
312 | glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
|
---|
313 |
|
---|
314 | glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
---|
315 | // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR);
|
---|
316 | glEnable(GL_COLOR_MATERIAL);
|
---|
317 |
|
---|
318 | glShadeModel( GL_FLAT );
|
---|
319 | }
|
---|
320 |
|
---|
321 |
|
---|
322 | void
|
---|
323 | QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle)
|
---|
324 | {
|
---|
325 | if (!mTopView) {
|
---|
326 | int ww = w;
|
---|
327 | int hh = h;
|
---|
328 | glViewport(0, 0, ww, hh);
|
---|
329 | glMatrixMode(GL_PROJECTION);
|
---|
330 | glLoadIdentity();
|
---|
331 | gluPerspective(angle, ww/(float)hh, 0.1, 2.0 * Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
332 | glMatrixMode(GL_MODELVIEW);
|
---|
333 | } else {
|
---|
334 | int ww = w;
|
---|
335 | int hh = h;
|
---|
336 | glViewport(0, 0, ww, hh);
|
---|
337 | glMatrixMode(GL_PROJECTION);
|
---|
338 | glLoadIdentity();
|
---|
339 | gluPerspective(50.0, ww / (float)hh, 0.1, 20.0 * Magnitude(mSceneGraph->GetBox().Diagonal()));
|
---|
340 | glMatrixMode(GL_MODELVIEW);
|
---|
341 | }
|
---|
342 | }
|
---|
343 |
|
---|
344 |
|
---|
345 | bool QtGlRendererWidget::PvsChanged(ViewCell *viewCell) const
|
---|
346 | {
|
---|
347 | if (viewCell != mPvsCache.mViewCell)
|
---|
348 | return true;
|
---|
349 |
|
---|
350 | if (viewCell->GetPvs().GetSize() != mPvsCache.mUnfilteredPvsSize)
|
---|
351 | return true;
|
---|
352 |
|
---|
353 | return false;
|
---|
354 | }
|
---|
355 |
|
---|
356 |
|
---|
357 | void QtGlRendererWidget::_RenderPvs()
|
---|
358 | {
|
---|
359 | mUseFalseColors = false;
|
---|
360 |
|
---|
361 | int offset = (int)mObjects.size() * 3;
|
---|
362 | char *arrayPtr = mUseVbos ? NULL : (char *)mData;
|
---|
363 |
|
---|
364 | glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr);
|
---|
365 | glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
|
---|
366 | glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
|
---|
367 | }
|
---|
368 |
|
---|
369 |
|
---|
370 | void QtGlRendererWidget::_UpdatePvsIndices()
|
---|
371 | {
|
---|
372 | int indexBufferSize = 0;
|
---|
373 |
|
---|
374 | KdNode::NewMail();
|
---|
375 | //Intersectable::NewMail();
|
---|
376 |
|
---|
377 | mPvsSize = mPvsCache.mPvs.GetSize();
|
---|
378 |
|
---|
379 | ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
|
---|
380 |
|
---|
381 | while (it.HasMoreEntries())
|
---|
382 | {
|
---|
383 | Intersectable *obj = it.Next();
|
---|
384 | KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem();
|
---|
385 |
|
---|
386 | _UpdatePvsIndices(node, indexBufferSize);
|
---|
387 | }
|
---|
388 |
|
---|
389 | mIndexBufferSize = indexBufferSize;
|
---|
390 | }
|
---|
391 |
|
---|
392 |
|
---|
393 | void QtGlRendererWidget::_UpdatePvsIndices(KdNode *node, int &indexBufferSize)
|
---|
394 | {
|
---|
395 | if (node->Mailed())
|
---|
396 | return;
|
---|
397 |
|
---|
398 | node->Mail();
|
---|
399 |
|
---|
400 | // if (mObjects.size() * 3 < indexBufferSize) cerr << "problem: " << mObjects.size() * 3 << " < " << indexBufferSize << endl;
|
---|
401 | if (!node->IsLeaf())
|
---|
402 | {
|
---|
403 | KdInterior *kdInterior = static_cast<KdInterior *>(node);
|
---|
404 |
|
---|
405 | _UpdatePvsIndices(kdInterior->mBack, indexBufferSize);
|
---|
406 | _UpdatePvsIndices(kdInterior->mFront, indexBufferSize);
|
---|
407 | }
|
---|
408 | else
|
---|
409 | {
|
---|
410 | KdLeaf *leaf = static_cast<KdLeaf *>(node);
|
---|
411 |
|
---|
412 | leaf->mIndexBufferStart = indexBufferSize;
|
---|
413 |
|
---|
414 | for (size_t i = 0; i < leaf->mObjects.size(); ++ i)
|
---|
415 | {
|
---|
416 | TriangleIntersectable *obj =
|
---|
417 | static_cast<TriangleIntersectable *>(leaf->mObjects[i]);
|
---|
418 |
|
---|
419 | // check if already rendered
|
---|
420 | /*if (!obj->Mailed())
|
---|
421 | {
|
---|
422 | obj->Mail();
|
---|
423 |
|
---|
424 | mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0;
|
---|
425 | mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1;
|
---|
426 | mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2;
|
---|
427 |
|
---|
428 | indexBufferSize += 3;
|
---|
429 | }*/
|
---|
430 | if (obj->mRenderedFrame != mCurrentFrame)
|
---|
431 | {
|
---|
432 | obj->mRenderedFrame = mCurrentFrame;
|
---|
433 |
|
---|
434 | mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0;
|
---|
435 | mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1;
|
---|
436 | mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2;
|
---|
437 |
|
---|
438 | indexBufferSize += 3;
|
---|
439 | }
|
---|
440 | }
|
---|
441 |
|
---|
442 | leaf->mIndexBufferSize = indexBufferSize - leaf->mIndexBufferStart;
|
---|
443 | }
|
---|
444 |
|
---|
445 | //cout << "id: " << indexBufferSize << endl;
|
---|
446 | }
|
---|
447 |
|
---|
448 |
|
---|
449 | void QtGlRendererWidget::RenderPvs()
|
---|
450 | {
|
---|
451 | if (mUseVbos)
|
---|
452 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId);
|
---|
453 |
|
---|
454 | ++ mCurrentFrame;
|
---|
455 |
|
---|
456 | EnableDrawArrays();
|
---|
457 |
|
---|
458 | //Intersectable::NewMail();
|
---|
459 |
|
---|
460 | if (mDetectEmptyViewSpace)
|
---|
461 | glEnable(GL_CULL_FACE);
|
---|
462 | else
|
---|
463 | glDisable(GL_CULL_FACE);
|
---|
464 |
|
---|
465 | ViewCell *viewcell = NULL;
|
---|
466 | viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
|
---|
467 |
|
---|
468 | if (viewcell)
|
---|
469 | {
|
---|
470 | // copy the pvs so that it can be filtered ...
|
---|
471 | if (PvsChanged(viewcell))
|
---|
472 | {
|
---|
473 | mPvsCache.Reset();
|
---|
474 | mPvsCache.mViewCell = viewcell;
|
---|
475 | mPvsCache.mUnfilteredPvsSize = viewcell->GetPvs().GetSize();
|
---|
476 |
|
---|
477 | if (mUseSpatialFilter)
|
---|
478 | {
|
---|
479 | //ObjectPvs pvs;
|
---|
480 |
|
---|
481 | //mMutex.lock();
|
---|
482 | // mSpatialFilter size is in range 0.001 - 0.1
|
---|
483 | mViewCellsManager->ApplyFilter2(viewcell,
|
---|
484 | mUseFilter,
|
---|
485 | 100.0f * mSpatialFilterSize,
|
---|
486 | //pvs,
|
---|
487 | mPvsCache.mPvs,
|
---|
488 | &mPvsCache.filteredBoxes);
|
---|
489 | //mPvsCache.mPvs = pvs;
|
---|
490 | //mMutex.unlock();
|
---|
491 | }
|
---|
492 | else
|
---|
493 | {
|
---|
494 | mPvsCache.mPvs = viewcell->GetPvs();
|
---|
495 | }
|
---|
496 |
|
---|
497 | /// update the indices for rendering
|
---|
498 | _UpdatePvsIndices();
|
---|
499 |
|
---|
500 | emit PvsUpdated();
|
---|
501 | }
|
---|
502 |
|
---|
503 | //Intersectable::NewMail();
|
---|
504 | PvsData pvsData;
|
---|
505 |
|
---|
506 | // Render PVS
|
---|
507 | if (mUseSpatialFilter && mRenderBoxes)
|
---|
508 | {
|
---|
509 | for (int i=0; i < mPvsCache.filteredBoxes.size(); ++ i)
|
---|
510 | {
|
---|
511 | RenderBox(mPvsCache.filteredBoxes[i]);
|
---|
512 | }
|
---|
513 | }
|
---|
514 | else
|
---|
515 | {
|
---|
516 | if (!mRenderVisibilityEstimates)
|
---|
517 | {
|
---|
518 | _RenderPvs();
|
---|
519 | }
|
---|
520 | else
|
---|
521 | {
|
---|
522 | mPvsSize = mPvsCache.mPvs.GetSize();
|
---|
523 |
|
---|
524 | ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
|
---|
525 |
|
---|
526 | while (it.HasMoreEntries())
|
---|
527 | {
|
---|
528 | Intersectable *object = it.Next(pvsData);
|
---|
529 |
|
---|
530 | //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f
|
---|
531 | // glColor3f(visibility, 0.0f, 0.0f);
|
---|
532 | //cerr << "sumpdf: " << pvsData.mSumPdf << endl;
|
---|
533 | RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1));
|
---|
534 | glColor3f(color.r, color.g, color.b);
|
---|
535 |
|
---|
536 | mUseForcedColors = true;
|
---|
537 | RenderIntersectable(object);
|
---|
538 | mUseForcedColors = false;
|
---|
539 | }
|
---|
540 | }
|
---|
541 | }
|
---|
542 |
|
---|
543 | if (mRenderFilter)
|
---|
544 | {
|
---|
545 | mWireFrame = true;
|
---|
546 | RenderIntersectable(viewcell);
|
---|
547 | glPushMatrix();
|
---|
548 | glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z);
|
---|
549 | glScalef(5.0f,5.0f,5.0f);
|
---|
550 | glPushAttrib(GL_CURRENT_BIT);
|
---|
551 | glColor3f(1.0f, 0.0f, 0.0f);
|
---|
552 | // gluSphere((::GLUquadric *)mSphere,
|
---|
553 | // 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6);
|
---|
554 | glPopAttrib();
|
---|
555 | glPopMatrix();
|
---|
556 | mWireFrame = false;
|
---|
557 | }
|
---|
558 | }
|
---|
559 | else
|
---|
560 | {
|
---|
561 | /*ObjectContainer::const_iterator oi = mObjects.begin();
|
---|
562 | for (; oi != mObjects.end(); oi++)
|
---|
563 | RenderIntersectable(*oi);*/
|
---|
564 | RenderScene();
|
---|
565 | }
|
---|
566 |
|
---|
567 | //DisableDrawArrays();
|
---|
568 | //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
---|
569 | }
|
---|
570 |
|
---|
571 | float
|
---|
572 | QtGlRendererWidget::RenderErrors()
|
---|
573 | {
|
---|
574 | float pErrorPixels = -1.0f;
|
---|
575 |
|
---|
576 | SetupCamera();
|
---|
577 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
---|
578 |
|
---|
579 | glPushAttrib(GL_ENABLE_BIT);
|
---|
580 |
|
---|
581 | glStencilFunc(GL_EQUAL, 0x0, 0x1);
|
---|
582 | glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
---|
583 |
|
---|
584 | mUseForcedColors = true;
|
---|
585 |
|
---|
586 | glColor3f(0.0f, 0.8f, 0.2f);
|
---|
587 |
|
---|
588 | // Render PVS
|
---|
589 | RenderPvs();
|
---|
590 |
|
---|
591 | glEnable(GL_STENCIL_TEST);
|
---|
592 |
|
---|
593 | //mUseFalseColors = true;
|
---|
594 |
|
---|
595 | glDisable(GL_LIGHTING);
|
---|
596 |
|
---|
597 | OcclusionQuery *query = mOcclusionQueries[0];
|
---|
598 | query->BeginQuery();
|
---|
599 |
|
---|
600 | SetupCamera();
|
---|
601 |
|
---|
602 | glColor3f(1.0f, 0.0f, 0.0f);
|
---|
603 |
|
---|
604 | RenderScene();
|
---|
605 |
|
---|
606 | mUseForcedColors = false;
|
---|
607 |
|
---|
608 | query->EndQuery();
|
---|
609 |
|
---|
610 | glDisable(GL_STENCIL_TEST);
|
---|
611 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
612 |
|
---|
613 | glPopAttrib();
|
---|
614 |
|
---|
615 | // reenable other state
|
---|
616 | // int wait=0;
|
---|
617 | // while (!query.ResultAvailable()) {
|
---|
618 | // wait++;
|
---|
619 | // }
|
---|
620 |
|
---|
621 | int pixelCount = query->GetQueryResult();
|
---|
622 | pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
|
---|
623 | if (0) cout<<"error pixels="<<pixelCount<<endl;
|
---|
624 |
|
---|
625 | mRenderError = pErrorPixels;
|
---|
626 |
|
---|
627 | return pErrorPixels;
|
---|
628 | }
|
---|
629 |
|
---|
630 |
|
---|
631 | void QtGlRendererWidget::timerEvent(QTimerEvent *event)
|
---|
632 | {
|
---|
633 | //std::cout << "Timer ID:" << event->timerId();
|
---|
634 | update();
|
---|
635 | }
|
---|
636 |
|
---|
637 |
|
---|
638 | void QtGlRendererWidget::mousePressEvent(QMouseEvent *e)
|
---|
639 | {
|
---|
640 | int x = e->pos().x();
|
---|
641 | int y = e->pos().y();
|
---|
642 |
|
---|
643 | mousePoint.x = x;
|
---|
644 | mousePoint.y = y;
|
---|
645 |
|
---|
646 | }
|
---|
647 |
|
---|
648 | void
|
---|
649 | QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e)
|
---|
650 | {
|
---|
651 | float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3;
|
---|
652 | float TURN_SENSITIVITY=0.1f;
|
---|
653 | float TILT_SENSITIVITY=32.0 ;
|
---|
654 | float TURN_ANGLE= M_PI/36.0 ;
|
---|
655 |
|
---|
656 | int x = e->pos().x();
|
---|
657 | int y = e->pos().y();
|
---|
658 |
|
---|
659 | int diffx = -(mousePoint.x - x);
|
---|
660 | int diffy = -(mousePoint.y - y);
|
---|
661 |
|
---|
662 | if (e->modifiers() & Qt::ControlModifier)
|
---|
663 | {
|
---|
664 | mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0;
|
---|
665 | mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0;
|
---|
666 | }
|
---|
667 | else
|
---|
668 | {
|
---|
669 | mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
|
---|
670 | float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
|
---|
671 | float angle = atan2(mViewDirection.x, mViewDirection.z);
|
---|
672 | mViewDirection.x = sin(angle + adiff);
|
---|
673 | mViewDirection.z = cos(angle + adiff);
|
---|
674 | }
|
---|
675 |
|
---|
676 | mousePoint.x = x;
|
---|
677 | mousePoint.y = y;
|
---|
678 |
|
---|
679 | updateGL();
|
---|
680 | }
|
---|
681 |
|
---|
682 | void
|
---|
683 | QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *)
|
---|
684 | {
|
---|
685 | }
|
---|
686 |
|
---|
687 | void
|
---|
688 | QtGlRendererWidget::resizeGL(int w, int h)
|
---|
689 | {
|
---|
690 | SetupCameraProjection(w, h);
|
---|
691 | updateGL();
|
---|
692 | }
|
---|
693 |
|
---|
694 | void
|
---|
695 | QtGlRendererWidget::paintGL()
|
---|
696 | {
|
---|
697 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
698 |
|
---|
699 | if (1)
|
---|
700 | {
|
---|
701 | SetupCameraProjection(width(), height());
|
---|
702 | SetupCamera();
|
---|
703 |
|
---|
704 | if (mRenderErrors)
|
---|
705 | {
|
---|
706 | RenderErrors();
|
---|
707 | }
|
---|
708 | else
|
---|
709 | {
|
---|
710 | glColor3f(0.6f, 0.6f, 0.6f);
|
---|
711 | RenderPvs();
|
---|
712 | }
|
---|
713 | }
|
---|
714 |
|
---|
715 | RenderInfo();
|
---|
716 |
|
---|
717 | mFrame ++;
|
---|
718 |
|
---|
719 | }
|
---|
720 |
|
---|
721 |
|
---|
722 | void
|
---|
723 | QtGlRendererWidget::SetupCamera()
|
---|
724 | {
|
---|
725 | if (!mTopView)
|
---|
726 | GlRenderer::SetupCamera();
|
---|
727 | else {
|
---|
728 | if (0) {
|
---|
729 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05;
|
---|
730 | Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x,
|
---|
731 | -1,
|
---|
732 | mViewDirection.y);
|
---|
733 |
|
---|
734 | Vector3 target = mViewPoint + dist*mViewDirection;
|
---|
735 | Vector3 up(0,1,0);
|
---|
736 |
|
---|
737 | glLoadIdentity();
|
---|
738 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
739 | target.x, target.y, target.z,
|
---|
740 | up.x, up.y, up.z);
|
---|
741 | }
|
---|
742 | else
|
---|
743 | {
|
---|
744 | float dist = Magnitude(mSceneGraph->GetBox().Diagonal()) * mTopDistance;
|
---|
745 | Vector3 pos = mViewPoint + dist*Vector3(0,
|
---|
746 | 1,
|
---|
747 | 0);
|
---|
748 |
|
---|
749 | Vector3 target = mViewPoint;
|
---|
750 | Vector3 up(mViewDirection.x, 0, mViewDirection.z);
|
---|
751 |
|
---|
752 | glLoadIdentity();
|
---|
753 | gluLookAt(pos.x, pos.y, pos.z,
|
---|
754 | target.x, target.y, target.z,
|
---|
755 | up.x, up.y, up.z);
|
---|
756 |
|
---|
757 | }
|
---|
758 | }
|
---|
759 |
|
---|
760 | }
|
---|
761 |
|
---|
762 |
|
---|
763 | void
|
---|
764 | QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
|
---|
765 | {
|
---|
766 | switch (e->key()) {
|
---|
767 | case Qt::Key_T:
|
---|
768 | mTopView = !mTopView;
|
---|
769 | SetupCameraProjection(width(), height());
|
---|
770 | updateGL();
|
---|
771 | break;
|
---|
772 | case Qt::Key_V:
|
---|
773 | mRenderViewCells = !mRenderViewCells;
|
---|
774 | updateGL();
|
---|
775 | break;
|
---|
776 | case Qt::Key_P:
|
---|
777 | // set random viewpoint
|
---|
778 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
779 | updateGL();
|
---|
780 | break;
|
---|
781 | case Qt::Key_S: {
|
---|
782 | // set view poitn and direction
|
---|
783 | QString text;
|
---|
784 | bool ok;
|
---|
785 | text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z);
|
---|
786 | text = QInputDialog::getText(this,
|
---|
787 | "Enter a view point",
|
---|
788 | "",
|
---|
789 | QLineEdit::Normal,
|
---|
790 | text,
|
---|
791 | &ok);
|
---|
792 | if (!ok)
|
---|
793 | break;
|
---|
794 |
|
---|
795 | if (sscanf(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) {
|
---|
796 | text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z);
|
---|
797 | text = QInputDialog::getText(this,
|
---|
798 | "Enter a direction",
|
---|
799 | "",
|
---|
800 | QLineEdit::Normal,
|
---|
801 | text,
|
---|
802 | &ok);
|
---|
803 | if (!ok)
|
---|
804 | break;
|
---|
805 | if (sscanf(text.toAscii(), "%f %f %f", &mViewDirection.x,
|
---|
806 | &mViewDirection.y, &mViewDirection.z) == 3) {
|
---|
807 | updateGL();
|
---|
808 | }
|
---|
809 | break;
|
---|
810 | }
|
---|
811 | }
|
---|
812 | default:
|
---|
813 | e->ignore();
|
---|
814 | break;
|
---|
815 | }
|
---|
816 | }
|
---|
817 |
|
---|
818 |
|
---|
819 |
|
---|
820 | QtGlRendererWidget::QtGlRendererWidget(
|
---|
821 | SceneGraph *sceneGraph,
|
---|
822 | ViewCellsManager *viewcells,
|
---|
823 | KdTree *tree,
|
---|
824 | QWidget * parent,
|
---|
825 | const QGLWidget * shareWidget,
|
---|
826 | Qt::WFlags f
|
---|
827 | )
|
---|
828 | :
|
---|
829 | GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
|
---|
830 | {
|
---|
831 | mPreprocessorThread = NULL;
|
---|
832 | mTopView = false;
|
---|
833 | mRenderViewCells = false;
|
---|
834 | mTopDistance = 1.0f;
|
---|
835 | mCutViewCells = false;
|
---|
836 | mCutScene = false;
|
---|
837 | mRenderErrors = false;
|
---|
838 | mRenderBoxes = false;
|
---|
839 | mRenderFilter = true;
|
---|
840 | mRenderVisibilityEstimates = false;
|
---|
841 |
|
---|
842 | mHideByCost = false;
|
---|
843 |
|
---|
844 | mTransferFunction = 0.2f;
|
---|
845 | mIndexBufferSize = 0;
|
---|
846 |
|
---|
847 | //mCurrentFrame = 0;
|
---|
848 |
|
---|
849 | const int delay = 250; // in milliseconds
|
---|
850 | timerId = startTimer(delay);
|
---|
851 |
|
---|
852 | bool tmp;
|
---|
853 |
|
---|
854 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
855 | mUseFilter = tmp;
|
---|
856 |
|
---|
857 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
|
---|
858 | tmp );
|
---|
859 | mUseSpatialFilter = tmp;
|
---|
860 |
|
---|
861 | mShowRenderCost = false;
|
---|
862 | mShowPvsSizes = false;
|
---|
863 | mShowPiercingRays = false;
|
---|
864 | mSpatialFilterSize = 0.01;
|
---|
865 | mPvsSize = 0;
|
---|
866 | mRenderError = 0.0f;
|
---|
867 | mShowRays = false;
|
---|
868 |
|
---|
869 | mControlWidget = new QtRendererControlWidget(NULL);
|
---|
870 |
|
---|
871 | connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
|
---|
872 | connect(mControlWidget,
|
---|
873 | SIGNAL(SetTransferFunction(int)),
|
---|
874 | this,
|
---|
875 | SLOT(SetTransferFunction(int)));
|
---|
876 | connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs()));
|
---|
877 | connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility()));
|
---|
878 | connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation()));
|
---|
879 | connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this,
|
---|
880 | SLOT(SetRandomViewPoint()));
|
---|
881 |
|
---|
882 | connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
|
---|
883 | connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
|
---|
884 | connect(mControlWidget, SIGNAL(SetTransparency(int)), this, SLOT(SetTransparency(int)));
|
---|
885 |
|
---|
886 | connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
|
---|
887 | connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int)));
|
---|
888 | connect(mControlWidget, SIGNAL(SetHidingCost(int)), this, SLOT(SetHidingCost(int)));
|
---|
889 |
|
---|
890 | connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
|
---|
891 | connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool)));
|
---|
892 | connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool)));
|
---|
893 | connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
|
---|
894 | connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
|
---|
895 | connect(mControlWidget, SIGNAL(SetHideByCost(bool)), this, SLOT(SetHideByCost(bool)));
|
---|
896 | connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
|
---|
897 | connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
|
---|
898 | connect(mControlWidget, SIGNAL(SetRenderBoxes(bool)), this, SLOT(SetRenderBoxes(bool)));
|
---|
899 | connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
|
---|
900 | connect(mControlWidget, SIGNAL(SetRenderVisibilityEstimates(bool)),
|
---|
901 | this, SLOT(SetRenderVisibilityEstimates(bool)));
|
---|
902 | connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool)));
|
---|
903 | connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)),
|
---|
904 | this, SLOT(SetUseSpatialFilter(bool)));
|
---|
905 | connect(mControlWidget, SIGNAL(SetShowPiercingRays(bool)), this, SLOT(SetShowPiercingRays(bool)));
|
---|
906 |
|
---|
907 | connect(mControlWidget,
|
---|
908 | SIGNAL(SetShowRays(bool)),
|
---|
909 | this,
|
---|
910 | SLOT(SetShowRays(bool)));
|
---|
911 |
|
---|
912 | resize(1000, 500);
|
---|
913 | mControlWidget->show();
|
---|
914 | }
|
---|
915 |
|
---|
916 | void
|
---|
917 | QtGlRendererWidget::UpdateAllPvs()
|
---|
918 | {
|
---|
919 | // $$ does not work so far:(
|
---|
920 | mViewCellsManager->UpdatePvsForEvaluation();
|
---|
921 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
922 | }
|
---|
923 |
|
---|
924 | void
|
---|
925 | QtGlRendererWidget::ComputeVisibility()
|
---|
926 | {
|
---|
927 | cerr<<"Compute Visibility called!\n"<<endl;
|
---|
928 | if (!mPreprocessorThread->isRunning())
|
---|
929 | mPreprocessorThread->RunThread();
|
---|
930 | }
|
---|
931 |
|
---|
932 | void
|
---|
933 | QtGlRendererWidget::StopComputation()
|
---|
934 | {
|
---|
935 | cerr<<"stop computation called!\n"<<endl;
|
---|
936 | mViewCellsManager->GetPreprocessor()->mStopComputation = true;
|
---|
937 | }
|
---|
938 |
|
---|
939 | void
|
---|
940 | QtGlRendererWidget::SetRandomViewPoint()
|
---|
941 | {
|
---|
942 | cerr<<"stop computation called!\n"<<endl;
|
---|
943 | mViewCellsManager->GetViewPoint(mViewPoint);
|
---|
944 | updateGL();
|
---|
945 | }
|
---|
946 |
|
---|
947 | void
|
---|
948 | QtGlRendererWidget::RenderRenderCost()
|
---|
949 | {
|
---|
950 | static vector<float> costFunction;
|
---|
951 | static float maxCost = -1;
|
---|
952 | if (costFunction.size()==0) {
|
---|
953 | ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree();
|
---|
954 | if (tree) {
|
---|
955 | tree->GetCostFunction(costFunction);
|
---|
956 | maxCost = -1;
|
---|
957 | for (int i=0; i < costFunction.size(); i++) {
|
---|
958 | // cout<<i<<":"<<costFunction[i]<<" ";
|
---|
959 | // update cost function to an absolute value based on the total geometry count
|
---|
960 | costFunction[i]*=mSceneGraph->GetRoot()->mGeometry.size();
|
---|
961 | if (costFunction[i] > maxCost)
|
---|
962 | maxCost = costFunction[i];
|
---|
963 | }
|
---|
964 | }
|
---|
965 | }
|
---|
966 |
|
---|
967 |
|
---|
968 | int currentPos = (int)mViewCellsManager->GetViewCells().size();
|
---|
969 | float currentCost= -1;
|
---|
970 |
|
---|
971 | if (currentPos < costFunction.size())
|
---|
972 | currentCost = costFunction[currentPos];
|
---|
973 | #if 1
|
---|
974 | cout<<"costFunction.size()="<<(int)costFunction.size()<<endl;
|
---|
975 | cout<<"CP="<<currentPos<<endl;
|
---|
976 | cout<<"MC="<<maxCost<<endl;
|
---|
977 | cout<<"CC="<<currentCost<<endl;
|
---|
978 | #endif
|
---|
979 | if (costFunction.size()) {
|
---|
980 | float scaley = 1.0f/log10(maxCost);
|
---|
981 | float scalex = 1.0f/(float)costFunction.size();
|
---|
982 |
|
---|
983 | glDisable(GL_DEPTH_TEST);
|
---|
984 | // init ortographic projection
|
---|
985 | glMatrixMode(GL_PROJECTION);
|
---|
986 |
|
---|
987 | glPushMatrix();
|
---|
988 |
|
---|
989 | glLoadIdentity();
|
---|
990 | gluOrtho2D(0, 1.0f, 0, 1.0f);
|
---|
991 |
|
---|
992 | glTranslatef(0.1f, 0.1f, 0.0f);
|
---|
993 | glScalef(0.8f, 0.8f, 1.0f);
|
---|
994 | glMatrixMode(GL_MODELVIEW);
|
---|
995 | glLoadIdentity();
|
---|
996 |
|
---|
997 | glColor3f(1.0f,0,0);
|
---|
998 | glBegin(GL_LINE_STRIP);
|
---|
999 | // glVertex3f(0,0,0);
|
---|
1000 |
|
---|
1001 | for (int i=0; i < costFunction.size(); i++) {
|
---|
1002 | float x = i*scalex;
|
---|
1003 | float y = log10(costFunction[i])*scaley;
|
---|
1004 | glVertex3f(x,y,0.0f);
|
---|
1005 | }
|
---|
1006 | glEnd();
|
---|
1007 |
|
---|
1008 | glColor3f(1.0f,0,0);
|
---|
1009 | glBegin(GL_LINES);
|
---|
1010 | float x = currentPos*scalex;
|
---|
1011 | glVertex3f(x,0.0,0.0f);
|
---|
1012 | glVertex3f(x,1.0f,0.0f);
|
---|
1013 | glEnd();
|
---|
1014 |
|
---|
1015 | glColor3f(0.0f,0,0);
|
---|
1016 | // show a grid
|
---|
1017 | glBegin(GL_LINE_LOOP);
|
---|
1018 | glVertex3f(0,0,0.0f);
|
---|
1019 | glVertex3f(1,0,0.0f);
|
---|
1020 | glVertex3f(1,1,0.0f);
|
---|
1021 | glVertex3f(0,1,0.0f);
|
---|
1022 | glEnd();
|
---|
1023 |
|
---|
1024 | glBegin(GL_LINES);
|
---|
1025 | for (int i=0; i < costFunction.size(); i += 1000) {
|
---|
1026 | float x = i*scalex;
|
---|
1027 | glVertex3f(x,0.0,0.0f);
|
---|
1028 | glVertex3f(x,1.0f,0.0f);
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | for (int i=0; pow(10.0f, i) < maxCost; i+=1) {
|
---|
1032 | float y = i*scaley;
|
---|
1033 | // QString s;
|
---|
1034 | // s.sprintf("%d", (int)pow(10,i));
|
---|
1035 | // renderText(width()/2+5, y*height(), s);
|
---|
1036 | glVertex3f(0.0f, y, 0.0f);
|
---|
1037 | glVertex3f(1.0f, y, 0.0f);
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | glEnd();
|
---|
1041 |
|
---|
1042 |
|
---|
1043 | // restore the projection matrix
|
---|
1044 | glMatrixMode(GL_PROJECTION);
|
---|
1045 | glPopMatrix();
|
---|
1046 | glMatrixMode(GL_MODELVIEW);
|
---|
1047 | glEnable(GL_DEPTH_TEST);
|
---|
1048 |
|
---|
1049 | }
|
---|
1050 |
|
---|
1051 |
|
---|
1052 |
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | void
|
---|
1056 | QtGlRendererWidget::RenderInfo()
|
---|
1057 | {
|
---|
1058 |
|
---|
1059 | QString s;
|
---|
1060 | int vc = 0;
|
---|
1061 | if (mViewCellsManager)
|
---|
1062 | vc = (int)mViewCellsManager->GetViewCells().size();
|
---|
1063 |
|
---|
1064 | int filter = 0;
|
---|
1065 | if (mViewCellsManager)
|
---|
1066 | filter = mViewCellsManager->GetMaxFilterSize();
|
---|
1067 |
|
---|
1068 | glColor3f(1.0f,1.0f,1.0f);
|
---|
1069 |
|
---|
1070 | s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)",
|
---|
1071 | mFrame,
|
---|
1072 | mViewPoint.x,
|
---|
1073 | mViewPoint.y,
|
---|
1074 | mViewPoint.z,
|
---|
1075 | mViewDirection.x,
|
---|
1076 | mViewDirection.y,
|
---|
1077 | mViewDirection.z
|
---|
1078 | );
|
---|
1079 |
|
---|
1080 | renderText(20,20,s);
|
---|
1081 |
|
---|
1082 | s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f %",
|
---|
1083 | vc,
|
---|
1084 | filter,
|
---|
1085 | mPvsSize,
|
---|
1086 | mRenderError*100.0f);
|
---|
1087 |
|
---|
1088 |
|
---|
1089 | renderText(20,40,s);
|
---|
1090 |
|
---|
1091 |
|
---|
1092 |
|
---|
1093 |
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 |
|
---|
1097 | void
|
---|
1098 | QtGlRendererWidget::SetViewCellGranularity(int number)
|
---|
1099 | {
|
---|
1100 | if (mViewCellsManager) {
|
---|
1101 | // mViewCellsManager->SetMaxFilterSize(number);
|
---|
1102 |
|
---|
1103 | // $$ tmp off
|
---|
1104 | mViewCellsManager->CollectViewCells(number);
|
---|
1105 |
|
---|
1106 | // $$ does not work so far:(
|
---|
1107 | // mViewCellsManager->UpdatePvsForEvaluation();
|
---|
1108 | // mViewCellsManager->FinalizeViewCells(false);
|
---|
1109 | }
|
---|
1110 | updateGL();
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 | void
|
---|
1114 | QtGlRendererWidget::SetVisibilityFilterSize(int number)
|
---|
1115 | {
|
---|
1116 | if (mViewCellsManager)
|
---|
1117 | mViewCellsManager->SetMaxFilterSize(number);
|
---|
1118 | mPvsCache.Reset();
|
---|
1119 | updateGL();
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 | void
|
---|
1123 | QtGlRendererWidget::SetSpatialFilterSize(int number)
|
---|
1124 | {
|
---|
1125 | mSpatialFilterSize = 1e-3*number;
|
---|
1126 | mPvsCache.Reset();
|
---|
1127 | updateGL();
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | void
|
---|
1131 | QtGlRendererWidget::SetSceneCut(int number)
|
---|
1132 | {
|
---|
1133 | // assume the cut plane can only be aligned with xz plane
|
---|
1134 | // shift it along y according to number, which is percentage of the bounding
|
---|
1135 | // box position
|
---|
1136 | if (mViewCellsManager)
|
---|
1137 | {
|
---|
1138 | AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
|
---|
1139 | Vector3 p = box.Min() + (number/1000.0f)*box.Max();
|
---|
1140 | mSceneCutPlane.mNormal = Vector3(0,-1,0);
|
---|
1141 | mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p);
|
---|
1142 |
|
---|
1143 | updateGL();
|
---|
1144 | }
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | void
|
---|
1148 | QtGlRendererWidget::SetHidingCost(int number)
|
---|
1149 | {
|
---|
1150 | mHidingCost = (float)number / 1000.0f;
|
---|
1151 | //cout << "hiding cost " << mHidingCost << endl;
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 |
|
---|
1155 | void
|
---|
1156 | QtGlRendererWidget::SetTopDistance(int number)
|
---|
1157 | {
|
---|
1158 | mTopDistance = number/1000.0f;
|
---|
1159 | updateGL();
|
---|
1160 | }
|
---|
1161 |
|
---|
1162 | void
|
---|
1163 | QtGlRendererWidget::SetTransparency(int number)
|
---|
1164 | {
|
---|
1165 | mTransparency = number/1000.0f;
|
---|
1166 | updateGL();
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | void
|
---|
1170 | QtGlRendererWidget::RenderViewCells()
|
---|
1171 | {
|
---|
1172 | mUseFalseColors = true;
|
---|
1173 |
|
---|
1174 | glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
|
---|
1175 |
|
---|
1176 | glEnable(GL_CULL_FACE);
|
---|
1177 | glCullFace(GL_FRONT);
|
---|
1178 | //glDisable(GL_CULL_FACE);
|
---|
1179 |
|
---|
1180 | double eq[4];
|
---|
1181 | eq[0] = mSceneCutPlane.mNormal.x;
|
---|
1182 | eq[1] = mSceneCutPlane.mNormal.y;
|
---|
1183 | eq[2] = mSceneCutPlane.mNormal.z;
|
---|
1184 | eq[3] = mSceneCutPlane.mD;
|
---|
1185 |
|
---|
1186 | if (mCutViewCells)
|
---|
1187 | {
|
---|
1188 | glClipPlane(GL_CLIP_PLANE0, eq);
|
---|
1189 | glEnable(GL_CLIP_PLANE0);
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | int i;
|
---|
1193 |
|
---|
1194 | ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
|
---|
1195 | int maxPvs = -1;
|
---|
1196 | int maxPiercingRays = 1; // for savety
|
---|
1197 |
|
---|
1198 | for (i = 0; i < viewcells.size(); ++ i)
|
---|
1199 | {
|
---|
1200 | ViewCell *vc = viewcells[i];
|
---|
1201 |
|
---|
1202 | //const int p = vc->GetPvs().CountObjectsInPvs();
|
---|
1203 | const int p = vc->GetPvs().GetSize();
|
---|
1204 | if (p > maxPvs)
|
---|
1205 | maxPvs = p;
|
---|
1206 |
|
---|
1207 | const int piercingRays = vc->GetNumPiercingRays();
|
---|
1208 |
|
---|
1209 | if (piercingRays > maxPiercingRays)
|
---|
1210 | maxPiercingRays = piercingRays;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | if (!mShowPvsSizes && !mShowPiercingRays)
|
---|
1214 | {
|
---|
1215 | for (i = 0; i < viewcells.size(); ++ i)
|
---|
1216 | {
|
---|
1217 | ViewCell *vc = viewcells[i];
|
---|
1218 | RgbColor c;
|
---|
1219 |
|
---|
1220 | if (!mShowPvsSizes && !mShowPiercingRays)
|
---|
1221 | {
|
---|
1222 | mWireFrame = true;
|
---|
1223 | c = vc->GetColor();
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | glColor3f(c.r, c.g, c.b);
|
---|
1227 |
|
---|
1228 | if (!mHideByCost || (mHidingCost < vc->GetNumPiercingRays() / (float)maxPiercingRays))
|
---|
1229 | {
|
---|
1230 | RenderViewCell(vc);
|
---|
1231 | }
|
---|
1232 | }
|
---|
1233 | }
|
---|
1234 | else
|
---|
1235 | {
|
---|
1236 | //glDisable(GL_CULL_FACE);
|
---|
1237 | //glEnable(GL_CULL_FACE);
|
---|
1238 | //glFrontFace(GL_CCW);
|
---|
1239 | //glCullFace(GL_BACK);
|
---|
1240 | glEnable(GL_DEPTH_TEST);
|
---|
1241 | glDisable(GL_BLEND);
|
---|
1242 |
|
---|
1243 | //glDisable(GL_DEPTH_TEST);
|
---|
1244 | //glEnable(GL_BLEND);
|
---|
1245 |
|
---|
1246 | //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
---|
1247 | glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
---|
1248 |
|
---|
1249 | for (i = 0; i < viewcells.size(); ++ i)
|
---|
1250 | {
|
---|
1251 | ViewCell *vc = viewcells[i];
|
---|
1252 | const float dist = SqrDistance(mViewPoint, vc->GetBox().Center());
|
---|
1253 |
|
---|
1254 | vc->SetDistance(dist);
|
---|
1255 | }
|
---|
1256 |
|
---|
1257 | sort(viewcells.begin(), viewcells.end(), nearerThan);
|
---|
1258 |
|
---|
1259 | RgbColor c;
|
---|
1260 |
|
---|
1261 | for (i = 0; i < viewcells.size(); ++ i)
|
---|
1262 | {
|
---|
1263 | ViewCell *vc = viewcells[i];
|
---|
1264 |
|
---|
1265 | //cout << "dist: " << vc->GetDistance() << " ";
|
---|
1266 |
|
---|
1267 | if (mShowPiercingRays)
|
---|
1268 | {
|
---|
1269 | // const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs);
|
---|
1270 | const float importance = 5.0f * mTransferFunction *
|
---|
1271 | ((float)vc->GetNumPiercingRays() / (float)maxPiercingRays);
|
---|
1272 | // c = RgbColor(importance, 1.0f - importance, 0.0f);
|
---|
1273 | c = RainbowColorMapping(importance);
|
---|
1274 | }
|
---|
1275 | else
|
---|
1276 | {
|
---|
1277 | // const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs);
|
---|
1278 | const float importance = 5.0f * mTransferFunction *
|
---|
1279 | ((float)vc->GetPvs().GetSize() / (float)maxPvs);
|
---|
1280 | // c = RgbColor(importance, 1.0f - importance, 0.0f);
|
---|
1281 | c = RainbowColorMapping(importance);
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | const float alpha = 0.2f;
|
---|
1285 | glColor4f(c.r, c.g, c.b, alpha);
|
---|
1286 |
|
---|
1287 | if (!mHideByCost || (mHidingCost < vc->GetNumPiercingRays() / (float)maxPiercingRays))
|
---|
1288 | {
|
---|
1289 | RenderViewCell(vc);
|
---|
1290 | }
|
---|
1291 | }
|
---|
1292 |
|
---|
1293 | glEnable(GL_DEPTH_TEST);
|
---|
1294 | }
|
---|
1295 |
|
---|
1296 | mUseFalseColors = false;
|
---|
1297 | mWireFrame = false;
|
---|
1298 |
|
---|
1299 | glPopAttrib();
|
---|
1300 | }
|
---|
1301 |
|
---|
1302 |
|
---|
1303 |
|
---|
1304 | /*********************************************************************/
|
---|
1305 | /* QtGlDebuggerWidget implementation */
|
---|
1306 | /*********************************************************************/
|
---|
1307 |
|
---|
1308 |
|
---|
1309 | QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
|
---|
1310 | : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
|
---|
1311 | {
|
---|
1312 | // create the pbuffer
|
---|
1313 | //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
|
---|
1314 | timerId = startTimer(20);
|
---|
1315 | setWindowTitle(("OpenGL pbuffers"));
|
---|
1316 | }
|
---|
1317 |
|
---|
1318 |
|
---|
1319 | QtGlDebuggerWidget::~QtGlDebuggerWidget()
|
---|
1320 | {
|
---|
1321 | mRenderBuffer->releaseFromDynamicTexture();
|
---|
1322 | glDeleteTextures(1, &dynamicTexture);
|
---|
1323 |
|
---|
1324 | DEL_PTR(mRenderBuffer);
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 |
|
---|
1328 | QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f):
|
---|
1329 | QWidget(parent, f)
|
---|
1330 | {
|
---|
1331 |
|
---|
1332 | QVBoxLayout *vl = new QVBoxLayout;
|
---|
1333 | setLayout(vl);
|
---|
1334 |
|
---|
1335 | QWidget *vbox = new QGroupBox("ViewCells", this);
|
---|
1336 | layout()->addWidget(vbox);
|
---|
1337 |
|
---|
1338 | vl = new QVBoxLayout;
|
---|
1339 | vbox->setLayout(vl);
|
---|
1340 |
|
---|
1341 | QLabel *label = new QLabel("Granularity");
|
---|
1342 | vbox->layout()->addWidget(label);
|
---|
1343 |
|
---|
1344 | QSlider *slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1345 | vl->addWidget(slider);
|
---|
1346 | slider->show();
|
---|
1347 | slider->setRange(1, 10000);
|
---|
1348 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1349 | slider->setValue(200);
|
---|
1350 |
|
---|
1351 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
|
---|
1352 |
|
---|
1353 | ///////////////////////////
|
---|
1354 |
|
---|
1355 | label = new QLabel("Transfer function");
|
---|
1356 | vbox->layout()->addWidget(label);
|
---|
1357 |
|
---|
1358 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1359 | vl->addWidget(slider);
|
---|
1360 | slider->show();
|
---|
1361 | slider->setRange(1, 10000);
|
---|
1362 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1363 | slider->setValue(100);
|
---|
1364 |
|
---|
1365 |
|
---|
1366 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransferFunction(int)));
|
---|
1367 |
|
---|
1368 | ////////////////////////////////////////7
|
---|
1369 |
|
---|
1370 |
|
---|
1371 | QPushButton *button = new QPushButton("Update all PVSs", vbox);
|
---|
1372 | vbox->layout()->addWidget(button);
|
---|
1373 | connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs()));
|
---|
1374 |
|
---|
1375 |
|
---|
1376 | ////////////////////////////////////////77777
|
---|
1377 |
|
---|
1378 | label = new QLabel("Filter size");
|
---|
1379 | vbox->layout()->addWidget(label);
|
---|
1380 |
|
---|
1381 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1382 | vbox->layout()->addWidget(slider);
|
---|
1383 | slider->show();
|
---|
1384 | slider->setRange(1, 100);
|
---|
1385 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1386 | slider->setValue(3);
|
---|
1387 |
|
---|
1388 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int)));
|
---|
1389 |
|
---|
1390 |
|
---|
1391 | //////////////////////////////////////////
|
---|
1392 |
|
---|
1393 | label = new QLabel("Spatial Filter size");
|
---|
1394 | vbox->layout()->addWidget(label);
|
---|
1395 |
|
---|
1396 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1397 | vbox->layout()->addWidget(slider);
|
---|
1398 | slider->show();
|
---|
1399 | slider->setRange(1, 100);
|
---|
1400 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1401 | slider->setValue(10);
|
---|
1402 |
|
---|
1403 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int)));
|
---|
1404 |
|
---|
1405 |
|
---|
1406 | ///////////////////////////////////
|
---|
1407 |
|
---|
1408 |
|
---|
1409 | QWidget *hbox = new QWidget(vbox);
|
---|
1410 | vl->addWidget(hbox);
|
---|
1411 | QHBoxLayout *hlayout = new QHBoxLayout;
|
---|
1412 | hbox->setLayout(hlayout);
|
---|
1413 |
|
---|
1414 | QCheckBox *cb = new QCheckBox("Show viewcells", hbox);
|
---|
1415 | hlayout->addWidget(cb);
|
---|
1416 | cb->setChecked(false);
|
---|
1417 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool)));
|
---|
1418 |
|
---|
1419 | cb = new QCheckBox("Render cost curve", hbox);
|
---|
1420 | hlayout->addWidget(cb);
|
---|
1421 | cb->setChecked(false);
|
---|
1422 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool)));
|
---|
1423 |
|
---|
1424 | cb = new QCheckBox("Show render cost", hbox);
|
---|
1425 | hlayout->addWidget(cb);
|
---|
1426 | cb->setChecked(false);
|
---|
1427 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
|
---|
1428 |
|
---|
1429 | cb = new QCheckBox("Show rays", hbox);
|
---|
1430 | hlayout->addWidget(cb);
|
---|
1431 | cb->setChecked(false);
|
---|
1432 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
|
---|
1433 |
|
---|
1434 | cb = new QCheckBox("Show piercing rays", hbox);
|
---|
1435 | hlayout->addWidget(cb);
|
---|
1436 | cb->setChecked(false);
|
---|
1437 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPiercingRays(bool)));
|
---|
1438 |
|
---|
1439 |
|
---|
1440 | QButtonGroup *qbuttongroup = new QButtonGroup(hbox);//, "RenderingGroupBox");
|
---|
1441 | //qbuttongroup->setTitle(i18n("Rendering options"));
|
---|
1442 | /*qbuttongroup->setColumnLayout(0, Qt::Vertical);
|
---|
1443 | qbuttongroup->layout()->setSpacing(0);
|
---|
1444 | qbuttongroup->layout()->setMargin(0);
|
---|
1445 | */
|
---|
1446 | // Create a layout to organize the widgets.
|
---|
1447 | /* QVBoxLayout *qvboxlayout = new QVBoxLayout(qbuttongroup->layout());
|
---|
1448 | qvboxlayout->setAlignment(Qt::AlignTop)
|
---|
1449 | qvboxlayout->setSpacing(6);
|
---|
1450 | qvboxlayout->setMargin(11);
|
---|
1451 | */
|
---|
1452 | QRadioButton *rb;
|
---|
1453 |
|
---|
1454 | // Create a check box to be in the group box
|
---|
1455 | rb = new QRadioButton("piercing rays", hbox);
|
---|
1456 | rb->setText("here71");
|
---|
1457 | //qvboxlayout->addWidget(rb);
|
---|
1458 |
|
---|
1459 | // Create another check box to the group box
|
---|
1460 | /* m_qradiobuttonStartFile = new QRadioButton("startFile", hbox);
|
---|
1461 | m_qradiobuttonStartFile->setText(i18n( "Start with last file used" ) );
|
---|
1462 | qvboxlayout->addWidget(mRadiobuttonStartFile);
|
---|
1463 | */
|
---|
1464 |
|
---|
1465 | //////////////////////////////////
|
---|
1466 |
|
---|
1467 |
|
---|
1468 | /*cb = new QRadiobox("Top View", vbox);
|
---|
1469 | vbox->layout()->addWidget(cb);
|
---|
1470 | cb->setChecked(false);
|
---|
1471 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
|
---|
1472 | */
|
---|
1473 |
|
---|
1474 | vbox->resize(800,150);
|
---|
1475 |
|
---|
1476 |
|
---|
1477 | vbox = new QGroupBox("Rendering", this);
|
---|
1478 | layout()->addWidget(vbox);
|
---|
1479 |
|
---|
1480 | vl = new QVBoxLayout;
|
---|
1481 | vbox->setLayout(vl);
|
---|
1482 |
|
---|
1483 |
|
---|
1484 |
|
---|
1485 | cb = new QCheckBox("Cut view cells", vbox);
|
---|
1486 | vbox->layout()->addWidget(cb);
|
---|
1487 | cb->setChecked(false);
|
---|
1488 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool)));
|
---|
1489 |
|
---|
1490 |
|
---|
1491 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1492 | vbox->layout()->addWidget(slider);
|
---|
1493 | slider->show();
|
---|
1494 | slider->setRange(0, 1000);
|
---|
1495 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1496 | slider->setValue(1000);
|
---|
1497 |
|
---|
1498 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int)));
|
---|
1499 |
|
---|
1500 |
|
---|
1501 | cb = new QCheckBox("Hide view cells by render cost ", vbox);
|
---|
1502 | vbox->layout()->addWidget(cb);
|
---|
1503 | cb->setChecked(false);
|
---|
1504 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetHideByCost(bool)));
|
---|
1505 |
|
---|
1506 | ////////////////////////////
|
---|
1507 |
|
---|
1508 | const int range = 1000;
|
---|
1509 |
|
---|
1510 | label = new QLabel("Hide by cost");
|
---|
1511 | vbox->layout()->addWidget(label);
|
---|
1512 |
|
---|
1513 | // the render cost visualization
|
---|
1514 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1515 | vbox->layout()->addWidget(slider);
|
---|
1516 | slider->show();
|
---|
1517 | slider->setRange(0, range);
|
---|
1518 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1519 | slider->setValue(0);
|
---|
1520 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetHidingCost(int)));
|
---|
1521 |
|
---|
1522 | ///////////////////////////////////////////
|
---|
1523 |
|
---|
1524 | cb = new QCheckBox("Top View", vbox);
|
---|
1525 | vbox->layout()->addWidget(cb);
|
---|
1526 | cb->setChecked(false);
|
---|
1527 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
|
---|
1528 |
|
---|
1529 |
|
---|
1530 | label = new QLabel("Top distance");
|
---|
1531 | vbox->layout()->addWidget(label);
|
---|
1532 |
|
---|
1533 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1534 | vbox->layout()->addWidget(slider);
|
---|
1535 | slider->show();
|
---|
1536 | slider->setRange(1, 1000);
|
---|
1537 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1538 | slider->setValue(500);
|
---|
1539 |
|
---|
1540 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
|
---|
1541 |
|
---|
1542 |
|
---|
1543 | ///////////////////////////////////////////
|
---|
1544 |
|
---|
1545 | cb = new QCheckBox("Transparency", vbox);
|
---|
1546 | vbox->layout()->addWidget(cb);
|
---|
1547 | cb->setChecked(false);
|
---|
1548 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTransparency(bool)));
|
---|
1549 |
|
---|
1550 | label = new QLabel("Use transparency");
|
---|
1551 | vbox->layout()->addWidget(label);
|
---|
1552 |
|
---|
1553 | // the render cost visualization
|
---|
1554 | slider = new QSlider(Qt::Horizontal, vbox);
|
---|
1555 | vbox->layout()->addWidget(slider);
|
---|
1556 | slider->show();
|
---|
1557 | slider->setRange(0, range);
|
---|
1558 | slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
1559 | slider->setValue(0);
|
---|
1560 |
|
---|
1561 | connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTransparency(int)));
|
---|
1562 |
|
---|
1563 | //////////////////////////////
|
---|
1564 |
|
---|
1565 |
|
---|
1566 | cb = new QCheckBox("Cut scene", vbox);
|
---|
1567 | vbox->layout()->addWidget(cb);
|
---|
1568 | cb->setChecked(false);
|
---|
1569 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool)));
|
---|
1570 |
|
---|
1571 | cb = new QCheckBox("Render boxes", vbox);
|
---|
1572 | vbox->layout()->addWidget(cb);
|
---|
1573 | cb->setChecked(false);
|
---|
1574 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderBoxes(bool)));
|
---|
1575 |
|
---|
1576 | cb = new QCheckBox("Render visibility estimates", vbox);
|
---|
1577 | vbox->layout()->addWidget(cb);
|
---|
1578 | cb->setChecked(false);
|
---|
1579 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderVisibilityEstimates(bool)));
|
---|
1580 |
|
---|
1581 |
|
---|
1582 | cb = new QCheckBox("Render errors", vbox);
|
---|
1583 | vbox->layout()->addWidget(cb);
|
---|
1584 | cb->setChecked(false);
|
---|
1585 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
|
---|
1586 |
|
---|
1587 |
|
---|
1588 | bool tmp;
|
---|
1589 |
|
---|
1590 | cb = new QCheckBox("Use filter", vbox);
|
---|
1591 | vbox->layout()->addWidget(cb);
|
---|
1592 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilityFilter", tmp );
|
---|
1593 | cb->setChecked(tmp);
|
---|
1594 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool)));
|
---|
1595 |
|
---|
1596 |
|
---|
1597 | cb = new QCheckBox("Use spatial filter", vbox);
|
---|
1598 | vbox->layout()->addWidget(cb);
|
---|
1599 | Environment::GetSingleton()->GetBoolValue("Preprocessor.applyVisibilitySpatialFilter",
|
---|
1600 | tmp );
|
---|
1601 | cb->setChecked(tmp);
|
---|
1602 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(bool)));
|
---|
1603 |
|
---|
1604 | cb = new QCheckBox("Render filter", vbox);
|
---|
1605 | vbox->layout()->addWidget(cb);
|
---|
1606 | cb->setChecked(true);
|
---|
1607 | connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
|
---|
1608 |
|
---|
1609 |
|
---|
1610 | vbox = new QGroupBox("PVS Errors", this);
|
---|
1611 | layout()->addWidget(vbox);
|
---|
1612 |
|
---|
1613 | vl = new QVBoxLayout;
|
---|
1614 | vbox->setLayout(vl);
|
---|
1615 |
|
---|
1616 | button = new QPushButton("Compute Visibility", vbox);
|
---|
1617 | vbox->layout()->addWidget(button);
|
---|
1618 | connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility()));
|
---|
1619 |
|
---|
1620 | button = new QPushButton("Stop Computation", vbox);
|
---|
1621 | vbox->layout()->addWidget(button);
|
---|
1622 | connect(button, SIGNAL(clicked()), SLOT(StopComputation()));
|
---|
1623 |
|
---|
1624 | button = new QPushButton("Set Random View Point", vbox);
|
---|
1625 | vbox->layout()->addWidget(button);
|
---|
1626 | connect(button, SIGNAL(clicked()), SLOT(SetRandomViewPoint()));
|
---|
1627 |
|
---|
1628 |
|
---|
1629 | if (0) {
|
---|
1630 | vbox = new QGroupBox("PVS Errors", this);
|
---|
1631 | layout()->addWidget(vbox);
|
---|
1632 |
|
---|
1633 | vl = new QVBoxLayout;
|
---|
1634 | vbox->setLayout(vl);
|
---|
1635 |
|
---|
1636 | mPvsErrorWidget = new QListWidget(vbox);
|
---|
1637 | vbox->layout()->addWidget(mPvsErrorWidget);
|
---|
1638 |
|
---|
1639 | connect(mPvsErrorWidget,
|
---|
1640 | SIGNAL(doubleClicked(const QModelIndex &)),
|
---|
1641 | this,
|
---|
1642 | SLOT(PvsErrorClicked(const QModelIndex &)));
|
---|
1643 |
|
---|
1644 | button = new QPushButton("Next Error Frame", vbox);
|
---|
1645 | vbox->layout()->addWidget(button);
|
---|
1646 | connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
|
---|
1647 | }
|
---|
1648 |
|
---|
1649 |
|
---|
1650 | //mHidingCost = 0.1f;
|
---|
1651 |
|
---|
1652 | setWindowTitle("Preprocessor Control Widget");
|
---|
1653 | adjustSize();
|
---|
1654 | }
|
---|
1655 |
|
---|
1656 |
|
---|
1657 |
|
---|
1658 |
|
---|
1659 | void
|
---|
1660 | QtRendererControlWidget::FocusNextPvsErrorFrame(void)
|
---|
1661 | {
|
---|
1662 |
|
---|
1663 |
|
---|
1664 | }
|
---|
1665 |
|
---|
1666 | void
|
---|
1667 | QtRendererControlWidget::UpdatePvsErrorItem(int row,
|
---|
1668 | GlRendererBuffer::PvsErrorEntry &pvsErrorEntry)
|
---|
1669 | {
|
---|
1670 |
|
---|
1671 | QListWidgetItem *i = mPvsErrorWidget->item(row);
|
---|
1672 | QString s;
|
---|
1673 | s.sprintf("%5.5f", pvsErrorEntry.mError);
|
---|
1674 | if (i) {
|
---|
1675 | i->setText(s);
|
---|
1676 | } else {
|
---|
1677 | new QListWidgetItem(s, mPvsErrorWidget);
|
---|
1678 | }
|
---|
1679 | mPvsErrorWidget->update();
|
---|
1680 | }
|
---|
1681 |
|
---|
1682 |
|
---|
1683 | void QtGlDebuggerWidget::initializeGL()
|
---|
1684 | {
|
---|
1685 | glMatrixMode(GL_PROJECTION);
|
---|
1686 | glLoadIdentity();
|
---|
1687 |
|
---|
1688 | glFrustum(-1, 1, -1, 1, 10, 100);
|
---|
1689 | glTranslatef(-0.5f, -0.5f, -0.5f);
|
---|
1690 | glTranslatef(0.0f, 0.0f, -15.0f);
|
---|
1691 | glMatrixMode(GL_MODELVIEW);
|
---|
1692 |
|
---|
1693 | glEnable(GL_CULL_FACE);
|
---|
1694 | initCommon();
|
---|
1695 | initPbuffer();
|
---|
1696 |
|
---|
1697 | }
|
---|
1698 |
|
---|
1699 |
|
---|
1700 | void QtGlDebuggerWidget::resizeGL(int w, int h)
|
---|
1701 | {
|
---|
1702 | glViewport(0, 0, w, h);
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 |
|
---|
1706 | void QtGlDebuggerWidget::paintGL()
|
---|
1707 | {
|
---|
1708 | // draw a spinning cube into the pbuffer..
|
---|
1709 | mRenderBuffer->makeCurrent();
|
---|
1710 |
|
---|
1711 | BeamSampleStatistics stats;
|
---|
1712 | mRenderBuffer->SampleBeamContributions(mSourceObject, mBeam, mSamples, stats);
|
---|
1713 |
|
---|
1714 | glFlush();
|
---|
1715 |
|
---|
1716 | // rendering directly to a texture is not supported on X11, unfortunately
|
---|
1717 | mRenderBuffer->updateDynamicTexture(dynamicTexture);
|
---|
1718 |
|
---|
1719 | // and use the pbuffer contents as a texture when rendering the
|
---|
1720 | // background and the bouncing cubes
|
---|
1721 | makeCurrent();
|
---|
1722 | glBindTexture(GL_TEXTURE_2D, dynamicTexture);
|
---|
1723 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
1724 |
|
---|
1725 | // draw the background
|
---|
1726 | glMatrixMode(GL_MODELVIEW);
|
---|
1727 | glPushMatrix();
|
---|
1728 | glLoadIdentity();
|
---|
1729 | glMatrixMode(GL_PROJECTION);
|
---|
1730 | glPushMatrix();
|
---|
1731 | glLoadIdentity();
|
---|
1732 |
|
---|
1733 | glPopMatrix();
|
---|
1734 | glMatrixMode(GL_MODELVIEW);
|
---|
1735 | glPopMatrix();
|
---|
1736 | }
|
---|
1737 |
|
---|
1738 |
|
---|
1739 | void QtGlDebuggerWidget::initPbuffer()
|
---|
1740 | {
|
---|
1741 | // set up the pbuffer context
|
---|
1742 | mRenderBuffer->makeCurrent();
|
---|
1743 | /*mRenderBuffer->InitGL();
|
---|
1744 |
|
---|
1745 | glViewport(0, 0, mRenderBuffer->size().width(), mRenderBuffer->size().height());
|
---|
1746 | glMatrixMode(GL_PROJECTION);
|
---|
1747 | glLoadIdentity();
|
---|
1748 | glOrtho(-1, 1, -1, 1, -99, 99);
|
---|
1749 | glTranslatef(-0.5f, -0.5f, 0.0f);
|
---|
1750 | glMatrixMode(GL_MODELVIEW);
|
---|
1751 | glLoadIdentity();
|
---|
1752 |
|
---|
1753 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/
|
---|
1754 |
|
---|
1755 | // generate a texture that has the same size/format as the pbuffer
|
---|
1756 | dynamicTexture = mRenderBuffer->generateDynamicTexture();
|
---|
1757 |
|
---|
1758 | // bind the dynamic texture to the pbuffer - this is a no-op under X11
|
---|
1759 | mRenderBuffer->bindToDynamicTexture(dynamicTexture);
|
---|
1760 | makeCurrent();
|
---|
1761 | }
|
---|
1762 |
|
---|
1763 | void QtGlDebuggerWidget::initCommon()
|
---|
1764 | {
|
---|
1765 | glEnable(GL_TEXTURE_2D);
|
---|
1766 | glEnable(GL_DEPTH_TEST);
|
---|
1767 |
|
---|
1768 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
---|
1769 | }
|
---|
1770 |
|
---|
1771 |
|
---|
1772 |
|
---|
1773 | }
|
---|