osgEarth 2.1.1
Classes | Functions

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

#include <osg/Notify>
#include <osg/Shape>
#include <osg/ShapeDrawable>
#include <osg/Geode>
#include <osg/PagedLOD>
#include <osg/PolygonMode>
#include <osg/AutoTransform>
#include <osg/MatrixTransform>
#include <osgText/Text>
#include <osgGA/StateSetManipulator>
#include <osgGA/GUIEventHandler>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgUtil/LineSegmentIntersector>
#include <osgEarth/MapNode>
#include <osgEarth/FindNode>
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthDrivers/tms/TMSOptions>
#include <osgEarthDrivers/engine_seamless/PatchInfo>
#include <osgEarthDrivers/engine_seamless/SeamlessOptions>
#include <sstream>
Include dependency graph for osgearth_seamless.cpp:

Go to the source code of this file.

Classes

struct  QueryTileHandler

Functions

static osg::MatrixTransform * createFlag ()
static void updateFlag (osg::MatrixTransform *xf, const osg::Matrix &mat, const osgEarth::TileKey &key)
int main (int argc, char **argv)

Function Documentation

static osg::MatrixTransform* createFlag ( ) [static]

Definition at line 49 of file osgearth_seamless.cpp.

{
    osg::Cylinder* c = new osg::Cylinder( osg::Vec3d(0,0,0), 2.0f, 250.f );
    osg::Geode* g = new osg::Geode();
    g->addDrawable( new osg::ShapeDrawable( c ) );
    osgText::Text* text = new osgText::Text();
    text->setCharacterSizeMode( osgText::Text::SCREEN_COORDS );
    text->setCharacterSize( 72.f );
    text->setBackdropType( osgText::Text::OUTLINE );
    text->setText( "00000000000000" );
    text->setAutoRotateToScreen( true );
    text->setPosition( osg::Vec3d( 0, 0, 125 ) );
    text->setDataVariance( osg::Object::DYNAMIC );
    g->addDrawable( text );
    osg::StateSet* ss = g->getOrCreateStateSet();
    ss->setAttribute(new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK,
                                          osg::PolygonMode::FILL),
                     osg::StateAttribute::ON | osg::StateAttribute::PROTECTED);
    osg::AutoTransform* at = new osg::AutoTransform();
    at->setAutoScaleToScreen( true );
    at->addChild( g );
    at->getOrCreateStateSet()->setMode( GL_LIGHTING, 0 );
    osg::MatrixTransform* xf = new osg::MatrixTransform();
    xf->addChild( at );
    xf->setDataVariance( osg::Object::DYNAMIC );
    return xf;
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 159 of file osgearth_seamless.cpp.

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

    osgViewer::Viewer viewer(arguments);

    // install the programmable manipulator.
    osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator();
    viewer.setCameraManipulator( manip );

    osgEarth::MapNode* mapNode = NULL;

    osg::Node* loadedNode = osgDB::readNodeFiles( arguments );
    if (!loadedNode)
    {
        // load up a map with an elevation layer:
        osgEarth::Map *map = new osgEarth::Map();

        // Add some imagery
        {
            TMSOptions tms;
            tms.url() = "http://demo.pelicanmapping.com/rmweb/data/bluemarble-tms/tms.xml";
            map->addImageLayer( new osgEarth::ImageLayer( "BLUEMARBLE", tms ) );
        }

        // Add some elevation
        {
            TMSOptions tms;
            tms.url() = "http://demo.pelicanmapping.com/rmweb/data/srtm30_plus_tms/tms.xml";
            map->addElevationLayer( new osgEarth::ElevationLayer( "SRTM", tms ) );
        }

        MapNodeOptions nodeOptions;
        nodeOptions.setTerrainOptions( osgEarth::Drivers::SeamlessOptions() );

        mapNode = new osgEarth::MapNode( map, nodeOptions );
    }
    else
    {
        mapNode = findTopMostNodeOfType<osgEarth::MapNode>( loadedNode );
    }

    osg::Group* root = new osg::Group();

    // The MapNode will render the Map object in the scene graph.
    mapNode->setNodeMask( 0x01 );
    root->addChild( mapNode );

    manip->setNode(mapNode->getTerrainEngine());
    if ( mapNode->getMap()->isGeocentric() )
    {
        manip->setHomeViewpoint( 
            osgEarth::Util::Viewpoint( osg::Vec3d( -90, 0, 0 ), 0.0, -90.0, 5e7 ) );

        // add a handler that will automatically calculate good clipping planes
        viewer.addEventHandler( new osgEarth::Util::AutoClipPlaneHandler() );
    }
    // A flag so we can see where we clicked
    osg::MatrixTransform* flag = createFlag();
    flag->setNodeMask( 0x02 );
    root->addChild( flag );

    viewer.setSceneData( root );

    // An event handler that will respond to mouse clicks:
    viewer.addEventHandler(
        new QueryTileHandler(flag, mapNode->getMap()->getProfile()->getSRS()));

    // add some stock OSG handlers:
    viewer.addEventHandler(new osgViewer::StatsHandler());
    viewer.addEventHandler(new osgViewer::WindowSizeHandler());
    viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));

    return viewer.run();
}

Here is the call graph for this function:

static void updateFlag ( osg::MatrixTransform *  xf,
const osg::Matrix &  mat,
const osgEarth::TileKey key 
) [static]

Definition at line 78 of file osgearth_seamless.cpp.

{
    osg::Geode* g = static_cast<osg::Geode*>( xf->getChild(0)->asGroup()->getChild(0) );
    std::stringstream buf;
    buf << key.getLevelOfDetail() << " " << key.getTileX() << " "
        << key.getTileY();
    std::string bufStr;
    bufStr = buf.str();
    static_cast<osgText::Text*>( g->getDrawable(1) )->setText( bufStr );
    xf->setMatrix( mat );
}

Here is the call graph for this function:

Here is the caller graph for this function:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines