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