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