-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:gwaldron/osgearth
- Loading branch information
Showing
13 changed files
with
730 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* -*-c++-*- */ | ||
/* osgEarth - Geospatial SDK for OpenSceneGraph | ||
* Copyright 2020 Pelican Mapping | ||
* http://osgearth.org | ||
* | ||
* osgEarth is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
#ifndef OSGEARTH_COMPOSITE_TILED_MODEL_LAYER | ||
#define OSGEARTH_COMPOSITE_TILED_MODEL_LAYER 1 | ||
|
||
#include <osgEarth/Common> | ||
#include <osgEarth/Layer> | ||
#include <osgEarth/TiledModelLayer> | ||
|
||
namespace osgEarth { | ||
class Map; | ||
} | ||
|
||
namespace osgEarth | ||
{ | ||
class OSGEARTH_EXPORT CompositeTiledModelLayer : public TiledModelLayer | ||
{ | ||
public: // serialization | ||
struct OSGEARTH_EXPORT Options : public TiledModelLayer::Options | ||
{ | ||
META_LayerOptions(osgEarth, Options, TiledModelLayer::Options); | ||
OE_OPTION(ProfileOptions, profile); | ||
|
||
OE_OPTION_VECTOR(ConfigOptions, layers); | ||
|
||
Config getConfig() const override; | ||
void fromConfig(const Config& conf); | ||
}; | ||
|
||
public: | ||
META_Layer(osgEarth, CompositeTiledModelLayer, Options, TiledModelLayer, CompositeTiledModel); | ||
|
||
//! Tiling profile (required) | ||
void setProfile(const Profile* profile); | ||
const Profile* getProfile() const override { return _profile.get(); } | ||
|
||
unsigned getMinLevel() const override; | ||
|
||
//! Maximum level of detail to access | ||
unsigned getMaxLevel() const override; | ||
|
||
public: // Layer | ||
|
||
//! opens the layer and returns the status | ||
Status openImplementation() override; | ||
|
||
//! Serialization | ||
Config getConfig() const override; | ||
|
||
public: // Layer | ||
|
||
//! called by the map when this layer is added | ||
void addedToMap(const Map*) override; | ||
|
||
//! called by the map when this layer is removed | ||
void removedFromMap(const Map*) override; | ||
|
||
protected: // TiledModelLayer | ||
|
||
//! Creates an OSG node from a tile key. | ||
osg::ref_ptr<osg::Node> createTileImplementation(const TileKey&, ProgressCallback*) const override; | ||
|
||
protected: | ||
|
||
virtual ~CompositeTiledModelLayer(); | ||
|
||
private: | ||
osg::ref_ptr<const Profile> _profile; | ||
osg::observer_ptr< const Map > _map; | ||
|
||
unsigned int _minLevel = 0; | ||
unsigned int _maxLevel = 0; | ||
|
||
std::vector< osg::ref_ptr< TiledModelLayer > > _layers; | ||
}; | ||
|
||
} // namespace osgEarth | ||
|
||
#endif // OSGEARTH_COMPOSITE_TILED_MODEL_LAYER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* -*-c++-*- */ | ||
/* osgEarth - Geospatial SDK for OpenSceneGraph | ||
* Copyright 2020 Pelican Mapping | ||
* http://osgearth.org | ||
* | ||
* osgEarth is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
#include <osgEarth/CompositeTiledModelLayer> | ||
#include <osgEarth/NodeUtils> | ||
#include <osgEarth/SimplePager> | ||
|
||
#include <vector> | ||
|
||
using namespace osgEarth; | ||
|
||
#define LC "[CompositeTiledModelLayer] " | ||
|
||
#define OE_TEST OE_NULL | ||
|
||
REGISTER_OSGEARTH_LAYER(CompositeTiledModel, CompositeTiledModelLayer); | ||
|
||
void CompositeTiledModelLayer::Options::fromConfig(const Config& conf) | ||
{ | ||
conf.get("profile", profile()); | ||
|
||
const ConfigSet& layers = conf.child("layers").children(); | ||
for (ConfigSet::const_iterator i = layers.begin(); i != layers.end(); ++i) | ||
{ | ||
_layers.push_back(ConfigOptions(*i)); | ||
} | ||
} | ||
|
||
Config | ||
CompositeTiledModelLayer::Options::getConfig() const | ||
{ | ||
Config conf = TiledModelLayer::Options::getConfig(); | ||
conf.set("profile", profile()); | ||
|
||
if (_layers.empty() == false) | ||
{ | ||
Config layersConf("layers"); | ||
for (std::vector<ConfigOptions>::const_iterator i = _layers.begin(); i != _layers.end(); ++i) | ||
{ | ||
layersConf.add(i->getConfig()); | ||
} | ||
conf.set(layersConf); | ||
} | ||
|
||
return conf; | ||
} | ||
|
||
//........................................................................... | ||
|
||
CompositeTiledModelLayer::~CompositeTiledModelLayer() | ||
{ | ||
//NOP | ||
} | ||
|
||
void CompositeTiledModelLayer::setProfile(const Profile* profile) | ||
{ | ||
_profile = profile; | ||
if (_profile) | ||
{ | ||
options().profile() = profile->toProfileOptions(); | ||
} | ||
} | ||
|
||
Config | ||
CompositeTiledModelLayer::getConfig() const | ||
{ | ||
Config conf = TiledModelLayer::getConfig(); | ||
return conf; | ||
} | ||
|
||
Status | ||
CompositeTiledModelLayer::openImplementation() | ||
{ | ||
Status parent = super::openImplementation(); | ||
if (parent.isError()) | ||
return parent; | ||
|
||
_profile = Profile::create(*options().profile()); | ||
|
||
// Open all the layers | ||
for (auto& layerConf : options().layers()) | ||
{ | ||
osg::ref_ptr< Layer > layer = Layer::create(layerConf); | ||
TiledModelLayer* tiledLayer = dynamic_cast<TiledModelLayer*>(layer.get()); | ||
if (tiledLayer) | ||
{ | ||
tiledLayer->open(); | ||
tiledLayer->setReadOptions(getReadOptions()); | ||
_layers.push_back(tiledLayer); | ||
} | ||
else | ||
{ | ||
OE_WARN << LC << "Layer is not a TiledModelLayer" << std::endl; | ||
} | ||
} | ||
|
||
return Status::NoError; | ||
} | ||
|
||
void | ||
CompositeTiledModelLayer::addedToMap(const Map* map) | ||
{ | ||
for (auto& layer : _layers) | ||
{ | ||
layer->addedToMap(map); | ||
} | ||
|
||
// Check to make sure the layers are all using the same profile | ||
for (auto& layer : _layers) | ||
{ | ||
if (!layer->getProfile()->isEquivalentTo(_profile)) | ||
{ | ||
OE_WARN << LC << "Layer " << layer->getName() << " does not have the same profile as the composite layer" << std::endl; | ||
} | ||
} | ||
|
||
// Compute the min and max levels | ||
if (!_layers.empty()) | ||
{ | ||
_minLevel = 1000; | ||
_maxLevel = 0; | ||
for (auto& layer : _layers) | ||
{ | ||
if (layer->getMinLevel() < _minLevel) | ||
{ | ||
_minLevel = layer->getMinLevel(); | ||
} | ||
if (layer->getMaxLevel() > _maxLevel) | ||
{ | ||
_maxLevel = layer->getMaxLevel(); | ||
} | ||
} | ||
} | ||
|
||
super::addedToMap(map); | ||
} | ||
|
||
void | ||
CompositeTiledModelLayer::removedFromMap(const Map* map) | ||
{ | ||
super::removedFromMap(map); | ||
|
||
for (auto& layer : _layers) | ||
{ | ||
layer->removedFromMap(map); | ||
} | ||
} | ||
|
||
osg::ref_ptr<osg::Node> | ||
CompositeTiledModelLayer::createTileImplementation(const TileKey& key, ProgressCallback* progress) const | ||
{ | ||
osg::ref_ptr<osg::Group> group = new osg::Group(); | ||
|
||
for (unsigned int i = 0; i < this->_layers.size(); i++) | ||
{ | ||
osg::ref_ptr<osg::Node> node = this->_layers[i]->createTile(key, progress); | ||
if (node.valid()) | ||
{ | ||
group->addChild(node); | ||
} | ||
} | ||
return group; | ||
} | ||
|
||
unsigned | ||
CompositeTiledModelLayer::getMinLevel() const | ||
{ | ||
return _minLevel; | ||
} | ||
|
||
unsigned | ||
CompositeTiledModelLayer::getMaxLevel() const | ||
{ | ||
return _maxLevel; | ||
} | ||
|
Oops, something went wrong.