mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 18:51:17 -06:00
Layer support for globe browsing: Add layers using the function openspace.globebrowsing.addLayer Delete layers using openspace.globebrowsing.deleteLayer Layer type does not necessarily have to be of tile type. For example solidcolor does not use tiles Blend modes for layers are Normal, Add, Subtract, Multiply, Color Layer adjustments to affect layers. The current only active one is chroma key to cut out a color from the layer. Transfer functions or clipping masks are examples of layer adjustments for the future. Support for adding layer specifications for quickly accessing GIBS layers: openspace.globebrowsing.createGibsGdalXml openspace.globebrowsing.createTemporalGibsGdalXml The arguments for these functions are currently strings. Would it be better to use a lua dictionary? No data values for height layers are correctly regarded (can be seen on Earth. No longer bumps on the poles) Other minor things: Worked a bit on point globe to render globes at large distances. Currently not in use and doesn't have anything to do with the other things. Concurrent job manager takes a thread pool as argument and not a pointer to one. This is because the concurrent job manager needs to have ownership of the thread pool for correct deinitialization. Will cause breaking change for users of concurrent job manager if merged in to master. * Add ability to add layers programatically. * Clean up * Fix order of deletion in concurrent job manager and clean up * Can create by level tile provider with empty dictionary. * Add script to add GIBS datasets. * Start working with layer adjustment * Update mod files * More work on point globe * Add script to create temporal GIBS datasets. * Update temporal tile provider to be able to take gdal descriptions without file path. * Add adjustment property to layers. * Rename adjustment layer * Add adjustment code to all layer groups * Remove caching of gdal datasets due to cluttering of folders * Document layer support * Update Mars mod * Make Mercury great again. * Cleanup and add blend mode Color * Enable setting of layeradjustment and blend mode from mod files. * No more use for grayscale color overlays. Use grayscale layer with color blend mode instead. * Clean up mod files * Clean up * Clean up * No need for grayscale layers. Reading grayscale in to rgb instead for color layers. * Remove unused layer groups * Correctly read to grayscale layers * Update globe mod files * Rename ColorOverlays to Overlays. * Clean up * Clean up * Solve compilation error
327 lines
11 KiB
C++
327 lines
11 KiB
C++
/*****************************************************************************************
|
|
* *
|
|
* OpenSpace *
|
|
* *
|
|
* Copyright (c) 2014-2017 *
|
|
* *
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
|
* software and associated documentation files (the "Software"), to deal in the Software *
|
|
* without restriction, including without limitation the rights to use, copy, modify, *
|
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
|
* permit persons to whom the Software is furnished to do so, subject to the following *
|
|
* conditions: *
|
|
* *
|
|
* The above copyright notice and this permission notice shall be included in all copies *
|
|
* or substantial portions of the Software. *
|
|
* *
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
|
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
****************************************************************************************/
|
|
|
|
#include <modules/globebrowsing/rendering/layer/layer.h>
|
|
|
|
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
|
|
|
namespace openspace {
|
|
namespace globebrowsing {
|
|
|
|
namespace {
|
|
const char* _loggerCat = "Layer";
|
|
|
|
const char* keyName = "Name";
|
|
const char* keyEnabled = "Enabled";
|
|
const char* keyLayerGroupID = "LayerGroupID";
|
|
const char* keySettings = "Settings";
|
|
const char* keyAdjustment = "Adjustment";
|
|
const char* KeyBlendMode = "BlendMode";
|
|
}
|
|
|
|
Layer::Layer(layergroupid::GroupID id, const ghoul::Dictionary& layerDict)
|
|
: properties::PropertyOwner(layerDict.value<std::string>(keyName))
|
|
, _typeOption(
|
|
"type",
|
|
"Type",
|
|
properties::OptionProperty::DisplayType::Dropdown
|
|
)
|
|
, _blendModeOption(
|
|
"blendMode",
|
|
"Blend Mode",
|
|
properties::OptionProperty::DisplayType::Dropdown
|
|
)
|
|
, _enabled(properties::BoolProperty("enabled", "Enabled", false))
|
|
, _reset("reset", "Reset")
|
|
, _tileProvider(nullptr)
|
|
, _otherTypesProperties{
|
|
properties::Vec3Property (
|
|
"color",
|
|
"Color",
|
|
glm::vec4(1.f, 1.f, 1.f, 1.f),
|
|
glm::vec4(0.f),
|
|
glm::vec4(1.f))
|
|
}
|
|
, _layerGroupId(id)
|
|
{
|
|
layergroupid::TypeID typeID = parseTypeIdFromDictionary(layerDict);
|
|
if (typeID == layergroupid::TypeID::Unknown) {
|
|
throw ghoul::RuntimeError("Unknown layer type!");
|
|
}
|
|
|
|
initializeBasedOnType(typeID, layerDict);
|
|
|
|
bool enabled = false; // defaults to false if unspecified
|
|
layerDict.getValue(keyEnabled, enabled);
|
|
_enabled.setValue(enabled);
|
|
|
|
// Initialize settings
|
|
ghoul::Dictionary settingsDict;
|
|
if (layerDict.getValue(keySettings, settingsDict)) {
|
|
_renderSettings.setValuesFromDictionary(settingsDict);
|
|
}
|
|
|
|
// Initiallize layer adjustment
|
|
ghoul::Dictionary adjustmentDict;
|
|
if (layerDict.getValue(keyAdjustment, adjustmentDict)) {
|
|
_layerAdjustment.setValuesFromDictionary(adjustmentDict);
|
|
}
|
|
|
|
// Add options to option properties
|
|
for (int i = 0; i < layergroupid::NUM_LAYER_TYPES; ++i) {
|
|
_typeOption.addOption(i, layergroupid::LAYER_TYPE_NAMES[i]);
|
|
}
|
|
_typeOption.setValue(static_cast<int>(typeID));
|
|
_type = static_cast<layergroupid::TypeID>(_typeOption.value());
|
|
|
|
for (int i = 0; i < layergroupid::NUM_BLEND_MODES; ++i) {
|
|
_blendModeOption.addOption(i, layergroupid::BLEND_MODE_NAMES[i]);
|
|
}
|
|
|
|
// Initialize blend mode
|
|
std::string blendModeName;
|
|
if (layerDict.getValue(KeyBlendMode, blendModeName)) {
|
|
layergroupid::BlendModeID blendModeID =
|
|
layergroupid::getBlendModeIDFromName(blendModeName);
|
|
_blendModeOption.setValue(static_cast<int>(blendModeID));
|
|
}
|
|
else {
|
|
_blendModeOption.setValue(static_cast<int>(layergroupid::BlendModeID::Normal));
|
|
}
|
|
|
|
// On change callbacks definitions
|
|
_enabled.onChange([&](){
|
|
if (_onChangeCallback) {
|
|
_onChangeCallback();
|
|
}
|
|
});
|
|
|
|
_reset.onChange([&](){
|
|
if (_tileProvider) {
|
|
_tileProvider->reset();
|
|
}
|
|
});
|
|
|
|
_typeOption.onChange([&](){
|
|
removeVisibleProperties();
|
|
_type = static_cast<layergroupid::TypeID>(_typeOption.value());
|
|
ghoul::Dictionary dict;
|
|
initializeBasedOnType(type(), dict);
|
|
addVisibleProperties();
|
|
if (_onChangeCallback) {
|
|
_onChangeCallback();
|
|
}
|
|
});
|
|
|
|
_blendModeOption.onChange([&](){
|
|
if (_onChangeCallback) {
|
|
_onChangeCallback();
|
|
}
|
|
});
|
|
|
|
_layerAdjustment.onChange([&](){
|
|
if (_onChangeCallback) {
|
|
_onChangeCallback();
|
|
}
|
|
});
|
|
|
|
_typeOption.setReadOnly(true);
|
|
|
|
// Add the properties
|
|
addProperty(_typeOption);
|
|
addProperty(_blendModeOption);
|
|
addProperty(_enabled);
|
|
addProperty(_reset);
|
|
|
|
_otherTypesProperties.color.setViewOption(properties::Property::ViewOptions::Color);
|
|
|
|
addVisibleProperties();
|
|
|
|
addPropertySubOwner(_renderSettings);
|
|
addPropertySubOwner(_layerAdjustment);
|
|
}
|
|
|
|
ChunkTilePile Layer::getChunkTilePile(const TileIndex& tileIndex, int pileSize) const {
|
|
if (_tileProvider) {
|
|
return _tileProvider->getChunkTilePile(tileIndex, pileSize);
|
|
}
|
|
else {
|
|
ChunkTilePile chunkTilePile;
|
|
chunkTilePile.resize(pileSize);
|
|
for (int i = 0; i < pileSize; ++i) {
|
|
chunkTilePile[i].tile = Tile::TileUnavailable;
|
|
chunkTilePile[i].uvTransform.uvOffset = { 0, 0 };
|
|
chunkTilePile[i].uvTransform.uvScale = { 1, 1 };
|
|
}
|
|
return chunkTilePile;
|
|
}
|
|
}
|
|
|
|
Tile::Status Layer::getTileStatus(const TileIndex& index) const {
|
|
if (_tileProvider) {
|
|
return _tileProvider->getTileStatus(index);
|
|
}
|
|
else {
|
|
return Tile::Status::Unavailable;
|
|
}
|
|
}
|
|
|
|
layergroupid::TypeID Layer::type() const {
|
|
return _type;
|
|
};
|
|
|
|
layergroupid::BlendModeID Layer::blendMode() const {
|
|
return static_cast<layergroupid::BlendModeID>(_blendModeOption.value());
|
|
};
|
|
|
|
|
|
TileDepthTransform Layer::depthTransform() const {
|
|
if (_tileProvider) {
|
|
return _tileProvider->depthTransform();
|
|
}
|
|
else {
|
|
return {1.0f, 0.0f};
|
|
}
|
|
}
|
|
|
|
bool Layer::enabled() const {
|
|
return _enabled.value();
|
|
}
|
|
|
|
tileprovider::TileProvider* Layer::tileProvider() const {
|
|
return _tileProvider.get();
|
|
}
|
|
|
|
const Layer::OtherTypesProperties& Layer::otherTypesProperties() const {
|
|
return _otherTypesProperties;
|
|
}
|
|
|
|
const LayerRenderSettings& Layer::renderSettings() const {
|
|
return _renderSettings;
|
|
}
|
|
|
|
const LayerAdjustment& Layer::layerAdjustment() const {
|
|
return _layerAdjustment;
|
|
}
|
|
|
|
void Layer::onChange(std::function<void(void)> callback) {
|
|
_onChangeCallback = callback;
|
|
}
|
|
|
|
void Layer::update() {
|
|
if (_tileProvider) {
|
|
_tileProvider->update();
|
|
}
|
|
}
|
|
|
|
layergroupid::TypeID Layer::parseTypeIdFromDictionary(
|
|
const ghoul::Dictionary& initDict) const
|
|
{
|
|
if (initDict.hasKeyAndValue<std::string>("Type")) {
|
|
const std::string typeString = initDict.value<std::string>("Type");
|
|
return layergroupid::getTypeIDFromTypeString(typeString);
|
|
}
|
|
else {
|
|
return layergroupid::TypeID::DefaultTileLayer;
|
|
}
|
|
}
|
|
|
|
void Layer::initializeBasedOnType(layergroupid::TypeID typeId, ghoul::Dictionary initDict) {
|
|
switch (typeId) {
|
|
// Intentional fall through. Same for all tile layers
|
|
case layergroupid::TypeID::DefaultTileLayer:
|
|
case layergroupid::TypeID::SingleImageTileLayer:
|
|
case layergroupid::TypeID::SizeReferenceTileLayer:
|
|
case layergroupid::TypeID::TemporalTileLayer:
|
|
case layergroupid::TypeID::TileIndexTileLayer:
|
|
case layergroupid::TypeID::ByIndexTileLayer:
|
|
case layergroupid::TypeID::ByLevelTileLayer: {
|
|
// We add the id to the dictionary since it needs to be known by
|
|
// the tile provider
|
|
ghoul::Dictionary tileProviderInitDict = initDict;
|
|
tileProviderInitDict.setValue(keyLayerGroupID, _layerGroupId);
|
|
if (tileProviderInitDict.hasKeyAndValue<std::string>(keyName)) {
|
|
std::string name;
|
|
tileProviderInitDict.getValue(keyName, name);
|
|
LDEBUG("Initializing tile provider for layer: '" + name + "'");
|
|
}
|
|
_tileProvider = std::shared_ptr<tileprovider::TileProvider>(
|
|
tileprovider::TileProvider::createFromDictionary(typeId, tileProviderInitDict)
|
|
);
|
|
break;
|
|
}
|
|
case layergroupid::TypeID::SolidColor:
|
|
break;
|
|
default:
|
|
throw ghoul::RuntimeError("Unable to create layer. Unknown type.");
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Layer::addVisibleProperties() {
|
|
switch (type()) {
|
|
// Intentional fall through. Same for all tile layers
|
|
case layergroupid::TypeID::DefaultTileLayer:
|
|
case layergroupid::TypeID::SingleImageTileLayer:
|
|
case layergroupid::TypeID::SizeReferenceTileLayer:
|
|
case layergroupid::TypeID::TemporalTileLayer:
|
|
case layergroupid::TypeID::TileIndexTileLayer:
|
|
case layergroupid::TypeID::ByIndexTileLayer:
|
|
case layergroupid::TypeID::ByLevelTileLayer:
|
|
if (_tileProvider) {
|
|
addPropertySubOwner(*_tileProvider);
|
|
}
|
|
break;
|
|
case layergroupid::TypeID::SolidColor:
|
|
addProperty(_otherTypesProperties.color);
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Layer::removeVisibleProperties() {
|
|
switch (type()) {
|
|
// Intentional fall through. Same for all tile layers
|
|
case layergroupid::TypeID::DefaultTileLayer:
|
|
case layergroupid::TypeID::SingleImageTileLayer:
|
|
case layergroupid::TypeID::SizeReferenceTileLayer:
|
|
case layergroupid::TypeID::TemporalTileLayer:
|
|
case layergroupid::TypeID::TileIndexTileLayer:
|
|
case layergroupid::TypeID::ByIndexTileLayer:
|
|
case layergroupid::TypeID::ByLevelTileLayer:
|
|
if (_tileProvider) {
|
|
removePropertySubOwner(*_tileProvider);
|
|
}
|
|
break;
|
|
case layergroupid::TypeID::SolidColor:
|
|
removeProperty(_otherTypesProperties.color);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
} // namespace globebrowsing
|
|
} // namespace openspace
|