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