osgEarth 2.1.1
|
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 <osgDB/FileNameUtils> 00021 #include <osgDB/FileUtils> 00022 00023 #include <osg/io_utils> 00024 00025 #include <osgEarth/Common> 00026 #include <osgEarth/Map> 00027 #include <osgEarth/CacheSeed> 00028 #include <osgEarth/MapNode> 00029 #include <osgEarth/Registry> 00030 00031 #include <osgEarth/Caching> 00032 00033 #include <iostream> 00034 #include <sstream> 00035 #include <iterator> 00036 00037 using namespace osgEarth; 00038 00039 #define LC "[osgearth_cache] " 00040 00041 int list( osg::ArgumentParser& args ); 00042 int seed( osg::ArgumentParser& args ); 00043 int purge( osg::ArgumentParser& args ); 00044 int usage( const std::string& msg ); 00045 int message( const std::string& msg ); 00046 00047 00048 int 00049 main(int argc, char** argv) 00050 { 00051 osg::ArgumentParser args(&argc,argv); 00052 00053 if ( args.read( "--seed") ) 00054 return seed( args ); 00055 else if ( args.read( "--list" ) ) 00056 return list( args ); 00057 else if ( args.read( "--purge" ) ) 00058 return purge( args ); 00059 else 00060 return usage(""); 00061 } 00062 00063 int 00064 usage( const std::string& msg ) 00065 { 00066 if ( !msg.empty() ) 00067 { 00068 std::cout << msg << std::endl; 00069 } 00070 00071 std::cout 00072 << std::endl 00073 << "USAGE: osgearth_cache" << std::endl 00074 << std::endl 00075 << " --list file.earth ; Lists info about the cache in a .earth file" << std::endl 00076 << std::endl 00077 << " --seed file.earth ; Seeds the cache in a .earth file" << std::endl 00078 << " [--min-level level] ; Lowest LOD level to seed (default=0)" << std::endl 00079 << " [--max-level level] ; Highest LOD level to seed (defaut=highest available)" << std::endl 00080 << " [--bounds xmin ymin xmax ymax] ; Geospatial bounding box to seed" << std::endl 00081 << " [--cache-path path] ; Overrides the cache path in the .earth file" << std::endl 00082 << " [--cache-type type] ; Overrides the cache type in the .earth file" << std::endl 00083 //<< std::endl 00084 //<< " --purge file.earth ; Purges cached data from the cache in a .earth file" << std::endl 00085 //<< " [--layer name] ; Named layer for which to purge the cache" << std::endl 00086 //<< " [--all] ; Purge all data from the cache" << std::endl 00087 << std::endl; 00088 00089 return -1; 00090 } 00091 00092 int message( const std::string& msg ) 00093 { 00094 if ( !msg.empty() ) 00095 { 00096 std::cout << msg << std::endl << std::endl; 00097 } 00098 return 0; 00099 } 00100 00101 00102 int 00103 seed( osg::ArgumentParser& args ) 00104 { 00105 //Read the min level 00106 unsigned int minLevel = 0; 00107 while (args.read("--min-level", minLevel)); 00108 00109 //Read the max level 00110 unsigned int maxLevel = 5; 00111 while (args.read("--max-level", maxLevel)); 00112 00113 //Read the bounds 00114 Bounds bounds(0, 0, 0, 0); 00115 while (args.read("--bounds", bounds.xMin(), bounds.yMin(), bounds.xMax(), bounds.yMax())); 00116 while (args.read("-b", bounds.xMin(), bounds.yMin(), bounds.xMax(), bounds.yMax())); 00117 00118 //Read the cache override directory 00119 std::string cachePath; 00120 while (args.read("--cache-path", cachePath)); 00121 00122 //Read the cache type 00123 std::string cacheType; 00124 while (args.read("--cache-type", cacheType)); 00125 00126 bool quiet = args.read("--quiet"); 00127 00128 //Read in the earth file. 00129 osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles( args ); 00130 if ( !node.valid() ) 00131 return usage( "Failed to read .earth file." ); 00132 00133 MapNode* mapNode = MapNode::findMapNode( node.get() ); 00134 if ( !mapNode ) 00135 return usage( "Input file was not a .earth file" ); 00136 00137 CacheSeed seeder; 00138 seeder.setMinLevel( minLevel ); 00139 seeder.setMaxLevel( maxLevel ); 00140 seeder.setBounds( bounds ); 00141 if (!quiet) 00142 { 00143 seeder.setProgressCallback(new ConsoleProgressCallback); 00144 } 00145 seeder.seed( mapNode->getMap() ); 00146 00147 return 0; 00148 } 00149 00150 int 00151 list( osg::ArgumentParser& args ) 00152 { 00153 osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles( args ); 00154 if ( !node.valid() ) 00155 return usage( "Failed to read .earth file." ); 00156 00157 MapNode* mapNode = MapNode::findMapNode( node.get() ); 00158 if ( !mapNode ) 00159 return usage( "Input file was not a .earth file" ); 00160 00161 Map* map = mapNode->getMap(); 00162 const Cache* cache = map->getCache(); 00163 00164 if ( !cache ) 00165 return message( "Earth file does not contain a cache." ); 00166 00167 std::cout 00168 << "Cache config = " << cache->getCacheOptions().getConfig().toString() << std::endl; 00169 00170 MapFrame mapf( mapNode->getMap() ); 00171 00172 TerrainLayerVector layers; 00173 std::copy( mapf.imageLayers().begin(), mapf.imageLayers().end(), std::back_inserter(layers) ); 00174 std::copy( mapf.elevationLayers().begin(), mapf.elevationLayers().end(), std::back_inserter(layers) ); 00175 00176 for( TerrainLayerVector::const_iterator i =layers.begin(); i != layers.end(); ++i ) 00177 { 00178 TerrainLayer* layer = i->get(); 00179 const CacheSpec& spec = layer->getCacheSpec(); 00180 std::cout 00181 << "Layer = \"" << layer->getName() << "\", cacheId = " << spec.cacheId() << std::endl; 00182 } 00183 00184 return 0; 00185 } 00186 00187 int 00188 purge( osg::ArgumentParser& args ) 00189 { 00190 return usage( "Sorry, but purge is not yet implemented." ); 00191 00192 osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles( args ); 00193 if ( !node.valid() ) 00194 return usage( "Failed to read .earth file." ); 00195 00196 MapNode* mapNode = MapNode::findMapNode( node.get() ); 00197 if ( !mapNode ) 00198 return usage( "Input file was not a .earth file" ); 00199 00200 Map* map = mapNode->getMap(); 00201 const Cache* cache = map->getCache(); 00202 00203 if ( !cache ) 00204 return message( "Earth file does not contain a cache." ); 00205 }