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