Line | |
---|
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> |
---|
10 | #include <string> |
---|
11 | #include <osg/Image> |
---|
12 | #include <osgDB/WriteFile> |
---|
13 | #include <osgDB/FileUtils> |
---|
14 | //#include <osgDB/FileNameUtils> |
---|
15 | #include <animation.h> |
---|
16 | |
---|
17 | |
---|
18 | Animation::Animation() |
---|
19 | { |
---|
20 | _valid = false; |
---|
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 | |
---|
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) ) |
---|
54 | { |
---|
55 | std::cout << "Saved " << filename << std::endl; |
---|
56 | return true; |
---|
57 | } |
---|
58 | |
---|
59 | return false; |
---|
60 | |
---|
61 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.