Rev | Line | |
---|
[125] | 1 | /* |
---|
| 2 | SWWViewer |
---|
| 3 | |
---|
| 4 | An OpenSceneGraph viewer for pyVolution SWW files. |
---|
| 5 | copyright (C) 2004-2005 Geoscience Australia |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | #include <iostream> |
---|
[132] | 10 | #include <string> |
---|
[125] | 11 | #include <osg/Image> |
---|
| 12 | #include <osgDB/WriteFile> |
---|
[132] | 13 | #include <osgDB/FileUtils> |
---|
| 14 | //#include <osgDB/FileNameUtils> |
---|
[125] | 15 | #include <animation.h> |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | Animation::Animation() |
---|
| 19 | { |
---|
[132] | 20 | _valid = false; |
---|
[125] | 21 | _image = new osg::Image; |
---|
| 22 | |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | void Animation::setDirectory( std::string dirname ) |
---|
| 28 | { |
---|
| 29 | osgDB::makeDirectory( dirname ); |
---|
| 30 | _dirname = dirname; |
---|
| 31 | _valid = true; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | void Animation::setViewer( CustomViewer viewer ) |
---|
| 37 | { |
---|
| 38 | viewer.getCamera(0)->getProjectionRectangle( _x, _y, _width, _height ); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | bool Animation::saveImage( unsigned int playback_index ) |
---|
| 45 | { |
---|
| 46 | _image->readPixels( _x, _y, _width, _height, GL_RGB, GL_UNSIGNED_BYTE); |
---|
| 47 | |
---|
[132] | 48 | // restricted to 9999 frames (famous last words but that should be enough ;-) |
---|
| 49 | char nstr[5]; |
---|
| 50 | sprintf(nstr, "%04d", playback_index); |
---|
| 51 | |
---|
| 52 | std::string filename = std::string( _dirname + "/frame" + nstr + ".jpg" ); |
---|
| 53 | if ( osgDB::writeImageFile(*_image, filename) ) |
---|
[125] | 54 | { |
---|
[132] | 55 | std::cout << "Saved " << filename << std::endl; |
---|
[125] | 56 | return true; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | return false; |
---|
| 60 | |
---|
| 61 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.