Changeset 746 for GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
- Timestamp:
- 04/11/06 15:33:37 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r713 r746 54 54 mWireFrame = false; 55 55 environment->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace); 56 mSnapErrorFrames = false;57 mSnapPrefix = " ";58 56 mSnapErrorFrames = true; 57 mSnapPrefix = "snap/"; 58 mUseForcedColors = false; 59 59 } 60 60 … … 162 162 int i = 0; 163 163 164 if (!mUseFalseColors )164 if (!mUseFalseColors && !mUseForcedColors) 165 165 SetupMaterial(mesh->mMaterial); 166 166 … … 202 202 wglGetProcAddress("glGetOcclusionQueryuivNV"); 203 203 204 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 205 204 205 206 #if 0 207 GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; 208 /* mat_specular and mat_shininess are NOT default values */ 209 GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; 210 GLfloat mat_specular[] = { 0.3, 0.3, 0.3, 1.0 }; 211 GLfloat mat_shininess[] = { 1.0 }; 212 213 GLfloat light_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; 214 GLfloat light_diffuse[] = { 0.4, 0.4, 0.4, 1.0 }; 215 GLfloat light_specular[] = { 0.3, 0.3, 0.3, 1.0 }; 216 217 GLfloat lmodel_ambient[] = { 0.3, 0.3, 0.3, 1.0 }; 218 219 220 // default Material 221 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); 222 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); 223 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 224 glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 225 226 // a light 227 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 228 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 229 glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); 230 231 glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); 232 glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); 233 glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); 234 235 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); 236 237 glEnable(GL_LIGHTING); 238 glEnable(GL_LIGHT0); 239 glEnable(GL_LIGHT1); 240 241 242 // set position of the light 243 GLfloat infinite_light[] = { 1.0, 0.8, 1.0, 0.0 }; 244 glLightfv (GL_LIGHT0, GL_POSITION, infinite_light); 245 246 // set position of the light2 247 GLfloat infinite_light2[] = { -0.3, 1.5, 1.0, 0.0 }; 248 glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2); 249 250 glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 251 // glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR); 252 glEnable(GL_COLOR_MATERIAL); 253 254 glShadeModel( GL_FLAT ); 255 256 glDepthFunc( GL_LESS ); 257 glEnable( GL_DEPTH_TEST ); 258 #endif 259 260 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); 261 262 glEnable( GL_NORMALIZE ); 263 264 glClearColor(0.0f, 0.0f, 1.0f, 1.0f); 206 265 } 207 266 … … 213 272 if (mViewCellsManager) 214 273 vc = mViewCellsManager->GetViewCells().size(); 215 s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f) viewcells:%04d", 274 int filter = 0; 275 if (mViewCellsManager) 276 filter = mViewCellsManager->GetMaxFilterSize(); 277 278 s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f) viewcells:%04d filter:%04d pvs:%04d error:%5.5f\%", 216 279 mFrame, 217 280 mViewPoint.x, … … 221 284 mViewDirection.y, 222 285 mViewDirection.z, 223 vc 286 vc, 287 288 filter, 289 mPvsSize, 290 mRenderError*100.0f 224 291 ); 292 293 glColor3f(0.0f,0.0f,0.0f); 225 294 renderText(0,20,s); 295 296 if (mShowRenderCost) { 297 static vector<float> costFunction; 298 static float maxCost = -1; 299 if (costFunction.size()==0) { 300 ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree(); 301 if (tree) { 302 tree->GetCostFunction(costFunction); 303 maxCost = -1; 304 for (int i=0; i < costFunction.size(); i++) { 305 // cout<<i<<":"<<costFunction[i]<<" "; 306 if (costFunction[i] > maxCost) 307 maxCost = costFunction[i]; 308 } 309 } 310 } 311 312 313 int currentPos = mViewCellsManager->GetViewCells().size(); 314 float currentCost=-1; 315 316 if (currentPos < costFunction.size()) 317 currentCost = costFunction[currentPos]; 318 #if 0 319 cout<<"costFunction.size()="<<costFunction.size()<<endl; 320 cout<<"CP="<<currentPos<<endl; 321 cout<<"MC="<<maxCost<<endl; 322 cout<<"CC="<<currentCost<<endl; 323 #endif 324 if (costFunction.size()) { 325 glDisable(GL_DEPTH_TEST); 326 // init ortographic projection 327 glMatrixMode(GL_PROJECTION); 328 glPushMatrix(); 329 330 glLoadIdentity(); 331 gluOrtho2D(0, 1.0f, 0, 1.0f); 332 333 glTranslatef(0.1f, 0.1f, 0.0f); 334 glScalef(0.8f, 0.8f, 1.0f); 335 glMatrixMode(GL_MODELVIEW); 336 glLoadIdentity(); 337 338 glColor3f(1.0f,0,0); 339 glBegin(GL_LINE_STRIP); 340 // glVertex3f(0,0,0); 341 342 for (int i=0; i < costFunction.size(); i++) { 343 float x = i/(float)costFunction.size(); 344 float y = costFunction[i]/(maxCost*0.5f); 345 glVertex3f(x,y,0.0f); 346 } 347 glEnd(); 348 349 glColor3f(1.0f,0,0); 350 glBegin(GL_LINES); 351 float x = currentPos/(float)costFunction.size(); 352 glVertex3f(x,0.0,0.0f); 353 glVertex3f(x,1.0f,0.0f); 354 glEnd(); 355 356 glColor3f(0.0f,0,0); 357 // show a grid 358 glBegin(GL_LINE_LOOP); 359 glVertex3f(0,0,0.0f); 360 glVertex3f(1,0,0.0f); 361 glVertex3f(1,1,0.0f); 362 glVertex3f(0,1,0.0f); 363 glEnd(); 364 365 glBegin(GL_LINES); 366 for (int i=0; i < 50000 && i < costFunction.size(); i+=10000) { 367 float x = i/(float)costFunction.size(); 368 glVertex3f(x,0.0,0.0f); 369 glVertex3f(x,1.0f,0.0f); 370 } 371 372 for (int i=0; i < maxCost; i+=100) { 373 float y = i/(maxCost*0.5f); 374 glVertex3f(0,y,0.0f); 375 glVertex3f(1,y,0.0f); 376 } 377 378 glEnd(); 379 380 381 // restore the projection matrix 382 glMatrixMode(GL_PROJECTION); 383 glPopMatrix(); 384 glMatrixMode(GL_MODELVIEW); 385 glEnable(GL_DEPTH_TEST); 386 387 } 388 } 226 389 } 227 390 … … 365 528 366 529 glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 367 530 368 531 // Render PVS 369 532 std::map<Intersectable *, … … 467 630 } 468 631 632 void 633 GlRendererWidget::RenderPvs() 634 { 635 SetupCamera(); 636 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 637 638 ViewCell *viewcell; 639 // viewcell = mViewCellsManager->GetViewCell(mViewPoint); 640 641 PrVs prvs; 642 // mViewCellsManager->SetMaxFilterSize(1); 643 mViewCellsManager->GetPrVS(mViewPoint, prvs); 644 viewcell = prvs.mViewCell; 645 646 if (viewcell) { 647 ObjectPvs &pvs = viewcell->GetPvs(); 648 649 // read back the texture 650 std::map<Intersectable *, 651 PvsData<Intersectable *>, 652 LtSample<Intersectable *> >::const_iterator it = pvs.mEntries.begin(); 653 654 mPvsSize = pvs.mEntries.size(); 655 656 for (; it != pvs.mEntries.end(); ++ it) { 657 Intersectable *object = (*it).first; 658 float visibility = log10((*it).second.mSumPdf + 1)/5.0f; 659 glColor3f(visibility, 0.0f, 0.0f); 660 mUseForcedColors = true; 661 RenderIntersectable(object); 662 mUseForcedColors = false; 663 } 664 665 if (mRenderFilter) { 666 mWireFrame = true; 667 RenderIntersectable(viewcell); 668 mWireFrame = false; 669 } 670 mViewCellsManager->DeleteLocalMergeTree(viewcell); 671 } else { 672 ObjectContainer::const_iterator oi = mObjects.begin(); 673 for (; oi != mObjects.end(); oi++) 674 RenderIntersectable(*oi); 675 } 676 } 677 469 678 float 470 679 GlRendererWidget::RenderErrors() … … 520 729 PvsData<Intersectable *>, 521 730 LtSample<Intersectable *> >::const_iterator it = viewcell->GetPvs().mEntries.begin(); 522 731 732 mPvsSize = viewcell->GetPvs().mEntries.size(); 733 523 734 for (; it != viewcell->GetPvs().mEntries.end(); ++ it) { 524 735 Intersectable *object = (*it).first; … … 540 751 diff.setPixel(x, y, qRgba(255,128,128,255)); 541 752 errorPixels++; 542 543 753 } 544 754 pErrorPixels = ((float)errorPixels)/(im1.height()*im1.width()); … … 556 766 // now render im1 557 767 if (viewcell) { 558 if ( 1 ||mTopView) {768 if (0 && mTopView) { 559 769 mWireFrame = true; 560 770 RenderIntersectable(viewcell); … … 608 818 mViewCellsManager->DeleteLocalMergeTree(viewcell); 609 819 820 mRenderError = pErrorPixels; 610 821 return pErrorPixels; 611 822 } … … 673 884 mPvsErrorBuffer[i].mPvsSize = pvsSize; 674 885 886 emit UpdatePvsErrorItem(i, 887 mPvsErrorBuffer[i]); 888 675 889 cout<<"("<<i<<","<<mPvsErrorBuffer[i].mError<<")"; 676 890 // swapBuffers(); … … 762 976 763 977 if (!mRenderViewCells) { 764 RenderErrors(); 978 if (mRenderErrors) 979 RenderErrors(); 980 else 981 RenderPvs(); 765 982 RenderInfo(); 766 983 } else { 767 984 RenderViewCells(); 768 985 769 986 mWireFrame = true; 770 987 RenderScene(); 771 988 mWireFrame = false; 989 772 990 RenderInfo(); 773 991 } … … 854 1072 vl->addWidget(slider); 855 1073 slider->show(); 856 slider->setRange(1, 200);1074 slider->setRange(1, 10000); 857 1075 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 858 1076 slider->setValue(200); … … 884 1102 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool))); 885 1103 1104 cb = new QCheckBox("Show render cost", hbox); 1105 hlayout->addWidget(cb); 1106 cb->setChecked(false); 1107 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool))); 1108 1109 cb = new QCheckBox("Show pvs sizes", hbox); 1110 hlayout->addWidget(cb); 1111 cb->setChecked(false); 1112 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool))); 1113 886 1114 vbox->resize(800,100); 887 1115 … … 892 1120 vl = new QVBoxLayout; 893 1121 vbox->setLayout(vl); 894 1122 1123 1124 895 1125 slider = new QSlider(Qt::Horizontal, vbox); 896 1126 vbox->layout()->addWidget(slider); … … 902 1132 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int))); 903 1133 1134 cb = new QCheckBox("Render errors", vbox); 1135 vbox->layout()->addWidget(cb); 1136 cb->setChecked(true); 1137 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool))); 1138 1139 cb = new QCheckBox("Render filter", vbox); 1140 vbox->layout()->addWidget(cb); 1141 cb->setChecked(true); 1142 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool))); 904 1143 905 1144 cb = new QCheckBox("Cut view cells", vbox); … … 922 1161 923 1162 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int))); 924 925 926 927 1163 928 1164 cb = new QCheckBox("Top View", vbox); … … 930 1166 cb->setChecked(false); 931 1167 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); 932 1168 1169 vbox = new QGroupBox("PVS Errors", this); 1170 layout()->addWidget(vbox); 1171 1172 vl = new QVBoxLayout; 1173 vbox->setLayout(vl); 1174 1175 mPvsErrorWidget = new QListWidget(vbox); 1176 vbox->layout()->addWidget(mPvsErrorWidget); 1177 1178 connect(mPvsErrorWidget, 1179 SIGNAL(doubleClicked(const QModelIndex &)), 1180 this, 1181 SLOT(PvsErrorClicked(const QModelIndex &))); 1182 1183 QPushButton *button = new QPushButton("Next Error Frame", vbox); 1184 vbox->layout()->addWidget(button); 1185 connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void))); 1186 933 1187 setWindowTitle("Preprocessor Control Widget"); 934 1188 adjustSize(); 1189 } 1190 1191 1192 1193 void 1194 RendererControlWidget::FocusNextPvsErrorFrame(void) 1195 { 1196 1197 1198 } 1199 1200 void 1201 RendererControlWidget::UpdatePvsErrorItem(int row, 1202 GlRendererBuffer::PvsErrorEntry &pvsErrorEntry) 1203 { 1204 1205 QListWidgetItem *i = mPvsErrorWidget->item(row); 1206 QString s; 1207 s.sprintf("%5.5f", pvsErrorEntry.mError); 1208 if (i) { 1209 i->setText(s); 1210 } else { 1211 new QListWidgetItem(s, mPvsErrorWidget); 1212 } 1213 mPvsErrorWidget->update(); 935 1214 } 936 1215 … … 950 1229 mCutViewCells = false; 951 1230 mCutScene = false; 952 953 RendererControlWidget *cw = new RendererControlWidget(NULL); 954 connect(cw, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); 955 connect(cw, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 956 connect(cw, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); 957 958 //connect(cw, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetMaxFilterSize(int))); 959 // connect(cw, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int))); 960 //connect(cw, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetViewCellGranularity(int))); 961 962 connect(cw, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool))); 963 connect(cw, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool))); 964 connect(cw, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool))); 965 connect(cw, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 966 967 cw->show(); 1231 mRenderErrors = true; 1232 mRenderFilter = true; 1233 mShowRenderCost = false; 1234 mShowPvsSizes = false; 1235 1236 mPvsSize = 0; 1237 mRenderError = 0.0f; 1238 mControlWidget = new RendererControlWidget(NULL); 1239 1240 connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); 1241 connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 1242 connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); 1243 1244 connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int))); 1245 1246 connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool))); 1247 connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool))); 1248 connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool))); 1249 connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool))); 1250 connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool))); 1251 connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 1252 connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool))); 1253 connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool))); 1254 1255 1256 mControlWidget->show(); 968 1257 } 969 1258 … … 972 1261 { 973 1262 if (mViewCellsManager) 974 mViewCellsManager->SetMaxFilterSize(number);975 //mViewCellsManager->CollectViewCells(number);1263 // mViewCellsManager->SetMaxFilterSize(number); 1264 mViewCellsManager->CollectViewCells(number); 976 1265 updateGL(); 977 1266 } … … 1029 1318 int i; 1030 1319 ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); 1320 int maxPvs = -1; 1321 for (i=0; i < viewcells.size(); i++) { 1322 ViewCell *vc = viewcells[i]; 1323 int p = vc->GetPvs().GetSize(); 1324 if (p > maxPvs) 1325 maxPvs = p; 1326 } 1327 1328 1031 1329 for (i=0; i < viewcells.size(); i++) { 1032 1330 ViewCell *vc = viewcells[i]; 1033 1331 // Mesh *m = vc->GetMesh(); 1034 RgbColor c = vc->GetColor(); 1332 1333 1334 RgbColor c; 1335 1336 if (!mShowPvsSizes) 1337 c = vc->GetColor(); 1338 else { 1339 float importance = (float)vc->GetPvs().GetSize() / (float)maxPvs; 1340 c = RgbColor(importance, 1.0f - importance, 0.0f); 1341 } 1035 1342 glColor3f(c.r, c.g, c.b); 1343 1036 1344 RenderViewCell(vc); 1037 1345 }
Note: See TracChangeset
for help on using the changeset viewer.