Changeset 2686 for GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface
- Timestamp:
- 05/18/08 00:30:13 (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
r2685 r2686 30 30 31 31 #include <QVBoxLayout> 32 static GLint cubeArray[][3] = { 33 {0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}, 34 {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}, 35 {0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}, 36 {0, 1, 0}, {0, 1, 1}, {1, 1, 1}, {1, 1, 0}, 37 {0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1}, 38 {1, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 0, 1} 39 }; 40 41 static GLint cubeTextureArray[][2] = { 42 {0, 0}, {1, 0}, {1, 1}, {0, 1}, 43 {0, 0}, {0, 1}, {1, 1}, {1, 0}, 44 {0, 0}, {1, 0}, {1, 1}, {0, 1}, 45 {1, 0}, {0, 0}, {0, 1}, {1, 1}, 46 {0, 0}, {1, 0}, {1, 1}, {0, 1}, 47 {1, 0}, {0, 0}, {0, 1}, {1, 1} 48 }; 49 50 static GLint faceArray[][2] = { 51 {1, -1}, {1, 1}, {-1, 1}, {-1, -1} 52 }; 53 54 static GLubyte colorArray[][4] = { 55 {170, 202, 0, 255}, 56 {120, 143, 0, 255}, 57 {83, 102, 0, 255}, 58 {120, 143, 0, 255} 59 }; 60 61 32 33 34 using namespace std; 62 35 63 36 … … 79 52 80 53 54 static SimpleRayContainer sViewPointsList; 55 static SimpleRayContainer::const_iterator sViewPointsListIt; 56 57 81 58 82 59 static inline bool ilt(Intersectable *obj1, Intersectable *obj2) … … 99 76 } 100 77 #endif 101 102 103 void QtGlRendererBuffer::dummyBuffer()104 {105 //QGLPixelBuffer *dummy = new QGLPixelBuffer(QSize(256, 256), format(), this);106 107 // set up the pbuffer context108 makeCurrent();109 110 glEnableClientState(GL_VERTEX_ARRAY);111 glEnableClientState(GL_TEXTURE_COORD_ARRAY);112 glVertexPointer(3, GL_INT, 0, cubeArray);113 glTexCoordPointer(2, GL_INT, 0, cubeTextureArray);114 glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorArray);115 116 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);117 glEnable(GL_BLEND);118 glEnable(GL_TEXTURE_2D);119 glEnable(GL_DEPTH_TEST);120 121 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);122 123 glViewport(0, 0, size().width(), size().height());124 glMatrixMode(GL_PROJECTION);125 glLoadIdentity();126 glOrtho(-1, 1, -1, 1, -99, 99);127 glTranslatef(-0.5f, -0.5f, 0.0f);128 glMatrixMode(GL_MODELVIEW);129 glLoadIdentity();130 131 132 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);133 134 // draw cube background135 glPushMatrix();136 glLoadIdentity();137 glTranslatef(0.5f, 0.5f, -2.0f);138 glDisable(GL_TEXTURE_2D);139 glEnableClientState(GL_COLOR_ARRAY);140 glVertexPointer(2, GL_INT, 0, faceArray);141 glDrawArrays(GL_QUADS, 0, 4);142 glVertexPointer(3, GL_INT, 0, cubeArray);143 glDisableClientState(GL_COLOR_ARRAY);144 glEnable(GL_TEXTURE_2D);145 glPopMatrix();146 147 // draw cube148 glTranslatef(0.5f, 0.5f, 0.5f);149 glRotatef(3.0f, 1.0f, 1.0f, 1.0f);150 glTranslatef(-0.5f, -0.5f, -0.5f);151 glColor4f(0.9f, 0.9f, 0.9f, 1.0f);152 glDrawArrays(GL_QUADS, 0, 24);153 154 QImage im = toImage();155 QString qstr("test.png");156 157 im.save(qstr, "PNG");158 159 doneCurrent();160 }161 78 162 79 … … 210 127 { 211 128 EnableDrawArrays(); 129 130 // prepare pvs for rendering 212 131 PreparePvs(pvs); 213 132 … … 348 267 pErrorPixels = (float)pixelCount / (GetWidth() * GetHeight()); 349 268 269 const int pixelThres = 100000; 270 350 271 // some error happened 351 if (pixelCount > 0)352 { 353 cout << "frame " << mFrame << " vc id: " << viewcell->GetId() << " pvs: " << pvsSize << " pc: " << pixelCount << endl;272 if (pixelCount > pixelThres) 273 { 274 cout << "frame " << mFrame << " vc id: " << viewcell->GetId() << " pvs: " << pvsSize << " pc: " << pixelCount << " vp: " << mViewPoint << endl; 354 275 355 276 if (mSnapErrorFrames) … … 611 532 { 612 533 Intersectable *obj = it.Next(); 534 613 535 switch (obj->Type()) 614 536 { … … 620 542 break; 621 543 #if DYNAMIC_OBJECTS_HACK 622 #if USE_TRANSFORMED_MESH_INSTANCE_HACK 623 624 case Intersectable::TRANSFORMED_MESH_INSTANCE: 625 mDynamicObjects.push_back(static_cast<TransformedMeshInstance *>(obj)); 626 break; 627 628 #else 544 629 545 case Intersectable::SCENEGRAPHLEAF_INTERSECTABLE: 630 546 mDynamicObjects.push_back(static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem()); 631 547 break; 632 #endif633 548 #endif 634 549 default: … … 660 575 if (viewcell) 661 576 { 662 #if 0577 #if 1 663 578 // copy the pvs so that it can be filtered ... 664 579 if (PvsChanged(viewcell)) … … 689 604 PreparePvs(mPvsCache.mPvs); 690 605 emit PvsUpdated(); 606 691 607 mCurrentPvsCost = mPvsCache.mPvs.EvalPvsCost(); 692 608 } 693 609 #else 694 610 611 // update the indices for rendering 695 612 PreparePvs(viewcell->GetPvs()); 696 613 emit PvsUpdated(); … … 721 638 mWireFrame = false; 722 639 } 723 mCurrentPvsCost = viewcell->GetPvs().EvalPvsCost(); 640 641 //mCurrentPvsCost = viewcell->GetPvs().EvalPvsCost(); 724 642 } 725 643 else … … 797 715 798 716 799 void QtGlRendererWidget::timerEvent(QTimerEvent *event) 800 { 801 //std::cout << "Timer ID:" << event->timerId(); 802 update(); 717 void QtGlRendererWidget::timerEvent(QTimerEvent *timerEvent) 718 { 719 if (mReplayMode && (timerEvent->timerId() == mReplayTimerId)) 720 { 721 if (sViewPointsListIt == sViewPointsList.end()) 722 { 723 cout << "stopping replay" << endl; 724 mReplayMode = false; 725 } 726 else 727 { 728 SimpleRay sray = *sViewPointsListIt; 729 730 mViewPoint = sray.mOrigin; 731 mViewDirection = sray.mDirection; 732 733 ++ sViewPointsListIt; 734 } 735 736 737 updateGL(); 738 } 739 740 if (timerEvent->timerId() == mUpdateTimerId) 741 update(); 803 742 } 804 743 … … 826 765 QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e) 827 766 { 767 if (mReplayMode) 768 return; 769 828 770 float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; 829 771 float TURN_SENSITIVITY = 0.1f; … … 838 780 839 781 const float t = 1.0f; 840 841 782 if (e->modifiers() & Qt::ControlModifier) 842 783 { … … 1079 1020 mComputeGVS = false; 1080 1021 mUseRandomColorPerPvsObject = false; 1022 //mUseRandomColorPerPvsObject = true; 1081 1023 1082 1024 mHideByCost = false; … … 1087 1029 1088 1030 const int delay = 250; // in milliseconds 1089 timerId = startTimer(delay); 1031 mUpdateTimerId = startTimer(delay); 1032 mReplayTimerId = startTimer(1); // use fastest replay rate 1090 1033 1091 1034 bool tmp; … … 1121 1064 mShowRays = false; 1122 1065 1066 mReplayMode = false; 1067 1123 1068 SetSceneCut(1000); 1124 1069 mControlWidget = new QtRendererControlWidget(NULL); … … 1133 1078 connect(mControlWidget, SIGNAL(StoreStatistics(void)), this, SLOT(StoreStatistics(void))); 1134 1079 connect(mControlWidget, SIGNAL(ComputeGVS(void)), this, SLOT(ComputeGVS(void))); 1080 connect(mControlWidget, SIGNAL(ReplayViewPoints(void)), this, SLOT(ReplayViewPoints(void))); 1135 1081 connect(mControlWidget, SIGNAL(LoadObject(void)), this, SLOT(LoadObject(void))); 1136 1082 … … 2303 2249 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool))); 2304 2250 2305 2306 2251 /*vbox = new QGroupBox("PVS Errors", this); 2307 2252 layout()->addWidget(vbox); … … 2328 2273 #endif 2329 2274 2275 #if 0 2276 2330 2277 button = new QPushButton("Compute GVS", vbox); 2331 2278 vbox->layout()->addWidget(button); 2332 2279 connect(button, SIGNAL(clicked()), SIGNAL(ComputeGVS())); 2280 2281 #else 2282 2283 button = new QPushButton("Replay view points", vbox); 2284 vbox->layout()->addWidget(button); 2285 connect(button, SIGNAL(clicked()), SIGNAL(ReplayViewPoints())); 2286 2287 #endif 2333 2288 2334 2289 #if DYNAMIC_OBJECTS_HACK … … 2410 2365 // create the pbuffer 2411 2366 //pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this); 2412 timerId = startTimer(20);2367 //mUpdateTimerId = startTimer(20); 2413 2368 setWindowTitle(("OpenGL pbuffers")); 2414 2369 } … … 2514 2469 while (it.HasMoreEntries()) 2515 2470 { 2516 Intersectable *obj ect= it.Next(pvsData);2471 Intersectable *obj = it.Next(pvsData); 2517 2472 2518 2473 RgbColor color; 2519 2474 2520 //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f2521 // glColor3f(visibility, 0.0f, 0.0f);2522 2475 //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 2523 2476 if (mUseRandomColorPerPvsObject) 2524 2477 { 2525 KdIntersectable *kdint = static_cast<KdIntersectable *>(obj ect);2478 KdIntersectable *kdint = static_cast<KdIntersectable *>(obj); 2526 2479 2527 2480 if (kdint->mGenericIdx == -1) 2528 2481 { 2529 2482 kdint->mGenericIdx = (int)mColors.size(); 2530 mColors.push_back(RandomColor( ));2483 mColors.push_back(RandomColor(0, 1)); 2531 2484 } 2532 2485 color = mColors[kdint->mGenericIdx]; … … 2540 2493 2541 2494 mUseForcedColors = true; 2542 RenderIntersectable(obj ect);2495 RenderIntersectable(obj); 2543 2496 mUseForcedColors = false; 2544 2497 } 2545 2498 } 2546 2499 2547 void 2548 QtGlRendererWidget::UpdateDynamicObjects() 2549 { 2550 preprocessor->ScheduleUpdateDynamicObjects(); 2551 2552 } 2553 2554 } 2500 2501 void QtGlRendererWidget::UpdateDynamicObjects() 2502 { 2503 preprocessor->ScheduleUpdateDynamicObjects(); 2504 } 2505 2506 2507 void QtGlRendererWidget::ReplayViewPoints() 2508 { 2509 ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList(); 2510 2511 ViewCellPointsList::const_iterator vit, vit_end = vcPoints->end(); 2512 2513 sViewPointsList.clear(); 2514 2515 for (vit = vcPoints->begin(); vit != vit_end; ++ vit) 2516 { 2517 ViewCellPoints *vp = *vit; 2518 2519 SimpleRayContainer::const_iterator rit, rit_end = vp->second.end(); 2520 2521 for (rit = vp->second.begin(); rit != rit_end; ++ rit) 2522 { 2523 sViewPointsList.push_back(*rit); 2524 } 2525 } 2526 2527 if (!sViewPointsList.empty()) 2528 { 2529 cout << "replaying " << (int)sViewPointsList.size() << " view points " << endl; 2530 2531 mReplayMode = true; 2532 sViewPointsListIt = sViewPointsList.begin(); 2533 } 2534 } 2535 2536 } -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
r2679 r2686 75 75 int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const; 76 76 77 unsigned int mydynamicTexture; 78 void dummyBuffer(); 77 79 78 public: 80 79 … … 107 106 108 107 signals: 108 109 void ReplayViewPoints(); 109 110 void UpdateDynamicObjects(); 110 111 void ComputeVisibility(); … … 195 196 float mSpatialFilterSize; 196 197 197 //LogWriter *mLogWriter;198 198 Plane3 mSceneCutPlane; 199 199 float mHidingCost; … … 213 213 214 214 int mCurrentDynamicObjectIdx; 215 216 bool mReplayMode; 215 217 216 218 // some statistics … … 236 238 237 239 bool mUseRandomColorPerPvsObject; 240 241 int mUpdateTimerId; 242 int mReplayTimerId; 238 243 239 244 #if DYNAMIC_OBJECTS_HACK … … 281 286 virtual int GetHeight() const { return height(); } 282 287 283 virtual void 284 SetupCameraProjection(const int w, const int h, const float angle = 70.0f); 288 virtual void SetupCameraProjection(const int w, 289 const int h, 290 const float angle = 70.0f); 285 291 286 292 void RenderViewCells(); … … 303 309 304 310 void AssignColorByComparison(const ViewCellContainer &viewcells, 305 //const ViewCellInfoContainer &info1,306 311 const ViewCellInfoContainer &compareInfo); 307 312 308 313 void WriteViewCellInfos(); 309 314 310 311 ///////// 312 //QMutex mMutex; 313 315 314 316 315 317 public slots: 316 318 319 /** Replay the view points stored in the view points list. 320 */ 321 void ReplayViewPoints(); 317 322 void UpdateDynamicObjects(); 318 323 void UpdateAllPvs(); … … 553 558 } 554 559 555 560 556 561 /** Prepare pvs for rendering. 557 562 */ … … 565 570 566 571 float ComputeRenderCost(ViewCell *vc); 567 568 572 569 573 -
GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
r2670 r2686 67 67 GLfloat mat_shininess[] = { 1.0 }; 68 68 69 GLfloat light_ambient[] = { 0.2 , 0.2, 0.2, 1.0};70 GLfloat light_diffuse[] = { 0.4 , 0.4, 0.4, 1.0};71 GLfloat light_specular[] = { 0.3 , 0.3, 0.3, 1.0};72 73 GLfloat lmodel_ambient[] = {0.3 , 0.3, 0.3, 1.0};69 GLfloat light_ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; 70 GLfloat light_diffuse[] = { 0.4f, 0.4f, 0.4f, 1.0f }; 71 GLfloat light_specular[] = { 0.3f, 0.3f, 0.3f, 1.0f }; 72 73 GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f}; 74 74 75 75
Note: See TracChangeset
for help on using the changeset viewer.