Changeset 1205 for GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE
- Timestamp:
- 08/16/06 18:02:25 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
r1204 r1205 94 94 } 95 95 96 String mSceneManager; 96 97 String mDemoInfileName; 97 98 String mDemoOutfileName; … … 105 106 Real mKI; 106 107 String mRenderMethod; 108 String mComment; 107 109 }; 108 110 … … 233 235 void togglePlayback(); 234 236 237 /** write FPS stats to log file (csv) **/ 238 void saveLog(); 239 235 240 void saveFrameInfo(Real elapsedTime); 236 241 -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp
r1204 r1205 33 33 .addOpt("","kt", ARGUMENT_REQUIRED) 34 34 .addOpt("","ki", ARGUMENT_REQUIRED) 35 .addOpt("r","rendermethod", ARGUMENT_REQUIRED); 35 .addOpt("r","rendermode", ARGUMENT_REQUIRED) 36 .addOpt("s","scenemgr", ARGUMENT_REQUIRED); 36 37 37 38 … … 78 79 } 79 80 81 if (cmdparser.getOpt("s",tmp)) 82 { 83 if (tmp == "KDT" || tmp == "OCT" || tmp == "OCM" || tmp == "GEN") 84 { 85 options.mSceneManager = tmp; 86 } 87 else 88 { 89 MessageBox(NULL, ("Invalid argument for option --scenemgr: " + tmp).c_str(), "Error", MB_OK | MB_ICONERROR ); 90 return -1; 91 } 92 } 93 80 94 } 81 95 catch (std::string s) … … 177 191 178 192 // set default demo output name to avoid SNAFUs 179 if (mOptions.mDemoOutfileName.empty())180 mOptions.mDemoOutfileName = "demo.bin";193 //if (mOptions.mDemoOutfileName.empty()) 194 // mOptions.mDemoOutfileName = "demo.bin"; 181 195 182 196 if (mOptions.mDemoLogfileName.empty()) … … 184 198 185 199 // set default demo logfile name to avoid SNAFUs 186 if (mOptions.mDemoLogfileName.empty()) 187 mOptions.mDemoLogfileName = "demo.csv"; 200 //if (mOptions.mDemoLogfileName.empty()) 201 // mOptions.mDemoLogfileName = "demo.csv"; 202 203 // override scene manager set in config file 204 if (!mOptions.mSceneManager.empty()) 205 { 206 if (mOptions.mSceneManager == "KDT") 207 mSelectedSceneManager = "KdTreeSceneManager"; 208 else if (mOptions.mSceneManager == "OCT") 209 mSelectedSceneManager = "OctreeSceneManager"; 210 else if (mOptions.mSceneManager == "OCM") 211 mSelectedSceneManager = "OcclusionCullingSceneManager"; 212 else if (mOptions.mSceneManager == "GEN") 213 mSelectedSceneManager = "DefaultSceneManager"; 214 } 215 // the other way round for log 216 else 217 { 218 if (mSelectedSceneManager == "KdTreeSceneManager") 219 mOptions.mSceneManager = "KDT"; 220 else if (mSelectedSceneManager == "OctreeSceneManager") 221 mOptions.mSceneManager = "OCT"; 222 else if (mSelectedSceneManager == "OcclusionCullingSceneManager") 223 mOptions.mSceneManager = "OCM"; 224 else if (mSelectedSceneManager == "DefaultSceneManager") 225 mOptions.mSceneManager = "GEN"; 226 } 188 227 189 228 ExampleApplication::setupResources(); -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp
r1204 r1205 4 4 #include <OgrePanelOverlayElement.h> 5 5 #include "TestKdTreeAppListener.h" 6 #include <windows.h> 6 7 7 8 void KdTreeAppListener::updateStats(void) … … 1023 1024 if (mOptions.mDemoMode) 1024 1025 { 1025 // write FPS log 1026 Real minFPS = Math::POS_INFINITY, maxFPS = 0.0, avgFPS = 0.0; 1027 std::ofstream demolog(mOptions.mDemoLogfileName.c_str()); 1028 if (demolog) 1029 { 1030 for (std::list<Real>::iterator it = mDemoFPS.begin(); it != mDemoFPS.end(); it ++) 1031 { 1032 demolog << (int)*it << "\n"; 1033 1034 if (*it < minFPS) 1035 minFPS = *it; 1036 1037 if (*it > maxFPS) 1038 maxFPS = *it; 1039 1040 avgFPS += *it; 1041 } 1042 1043 avgFPS /= mDemoFPS.size(); 1044 1045 demolog << "\n" << (int)minFPS << "\n" << (int)avgFPS << "\n" << (int)maxFPS << "\n"; 1046 1047 demolog.close(); 1048 } 1026 saveLog(); 1049 1027 return false; 1050 1028 } … … 1242 1220 // open file 1243 1221 std::ofstream dest(filename.c_str()); 1244 if (!dest) 1245 { 1246 LogManager::getSingleton().logMessage("Failed to open file for saving demo: " + filename); 1247 return; 1248 } 1249 1250 FrameList::iterator it = framelist.begin(); 1251 FrameList::iterator end = framelist.end(); 1252 1253 // dump values 1254 while (it != end) 1255 { 1256 dest << 1257 StringConverter::toString(it->mPosition) << " " << 1258 StringConverter::toString(it->mOrientation) << " " << 1259 StringConverter::toString(it->mElapsedTime) << "\n"; 1260 ++ it; 1261 } 1262 1263 dest.close(); 1222 if (dest.is_open()) 1223 { 1224 FrameList::iterator it = framelist.begin(); 1225 FrameList::iterator end = framelist.end(); 1226 1227 // dump values 1228 while (it != end) 1229 { 1230 dest << 1231 StringConverter::toString(it->mPosition) << " " << 1232 StringConverter::toString(it->mOrientation) << " " << 1233 StringConverter::toString(it->mElapsedTime) << "\n"; 1234 ++ it; 1235 } 1236 1237 dest.close(); 1238 } 1239 else 1240 { 1241 LogManager::getSingleton().logMessage("##Error##: Failed to open file for saving demo: " + filename); 1242 } 1243 1244 1264 1245 } 1265 1246 … … 1269 1250 std::ofstream dest(filename.c_str(), std::ios_base::out | std::ios_base::binary); 1270 1251 1271 if (!dest) 1272 { 1273 LogManager::getSingleton().logMessage("Failed to open file for saving demo: " + filename); 1274 return; 1275 } 1276 1277 FrameList::iterator it = framelist.begin(); 1278 FrameList::iterator end = framelist.end(); 1279 1280 int size = sizeof(Real); 1281 1282 // dump values 1283 while (it != end) 1284 { 1285 dest.write((char *)&it->mPosition.x, size); 1286 dest.write((char *)&it->mPosition.y, size); 1287 dest.write((char *)&it->mPosition.z, size); 1288 dest.write((char *)&it->mOrientation.w, size); 1289 dest.write((char *)&it->mOrientation.x, size); 1290 dest.write((char *)&it->mOrientation.y, size); 1291 dest.write((char *)&it->mOrientation.z, size); 1292 dest.write((char *)&it->mElapsedTime, size); 1293 ++ it; 1294 } 1295 1296 dest.close(); 1252 if (dest.is_open()) 1253 { 1254 FrameList::iterator it = framelist.begin(); 1255 FrameList::iterator end = framelist.end(); 1256 1257 int size = sizeof(Real); 1258 1259 // dump values 1260 while (it != end) 1261 { 1262 dest.write((char *)&it->mPosition.x, size); 1263 dest.write((char *)&it->mPosition.y, size); 1264 dest.write((char *)&it->mPosition.z, size); 1265 dest.write((char *)&it->mOrientation.w, size); 1266 dest.write((char *)&it->mOrientation.x, size); 1267 dest.write((char *)&it->mOrientation.y, size); 1268 dest.write((char *)&it->mOrientation.z, size); 1269 dest.write((char *)&it->mElapsedTime, size); 1270 ++ it; 1271 } 1272 1273 dest.close(); 1274 } 1275 else 1276 { 1277 LogManager::getSingleton().logMessage("##Error##: Failed to open file for saving demo: " + filename); 1278 } 1297 1279 } 1298 1280 … … 1315 1297 // open file 1316 1298 std::ifstream src(filename.c_str()); 1317 if (!src) 1318 { 1319 LogManager::getSingleton().logMessage("Failed to open file for reading demo: " + filename); 1320 return; 1321 } 1322 1323 // clear the list 1324 framelist.clear(); 1325 1326 Vector3 pos; 1327 Quaternion or; 1328 Real time; 1329 1330 while (!src.eof()) 1331 { 1332 src >> pos.x; 1333 src >> pos.y; 1334 src >> pos.z; 1335 1336 src >> or.w; 1337 src >> or.x; 1338 src >> or.y; 1339 src >> or.z; 1340 1341 src >> time; 1342 1343 framelist.push_back(FrameInfo(pos, or, time)); 1344 } 1345 1346 // HACK pop last frame, was doubled while reading 1347 framelist.pop_back(); 1348 1349 src.close(); 1299 if (src.is_open()) 1300 { 1301 // clear the list 1302 framelist.clear(); 1303 1304 Vector3 pos; 1305 Quaternion or; 1306 Real time; 1307 1308 while (!src.eof()) 1309 { 1310 src >> pos.x; 1311 src >> pos.y; 1312 src >> pos.z; 1313 1314 src >> or.w; 1315 src >> or.x; 1316 src >> or.y; 1317 src >> or.z; 1318 1319 src >> time; 1320 1321 framelist.push_back(FrameInfo(pos, or, time)); 1322 } 1323 1324 // HACK pop last frame, was doubled while reading 1325 framelist.pop_back(); 1326 1327 src.close(); 1328 } 1329 else 1330 { 1331 LogManager::getSingleton().logMessage("##Error##: Failed to open file for reading demo: " + filename); 1332 } 1350 1333 } 1351 1334 … … 1355 1338 // open file 1356 1339 std::ifstream src(filename.c_str(), std::ios_base::out | std::ios_base::binary); 1357 if (!src) 1358 { 1359 LogManager::getSingleton().logMessage("Failed to open file for reading demo: " + filename); 1360 return; 1361 } 1362 1363 // clear the list 1364 framelist.clear(); 1365 1366 int size = sizeof(Real); 1367 1368 Vector3 pos; 1369 Quaternion or; 1370 Real time; 1371 1372 while (!src.eof()) 1373 { 1374 src.read((char *)&pos.x, size); 1375 src.read((char *)&pos.y, size); 1376 src.read((char *)&pos.z, size); 1377 src.read((char *)&or.w, size); 1378 src.read((char *)&or.x, size); 1379 src.read((char *)&or.y, size); 1380 src.read((char *)&or.z, size); 1381 src.read((char *)&time, size); 1382 1383 framelist.push_back(FrameInfo(pos, or, time)); 1384 } 1385 1386 // HACK pop last frame, was doubled while reading 1387 framelist.pop_back(); 1388 1389 src.close(); 1340 if (src.is_open()) 1341 { 1342 // clear the list 1343 framelist.clear(); 1344 1345 int size = sizeof(Real); 1346 1347 Vector3 pos; 1348 Quaternion or; 1349 Real time; 1350 1351 while (!src.eof()) 1352 { 1353 src.read((char *)&pos.x, size); 1354 src.read((char *)&pos.y, size); 1355 src.read((char *)&pos.z, size); 1356 src.read((char *)&or.w, size); 1357 src.read((char *)&or.x, size); 1358 src.read((char *)&or.y, size); 1359 src.read((char *)&or.z, size); 1360 src.read((char *)&time, size); 1361 1362 framelist.push_back(FrameInfo(pos, or, time)); 1363 } 1364 1365 // HACK pop last frame, was doubled while reading 1366 framelist.pop_back(); 1367 1368 src.close(); 1369 } 1370 else 1371 { 1372 LogManager::getSingleton().logMessage("##Error##: Failed to open file for reading demo: " + filename); 1373 } 1374 } 1375 1376 //----------------------------------------------------------------------------- 1377 void KdTreeAppListener::saveLog() 1378 { 1379 // field separator and record separator 1380 static const String fs = ",", rs ="\n", ds = ":"; 1381 // stats 1382 Real minFPS = Math::POS_INFINITY, maxFPS = 0.0, avgFPS = 0.0; 1383 String demofile; 1384 1385 // check if logfile exists 1386 std::ifstream logread(mOptions.mDemoLogfileName.c_str()); 1387 if (logread.is_open()) 1388 { 1389 // read first item, it's the name of the demo 1390 // if matches, OK, otherwise do something 1391 logread >> demofile; 1392 if (!StringUtil::startsWith(demofile, mOptions.mDemoInfileName)) 1393 { 1394 LogManager::getSingleton().logMessage( 1395 "##Error##: Saved demo stats do not match the current demo: " + 1396 demofile + " != " + mOptions.mDemoInfileName); 1397 logread.close(); 1398 return; 1399 } 1400 } 1401 // otherwise write header 1402 else 1403 { 1404 std::ofstream logheader(mOptions.mDemoLogfileName.c_str()); 1405 if (logheader.is_open()) 1406 { 1407 // demo title 1408 logheader << mOptions.mDemoInfileName << fs; 1409 // seconds 1410 for (size_t i = 0; i < mDemoFPS.size(); i ++) 1411 { 1412 logheader << (i+1) << fs; 1413 } 1414 // minFPS, avgFPS, maxFPS, comment, record separator 1415 logheader << "min FPS" << fs << "avg FPS" << fs << "max FPS" << fs << "Comment" << rs; 1416 logheader.close(); 1417 } 1418 else 1419 { 1420 LogManager::getSingleton().logMessage( 1421 "##Error##: Failed to write log demo header to " + 1422 mOptions.mDemoLogfileName); 1423 return; 1424 1425 } 1426 } 1427 1428 // append current stats 1429 std::ofstream logwrite(mOptions.mDemoLogfileName.c_str(), std::ios_base::app); 1430 if (logwrite.is_open()) 1431 { 1432 // demo settings 1433 logwrite << mOptions.mSceneManager; 1434 if (mOptions.mSceneManager == "KDT") 1435 { 1436 logwrite << ds << mOptions.mRenderMethod << ds << mOptions.mMaxDepth << ds 1437 << mOptions.mKT << ds << mOptions.mKI; 1438 } 1439 //else if (mOptions.mSceneManager == "OCM" && mOptions.mRenderMethod != "INT") 1440 //{ 1441 // logwrite << ds << mOptions.mRenderMethod; 1442 //} 1443 logwrite << fs; 1444 // per second stats 1445 for (std::list<Real>::iterator it = mDemoFPS.begin(); it != mDemoFPS.end(); it ++) 1446 { 1447 if (*it < minFPS) 1448 minFPS = *it; 1449 1450 if (*it > maxFPS) 1451 maxFPS = *it; 1452 1453 avgFPS += *it; 1454 1455 logwrite << (int)(*it) << fs; 1456 1457 } 1458 avgFPS /= mDemoFPS.size(); 1459 // minFPS, avgFPS, maxFPS, comment, record separator 1460 logwrite << (int)minFPS << fs << (int)avgFPS << fs << (int)maxFPS << fs << mOptions.mComment << rs; 1461 logwrite.close(); 1462 } 1463 else 1464 { 1465 LogManager::getSingleton().logMessage( 1466 "##Error##: Failed to write demo log to " + 1467 mOptions.mDemoLogfileName); 1468 } 1390 1469 } 1391 1470
Note: See TracChangeset
for help on using the changeset viewer.