~ubuntu-branches/debian/sid/osgearth/sid

« back to all changes in this revision

Viewing changes to src/osgEarth/TerrainLayer

  • Committer: Bazaar Package Importer
  • Author(s): Pirmin Kalberer
  • Date: 2011-07-14 22:13:36 UTC
  • Revision ID: james.westby@ubuntu.com-20110714221336-94igk9rskxveh794
Tags: upstream-2.0+dfsg
ImportĀ upstreamĀ versionĀ 2.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*-c++-*- */
 
2
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 
3
 * Copyright 2008-2010 Pelican Mapping
 
4
 * http://osgearth.org
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>
 
18
 */
 
19
 
 
20
#ifndef OSGEARTH_TERRAIN_LAYER_H
 
21
#define OSGEARTH_TERRAIN_LAYER_H 1
 
22
 
 
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>
 
30
 
 
31
namespace osgEarth
 
32
{
 
33
    /**
 
34
     * Initialization (and serializable) options for a terrain layer.
 
35
     */
 
36
    class OSGEARTH_EXPORT TerrainLayerOptions : public ConfigOptions
 
37
    {
 
38
    public:
 
39
        TerrainLayerOptions( const ConfigOptions& options =ConfigOptions() );
 
40
        TerrainLayerOptions( const std::string& name, const TileSourceOptions& driverOptions );
 
41
 
 
42
        /**
 
43
         * The readable name of the layer.
 
44
         */
 
45
        std::string& name() { return _name; }
 
46
        const std::string& name() const { return _name; }
 
47
 
 
48
        /**
 
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.
 
52
         */
 
53
        optional<ProfileOptions>& profile() { return _profile; }
 
54
        const optional<ProfileOptions>& profile() const { return _profile; }
 
55
 
 
56
        /**
 
57
         * Options for the underlyint tile source driver.
 
58
         */
 
59
        optional<TileSourceOptions>& driver() { return _driver; }
 
60
        const optional<TileSourceOptions>& driver() const { return _driver; }
 
61
 
 
62
        /**
 
63
         * Gets or sets the minimum level of detail for which this layer should generate data.
 
64
         */
 
65
        optional<int>& minLevel() { return _minLevel; }
 
66
        const optional<int>& minLevel() const { return _minLevel; }
 
67
 
 
68
        /**
 
69
         * The maximum level of detail for which this layer should generate data.
 
70
         */
 
71
        optional<int>& maxLevel() { return _maxLevel; }
 
72
        const optional<int>& maxLevel() const { return _maxLevel; }
 
73
 
 
74
                /**
 
75
                 * Whether to render this layer with the map.
 
76
                 */        
 
77
        optional<bool>& enabled() { return _enabled; }
 
78
        const optional<bool>& enabled() const { return _enabled; }
 
79
 
 
80
                /**
 
81
                 * Whether to use exact cropping if image cropping is necessary
 
82
                 */
 
83
        optional<bool>& exactCropping() { return _exactCropping; }
 
84
        const optional<bool>& exactCropping() const { return _exactCropping; }
 
85
 
 
86
                /**
 
87
                 * The desired tile size to reproject imagery to if necessary.
 
88
                 */
 
89
        optional<unsigned int> reprojectedTileSize() { return _reprojectedTileSize; }
 
90
        const optional<unsigned int> reprojectedTileSize() const { return _reprojectedTileSize; }
 
91
 
 
92
                /**
 
93
                 * The format that this MapLayer should use when caching.
 
94
                 */
 
95
        optional<std::string>& cacheFormat() { return _cacheFormat; }
 
96
        const optional<std::string>& cacheFormat() const { return _cacheFormat; }
 
97
 
 
98
        /**
 
99
         * Whether to cache this layer or not.
 
100
         */
 
101
        optional<bool>& cacheEnabled() { return _cacheEnabled; }
 
102
        const optional<bool>& cacheEnabled() const { return _cacheEnabled; }
 
103
 
 
104
                /**
 
105
                 * Whether to try to run this MapLayer strictly from the cache only.
 
106
                 */
 
107
        optional<bool>& cacheOnly() { return _cacheOnly; }
 
108
        const optional<bool>& cacheOnly() const { return _cacheOnly; }
 
109
 
 
110
        /**
 
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.
 
114
         */
 
115
        optional<std::string>& cacheId() { return _cacheId; }
 
116
        const optional<std::string>& cacheId() const { return _cacheId; }
 
117
        
 
118
        /**
 
119
         * The loading weight of this MapLayer (for threaded loading policies).
 
120
         */
 
121
        optional<float>& loadingWeight() { return _loadingWeight; }
 
122
        const optional<float>& loadingWeight() const { return _loadingWeight; }
 
123
 
 
124
        /**
 
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.
 
129
         */
 
130
        optional<double>& edgeBufferRatio() { return _edgeBufferRatio;}
 
131
        const optional<double>& edgeBufferRatio() const { return _edgeBufferRatio; }
 
132
 
 
133
    public:
 
134
        virtual Config getConfig() const;
 
135
        virtual void mergeConfig( const Config& conf );
 
136
 
 
137
    private:
 
138
        void fromConfig( const Config& conf );
 
139
        void setDefaults();
 
140
       
 
141
        std::string _name;
 
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;
 
155
    };
 
156
 
 
157
    /**
 
158
     * Runtime property notification callback for TerrainLayers.
 
159
     */
 
160
    struct TerrainLayerCallback : public osg::Referenced
 
161
    {
 
162
        virtual void onEnabledChanged( class TerrainLayer* layer ) { }
 
163
    };
 
164
 
 
165
    typedef void (TerrainLayerCallback::*TerrainLayerCallbackMethodPtr)(TerrainLayer* layer);
 
166
 
 
167
 
 
168
    /**
 
169
     * A layer that comprises the terrain skin (image or elevation layer)
 
170
     */
 
171
    class OSGEARTH_EXPORT TerrainLayer : public Layer
 
172
    {
 
173
    protected:
 
174
        TerrainLayer();
 
175
        
 
176
        TerrainLayer( TileSource* tileSource );
 
177
 
 
178
    public:
 
179
 
 
180
        virtual const TerrainLayerOptions& getTerrainLayerOptions() const =0;
 
181
 
 
182
        void setEnabled( bool value );
 
183
        bool getEnabled() const { return _actualEnabled; }
 
184
 
 
185
        /**
 
186
         * Gets the readable name of the map layer.
 
187
         */
 
188
        const std::string& getName() const { 
 
189
            return getTerrainLayerOptions().name(); }
 
190
 
 
191
                /**
 
192
                 * Gets the profile of this MapLayer
 
193
                 */
 
194
                const Profile* getProfile() const;
 
195
 
 
196
        /**
 
197
         * Gets the underlying TileSource engine that serves this map layer. Use with caution.
 
198
         */
 
199
        TileSource* getTileSource() const;
 
200
 
 
201
                /**
 
202
                 * Gets the tile size of the this MapLayer
 
203
                 */
 
204
        unsigned int getTileSize() const { return _tileSize; }
 
205
 
 
206
                /**
 
207
                 * Gets the maximum data level of this MapLayer
 
208
                 */
 
209
                unsigned int getMaxDataLevel() const;
 
210
 
 
211
        /**
 
212
         * Whether the layer represents dynamic data, i.e. tile data that can change.
 
213
         */
 
214
        bool isDynamic() const;
 
215
 
 
216
        const std::string& getCacheFormat() const {  return _actualCacheFormat; }
 
217
 
 
218
    public: // methods
 
219
 
 
220
                /**
 
221
                 * Whether the given key is valid for this layer
 
222
                 */
 
223
                bool isKeyValid(const TileKey& key) const;
 
224
 
 
225
                /**
 
226
                 * Gets the Cache to be used on this TerrainLayer.
 
227
                 */
 
228
        Cache* getCache() const { return _cache.get(); }
 
229
 
 
230
                /**
 
231
                 * Sets the cache to be used on this MapLayer
 
232
         * TODO: is it legal to set this at any time?
 
233
                 */
 
234
                void setCache( Cache* cache );
 
235
 
 
236
        /**
 
237
         * Gets the key that this layer uses to access the cache
 
238
         */
 
239
        const CacheSpec& getCacheSpec() const { return _cacheSpec; }
 
240
        
 
241
        /**
 
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
 
245
         * data will be used.
 
246
         */
 
247
        virtual void setTargetProfileHint( const Profile* profile );
 
248
 
 
249
    protected:
 
250
 
 
251
                virtual void initTileSource();
 
252
 
 
253
        virtual std::string suggestCacheFormat() const;
 
254
 
 
255
    protected:
 
256
 
 
257
        // these are called "actual" because they override the corresponding
 
258
        // init settings found in the TerrainLayerOptions.
 
259
        bool         _actualEnabled;
 
260
        std::string  _actualCacheFormat;
 
261
        bool         _actualCacheOnly;
 
262
        
 
263
        osg::ref_ptr<TileSource> _tileSource;
 
264
                osg::ref_ptr<Cache>      _cache;
 
265
        CacheSpec                _cacheSpec;
 
266
 
 
267
                osg::ref_ptr< const Profile > _profile;
 
268
        osg::ref_ptr< const Profile > _cacheProfile;
 
269
 
 
270
        optional<bool> _overrideCacheOnly;
 
271
 
 
272
        bool _tileSourceInitialized;
 
273
 
 
274
        osg::ref_ptr<const Profile> _targetProfileHint;
 
275
 
 
276
    private:
 
277
        std::string _name;
 
278
        bool _cacheOnlyEnv;
 
279
                unsigned int _tileSize;        
 
280
        std::string _referenceURI;
 
281
        OpenThreads::Mutex _initTileSourceMutex;
 
282
 
 
283
        void init();
 
284
        virtual void fireCallback( TerrainLayerCallbackMethodPtr method ) =0;
 
285
 
 
286
        // methods accesible by Map:
 
287
        friend class Map;
 
288
        void setReferenceURI( const std::string& uri );
 
289
        void setCacheOnly( bool value );
 
290
    };
 
291
 
 
292
    typedef std::vector<osg::ref_ptr<TerrainLayer> > TerrainLayerVector;
 
293
 
 
294
} // namespace TerrainLayer
 
295
 
 
296
#endif // OSGEARTH_TERRAIN_LAYER_H