2
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
3
* Copyright 2008-2010 Pelican Mapping
6
* osgEarth is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>
20
#ifndef OSGEARTH_TERRAIN_LAYER_H
21
#define OSGEARTH_TERRAIN_LAYER_H 1
23
#include <osgEarth/Common>
24
#include <osgEarth/Layer>
25
#include <osgEarth/Config>
26
#include <osgEarth/TileSource>
27
#include <osgEarth/Profile>
28
#include <osgEarth/Caching>
29
#include <osgEarth/ThreadingUtils>
34
* Initialization (and serializable) options for a terrain layer.
36
class OSGEARTH_EXPORT TerrainLayerOptions : public ConfigOptions
39
TerrainLayerOptions( const ConfigOptions& options =ConfigOptions() );
40
TerrainLayerOptions( const std::string& name, const TileSourceOptions& driverOptions );
43
* The readable name of the layer.
45
std::string& name() { return _name; }
46
const std::string& name() const { return _name; }
49
* Gets the explicit profile setup for this map layer. By default, the layer will
50
* try to automatically determine the Profile from the tile source. This property
51
* sets it explicitly instead.
53
optional<ProfileOptions>& profile() { return _profile; }
54
const optional<ProfileOptions>& profile() const { return _profile; }
57
* Options for the underlyint tile source driver.
59
optional<TileSourceOptions>& driver() { return _driver; }
60
const optional<TileSourceOptions>& driver() const { return _driver; }
63
* Gets or sets the minimum level of detail for which this layer should generate data.
65
optional<int>& minLevel() { return _minLevel; }
66
const optional<int>& minLevel() const { return _minLevel; }
69
* The maximum level of detail for which this layer should generate data.
71
optional<int>& maxLevel() { return _maxLevel; }
72
const optional<int>& maxLevel() const { return _maxLevel; }
75
* Whether to render this layer with the map.
77
optional<bool>& enabled() { return _enabled; }
78
const optional<bool>& enabled() const { return _enabled; }
81
* Whether to use exact cropping if image cropping is necessary
83
optional<bool>& exactCropping() { return _exactCropping; }
84
const optional<bool>& exactCropping() const { return _exactCropping; }
87
* The desired tile size to reproject imagery to if necessary.
89
optional<unsigned int> reprojectedTileSize() { return _reprojectedTileSize; }
90
const optional<unsigned int> reprojectedTileSize() const { return _reprojectedTileSize; }
93
* The format that this MapLayer should use when caching.
95
optional<std::string>& cacheFormat() { return _cacheFormat; }
96
const optional<std::string>& cacheFormat() const { return _cacheFormat; }
99
* Whether to cache this layer or not.
101
optional<bool>& cacheEnabled() { return _cacheEnabled; }
102
const optional<bool>& cacheEnabled() const { return _cacheEnabled; }
105
* Whether to try to run this MapLayer strictly from the cache only.
107
optional<bool>& cacheOnly() { return _cacheOnly; }
108
const optional<bool>& cacheOnly() const { return _cacheOnly; }
111
* Explicit cache ID to uniquely identify the cache that matched this
112
* layer's tile source properties. This is usually automatically
113
* generated but you can override it here.
115
optional<std::string>& cacheId() { return _cacheId; }
116
const optional<std::string>& cacheId() const { return _cacheId; }
119
* The loading weight of this MapLayer (for threaded loading policies).
121
optional<float>& loadingWeight() { return _loadingWeight; }
122
const optional<float>& loadingWeight() const { return _loadingWeight; }
125
* The ratio used to expand the extent of a tile when the layer
126
* needs to be mosaiced to projected. This can be used to increase the
127
* number of tiles grabbed to ensure that enough data is grabbed to
128
* overlap the incoming tile.
130
optional<double>& edgeBufferRatio() { return _edgeBufferRatio;}
131
const optional<double>& edgeBufferRatio() const { return _edgeBufferRatio; }
134
virtual Config getConfig() const;
135
virtual void mergeConfig( const Config& conf );
138
void fromConfig( const Config& conf );
142
optional<ProfileOptions> _profile;
143
optional<TileSourceOptions> _driver;
144
optional<int> _minLevel;
145
optional<int> _maxLevel;
146
optional<std::string> _cacheFormat;
147
optional<bool> _cacheEnabled;
148
optional<bool> _cacheOnly;
149
optional<float> _loadingWeight;
150
optional<bool> _exactCropping;
151
optional<bool> _enabled;
152
optional<unsigned int> _reprojectedTileSize;
153
optional<double> _edgeBufferRatio;
154
optional<std::string> _cacheId;
158
* Runtime property notification callback for TerrainLayers.
160
struct TerrainLayerCallback : public osg::Referenced
162
virtual void onEnabledChanged( class TerrainLayer* layer ) { }
165
typedef void (TerrainLayerCallback::*TerrainLayerCallbackMethodPtr)(TerrainLayer* layer);
169
* A layer that comprises the terrain skin (image or elevation layer)
171
class OSGEARTH_EXPORT TerrainLayer : public Layer
176
TerrainLayer( TileSource* tileSource );
180
virtual const TerrainLayerOptions& getTerrainLayerOptions() const =0;
182
void setEnabled( bool value );
183
bool getEnabled() const { return _actualEnabled; }
186
* Gets the readable name of the map layer.
188
const std::string& getName() const {
189
return getTerrainLayerOptions().name(); }
192
* Gets the profile of this MapLayer
194
const Profile* getProfile() const;
197
* Gets the underlying TileSource engine that serves this map layer. Use with caution.
199
TileSource* getTileSource() const;
202
* Gets the tile size of the this MapLayer
204
unsigned int getTileSize() const { return _tileSize; }
207
* Gets the maximum data level of this MapLayer
209
unsigned int getMaxDataLevel() const;
212
* Whether the layer represents dynamic data, i.e. tile data that can change.
214
bool isDynamic() const;
216
const std::string& getCacheFormat() const { return _actualCacheFormat; }
221
* Whether the given key is valid for this layer
223
bool isKeyValid(const TileKey& key) const;
226
* Gets the Cache to be used on this TerrainLayer.
228
Cache* getCache() const { return _cache.get(); }
231
* Sets the cache to be used on this MapLayer
232
* TODO: is it legal to set this at any time?
234
void setCache( Cache* cache );
237
* Gets the key that this layer uses to access the cache
239
const CacheSpec& getCacheSpec() const { return _cacheSpec; }
242
* Gives the terrain layer a hint as to what the target profile of
243
* images will be. This is optional, but it may allow the layer to enable
244
* certain optimizations since it has more information as to how the
247
virtual void setTargetProfileHint( const Profile* profile );
251
virtual void initTileSource();
253
virtual std::string suggestCacheFormat() const;
257
// these are called "actual" because they override the corresponding
258
// init settings found in the TerrainLayerOptions.
260
std::string _actualCacheFormat;
261
bool _actualCacheOnly;
263
osg::ref_ptr<TileSource> _tileSource;
264
osg::ref_ptr<Cache> _cache;
265
CacheSpec _cacheSpec;
267
osg::ref_ptr< const Profile > _profile;
268
osg::ref_ptr< const Profile > _cacheProfile;
270
optional<bool> _overrideCacheOnly;
272
bool _tileSourceInitialized;
274
osg::ref_ptr<const Profile> _targetProfileHint;
279
unsigned int _tileSize;
280
std::string _referenceURI;
281
OpenThreads::Mutex _initTileSourceMutex;
284
virtual void fireCallback( TerrainLayerCallbackMethodPtr method ) =0;
286
// methods accesible by Map:
288
void setReferenceURI( const std::string& uri );
289
void setCacheOnly( bool value );
292
typedef std::vector<osg::ref_ptr<TerrainLayer> > TerrainLayerVector;
294
} // namespace TerrainLayer
296
#endif // OSGEARTH_TERRAIN_LAYER_H