osgEarth 2.1.1

/home/cube/sources/osgearth/src/applications/osgearth_kml/osgearth_kml.cpp

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003 * Copyright 2008-2010 Pelican Mapping
00004 * http://osgearth.org
00005 *
00006 * osgEarth is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU Lesser General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU Lesser General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU Lesser General Public License
00017 * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018 */
00019 
00020 #include <osg/Notify>
00021 #include <osgGA/StateSetManipulator>
00022 #include <osgGA/GUIEventHandler>
00023 #include <osgViewer/Viewer>
00024 #include <osgViewer/ViewerEventHandlers>
00025 #include <osgEarth/MapNode>
00026 #include <osgEarthUtil/EarthManipulator>
00027 #include <osgEarthUtil/AutoClipPlaneHandler>
00028 #include <osgEarthDrivers/kml/KML>
00029 
00030 using namespace osgEarth::Util;
00031 
00032 int
00033 usage( const std::string& msg )
00034 {
00035     OE_NOTICE << msg << std::endl;
00036     OE_NOTICE << std::endl;
00037     OE_NOTICE << "USAGE: osgearth_kml file.earth file.kml" << std::endl;
00038     return -1;
00039 }
00040 
00041 int
00042 main(int argc, char** argv)
00043 {
00044     osg::ArgumentParser arguments(&argc,argv);
00045     osgViewer::Viewer viewer(arguments);
00046 
00047     osg::Group* root = new osg::Group();
00048 
00049     // load the .earth file from the command line.
00050     MapNode* mapNode = MapNode::load( arguments );
00051     if (!mapNode)
00052         return usage( "Unable to load earth model." );
00053 
00054     root->addChild( mapNode );
00055 
00056     for( int a = 1; a < argc; ++a )
00057     {
00058         std::string kmlFile( argv[a] );
00059         if ( endsWith( kmlFile, ".kml" ) )
00060         {
00061             osg::ref_ptr<osgDB::Options> options = new osgDB::Options();
00062             options->setPluginData( "osgEarth::MapNode", mapNode );
00063             osg::Node* kml = osgDB::readNodeFile( kmlFile, options.get() );
00064             if ( kml )
00065                 root->addChild( kml );
00066         }
00067     }
00068 
00069     viewer.setCameraManipulator( new EarthManipulator() );
00070     viewer.setSceneData( root );
00071     viewer.getDatabasePager()->setDoPreCompile( true );
00072 
00073     // add some stock OSG handlers:
00074     viewer.addEventHandler(new osgViewer::StatsHandler());
00075     viewer.addEventHandler(new osgViewer::WindowSizeHandler());
00076     viewer.addEventHandler(new osgViewer::ThreadingHandler());
00077     viewer.addEventHandler(new osgViewer::LODScaleHandler());
00078     viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
00079     viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage()));
00080 
00081     return viewer.run();
00082 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines