Skip to content

Commit faf6a4e

Browse files
committed
Merge branch 'master' of github.com:gwaldron/osgearth
2 parents 147045c + d6723e3 commit faf6a4e

13 files changed

+730
-665
lines changed

src/osgEarth/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ SET(LIB_PUBLIC_HEADERS
114114
ColorFilter
115115
Common
116116
Composite
117+
CompositeTiledModelLayer
117118
Config
118119
Containers
119120
Coverage
@@ -260,7 +261,6 @@ SET(LIB_PUBLIC_HEADERS
260261
TileHandler
261262
TileMesher
262263
TileRasterizer
263-
TiledFeatureModelGraph
264264
TiledFeatureModelLayer
265265
TiledModelLayer
266266
TileSource
@@ -283,7 +283,6 @@ SET(LIB_PUBLIC_HEADERS
283283
WMS
284284
XmlUtils
285285
XYZ
286-
XYZModelGraph
287286
XYZModelLayer
288287

289288
ActivityMonitorTool
@@ -551,6 +550,7 @@ set(TARGET_SRC
551550
Color.cpp
552551
ColorFilter.cpp
553552
Composite.cpp
553+
CompositeTiledModelLayer.cpp
554554
Compressors.cpp
555555
Config.cpp
556556
CoverageLayer.cpp
@@ -676,7 +676,6 @@ set(TARGET_SRC
676676
TileHandler.cpp
677677
TileMesher.cpp
678678
TileRasterizer.cpp
679-
TiledFeatureModelGraph.cpp
680679
TiledFeatureModelLayer.cpp
681680
TiledModelLayer.cpp
682681
TileVisitor.cpp
@@ -699,7 +698,6 @@ set(TARGET_SRC
699698
WMS.cpp
700699
XmlUtils.cpp
701700
XYZ.cpp
702-
XYZModelGraph.cpp
703701
XYZModelLayer.cpp
704702

705703
ActivityMonitorTool.cpp

src/osgEarth/CompositeTiledModelLayer

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* -*-c++-*- */
2+
/* osgEarth - Geospatial SDK for OpenSceneGraph
3+
* Copyright 2020 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+
#ifndef OSGEARTH_COMPOSITE_TILED_MODEL_LAYER
20+
#define OSGEARTH_COMPOSITE_TILED_MODEL_LAYER 1
21+
22+
#include <osgEarth/Common>
23+
#include <osgEarth/Layer>
24+
#include <osgEarth/TiledModelLayer>
25+
26+
namespace osgEarth {
27+
class Map;
28+
}
29+
30+
namespace osgEarth
31+
{
32+
class OSGEARTH_EXPORT CompositeTiledModelLayer : public TiledModelLayer
33+
{
34+
public: // serialization
35+
struct OSGEARTH_EXPORT Options : public TiledModelLayer::Options
36+
{
37+
META_LayerOptions(osgEarth, Options, TiledModelLayer::Options);
38+
OE_OPTION(ProfileOptions, profile);
39+
40+
OE_OPTION_VECTOR(ConfigOptions, layers);
41+
42+
Config getConfig() const override;
43+
void fromConfig(const Config& conf);
44+
};
45+
46+
public:
47+
META_Layer(osgEarth, CompositeTiledModelLayer, Options, TiledModelLayer, CompositeTiledModel);
48+
49+
//! Tiling profile (required)
50+
void setProfile(const Profile* profile);
51+
const Profile* getProfile() const override { return _profile.get(); }
52+
53+
unsigned getMinLevel() const override;
54+
55+
//! Maximum level of detail to access
56+
unsigned getMaxLevel() const override;
57+
58+
public: // Layer
59+
60+
//! opens the layer and returns the status
61+
Status openImplementation() override;
62+
63+
//! Serialization
64+
Config getConfig() const override;
65+
66+
public: // Layer
67+
68+
//! called by the map when this layer is added
69+
void addedToMap(const Map*) override;
70+
71+
//! called by the map when this layer is removed
72+
void removedFromMap(const Map*) override;
73+
74+
protected: // TiledModelLayer
75+
76+
//! Creates an OSG node from a tile key.
77+
osg::ref_ptr<osg::Node> createTileImplementation(const TileKey&, ProgressCallback*) const override;
78+
79+
protected:
80+
81+
virtual ~CompositeTiledModelLayer();
82+
83+
private:
84+
osg::ref_ptr<const Profile> _profile;
85+
osg::observer_ptr< const Map > _map;
86+
87+
unsigned int _minLevel = 0;
88+
unsigned int _maxLevel = 0;
89+
90+
std::vector< osg::ref_ptr< TiledModelLayer > > _layers;
91+
};
92+
93+
} // namespace osgEarth
94+
95+
#endif // OSGEARTH_COMPOSITE_TILED_MODEL_LAYER
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/* -*-c++-*- */
2+
/* osgEarth - Geospatial SDK for OpenSceneGraph
3+
* Copyright 2020 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+
#include <osgEarth/CompositeTiledModelLayer>
20+
#include <osgEarth/NodeUtils>
21+
#include <osgEarth/SimplePager>
22+
23+
#include <vector>
24+
25+
using namespace osgEarth;
26+
27+
#define LC "[CompositeTiledModelLayer] "
28+
29+
#define OE_TEST OE_NULL
30+
31+
REGISTER_OSGEARTH_LAYER(CompositeTiledModel, CompositeTiledModelLayer);
32+
33+
void CompositeTiledModelLayer::Options::fromConfig(const Config& conf)
34+
{
35+
conf.get("profile", profile());
36+
37+
const ConfigSet& layers = conf.child("layers").children();
38+
for (ConfigSet::const_iterator i = layers.begin(); i != layers.end(); ++i)
39+
{
40+
_layers.push_back(ConfigOptions(*i));
41+
}
42+
}
43+
44+
Config
45+
CompositeTiledModelLayer::Options::getConfig() const
46+
{
47+
Config conf = TiledModelLayer::Options::getConfig();
48+
conf.set("profile", profile());
49+
50+
if (_layers.empty() == false)
51+
{
52+
Config layersConf("layers");
53+
for (std::vector<ConfigOptions>::const_iterator i = _layers.begin(); i != _layers.end(); ++i)
54+
{
55+
layersConf.add(i->getConfig());
56+
}
57+
conf.set(layersConf);
58+
}
59+
60+
return conf;
61+
}
62+
63+
//...........................................................................
64+
65+
CompositeTiledModelLayer::~CompositeTiledModelLayer()
66+
{
67+
//NOP
68+
}
69+
70+
void CompositeTiledModelLayer::setProfile(const Profile* profile)
71+
{
72+
_profile = profile;
73+
if (_profile)
74+
{
75+
options().profile() = profile->toProfileOptions();
76+
}
77+
}
78+
79+
Config
80+
CompositeTiledModelLayer::getConfig() const
81+
{
82+
Config conf = TiledModelLayer::getConfig();
83+
return conf;
84+
}
85+
86+
Status
87+
CompositeTiledModelLayer::openImplementation()
88+
{
89+
Status parent = super::openImplementation();
90+
if (parent.isError())
91+
return parent;
92+
93+
_profile = Profile::create(*options().profile());
94+
95+
// Open all the layers
96+
for (auto& layerConf : options().layers())
97+
{
98+
osg::ref_ptr< Layer > layer = Layer::create(layerConf);
99+
TiledModelLayer* tiledLayer = dynamic_cast<TiledModelLayer*>(layer.get());
100+
if (tiledLayer)
101+
{
102+
tiledLayer->open();
103+
tiledLayer->setReadOptions(getReadOptions());
104+
_layers.push_back(tiledLayer);
105+
}
106+
else
107+
{
108+
OE_WARN << LC << "Layer is not a TiledModelLayer" << std::endl;
109+
}
110+
}
111+
112+
return Status::NoError;
113+
}
114+
115+
void
116+
CompositeTiledModelLayer::addedToMap(const Map* map)
117+
{
118+
for (auto& layer : _layers)
119+
{
120+
layer->addedToMap(map);
121+
}
122+
123+
// Check to make sure the layers are all using the same profile
124+
for (auto& layer : _layers)
125+
{
126+
if (!layer->getProfile()->isEquivalentTo(_profile))
127+
{
128+
OE_WARN << LC << "Layer " << layer->getName() << " does not have the same profile as the composite layer" << std::endl;
129+
}
130+
}
131+
132+
// Compute the min and max levels
133+
if (!_layers.empty())
134+
{
135+
_minLevel = 1000;
136+
_maxLevel = 0;
137+
for (auto& layer : _layers)
138+
{
139+
if (layer->getMinLevel() < _minLevel)
140+
{
141+
_minLevel = layer->getMinLevel();
142+
}
143+
if (layer->getMaxLevel() > _maxLevel)
144+
{
145+
_maxLevel = layer->getMaxLevel();
146+
}
147+
}
148+
}
149+
150+
super::addedToMap(map);
151+
}
152+
153+
void
154+
CompositeTiledModelLayer::removedFromMap(const Map* map)
155+
{
156+
super::removedFromMap(map);
157+
158+
for (auto& layer : _layers)
159+
{
160+
layer->removedFromMap(map);
161+
}
162+
}
163+
164+
osg::ref_ptr<osg::Node>
165+
CompositeTiledModelLayer::createTileImplementation(const TileKey& key, ProgressCallback* progress) const
166+
{
167+
osg::ref_ptr<osg::Group> group = new osg::Group();
168+
169+
for (unsigned int i = 0; i < this->_layers.size(); i++)
170+
{
171+
osg::ref_ptr<osg::Node> node = this->_layers[i]->createTile(key, progress);
172+
if (node.valid())
173+
{
174+
group->addChild(node);
175+
}
176+
}
177+
return group;
178+
}
179+
180+
unsigned
181+
CompositeTiledModelLayer::getMinLevel() const
182+
{
183+
return _minLevel;
184+
}
185+
186+
unsigned
187+
CompositeTiledModelLayer::getMaxLevel() const
188+
{
189+
return _maxLevel;
190+
}
191+

0 commit comments

Comments
 (0)