osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarth/MaskLayer.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 <osgEarth/MaskLayer>
00020 #include <osgEarth/Map>
00021 
00022 #define LC "[MaskLayer] "
00023 
00024 using namespace osgEarth;
00025 //------------------------------------------------------------------------
00026 
00027 MaskLayerOptions::MaskLayerOptions( const ConfigOptions& options ) :
00028 ConfigOptions( options )
00029 {
00030     setDefaults();
00031     fromConfig( _conf ); 
00032 }
00033 
00034 MaskLayerOptions::MaskLayerOptions( const std::string& name, const MaskSourceOptions& driverOptions ) :
00035 ConfigOptions()
00036 {
00037     setDefaults();
00038     fromConfig( _conf );
00039     _name = name;
00040     _driver = driverOptions;
00041 }
00042 
00043 void
00044 MaskLayerOptions::setDefaults()
00045 {
00046     //nop
00047 }
00048 
00049 Config
00050 MaskLayerOptions::getConfig() const
00051 {
00052     Config conf = ConfigOptions::getConfig();
00053 
00054     conf.updateIfSet( "name", _name );
00055 
00056     return conf;
00057 }
00058 
00059 void
00060 MaskLayerOptions::fromConfig( const Config& conf )
00061 {
00062     conf.getIfSet( "name", _name );
00063 }
00064 
00065 void
00066 MaskLayerOptions::mergeConfig( const Config& conf )
00067 {
00068     ConfigOptions::mergeConfig( conf );
00069     fromConfig( conf );
00070 }
00071 
00072 //------------------------------------------------------------------------
00073 
00074 MaskLayer::MaskLayer( const MaskLayerOptions& options ) :
00075 _initOptions( options )
00076 {
00077     copyOptions();
00078 }
00079 
00080 MaskLayer::MaskLayer( const std::string& name, const MaskSourceOptions& options ) :
00081 _initOptions( MaskLayerOptions( name, options ) )
00082 {
00083     copyOptions();
00084 }
00085 
00086 MaskLayer::MaskLayer( const MaskLayerOptions& options, MaskSource* source ) :
00087 _maskSource( source ),
00088 _initOptions( options )
00089 {
00090     copyOptions();
00091 }
00092 
00093 void
00094 MaskLayer::copyOptions()
00095 {
00096     _runtimeOptions = _initOptions;
00097 }
00098 
00099 void
00100 MaskLayer::initialize( const std::string& referenceURI, const Map* map )
00101 {
00102     _referenceURI = referenceURI;
00103 
00104     if ( !_maskSource.valid() && _initOptions.driver().isSet() )
00105     {
00106         _maskSource = MaskSourceFactory::create( *_initOptions.driver() );
00107     }
00108 
00109     if ( _maskSource.valid() )
00110     {
00111         _maskSource->initialize( _referenceURI, map );
00112     }
00113 }
00114 
00115 osg::Vec3dArray*
00116 MaskLayer::getOrCreateBoundary( float heightScale, const SpatialReference *srs, ProgressCallback* progress )
00117 {
00118     if ( _maskSource.valid() )
00119     {
00120         // if the model source has changed, regenerate the node.
00121         if ( _boundary.valid() && !_maskSource->inSyncWith(_maskSourceRev) )
00122         {
00123             _boundary = 0L;
00124         }
00125 
00126         if ( !_boundary.valid() )
00127         {
00128                         _boundary = _maskSource->createBoundary( srs, progress );
00129 
00130                         for (osg::Vec3dArray::iterator vIt = _boundary->begin(); vIt != _boundary->end(); ++vIt)
00131                                 vIt->z() = vIt->z() * heightScale;
00132 
00133             _maskSource->sync( _maskSourceRev );
00134         }
00135     }
00136 
00137     return _boundary.get();
00138 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines