/* SWWViewer An OpenSceneGraph viewer for pyVolution SWW files. copyright (C) 2004-2005 Geoscience Australia */ #include #include #include #include #include //#include #include Animation::Animation() { _valid = false; _image = new osg::Image; } void Animation::setDirectory( std::string dirname ) { osgDB::makeDirectory( dirname ); _dirname = dirname; _valid = true; } void Animation::setViewer( CustomViewer viewer ) { viewer.getCamera(0)->getProjectionRectangle( _x, _y, _width, _height ); } bool Animation::saveImage( unsigned int playback_index ) { _image->readPixels( _x, _y, _width, _height, GL_RGB, GL_UNSIGNED_BYTE); // restricted to 9999 frames (famous last words but that should be enough ;-) char nstr[5]; sprintf(nstr, "%04d", playback_index); std::string filename = std::string( _dirname + "/frame" + nstr + ".jpg" ); if ( osgDB::writeImageFile(*_image, filename) ) { std::cout << "Saved " << filename << std::endl; return true; } return false; }