Changeset 1202 for GTP/trunk/App/Demos
- Timestamp:
- 08/13/06 01:44:15 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTree.h
r1200 r1202 27 27 public: 28 28 29 KdTreeApp() { mFrameListener = 0; } 29 KdTreeApp() 30 { 31 mFrameListener = 0; 32 mRenderTargerListener = 0; 33 } 34 35 KdTreeApp(const String& infile, const String& outfile) 36 { 37 mFrameListener = 0; 38 mRenderTargerListener = 0; 39 mDemoInfileName = infile; 40 mDemoOutfileName = outfile; 41 } 30 42 31 43 ~KdTreeApp() … … 56 68 int mSelectEntities; 57 69 70 String mDemoInfileName; 71 String mDemoOutfileName; 72 58 73 virtual void setupResources(void); 59 74 … … 71 86 virtual bool configure(void); 72 87 88 /** load scene from file **/ 73 89 bool loadScene(const String& filename); 74 90 bool loadSceneIV(const String &filename, SceneNode *root, const int index); 91 92 void createMaterials(void); 75 93 private: 76 void createMaterials(void);77 94 std::string cat(std::string name, int x, int z) 78 95 { -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
r1200 r1202 46 46 using namespace Ogre; 47 47 48 struct FrameInfo 49 { 50 FrameInfo(Vector3 pos, Quaternion or, Real time): 51 mPosition(pos), mOrientation(or), mElapsedTime(time) 52 { } 53 54 Vector3 mPosition; 55 Quaternion mOrientation; 56 Real mElapsedTime; 57 }; 58 59 typedef std::list<FrameInfo> FrameList; 60 48 61 class KdTreeAppListener: public FrameListener, public KeyListener 49 62 { … … 110 123 111 124 // stuff for walkthrough recording/playback 112 struct FrameInfo 113 { 114 FrameInfo(Vector3 pos, Quaternion or, Real time): 115 mPosition(pos), mOrientation(or), mElapsedTime(time) 116 { } 117 118 Vector3 mPosition; 119 Quaternion mOrientation; 120 Real mElapsedTime; 121 }; 122 123 typedef std::list<FrameInfo> FrameList; 125 String mDemoInfileName; 126 String mDemoOutfileName; 124 127 125 128 enum AppState … … 139 142 OverlayElement * mDemoStatus; 140 143 144 void setDemoOverlay(); 145 141 146 void toggleRecord(); 142 147 void togglePlayback(); 143 // void resetPlayback();144 148 145 149 void saveFrameInfo(Real elapsedTime); 146 147 void setDemoOverlay(); 148 149 void saveFramesBinary(const String& filename); 150 void loadFramesBinary(const String& filename); 150 151 /** save demo frame data to file **/ 152 static void saveFrames(const String& filename, FrameList& framelist); 153 static void saveFramesAscii(const String& filename, FrameList& framelist); 154 static void saveFramesBinary(const String& filename, FrameList& framelist); 155 156 /** load demo frame data from file **/ 157 static void loadFrames(const String& filename, FrameList& framelist); 158 static void loadFramesAscii(const String& filename, FrameList& framelist); 159 static void loadFramesBinary(const String& filename, FrameList& framelist); 160 151 161 public: 152 void loadFrames(const String& filename);153 void saveFrames(const String& filename);154 155 162 // visualization modes for scene nodes 156 163 enum … … 163 170 164 171 // Constructor takes a RenderWindow because it uses that to determine input context 165 KdTreeAppListener(RenderWindow* win, SceneManager* sm, Real rs, Real ms, Real rp, 172 KdTreeAppListener(RenderWindow* win, SceneManager* sm, Real rs, Real ms, Real rp, 173 const String& infile, const String& outfile, 166 174 bool useBufferedInputKeys = false, bool useBufferedInputMouse = false); 167 175 -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/scripts/TestKdTree.vcproj
r1187 r1202 22 22 ImproveFloatingPointConsistency="TRUE" 23 23 AdditionalIncludeDirectories="..\include;"$(OGRE_PATH)\Samples\Common\include";"$(OGRE_PATH)\OgreMain\include";..\..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\include" 24 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;GTP_VISIBILITY_MODIFIED_OGRE ;KDTREE_FASTSTART"24 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;GTP_VISIBILITY_MODIFIED_OGRE" 25 25 MinimalRebuild="TRUE" 26 26 BasicRuntimeChecks="3" … … 85 85 OptimizeForWindowsApplication="TRUE" 86 86 AdditionalIncludeDirectories="..\include;"$(OGRE_PATH)\Samples\Common\include";"$(OGRE_PATH)\OgreMain\include";..\..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\include" 87 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;GTP_VISIBILITY_MODIFIED_OGRE ;KDTREE_FASTSTART"87 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;GTP_VISIBILITY_MODIFIED_OGRE" 88 88 StringPooling="TRUE" 89 89 MinimalRebuild="TRUE" -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp
r1200 r1202 9 9 extern "C" { 10 10 #endif 11 12 void splitStrCmdLine(const char *strCmdLine, std::vector<std::string>& argv); 13 bool getopt(const std::string& option, const std::vector<std::string>& argv, const std::string& optstring, std::string& optarg); 11 14 12 15 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 … … 16 19 #endif 17 20 { 21 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 22 // parse windows-style command line 23 std::string optarg = "i:o:", infile, outfile; 24 std::vector<std::string> argv; 25 26 splitStrCmdLine(strCmdLine, argv); 27 28 getopt("i", argv, optarg, infile); 29 getopt("o", argv, optarg, outfile); 30 31 // Create application object 32 KdTreeApp app(infile, outfile); 33 #else 34 // TODO: unix-style getopt 18 35 // Create application object 19 36 KdTreeApp app; 37 #endif 20 38 21 39 SET_TERM_HANDLER; … … 42 60 #endif 43 61 62 // split a space-separated string argument in an array of strings 63 // sensitive to " 64 void splitStrCmdLine(const char *strCmdLine, std::vector<std::string>& argv) 65 { 66 std::string cmdline(strCmdLine); 67 argv.clear(); 68 69 std::string tmp; 70 unsigned int strpos = 0; 71 bool skipspace = false; 72 73 while (strpos < cmdline.length()) 74 { 75 while (strpos < cmdline.length() && cmdline[strpos] == ' ') 76 strpos++; 77 tmp.clear(); 78 while (strpos < cmdline.length() && (cmdline[strpos] != ' ' || skipspace)) 79 { 80 if (cmdline[strpos] == '"') 81 { 82 ++ strpos; 83 skipspace = !skipspace; 84 if (!skipspace) 85 continue; 86 } 87 88 tmp += cmdline[strpos ++]; 89 } 90 argv.push_back(tmp); 91 } 92 93 //std::ofstream testout("test.txt"); 94 95 //testout << cmdline << "\n\n"; 96 97 //std::vector<std::string>::iterator it = argv.begin(); 98 //while (it != argv.end()) 99 //{ 100 // testout << *it << "\n"; 101 // ++ it; 102 //} 103 104 //testout.close(); 105 } 106 107 // simplified std::-based getopt (no long options) 108 // does not provide options consecutively like POSIX getopt, it rather gives you the value of the option you ask for 109 // or returns false if option not present or anything else went wrong 110 bool getopt(const std::string& option, const std::vector<std::string>& argv, const std::string& optstring, std::string& optarg) 111 { 112 static enum argtypes 113 { 114 no_argument, 115 required_argument, 116 optional_argument 117 }; 118 119 // early terminate 120 if (option.empty() || argv.empty() || optstring.empty()) 121 return false; 122 123 // verify presence of option 124 size_t iopt = optstring.find(option); 125 if (iopt == std::string::npos) 126 return false; 127 128 // check if mandatory or optional argument 129 int arg = no_argument; 130 if (++ iopt < optstring.size() && optstring[iopt] == ':') 131 arg = required_argument; 132 if (++ iopt < optstring.size() && optstring[iopt] == ':') 133 arg = optional_argument; 134 135 136 // find the arguments value 137 size_t item = 0; 138 std::string optstr = "-" + option; 139 140 while (item < argv.size()) 141 { 142 if (argv[item] == optstr) 143 { 144 switch (arg) 145 { 146 case no_argument: 147 optarg.clear(); 148 return true; 149 break; 150 case required_argument: 151 if (++ item < argv.size() && argv[item][0] != '-') 152 { 153 optarg = argv[item]; 154 return true; 155 } 156 else 157 { 158 optarg.clear(); 159 return false; 160 } 161 break; 162 case optional_argument: 163 if (++ item < argv.size() && argv[item][0] != '-') 164 { 165 optarg = argv[item]; 166 return true; 167 } 168 else 169 { 170 optarg.clear(); 171 return true; 172 } 173 break; 174 default: 175 return false; 176 } 177 } 178 ++ item; 179 } 180 181 return false; 182 } 183 44 184 #define ENT_GRID 0x01 45 185 #define ENT_RND 0x02 … … 94 234 tmp = cfDeath.getSetting("rotatespeed"); 95 235 mRotateSpeed = static_cast<Real>(strtod(tmp.c_str(), &errptr)); 236 237 // command line has preference over config file 238 if (mDemoInfileName.empty()) 239 mDemoInfileName = cfDeath.getSetting("demoinfile"); 240 241 if (mDemoOutfileName.empty()) 242 mDemoOutfileName = cfDeath.getSetting("demooutfile"); 96 243 97 244 ExampleApplication::setupResources(); … … 275 422 void KdTreeApp::createFrameListener(void) 276 423 { 277 mFrameListener = new KdTreeAppListener(mWindow, mSceneMgr, mRotateSpeed, mMoveSpeed, mRotationPeriod );424 mFrameListener = new KdTreeAppListener(mWindow, mSceneMgr, mRotateSpeed, mMoveSpeed, mRotationPeriod, mDemoInfileName, mDemoOutfileName); 278 425 mFrameListener->showDebugOverlay( true ); 279 426 mRoot->addFrameListener(mFrameListener); -
GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp
r1200 r1202 71 71 // Constructor takes a RenderWindow because it uses that to determine input context 72 72 KdTreeAppListener::KdTreeAppListener(RenderWindow* win, SceneManager* sm, Real rs, Real ms, Real rp, 73 bool useBufferedInputKeys, bool useBufferedInputMouse) 73 const String& infile, const String& outfile, 74 bool useBufferedInputKeys, bool useBufferedInputMouse) 74 75 { 75 76 mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); … … 102 103 mVizCamTransVect = Vector3::ZERO; 103 104 mSeqNum = 0; 105 106 mDemoInfileName = infile; 107 mDemoOutfileName = outfile; 104 108 105 109 mAppState = AS_NORMAL; … … 140 144 setDemoOverlay(); 141 145 142 //loadFrames("demo-in.txt");143 loadFramesBinary("demo-in.bin");146 if (!mDemoInfileName.empty()) 147 loadFrames(mDemoInfileName, mFrameList); 144 148 } 145 149 //----------------------------------------------------------------------- … … 153 157 { 154 158 PlatformManager::getSingleton().destroyInputReader( mInputDevice ); 155 }156 157 // save demo158 if (!mFrameList.empty())159 {160 //saveFrames("demo-out.txt");161 saveFramesBinary("demo-out.bin");162 159 } 163 160 } … … 346 343 { 347 344 toggleRecord(); 345 mTimeUntilNextToggle = 0.5; 346 } 347 348 if (mInputDevice->isKeyDown(KC_F6) && mTimeUntilNextToggle <= 0) 349 { 350 if (!mDemoOutfileName.empty() && !mFrameList.empty()) 351 saveFrames(mDemoOutfileName, mFrameList); 348 352 mTimeUntilNextToggle = 0.5; 349 353 } … … 1146 1150 } 1147 1151 1152 1148 1153 //----------------------------------------------------------------------------- 1149 //void KdTreeAppListener::resetPlayback() 1150 //{ 1151 // if (!mFrameList.empty()) 1152 // { 1153 // mCurrFrame = mFrameList.begin(); 1154 // mTimeRemaining = mCurrFrame->mElapsedTime; 1155 // } 1156 //} 1154 void KdTreeAppListener::saveFrames(const String& filename, FrameList& framelist) 1155 { 1156 size_t dot = filename.find_last_of("."); 1157 String ext = filename.substr(dot + 1, filename.length()); 1158 if (ext == "txt") 1159 saveFramesAscii(filename, framelist); 1160 else if (ext == "bin") 1161 saveFramesBinary(filename, framelist); 1162 else 1163 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid extension for demo file: " + ext, "KdTreeApp::loadFrames"); 1164 } 1157 1165 1158 1166 //----------------------------------------------------------------------------- 1159 void KdTreeAppListener::saveFrameInfo(Real elapsedTime) 1160 { 1161 mFrameList.push_back(FrameInfo(mCamNode->getPosition(), mCamNode->getOrientation(), elapsedTime)); 1162 } 1163 1164 //----------------------------------------------------------------------------- 1165 void KdTreeAppListener::saveFrames(const String& filename) 1167 void KdTreeAppListener::saveFramesAscii(const String& filename, FrameList& framelist) 1166 1168 { 1167 1169 // open file … … 1173 1175 } 1174 1176 1175 FrameList::iterator it = mFrameList.begin();1176 FrameList::iterator end = mFrameList.end();1177 FrameList::iterator it = framelist.begin(); 1178 FrameList::iterator end = framelist.end(); 1177 1179 1178 1180 // dump values … … 1190 1192 1191 1193 //----------------------------------------------------------------------------- 1192 void KdTreeAppListener::saveFramesBinary(const String& filename )1194 void KdTreeAppListener::saveFramesBinary(const String& filename, FrameList& framelist) 1193 1195 { 1194 1196 std::ofstream dest(filename.c_str(), std::ios_base::out | std::ios_base::binary); … … 1200 1202 } 1201 1203 1202 FrameList::iterator it = mFrameList.begin();1203 FrameList::iterator end = mFrameList.end();1204 1205 size_t size = sizeof(Real);1204 FrameList::iterator it = framelist.begin(); 1205 FrameList::iterator end = framelist.end(); 1206 1207 int size = sizeof(Real); 1206 1208 1207 1209 // dump values … … 1223 1225 1224 1226 //----------------------------------------------------------------------------- 1225 void KdTreeAppListener::loadFrames(const String& filename) 1227 void KdTreeAppListener::loadFrames(const String& filename, FrameList& framelist) 1228 { 1229 size_t dot = filename.find_last_of("."); 1230 String ext = filename.substr(dot + 1, filename.length()); 1231 if (ext == "txt") 1232 loadFramesAscii(filename, framelist); 1233 else if (ext == "bin") 1234 loadFramesBinary(filename, framelist); 1235 else 1236 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid extension for demo file: " + ext, "KdTreeApp::loadFrames"); 1237 } 1238 1239 //----------------------------------------------------------------------------- 1240 void KdTreeAppListener::loadFramesAscii(const String& filename, FrameList& framelist) 1226 1241 { 1227 1242 // open file … … 1234 1249 1235 1250 // clear the list 1236 mFrameList.clear();1251 framelist.clear(); 1237 1252 1238 1253 Vector3 pos; … … 1253 1268 src >> time; 1254 1269 1255 mFrameList.push_back(FrameInfo(pos, or, time));1270 framelist.push_back(FrameInfo(pos, or, time)); 1256 1271 } 1257 1272 1258 1273 // HACK pop last frame, was doubled while reading 1259 mFrameList.pop_back();1274 framelist.pop_back(); 1260 1275 1261 1276 src.close(); … … 1263 1278 1264 1279 //----------------------------------------------------------------------------- 1265 void KdTreeAppListener::loadFramesBinary(const String& filename )1280 void KdTreeAppListener::loadFramesBinary(const String& filename, FrameList& framelist) 1266 1281 { 1267 1282 // open file … … 1274 1289 1275 1290 // clear the list 1276 mFrameList.clear();1277 1278 size_t size = sizeof(Real);1291 framelist.clear(); 1292 1293 int size = sizeof(Real); 1279 1294 1280 1295 Vector3 pos; … … 1293 1308 src.read((char *)&time, size); 1294 1309 1295 mFrameList.push_back(FrameInfo(pos, or, time));1310 framelist.push_back(FrameInfo(pos, or, time)); 1296 1311 } 1297 1312 1298 1313 // HACK pop last frame, was doubled while reading 1299 mFrameList.pop_back();1314 framelist.pop_back(); 1300 1315 1301 1316 src.close(); 1302 1317 } 1318 1319 //----------------------------------------------------------------------------- 1320 void KdTreeAppListener::saveFrameInfo(Real elapsedTime) 1321 { 1322 mFrameList.push_back(FrameInfo(mCamNode->getPosition(), mCamNode->getOrientation(), elapsedTime)); 1323 } 1324 1303 1325 //----------------------------------------------------------------------------- 1304 1326 void KdTreeAppListener::setDemoOverlay()
Note: See TracChangeset
for help on using the changeset viewer.