osgEarth 2.1.1
Classes | Typedefs | Functions

/home/cube/sources/osgearth/src/applications/osgearth_ocean/osgearth_ocean.cpp File Reference

#include <osgEarth/Notify>
#include <osgDB/ReadFile>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgEarth/MapNode>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/OceanSurfaceNode>
#include <osgEarthUtil/Controls>
Include dependency graph for osgearth_ocean.cpp:

Go to the source code of this file.

Classes

struct  MyGraphicsContext
struct  MyEventHandler

Typedefs

typedef std::vector
< osg::ref_ptr< osg::Image > > 
ImageList

Functions

static osg::Node * createMenu (osgViewer::View *view)
osg::Image * make3DImage (const ImageList &images)
int usage (const std::string &msg)
int main (int argc, char **argv)

Typedef Documentation

typedef std::vector< osg::ref_ptr< osg::Image > > ImageList

Definition at line 194 of file osgearth_ocean.cpp.


Function Documentation

static osg::Node* createMenu ( osgViewer::View *  view) [static]

Definition at line 67 of file osgearth_ocean.cpp.

{
    using namespace osgEarth::Util::Controls;

    ControlCanvas* canvas = ControlCanvas::get( view );

    Grid* grid = new Grid();
    grid->setBackColor( 0, 0, 0, 0.5 );
    grid->setMargin( 5 );
    grid->setChildSpacing( 3 );
    grid->setVertAlign( Control::ALIGN_BOTTOM );
    int row = 0;

    grid->setControl( 1, row++, new LabelControl( "Ocean Demo", 18.0f, osg::Vec4(1,1,0,1) ) );
    grid->setControl( 1, row++, new LabelControl( "Zoom in to the coastline to see ocean effects.", 14.0f, osg::Vec4(.6,.6,.6,1) ) );

    grid->setControl( 0, row  , new LabelControl( "e" ) );
    grid->setControl( 1, row++, new LabelControl( "toggle ocean effects" ) );
    grid->setControl( 0, row  , new LabelControl( "m" ) );
    grid->setControl( 1, row++, new LabelControl( "toggle MSL adjustment" ) );
    grid->setControl( 0, row  , new LabelControl( "h/H" ) );
    grid->setControl( 1, row++, new LabelControl( "inc/dec wave height" ) );
    grid->setControl( 0, row  , new LabelControl( "p/P" ) );
    grid->setControl( 1, row++, new LabelControl( "inc/dec wave period" ) );
    grid->setControl( 0, row  , new LabelControl( "c/C" ) );
    grid->setControl( 1, row++, new LabelControl( "inc/dec ocean modulation color" ) );
    grid->setControl( 0, row  , new LabelControl( "a/A" ) );
    grid->setControl( 1, row++, new LabelControl( "inc/dec shimmer effect period" ) );
    grid->setControl( 0, row  , new LabelControl( "j/J" ) );
    grid->setControl( 1, row++, new LabelControl( "inc/dec surface image size" ) );
    grid->setControl( 0, row  , new LabelControl( "i" ) );
    grid->setControl( 1, row++, new LabelControl( "toggle ocean mask inversion" ) );
    grid->setControl( 0, row  , new LabelControl( "w" ) );
    grid->setControl( 1, row++, new LabelControl( "toggle wireframe mode" ) );

    canvas->addControl( grid );
    return canvas;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 229 of file osgearth_ocean.cpp.

{
    osg::ArgumentParser arguments(&argc,argv);

    std::string maskLayerName = "ocean";
    while( arguments.read("--mask-layer", maskLayerName) );

    bool invertMask = arguments.isOption("--invert-mask");

    osg::Group* group = new osg::Group;

    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);   
    if ( !loadedModel.valid() )
        return usage( "Failed to load an earth file." );

    osgEarth::Util::OceanSurfaceNode* ocean = new osgEarth::Util::OceanSurfaceNode();

    if ( !maskLayerName.empty() )
    {
        osgEarth::MapNode* mapNode = osgEarth::MapNode::findMapNode( loadedModel.get() );
        if ( mapNode )
        {
            osgEarth::MapFrame mapf( mapNode->getMap() );
            ocean->setOceanMaskImageLayer( mapf.getImageLayerByName( maskLayerName ) );
        }
    }

    ocean->setInvertMask( !invertMask );

    // install some water-surface images for an interesting shimmering effect:
    ImageList waterImages;
    waterImages.push_back( osgDB::readImageFile("../data/watersurface1.png") );
    waterImages.push_back( osgDB::readImageFile("../data/watersurface2.png") );
    waterImages.push_back( osgDB::readImageFile("../data/watersurface3.png") );
    waterImages.push_back( osgDB::readImageFile("../data/watersurface4.png") );

    osg::ref_ptr<osg::Image> waterImage = make3DImage(waterImages);    
    ocean->setOceanSurfaceImage( waterImage.get() );

    // Find the MapNode and add the ocean as a terrain decorator.
    osgEarth::MapNode* mapNode = osgEarth::MapNode::findMapNode( loadedModel.get() );
    mapNode->addTerrainDecorator( ocean );

    // assemble the rest of the scene graph and go
    osgViewer::Viewer viewer(arguments);

    group->addChild( loadedModel.get() );
    group->addChild( createMenu(&viewer) );
    viewer.setSceneData(group);
    
    viewer.setCameraManipulator( new osgEarth::Util::EarthManipulator() );

    viewer.addEventHandler(new MyEventHandler(ocean));
    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
    viewer.addEventHandler(new osgViewer::StatsHandler);

    return viewer.run();
}

Here is the call graph for this function:

osg::Image* make3DImage ( const ImageList images)

Definition at line 196 of file osgearth_ocean.cpp.

{
    MyGraphicsContext gc;
    osg::notify(osg::NOTICE) << "Made graphic context " << std::endl;
    /*for (unsigned int i = 0; i < images.size(); ++i)
    {
        images[i]->scaleImage(256, 256, 1);
        osg::notify(osg::NOTICE) << "Scaled image " << i << std::endl;
    }*/

    osg::Image* image3D = new osg::Image;
    image3D->allocateImage(images[0]->s(), images[0]->t(), images.size(),
                           images[0]->getPixelFormat(), images[0]->getDataType());
    
    for (unsigned int i = 0; i < images.size(); ++i)
    {
        image3D->copySubImage(0, 0, i, images[i].get());
    }
    image3D->setInternalTextureFormat(images[0]->getInternalTextureFormat());
    return image3D;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int usage ( const std::string &  msg)

Definition at line 219 of file osgearth_ocean.cpp.

{
    OE_NOTICE
        << msg << std::endl
        << "USAGE: osgearth_ocean [--mask-layer <layername>] [--invert-mask] <earthfile>" << std::endl
        << "(note: <layername> defaults to \"ocean\")" << std::endl;
    return -1;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines