- Timestamp:
- 05/16/13 17:52:29 (3 days ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgimagesequence/osgimagesequence.cpp
r13085 r13143 30 30 #include <osgDB/ReadFile> 31 31 #include <osgDB/WriteFile> 32 #include <osgDB/FileNameUtils> 33 #include <osgDB/FileUtils> 34 32 35 33 36 #include <osgViewer/Viewer> … … 37 40 38 41 42 static osgDB::DirectoryContents getSuitableFiles(osg::ArgumentParser& arguments) 43 { 44 osgDB::DirectoryContents files; 45 for(int i=1; i<arguments.argc(); ++i) 46 { 47 if (osgDB::fileType(arguments[i]) == osgDB::DIRECTORY) 48 { 49 const std::string& directory = arguments[i]; 50 osgDB::DirectoryContents dc = osgDB::getSortedDirectoryContents(directory); 51 52 for(osgDB::DirectoryContents::iterator itr = dc.begin(); itr != dc.end(); ++itr) 53 { 54 std::string full_file_name = directory + "/" + (*itr); 55 std::string ext = osgDB::getLowerCaseFileExtension(full_file_name); 56 if ((ext == "jpg") || (ext == "png") || (ext == "gif") || (ext == "rgb") || (ext == "dds") ) 57 { 58 files.push_back(full_file_name); 59 } 60 } 61 } 62 else { 63 files.push_back(arguments[i]); 64 } 65 } 66 return files; 67 } 39 68 40 69 … … 73 102 while (arguments.read("--fps",fps)) {} 74 103 75 if (arguments.argc()>1) 76 { 77 for(int i=1; i<arguments.argc(); ++i) 78 { 104 osgDB::DirectoryContents files = getSuitableFiles(arguments); 105 if (!files.empty()) 106 { 107 for(osgDB::DirectoryContents::iterator itr = files.begin(); 108 itr != files.end(); 109 ++itr) 110 { 111 const std::string& filename = *itr; 79 112 if (preLoad) 80 113 { 81 osg::ref_ptr<osg::Image> image = osgDB::readImageFile( arguments[i]);114 osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename); 82 115 if (image.valid()) 83 116 { … … 87 120 else 88 121 { 89 imageSequence->addImageFile( arguments[i]);90 } 91 } 92 122 imageSequence->addImageFile(filename); 123 } 124 125 } 93 126 94 127 if (length>0.0) … … 181 214 182 215 typedef std::vector< osg::observer_ptr<osg::ImageStream> > ImageStreamList; 216 217 struct ImageStreamPlaybackSpeedData { 218 double fps; 219 unsigned char* lastData; 220 double timeStamp, lastOutput; 221 222 ImageStreamPlaybackSpeedData() : fps(0), lastData(NULL), timeStamp(0), lastOutput(0) {} 223 224 }; 225 226 typedef std::vector< ImageStreamPlaybackSpeedData > ImageStreamPlayBackSpeedList; 183 227 184 228 protected: … … 245 289 bool _trackMouse; 246 290 ImageStreamList _imageStreamList; 291 ImageStreamPlayBackSpeedList _imageStreamPlayBackSpeedList; 247 292 248 293 }; … … 258 303 node->accept(fisv); 259 304 } 305 _imageStreamPlayBackSpeedList.resize(_imageStreamList.size()); 260 306 } 261 307 … … 265 311 switch(ea.getEventType()) 266 312 { 313 case(osgGA::GUIEventAdapter::FRAME): 314 { 315 double t = ea.getTime(); 316 bool printed(false); 317 318 ImageStreamPlayBackSpeedList::iterator fps_itr = _imageStreamPlayBackSpeedList.begin(); 319 for(ImageStreamList::iterator itr=_imageStreamList.begin(); 320 itr!=_imageStreamList.end(); 321 ++itr, ++fps_itr) 322 { 323 if (((*itr)->getStatus()==osg::ImageStream::PLAYING) && ((*itr)->data() != (*fps_itr).lastData)) 324 { 325 ImageStreamPlaybackSpeedData& data(*fps_itr); 326 double dt = (data.timeStamp > 0) ? t - data.timeStamp : 1/60.0; 327 data.lastData = (*itr)->data(); 328 data.fps = (*fps_itr).fps * 0.8 + 0.2 * (1/dt); 329 data.timeStamp = t; 330 331 if (t-data.lastOutput > 1) 332 { 333 std::cout << data.fps << " "; 334 data.lastOutput = t; 335 printed = true; 336 } 337 338 } 339 } 340 if (printed) 341 std::cout << std::endl; 342 } 343 break; 344 case(osgGA::GUIEventAdapter::MOVE): 345 { 346 if (_trackMouse) 347 { 348 for(ImageStreamList::iterator itr=_imageStreamList.begin(); 349 itr!=_imageStreamList.end(); 350 ++itr) 351 { 352 double dt = (*itr)->getLength() * ((1.0+ea.getXnormalized()) / 2.0); 353 (*itr)->seek(dt); 354 std::cout << "seeking to " << dt << " length: " <<(*itr)->getLength() << std::endl; 355 } 356 } 357 return false; 358 } 359 267 360 case(osgGA::GUIEventAdapter::KEYDOWN): 268 361 { … … 318 411 return true; 319 412 } 413 else if (ea.getKey() == 'i') 414 { 415 _trackMouse = !_trackMouse; 416 std::cout << "tracking mouse: " << (_trackMouse ? "ON" : "OFF") << std::endl; 417 418 for(ImageStreamList::iterator itr=_imageStreamList.begin(); 419 itr!=_imageStreamList.end(); 420 ++itr) 421 { 422 if ((*itr)->getStatus()==osg::ImageStream::PLAYING) 423 { 424 (*itr)->pause(); 425 } 426 else 427 { 428 (*itr)->play(); 429 } 430 } 431 432 433 } 320 434 return false; 321 435 } … … 324 438 return false; 325 439 } 440 441 return false; 326 442 } 327 443 328 444 void MovieEventHandler::getUsage(osg::ApplicationUsage& usage) const 329 445 { 446 usage.addKeyboardMouseBinding("i","toggle interactive mode, scrub via mouse-move"); 330 447 usage.addKeyboardMouseBinding("p","Play/Pause movie"); 331 448 usage.addKeyboardMouseBinding("r","Restart movie");
