osgEarth 2.1.1
|
#include <osg/Notify>
#include <osgGA/StateSetManipulator>
#include <osgGA/GUIEventHandler>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgEarth/MapNode>
#include <osgEarth/XmlUtils>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osgEarthUtil/Controls>
#include <osgEarthUtil/Graticule>
#include <osgEarthUtil/SkyNode>
#include <osgEarthUtil/Viewpoint>
#include <osgEarthUtil/Formatters>
#include <osgEarthUtil/Annotation>
#include <osgEarthSymbology/Color>
#include <osgEarthDrivers/kml/KML>
Go to the source code of this file.
Classes | |
struct | SkySliderHandler |
struct | ToggleNodeHandler |
struct | ClickViewpointHandler |
struct | MouseCoordsHandler |
struct | KMLUIBuilder |
struct | ViewpointHandler |
Functions | |
int | usage (const std::string &msg) |
void | createControlPanel (osgViewer::View *view, std::vector< Viewpoint > &vps) |
void | addMouseCoords (osgViewer::Viewer *viewer, osgEarth::MapNode *mapNode) |
int | main (int argc, char **argv) |
Variables | |
static EarthManipulator * | s_manip = 0L |
static Control * | s_controlPanel = 0L |
static SkyNode * | s_sky = 0L |
static bool | s_dms = false |
static bool | s_mgrs = false |
void addMouseCoords | ( | osgViewer::Viewer * | viewer, |
osgEarth::MapNode * | mapNode | ||
) |
Definition at line 269 of file osgearth_viewer.cpp.
{ ControlCanvas* canvas = ControlCanvas::get( viewer ); LabelControl* mouseCoords = new LabelControl(); mouseCoords->setHorizAlign(Control::ALIGN_CENTER ); mouseCoords->setVertAlign(Control::ALIGN_BOTTOM ); mouseCoords->setBackColor(0,0,0,0.5); mouseCoords->setSize(400,50); mouseCoords->setMargin( 10 ); canvas->addControl( mouseCoords ); viewer->addEventHandler( new MouseCoordsHandler(mouseCoords, mapNode ) ); }
void createControlPanel | ( | osgViewer::View * | view, |
std::vector< Viewpoint > & | vps | ||
) |
Definition at line 162 of file osgearth_viewer.cpp.
{ ControlCanvas* canvas = ControlCanvas::get( view ); VBox* main = new VBox(); main->setBackColor(0,0,0,0.5); main->setMargin( 10 ); main->setPadding( 10 ); main->setChildSpacing( 10 ); main->setAbsorbEvents( true ); main->setVertAlign( Control::ALIGN_BOTTOM ); if ( vps.size() > 0 ) { // the viewpoint container: Grid* g = new Grid(); g->setChildSpacing( 0 ); g->setChildVertAlign( Control::ALIGN_CENTER ); unsigned i; for( i=0; i<vps.size(); ++i ) { const Viewpoint& vp = vps[i]; std::stringstream buf; buf << (i+1); Control* num = new LabelControl(buf.str(), 16.0f, osg::Vec4f(1,1,0,1)); num->setPadding( 4 ); g->setControl( 0, i, num ); Control* vpc = new LabelControl(vp.getName().empty() ? "<no name>" : vp.getName(), 16.0f); vpc->setPadding( 4 ); vpc->setHorizFill( true ); vpc->setActiveColor( Color::Blue ); vpc->addEventHandler( new ClickViewpointHandler(vp) ); g->setControl( 1, i, vpc ); } main->addControl( g ); } // sky time slider: if ( s_sky ) { HBox* skyBox = new HBox(); skyBox->setChildVertAlign( Control::ALIGN_CENTER ); skyBox->setChildSpacing( 10 ); skyBox->setHorizFill( true ); skyBox->addControl( new LabelControl("Time: ", 16) ); HSliderControl* skySlider = new HSliderControl( 0.0f, 24.0f, 18.0f ); skySlider->setBackColor( Color::Gray ); skySlider->setHeight( 12 ); skySlider->setHorizFill( true, 200 ); skySlider->addEventHandler( new SkySliderHandler ); skyBox->addControl( skySlider ); main->addControl( skyBox ); } canvas->addControl( main ); s_controlPanel = main; }
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 316 of file osgearth_viewer.cpp.
{ osg::ArgumentParser arguments(&argc,argv); osg::DisplaySettings::instance()->setMinimumNumStencilBits( 8 ); osgViewer::Viewer viewer(arguments); bool useAutoClip = arguments.read( "--autoclip" ); bool useSky = arguments.read( "--sky" ); s_dms = arguments.read( "--dms" ); s_mgrs = arguments.read( "--mgrs" ); std::string kmlFile; arguments.read( "--kml", kmlFile ); // load the .earth file from the command line. osg::Node* earthNode = osgDB::readNodeFiles( arguments ); if (!earthNode) return usage( "Unable to load earth model." ); s_manip = new EarthManipulator(); s_manip->getSettings()->setArcViewpointTransitions( true ); viewer.setCameraManipulator( s_manip ); osg::Group* root = new osg::Group(); root->addChild( earthNode ); // create a graticule and clip plane handler. Graticule* graticule = 0L; osgEarth::MapNode* mapNode = osgEarth::MapNode::findMapNode( earthNode ); if ( mapNode ) { const Config& externals = mapNode->externalConfig(); if ( mapNode->getMap()->isGeocentric() ) { // Sky model. Config skyConf = externals.child( "sky" ); if ( !skyConf.empty() ) useSky = true; if ( useSky ) { double hours = skyConf.value( "hours", 12.0 ); s_sky = new SkyNode( mapNode->getMap() ); s_sky->setDateTime( 2011, 3, 6, hours ); s_sky->attach( &viewer ); root->addChild( s_sky ); } if ( externals.hasChild("autoclip") ) useAutoClip = externals.child("autoclip").boolValue( useAutoClip ); // the AutoClipPlaneHandler will automatically adjust the near/far clipping // planes based on your view of the horizon. This prevents near clipping issues // when you are very close to the ground. If your app never brings a user very // close to the ground, you may not need this. if ( useSky || useAutoClip ) { viewer.getCamera()->addEventCallback( new AutoClipPlaneCallback() ); } } // read in viewpoints, if any std::vector<Viewpoint> viewpoints; const ConfigSet children = externals.children("viewpoint"); if ( children.size() > 0 ) { for( ConfigSet::const_iterator i = children.begin(); i != children.end(); ++i ) viewpoints.push_back( Viewpoint(*i) ); viewer.addEventHandler( new ViewpointHandler(viewpoints) ); } // Add a control panel to the scene root->addChild( ControlCanvas::get( &viewer ) ); if ( viewpoints.size() > 0 || s_sky ) createControlPanel(&viewer, viewpoints); addMouseCoords( &viewer, mapNode ); // Load a KML file if specified if ( !kmlFile.empty() ) { KMLOptions kmlo; kmlo.defaultIconImage() = URI("http://www.osgearth.org/chrome/site/pushpin_yellow.png").readImage(); osg::Node* kml = KML::load( URI(kmlFile), mapNode, kmlo ); if ( kml ) { root->addChild( kml ); KMLUIBuilder uibuilder( ControlCanvas::get(&viewer) ); root->accept( uibuilder ); } } } // osgEarth benefits from pre-compilation of GL objects in the pager. In newer versions of // OSG, this activates OSG's IncrementalCompileOpeartion in order to avoid frame breaks. viewer.getDatabasePager()->setDoPreCompile( true ); viewer.setSceneData( root ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgViewer::ThreadingHandler()); viewer.addEventHandler(new osgViewer::LODScaleHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }
int usage | ( | const std::string & | msg | ) |
Definition at line 45 of file osgearth_viewer.cpp.
{ OE_NOTICE << msg << std::endl; OE_NOTICE << std::endl; OE_NOTICE << "USAGE: osgearth_viewer [options] file.earth" << std::endl; OE_NOTICE << " --sky : activates the atmospheric model" << std::endl; OE_NOTICE << " --autoclip : activates the auto clip-plane handler" << std::endl; OE_NOTICE << " --dms : format coordinates as degrees/minutes/seconds" << std::endl; OE_NOTICE << " --mgrs : format coordinates as MGRS" << std::endl; return -1; }
Control* s_controlPanel = 0L [static] |
Definition at line 60 of file osgearth_viewer.cpp.
bool s_dms = false [static] |
Definition at line 62 of file osgearth_viewer.cpp.
EarthManipulator* s_manip = 0L [static] |
Definition at line 59 of file osgearth_viewer.cpp.
bool s_mgrs = false [static] |
Definition at line 63 of file osgearth_viewer.cpp.
Definition at line 61 of file osgearth_viewer.cpp.