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