Changeset 2538 for GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface
- Timestamp:
- 07/09/07 09:58:07 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
r2530 r2538 15 15 #include "QtPreprocessorThread.h" 16 16 #include "Material.h" 17 #include "IntersectableWrapper.h" 18 17 19 18 20 #define USE_CG 1 … … 109 111 110 112 ObjectPvs pvs; 111 if (1) { 112 pvs = viewcell->GetPvs(); 113 } else { 114 mViewCellsManager->ApplyFilter2(viewcell, 115 false, 116 1.0f, 117 pvs); 118 } 113 114 if (1) 115 pvs = viewcell->GetPvs(); 116 else 117 mViewCellsManager->ApplyFilter2(viewcell, false, 1.0f, pvs); 119 118 120 119 // cout<<"pvs size"<<pvs.GetSize()<<endl<<flush; … … 128 127 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); 129 128 130 // //Render PVS129 // Render PVS 131 130 ObjectPvsIterator it = pvs.GetIterator(); 132 131 … … 349 348 350 349 351 352 void 353 QtGlRendererWidget::RenderPvs() 354 { 350 bool QtGlRendererWidget::PvsChanged(ViewCell *viewCell) const 351 { 352 if (viewCell != mPvsCache.mViewCell) 353 return true; 354 355 if (viewCell->GetPvs().GetSize() != mPvsCache.mUnfilteredPvsSize) 356 return true; 357 358 return false; 359 } 360 361 362 void QtGlRendererWidget::_RenderPvs() 363 { 364 mUseFalseColors = false; 365 366 int offset = mObjects.size() * 3; 367 char *arrayPtr = mUseVbos ? NULL : (char *)mData; 355 368 356 Intersectable::NewMail(); 357 358 ViewCell *viewcell = NULL; 359 360 if (mDetectEmptyViewSpace) 361 glEnable( GL_CULL_FACE ); 362 else 363 glDisable( GL_CULL_FACE ); 364 365 viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); 366 367 if (viewcell) { 368 // copy the pvs so that it can be filtered... 369 370 // mPvsCache.mPvs; 371 372 if (mPvsCache.mViewCell != viewcell) { 373 mPvsCache.Reset(); 374 mPvsCache.mViewCell = viewcell; 375 376 if (mUseSpatialFilter) { 377 // 9.11. 2006 -> experiment with new spatial filter 369 glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr); 370 glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); 371 glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices); 372 } 373 374 375 void QtGlRendererWidget::_UpdatePvsIndices() 376 { 377 mIndexBufferSize = 0; 378 KdNode::NewMail(); 379 380 mPvsSize = mPvsCache.mPvs.GetSize(); 381 382 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 383 384 for (; it.HasMoreEntries(); ) 385 { 386 Intersectable *obj = it.Next(); 387 KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem(); 388 _UpdatePvsIndices(node); 389 } 390 } 391 392 393 void QtGlRendererWidget::_UpdatePvsIndices(KdNode *node) 394 { 395 if (node->Mailed()) 396 return; 397 398 node->Mail(); 399 400 if (!node->IsLeaf()) 401 { 402 KdInterior *in = static_cast<KdInterior *>(node); 403 404 _UpdatePvsIndices(in->mBack); 405 _UpdatePvsIndices(in->mFront); 406 } 407 else 408 { 409 KdLeaf *leaf = static_cast<KdLeaf *>(node); 410 411 leaf->mIndexBufferStart = mIndexBufferSize; 412 413 for (size_t i = 0; i < leaf->mObjects.size(); ++ i) 414 { 415 TriangleIntersectable *obj = 416 static_cast<TriangleIntersectable *>(leaf->mObjects[i]); 417 418 // check if already rendered 419 if (!obj->Mailed()) 420 { 421 obj->Mail(); 422 423 mIndices[mIndexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0; 424 mIndices[mIndexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1; 425 mIndices[mIndexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2; 426 427 mIndexBufferSize += 3; 428 } 429 } 430 431 leaf->mIndexBufferSize = mIndexBufferSize - leaf->mIndexBufferStart; 432 } 433 } 434 435 436 void QtGlRendererWidget::RenderPvs() 437 { 438 if (mUseVbos) 439 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 440 441 EnableDrawArrays(); 442 443 Intersectable::NewMail(); 444 ViewCell *viewcell = NULL; 445 446 if (mDetectEmptyViewSpace) 447 glEnable(GL_CULL_FACE); 448 else 449 glDisable(GL_CULL_FACE); 450 451 viewcell = mViewCellsManager->GetViewCell(mViewPoint, true); 452 453 if (viewcell) 454 { 455 // copy the pvs so that it can be filtered... 456 if (PvsChanged(viewcell)) 457 { 458 mPvsCache.Reset(); 459 mPvsCache.mViewCell = viewcell; 460 mPvsCache.mUnfilteredPvsSize = viewcell->GetPvs().GetSize(); 461 462 if (mUseSpatialFilter) 463 { 464 // 9.11. 2006 -> experiment with new spatial filter 378 465 #if 0 379 mViewCellsManager->ApplySpatialFilter(mKdTree,380 381 382 466 mViewCellsManager->ApplySpatialFilter(mKdTree, 467 mSpatialFilterSize* 468 Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 469 mPvsCache.mPvs); 383 470 #else 384 // mSpatialFilter size is in range 0.001 - 0.1 385 mViewCellsManager->ApplyFilter2(viewcell, 386 mUseFilter, 387 100*mSpatialFilterSize, 388 mPvsCache.mPvs, 389 &mPvsCache.filteredBoxes 390 ); 471 //cout<<"updating filter" << endl; 472 // mSpatialFilter size is in range 0.001 - 0.1 473 mViewCellsManager->ApplyFilter2(viewcell, 474 mUseFilter, 475 100 * mSpatialFilterSize, 476 mPvsCache.mPvs, 477 &mPvsCache.filteredBoxes 478 ); 391 479 #endif 392 } else 393 mPvsCache.mPvs = viewcell->GetPvs(); 394 395 emit PvsUpdated(); 480 } 481 else 482 { 483 mPvsCache.mPvs = viewcell->GetPvs(); 484 } 485 486 /// update the indices for rendering 487 _UpdatePvsIndices(); 488 489 emit PvsUpdated(); 490 } 491 492 Intersectable::NewMail(); 493 PvsData pvsData; 494 495 // Render PVS 496 if (mUseSpatialFilter && mRenderBoxes) 497 { 498 for (int i=0; i < mPvsCache.filteredBoxes.size(); i++) 499 RenderBox(mPvsCache.filteredBoxes[i]); 500 } 501 else 502 { 503 if (!mRenderVisibilityEstimates) 504 { 505 _RenderPvs(); 506 } 507 else 508 { 509 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 510 511 mPvsSize = mPvsCache.mPvs.GetSize(); 512 for (; it.HasMoreEntries(); ) 513 { 514 Intersectable *object = it.Next(pvsData); 515 516 //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 517 // glColor3f(visibility, 0.0f, 0.0f); 518 //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 519 RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1)); 520 glColor3f(color.r, color.g, color.b); 521 522 mUseForcedColors = true; 523 RenderIntersectable(object); 524 mUseForcedColors = false; 525 } 526 } 527 } 528 529 if (mRenderFilter) 530 { 531 mWireFrame = true; 532 RenderIntersectable(viewcell); 533 glPushMatrix(); 534 glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z); 535 glScalef(5.0f,5.0f,5.0f); 536 glPushAttrib(GL_CURRENT_BIT); 537 glColor3f(1.0f, 0.0f, 0.0f); 538 // gluSphere((::GLUquadric *)mSphere, 539 // 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6); 540 glPopAttrib(); 541 glPopMatrix(); 542 mWireFrame = false; 543 } 544 } 545 else 546 { 547 /*ObjectContainer::const_iterator oi = mObjects.begin(); 548 for (; oi != mObjects.end(); oi++) 549 RenderIntersectable(*oi);*/ 550 RenderScene(); 396 551 } 397 552 398 Intersectable::NewMail(); 399 400 PvsData pvsData; 401 402 // Render PVS 403 if (mUseSpatialFilter && mRenderBoxes) { 404 for (int i=0; i < mPvsCache.filteredBoxes.size(); i++) 405 RenderBox(mPvsCache.filteredBoxes[i]); 406 } else { 407 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 408 409 mPvsSize = mPvsCache.mPvs.GetSize(); 410 for (; it.HasMoreEntries(); ) { 411 Intersectable *object = it.Next(pvsData); 412 413 if (mRenderVisibilityEstimates) { 414 //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 415 // glColor3f(visibility, 0.0f, 0.0f); 416 //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 417 RgbColor color = RainbowColorMapping(mTransferFunction*log10(pvsData.mSumPdf + 1)); 418 glColor3f(color.r, color.g, color.b); 419 420 mUseForcedColors = true; 421 RenderIntersectable(object); 422 mUseForcedColors = false; 423 } else { 424 mUseForcedColors = false; 425 RenderIntersectable(object); 426 } 427 } 428 } 429 430 if (mRenderFilter) { 431 mWireFrame = true; 432 RenderIntersectable(viewcell); 433 glPushMatrix(); 434 glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z); 435 glScalef(5.0f,5.0f,5.0f); 436 glPushAttrib(GL_CURRENT_BIT); 437 glColor3f(1.0f, 0.0f, 0.0f); 438 // gluSphere((::GLUquadric *)mSphere, 439 // 1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6); 440 glPopAttrib(); 441 glPopMatrix(); 442 mWireFrame = false; 443 } 444 } else { 445 ObjectContainer::const_iterator oi = mObjects.begin(); 446 for (; oi != mObjects.end(); oi++) 447 RenderIntersectable(*oi); 448 } 553 //DisableDrawArrays(); 554 //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 449 555 } 450 556 … … 466 572 glColor3f(0.0f, 0.8f, 0.2f); 467 573 468 // //Render PVS574 // Render PVS 469 575 RenderPvs(); 470 576 471 577 glEnable(GL_STENCIL_TEST); 472 578 473 // 579 //mUseFalseColors = true; 474 580 475 581 glDisable(GL_LIGHTING); … … 501 607 int pixelCount = query->GetQueryResult(); 502 608 pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight()); 503 cout<<"error pixels="<<pixelCount<<endl;609 if (0) cout<<"error pixels="<<pixelCount<<endl; 504 610 505 611 mRenderError = pErrorPixels; … … 509 615 510 616 511 void 512 QtGlRendererWidget::mousePressEvent(QMouseEvent *e) 617 void QtGlRendererWidget::timerEvent(QTimerEvent *event) 618 { 619 //std::cout << "Timer ID:" << event->timerId(); 620 update(); 621 } 622 623 624 void QtGlRendererWidget::mousePressEvent(QMouseEvent *e) 513 625 { 514 626 int x = e->pos().x(); … … 523 635 QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e) 524 636 { 525 float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; 526 float TURN_SENSITIVITY=0.1f; 527 float TILT_SENSITIVITY=32.0 ; 528 float TURN_ANGLE= M_PI/36.0 ; 529 530 int x = e->pos().x(); 531 int y = e->pos().y(); 532 533 int diffx = -(mousePoint.x - x); 534 int diffy = -(mousePoint.y - y); 535 536 if (e->modifiers() & Qt::ControlModifier) { 537 mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0; 538 mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0; 539 } else { 540 mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY); 541 float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY; 542 float angle = atan2(mViewDirection.x, mViewDirection.z); 543 mViewDirection.x = sin(angle+adiff); 544 mViewDirection.z = cos(angle+adiff); 545 } 546 547 mousePoint.x = x; 548 mousePoint.y = y; 549 550 updateGL(); 637 float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; 638 float TURN_SENSITIVITY=0.1f; 639 float TILT_SENSITIVITY=32.0 ; 640 float TURN_ANGLE= M_PI/36.0 ; 641 642 int x = e->pos().x(); 643 int y = e->pos().y(); 644 645 int diffx = -(mousePoint.x - x); 646 int diffy = -(mousePoint.y - y); 647 648 if (e->modifiers() & Qt::ControlModifier) 649 { 650 mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0; 651 mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0; 652 } 653 else 654 { 655 mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY); 656 float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY; 657 float angle = atan2(mViewDirection.x, mViewDirection.z); 658 mViewDirection.x = sin(angle + adiff); 659 mViewDirection.z = cos(angle + adiff); 660 } 661 662 mousePoint.x = x; 663 mousePoint.y = y; 664 665 updateGL(); 551 666 } 552 667 … … 554 669 QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *) 555 670 { 556 557 558 671 } 559 672 … … 584 697 RenderInfo(); 585 698 586 mFrame ++;699 mFrame ++; 587 700 588 701 } … … 707 820 mRenderVisibilityEstimates = false; 708 821 mTransferFunction = 0.2f; 822 mIndexBufferSize = 0; 823 824 const int delay = 500; // half a second 825 timerId = startTimer(delay); 709 826 710 827 bool tmp; … … 825 942 currentCost = costFunction[currentPos]; 826 943 #if 1 827 cout<<"costFunction.size()="<< costFunction.size()<<endl;944 cout<<"costFunction.size()="<<(int)costFunction.size()<<endl; 828 945 cout<<"CP="<<currentPos<<endl; 829 946 cout<<"MC="<<maxCost<<endl; … … 913 1030 int vc = 0; 914 1031 if (mViewCellsManager) 915 vc = mViewCellsManager->GetViewCells().size();1032 vc = (int)mViewCellsManager->GetViewCells().size(); 916 1033 917 1034 int filter = 0; … … 1070 1187 1071 1188 1072 1073 1074 /***********************************************************************/ 1075 /* QtGlDebuggerWidget implementation */ 1076 /***********************************************************************/ 1189 /*********************************************************************/ 1190 /* QtGlDebuggerWidget implementation */ 1191 /*********************************************************************/ 1077 1192 1078 1193 … … 1094 1209 DEL_PTR(mRenderBuffer); 1095 1210 } 1096 1097 1211 1098 1212 -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
r1997 r2538 148 148 float mTransferFunction; 149 149 150 unsigned int mIndexBufferSize; 150 151 151 152 QtRendererControlWidget *mControlWidget; … … 177 178 void resizeGL(int w, int h); 178 179 void paintGL(); 179 void timerEvent(QTimerEvent *) { 180 update(); 181 } 182 180 void timerEvent(QTimerEvent *event); 183 181 void mousePressEvent(QMouseEvent *); 184 182 void mouseReleaseEvent(QMouseEvent *); 185 183 void mouseMoveEvent(QMouseEvent *); 186 184 187 void keyPressEvent ( QKeyEvent * e ) ; 188 189 void 190 RenderPvs(); 191 192 float 193 RenderErrors(); 194 void 195 RenderInfo(); 185 void keyPressEvent(QKeyEvent * e); 186 187 void RenderPvs(); 188 189 float RenderErrors(); 190 void RenderInfo(); 196 191 197 192 virtual int GetWidth() const { return width(); } … … 211 206 show(); 212 207 } 208 209 bool PvsChanged(ViewCell *viewcell) const; 210 213 211 214 212 public slots: … … 306 304 updateGL(); 307 305 } 306 307 void _RenderPvs(); 308 309 void _UpdatePvsIndices(); 310 void _UpdatePvsIndices(KdNode *node); 308 311 309 312 signals: -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
r1997 r2538 100 100 QtGlViewer::paintGL() 101 101 { 102 103 102 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 103 glLoadIdentity(); 104 104 105 105 float m[4][4]; 106 106 107 glLoadIdentity(); 108 gluLookAt(0.0, 0.0, 1.0, /* eye is at (0,0,30) */ 109 0.0, 0.0, 0.0, /* center is at (0,0,0) */ 110 0.0, 1.0, 0.); /* up is in positive Y direction */ 111 112 build_rotmatrix(m, manipulatorLastQuat); 113 glMultMatrixf(&m[0][0]); 107 glLoadIdentity(); 108 gluLookAt(0.0, 0.0, 1.0, /* eye is at (0,0,30) */ 109 0.0, 0.0, 0.0, /* center is at (0,0,0) */ 110 0.0, 1.0, 0.); /* up is in positive Y direction */ 114 111 115 float s = scale*20.0f/Magnitude(mRenderer->mSceneGraph->GetBox().Diagonal()); 116 glScalef(s, s, s); 117 118 Vector3 t = -mRenderer->mSceneGraph->GetBox().Center(); 119 glTranslatef(t.x, t.y, t.z); 112 build_rotmatrix(m, manipulatorLastQuat); 113 glMultMatrixf(&m[0][0]); 114 115 float s = scale*20.0f/Magnitude(mRenderer->mSceneGraph->GetBox().Diagonal()); 116 glScalef(s, s, s); 117 118 Vector3 t = -mRenderer->mSceneGraph->GetBox().Center(); 119 glTranslatef(t.x, t.y, t.z); 120 120 121 121 RenderScene();
Note: See TracChangeset
for help on using the changeset viewer.