Merge remote-tracking branch 'origin/feature/globebrowsing' into release/ips

This commit is contained in:
Alexander Bock
2016-06-17 21:37:43 +02:00
7 changed files with 201 additions and 64 deletions
@@ -63,6 +63,13 @@ namespace openspace {
, initChunkVisible(properties::BoolProperty("initChunkVisible", "initChunkVisible", true))
, renderSmallChunksFirst(properties::BoolProperty("renderSmallChunksFirst", "renderSmallChunksFirst", true))
, chunkHeight(properties::FloatProperty("chunkHeight", "chunkHeight", 8700.0f, 0.0f, 8700.0f))
, _baseLayersSelection(properties::SelectionProperty("Base Layers", "Base Layers"))
, _nightLayersSelection(properties::SelectionProperty("Night Textures", "Night Textures"))
, _heightMapsSelection(properties::SelectionProperty("Height Maps", "Height Maps"))
, _waterMasksSelection(properties::SelectionProperty("Water Masks", "Water Masks"))
, _overlaysSelection(properties::SelectionProperty("Overlays", "Overlays"))
, blendHeightMap(properties::BoolProperty("blendHeightMap", "blendHeightMap", true))
, blendColorMap(properties::BoolProperty("blendColorMap", "blendColorMap", true))
, blendNightTexture(properties::BoolProperty("blendNightTexture", "blendNightTexture", true))
@@ -85,6 +92,12 @@ namespace openspace {
addProperty(renderSmallChunksFirst);
addProperty(chunkHeight);
addProperty(_baseLayersSelection);
addProperty(_nightLayersSelection);
addProperty(_heightMapsSelection);
addProperty(_waterMasksSelection);
addProperty(_overlaysSelection);
addProperty(blendHeightMap);
addProperty(blendColorMap);
addProperty(blendNightTexture);
@@ -122,20 +135,20 @@ namespace openspace {
_tileProviderManager = std::shared_ptr<TileProviderManager>(
new TileProviderManager(texturesDictionary, textureInitDataDictionary));
auto& colorTextureProviders = _tileProviderManager->getLayerCategory(LayeredTextures::ColorTextures);
auto& nightTextureProviders = _tileProviderManager->getLayerCategory(LayeredTextures::NightTextures);
auto& heightMapProviders = _tileProviderManager->getLayerCategory(LayeredTextures::HeightMaps);
auto& overlayProviders = _tileProviderManager->getLayerCategory(LayeredTextures::Overlays);
auto& waterMaskProviders =_tileProviderManager->getLayerCategory(LayeredTextures::WaterMasks);
addToggleLayerProperties(LayeredTextures::ColorTextures, _baseLayersSelection);
addToggleLayerProperties(LayeredTextures::NightTextures, _nightLayersSelection);
addToggleLayerProperties(LayeredTextures::HeightMaps, _heightMapsSelection);
addToggleLayerProperties(LayeredTextures::WaterMasks, _waterMasksSelection);
addToggleLayerProperties(LayeredTextures::Overlays, _overlaysSelection);
addToggleLayerProperties(colorTextureProviders, _activeColorLayers);
addToggleLayerProperties(nightTextureProviders, _activeNightLayers);
addToggleLayerProperties(overlayProviders, _activeOverlays);
addToggleLayerProperties(heightMapProviders, _activeHeightMapLayers);
addToggleLayerProperties(waterMaskProviders, _activeWaterMaskLayers);
_baseLayersSelection.onChange(std::bind(&RenderableGlobe::baseLayerSelectionChanged, this));
_nightLayersSelection.onChange(std::bind(&RenderableGlobe::nightLayersSelectionChanged, this));
_heightMapsSelection.onChange(std::bind(&RenderableGlobe::heightMapsSelectionChanged, this));
_waterMasksSelection.onChange(std::bind(&RenderableGlobe::waterMasksSelectionChanged, this));
_overlaysSelection.onChange(std::bind(&RenderableGlobe::overlaysSelectionChanged, this));
_chunkedLodGlobe = std::shared_ptr<ChunkedLodGlobe>(
new ChunkedLodGlobe(_ellipsoid, patchSegments, _tileProviderManager));
new ChunkedLodGlobe(_ellipsoid, patchSegments, _tileProviderManager));
_distanceSwitch.addSwitchValue(_chunkedLodGlobe, 1e12);
}
@@ -145,22 +158,37 @@ namespace openspace {
}
void RenderableGlobe::addToggleLayerProperties(
std::vector<TileProviderManager::TileProviderWithName>& tileProviders,
std::vector<properties::BoolProperty>& dest)
LayeredTextures::TextureCategory category,
properties::SelectionProperty& dest)
{
for (size_t i = 0; i < tileProviders.size(); i++) {
bool enabled = tileProviders[i].isActive;
std::string name = tileProviders[i].name;
dest.push_back(properties::BoolProperty(name, name, enabled));
}
auto it = dest.begin();
auto end = dest.end();
while (it != end) {
addProperty(*(it++));
auto& categoryProviders = _tileProviderManager->getLayerCategory(category);
for (size_t i = 0; i < categoryProviders.size(); i++) {
std::string name = categoryProviders[i].name;
dest.addOption( { static_cast<int>(i), name });
}
}
void RenderableGlobe::initializeToggleLayerProperties(
LayeredTextures::TextureCategory category,
properties::SelectionProperty& selectionProperty)
{
std::vector<int> enabledIndices;
auto& categoryProviders = _tileProviderManager->getLayerCategory(category);
for (size_t i = 0; i < categoryProviders.size(); i++) {
if (categoryProviders[i].isActive)
enabledIndices.push_back(i);
}
selectionProperty.setValue(enabledIndices);
}
bool RenderableGlobe::initialize() {
initializeToggleLayerProperties(LayeredTextures::ColorTextures, _baseLayersSelection);
initializeToggleLayerProperties(LayeredTextures::NightTextures, _nightLayersSelection);
initializeToggleLayerProperties(LayeredTextures::HeightMaps, _heightMapsSelection);
initializeToggleLayerProperties(LayeredTextures::WaterMasks, _waterMasksSelection);
initializeToggleLayerProperties(LayeredTextures::Overlays, _overlaysSelection);
return _distanceSwitch.initialize();
}
@@ -190,6 +218,7 @@ namespace openspace {
}
void RenderableGlobe::update(const UpdateData& data) {
// set spice-orientation in accordance to timestamp
//_chunkedLodGlobe->setStateMatrix(
// SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time));
@@ -217,7 +246,7 @@ namespace openspace {
_chunkedLodGlobe->showChunkBounds = showChunkBounds.value();
_chunkedLodGlobe->levelByProjArea = levelByProjArea.value();
_chunkedLodGlobe->limitLevelByAvailableHeightData = limitLevelByAvailableHeightData.value();
/*
std::vector<TileProviderManager::TileProviderWithName>& colorTextureProviders =
_tileProviderManager->getLayerCategory(LayeredTextures::ColorTextures);
std::vector<TileProviderManager::TileProviderWithName>& nightTextureProviders =
@@ -229,6 +258,7 @@ namespace openspace {
std::vector<TileProviderManager::TileProviderWithName>& waterMaskProviders =
_tileProviderManager->getLayerCategory(LayeredTextures::WaterMasks);
for (size_t i = 0; i < colorTextureProviders.size(); i++) {
colorTextureProviders[i].isActive = _activeColorLayers[i].value();
}
@@ -244,7 +274,7 @@ namespace openspace {
for (size_t i = 0; i < waterMaskProviders.size(); i++) {
waterMaskProviders[i].isActive = _activeWaterMaskLayers[i].value();
}
*/
// Update this after active layers have been updated
_tileProviderManager->prerender();
}
@@ -257,5 +287,45 @@ namespace openspace {
return _chunkedLodGlobe;
}
void RenderableGlobe::selectionChanged(
properties::SelectionProperty selectionProperty,
LayeredTextures::TextureCategory textureCategory)
{
const std::vector<int>& selectedIndices = selectionProperty;
auto& category = _tileProviderManager->getLayerCategory(textureCategory);
// First inactivate all of them
for (size_t i = 0; i < category.size(); i++) {
category[i].isActive = false;
}
// Activate the selected ones
for (size_t i = 0; i < selectedIndices.size(); i++){
category[selectedIndices[i]].isActive = true;
}
}
void RenderableGlobe::baseLayerSelectionChanged()
{
selectionChanged(_baseLayersSelection, LayeredTextures::ColorTextures);
}
void RenderableGlobe::nightLayersSelectionChanged()
{
selectionChanged(_nightLayersSelection, LayeredTextures::NightTextures);
}
void RenderableGlobe::heightMapsSelectionChanged()
{
selectionChanged(_heightMapsSelection, LayeredTextures::HeightMaps);
}
void RenderableGlobe::waterMasksSelectionChanged()
{
selectionChanged(_waterMasksSelection, LayeredTextures::WaterMasks);
}
void RenderableGlobe::overlaysSelectionChanged()
{
selectionChanged(_overlaysSelection, LayeredTextures::Overlays);
}
} // namespace openspace
+24 -2
View File
@@ -32,6 +32,8 @@
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/selectionproperty.h>
#include <openspace/util/updatestructures.h>
#include <modules/globebrowsing/meshes/trianglesoup.h>
@@ -78,6 +80,12 @@ public:
properties::FloatProperty chunkHeight;
// Layered rendering
properties::SelectionProperty _baseLayersSelection;
properties::SelectionProperty _nightLayersSelection;
properties::SelectionProperty _heightMapsSelection;
properties::SelectionProperty _waterMasksSelection;
properties::SelectionProperty _overlaysSelection;
properties::BoolProperty blendHeightMap;
properties::BoolProperty blendColorMap;
properties::BoolProperty blendNightTexture;
@@ -95,10 +103,15 @@ private:
std::string _frame;
void addToggleLayerProperties(
std::vector<TileProviderManager::TileProviderWithName>&,
std::vector<properties::BoolProperty>& dest
LayeredTextures::TextureCategory category,
properties::SelectionProperty& dest
);
void initializeToggleLayerProperties(
LayeredTextures::TextureCategory category,
properties::SelectionProperty& dest
);
double _time;
Ellipsoid _ellipsoid;
@@ -117,6 +130,15 @@ private:
std::vector<properties::BoolProperty> _activeHeightMapLayers;
std::vector<properties::BoolProperty> _activeWaterMaskLayers;
void selectionChanged(
properties::SelectionProperty selectionProperty,
LayeredTextures::TextureCategory textureCategory);
void baseLayerSelectionChanged();
void nightLayersSelectionChanged();
void heightMapsSelectionChanged();
void waterMasksSelectionChanged();
void overlaysSelectionChanged();
DistanceSwitch _distanceSwitch;
};
@@ -98,9 +98,14 @@ namespace openspace {
texDict.getValue("FilePath", path);
texDict.getValue("Enabled", enabled);
std::shared_ptr<TileProvider> tileProvider = initProvider(path, initData);
//bool enabled = dest.size() == 0; // Only enable first layer
std::shared_ptr<TileProvider> tileProvider;
try {
tileProvider = initProvider(path, initData);
}
catch (const ghoul::RuntimeError& e) {
LERROR(e.message);
continue;
}
dest.push_back({ name, tileProvider, enabled });
}
}
@@ -111,6 +116,9 @@ namespace openspace {
{
std::shared_ptr<TileProvider> tileProvider;
CPLXMLNode * node = CPLParseXMLFile(file.c_str());
if (!node) {
throw ghoul::RuntimeError("Unable to parse XML:\n" + file);
}
if (std::string(node->pszValue) == "OpenSpaceTemporalGDALDataset") {
tileProvider = std::shared_ptr<TileProvider>(
new TemporalTileProvider(file, initData));
@@ -79,8 +79,18 @@ namespace openspace {
end.setTime(timeEnd);
}
_timeQuantizer = TimeQuantizer(start, end, timeResolution);
try {
_timeQuantizer = TimeQuantizer(start, end, timeResolution);
}
catch (const ghoul::RuntimeError& e) {
throw ghoul::RuntimeError(
"Could not create time quantizer for Temporal GDAL dataset '" +
_datasetFile + "'. " + e.message);
}
_timeFormat = TimeIdProviderFactory::getProvider(timeIdFormat);
if (!_timeFormat) {
throw ghoul::RuntimeError("Invalid Time Format " + timeIdFormat + " in " + _datasetFile);
}
CPLXMLNode* gdalNode = CPLSearchXMLNode(node, "GDAL_WMS");
return CPLSerializeXMLTree(gdalNode);
@@ -89,6 +99,10 @@ namespace openspace {
std::string TemporalTileProvider::getXMLValue(CPLXMLNode* root, const std::string& key, const std::string& defaultVal) {
CPLXMLNode * n = CPLSearchXMLNode(root, key.c_str());
if (!n) {
throw ghoul::RuntimeError("Unable to parse file " + _datasetFile + ". " + key + " missing.");
}
bool hasValue = (n != nullptr && n->psChild != nullptr && n->psChild->pszValue != nullptr);
return hasValue ? std::string(n->psChild->pszValue) : defaultVal;
}
@@ -141,7 +155,13 @@ namespace openspace {
Time tCopy(t);
if (_timeQuantizer.quantize(tCopy)) {
TimeKey timekey = _timeFormat->stringify(tCopy);
return getTileProvider(timekey);
try {
return getTileProvider(timekey);
}
catch (const ghoul::RuntimeError& e) {
LERROR(e.message);
return nullptr;
}
}
return nullptr;
}
@@ -257,23 +277,29 @@ namespace openspace {
double TimeQuantizer::parseTimeResolutionStr(const std::string& resoltutionStr) {
const char unit = resoltutionStr.back();
double value = std::stod(resoltutionStr);
// convert value to seconds, based on unit.
// The switch statment has intentional fall throughs
switch (unit) {
case 'y': value *= 365;
case 'd': value *= 24.0;
case 'h': value *= 60.0;
case 'm': value *= 60.0;
case 's': value *= 1.0;
break;
default:
ghoul_assert(false, "Invalid unit format. Using default value 1 d");
value = 60 * 60 * 24;
std::string numberString = resoltutionStr.substr(0, resoltutionStr.length() - 1);
char* p;
double value = strtol(numberString.c_str(), &p, 10);
if (*p) { // not a number
throw ghoul::RuntimeError("Cannot convert " + numberString + " to number");
}
else {
// convert value to seconds, based on unit.
// The switch statment has intentional fall throughs
switch (unit) {
case 'y': value *= 365;
case 'd': value *= 24.0;
case 'h': value *= 60.0;
case 'm': value *= 60.0;
case 's': value *= 1.0;
break;
default:
throw ghoul::RuntimeError("Invalid unit format '" + std::string(1, unit) +
"'. Expected 'y', 'd', 'h', 'm' or 's'.");
}
return value;
}
return value;
}
bool TimeQuantizer::quantize(Time& t) const {
+4 -1
View File
@@ -59,7 +59,10 @@ namespace openspace {
}
_dataset = (GDALDataset *)GDALOpen(gdalDatasetDesc.c_str(), GA_ReadOnly);
ghoul_assert(_dataset != nullptr, "Failed to load dataset:\n" << gdalDatasetDesc);
if (!_dataset) {
throw ghoul::RuntimeError("Failed to load dataset:\n" + gdalDatasetDesc);
}
//ghoul_assert(_dataset != nullptr, "Failed to load dataset:\n" << gdalDatasetDesc);
_dataLayout = DataLayout(_dataset, dataType);
_depthTransform = calculateTileDepthTransform();