osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/earth/EarthFileSerializer1.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 #include "EarthFileSerializer"
00020 
00021 using namespace osgEarth;
00022 
00023 MapNode*
00024 EarthFileSerializer1::deserialize( const Config& conf, const std::string& referenceURI ) const
00025 {
00026     // piece together a MapOptions, TerrainOptions, and MapNodeOptions:
00027     Config mapOptionsConf;
00028     if ( conf.hasValue("name") )
00029         mapOptionsConf.update("name", conf.value("name"));
00030     if ( conf.hasValue("type") )
00031         mapOptionsConf.update("type", conf.value("type"));
00032 
00033     Config terrainOptionsConf;
00034     Config mapNodeOptionsConf;
00035 
00036     for( ConfigSet::const_iterator i = conf.children().begin(); i != conf.children().end(); ++i )
00037     {
00038         const Config& child = *i;
00039 
00040         if (child.key() == "profile" || 
00041             child.key() == "cache" )
00042         {
00043             if (child.key() == "cache")
00044             {
00045                 std::string type = child.attr("type");
00046                 if (type.empty()) type = "tms";
00047                 Config cacheConfig(child);
00048                 cacheConfig.attrs()["driver"] = type;
00049                 mapOptionsConf.add( cacheConfig );
00050             }
00051             else
00052             {
00053                 mapOptionsConf.add( child );
00054             }
00055         }
00056         else if (
00057             child.key() == "proxy" ||
00058             child.key() == "cache_only" )
00059         {
00060             mapNodeOptionsConf.add( child );
00061         }
00062         else if (
00063             child.key() == "vertical_scale" ||
00064             child.key() == "sample_ratio" ||
00065             child.key() == "min_tile_range_factor" ||
00066             child.key() == "normalize_edges" ||
00067             child.key() == "combine_layers" ||
00068             child.key() == "loading_policy" || 
00069             child.key() == "max_lod" ||
00070             child.key() == "lighting" )
00071         {
00072             terrainOptionsConf.add( child );
00073         }
00074         else if ( child.key() == "layering_technique" )
00075         {
00076             if ( child.value() == "multipass" )
00077                 terrainOptionsConf.update( "compositor", "multipass");
00078         }
00079     }
00080     MapOptions mapOptions( mapOptionsConf );
00081     MapNodeOptions mapNodeOptions( mapNodeOptionsConf );
00082     mapNodeOptions.setTerrainOptions( TerrainOptions(terrainOptionsConf) );
00083 
00084     //Set the reference URI of the cache config.
00085     if (mapOptions.cache().isSet())
00086     {
00087         mapOptions.cache()->setReferenceURI(referenceURI);
00088     }
00089 
00090     // the reference URI allows osgEarth to resolve relative paths within the configuration
00091     mapOptions.referenceURI() = referenceURI;
00092 
00093     Map* map = new Map( mapOptions );
00094 
00095     // Read the layers in LAST (otherwise they will not benefit from the cache/profile configuration)
00096 
00097     // Image layers:
00098     ConfigSet images = conf.children( "image" );
00099     for( ConfigSet::const_iterator i = images.begin(); i != images.end(); i++ )
00100     {
00101         Config layerDriverConf = *i;
00102         layerDriverConf.add( "default_tile_size", "256" );
00103 
00104         ImageLayerOptions layerOpt( layerDriverConf );
00105         layerOpt.name() = layerDriverConf.value("name");
00106         layerOpt.driver() = TileSourceOptions( layerDriverConf );
00107 
00108         map->addImageLayer( new ImageLayer(layerOpt) );
00109     }
00110 
00111     // Elevation layers:
00112     for( int k=0; k<2; ++k )
00113     {
00114         std::string tagName = k == 0 ? "elevation" : "heightfield"; // support both :)
00115 
00116         ConfigSet heightfields = conf.children( tagName );
00117         for( ConfigSet::const_iterator i = heightfields.begin(); i != heightfields.end(); i++ )
00118         {
00119             Config layerDriverConf = *i;
00120             layerDriverConf.add( "default_tile_size", "16" );
00121 
00122             ElevationLayerOptions layerOpt( layerDriverConf );
00123             layerOpt.name() = layerDriverConf.value( "name" );
00124             layerOpt.driver() = TileSourceOptions( layerDriverConf );
00125 
00126             map->addElevationLayer( new ElevationLayer(layerOpt) );
00127         }
00128     }
00129 
00130     // Model layers:
00131     ConfigSet models = conf.children( "model" );
00132     for( ConfigSet::const_iterator i = models.begin(); i != models.end(); i++ )
00133     {
00134         const Config& layerDriverConf = *i;
00135 
00136         ModelLayerOptions layerOpt( layerDriverConf );
00137         layerOpt.name() = layerDriverConf.value( "name" );
00138         layerOpt.driver() = ModelSourceOptions( layerDriverConf );
00139 
00140         map->addModelLayer( new ModelLayer(layerOpt) );
00141         //map->addModelLayer( new ModelLayer( i->value("name"), ModelSourceOptions(*i) ) );
00142     }
00143 
00144     // Mask layer:
00145     ConfigSet masks = conf.children( "mask" );
00146     for( ConfigSet::const_iterator i = masks.begin(); i != masks.end(); i++ )
00147     {
00148         Config maskLayerConf = *i;
00149 
00150         MaskLayerOptions options(maskLayerConf);
00151         options.name() = maskLayerConf.value( "name" );
00152         options.driver() = MaskSourceOptions(options);
00153 
00154         map->addTerrainMaskLayer( new MaskLayer(options) );
00155     }
00156 
00157     return new MapNode( map, mapNodeOptions );
00158 }
00159 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines