diff --git a/.gitignore b/.gitignore index 475ebd7f3a..b0c8998a68 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,5 @@ cmake-build-* x64/ customization.lua COMMIT.md -screenshots \ No newline at end of file +screenshots +cache_gdal/ diff --git a/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/ESRI_Imagery_World_2D.wms b/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/ESRI_Imagery_World_2D.wms index 7a1703861c..ed9f9b6905 100644 --- a/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/ESRI_Imagery_World_2D.wms +++ b/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/ESRI_Imagery_World_2D.wms @@ -13,6 +13,5 @@ 512 3 5 - false 5 diff --git a/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/Terrain.wms b/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/Terrain.wms index 25ba9e13da..ab5521e76e 100644 --- a/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/Terrain.wms +++ b/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/Terrain.wms @@ -5,5 +5,4 @@ 2 5 - false diff --git a/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/World_Imagery.wms b/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/World_Imagery.wms index 8b7db60839..79ec166a99 100644 --- a/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/World_Imagery.wms +++ b/data/assets/scene/solarsystem/planets/earth/map_service_configs/ESRI/World_Imagery.wms @@ -17,12 +17,5 @@ 256 3 5 - false 5 - - - ./gdalwmscache - .jpg - 21474836480 - diff --git a/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/CTX.wms b/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/CTX.wms index 4bebebede3..6a715034d5 100644 --- a/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/CTX.wms +++ b/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/CTX.wms @@ -16,7 +16,5 @@ 256 256 2 - false - ./gdal-cache/ctx 5 diff --git a/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Mola_Elevation.wms b/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Mola_Elevation.wms index 06b51a1f68..06b9855870 100644 --- a/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Mola_Elevation.wms +++ b/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Mola_Elevation.wms @@ -17,7 +17,5 @@ 256 256 1 - false - ./gdal-cache/mola_elevation 5 diff --git a/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Mola_PseudoColor.wms b/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Mola_PseudoColor.wms index 115fc98bd1..cdfd9ae5eb 100644 --- a/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Mola_PseudoColor.wms +++ b/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Mola_PseudoColor.wms @@ -12,9 +12,9 @@ 6 top - GEOGCS["GCS_Mars_2000_Sphere",DATUM["D_Mars_2000_Sphere",SPHEROID["Mars_2000_Sphere_IAU_IAG",3396190.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] - 360 - 360 - 3 - 10 + GEOGCS["GCS_Mars_2000_Sphere",DATUM["D_Mars_2000_Sphere",SPHEROID["Mars_2000_Sphere_IAU_IAG",3396190.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] + 360 + 360 + 3 + 10 diff --git a/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Themis_IR_Day.wms b/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Themis_IR_Day.wms index b52cfeb603..08951c67f1 100644 --- a/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Themis_IR_Day.wms +++ b/data/assets/scene/solarsystem/planets/mars/map_service_configs/LiU/Themis_IR_Day.wms @@ -3,14 +3,14 @@ http:/wms.itn.liu.se/Mars/Themis_IR_Day/tile/${z}/${y}/${x} - -180.0 - 90.0 - 180.0 - -90.0 - 213390 - 106695 - 9 - top + -180.0 + 90.0 + 180.0 + -90.0 + 213390 + 106695 + 9 + top GEOGCS["GCS_Mars_2000_Sphere",DATUM["D_Mars_2000_Sphere",SPHEROID["Mars_2000_Sphere_IAU_IAG",3396190.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] 256 diff --git a/data/assets/scene/solarsystem/planets/mars/map_service_configs/Utah/MolaCTX_Elevation.wms b/data/assets/scene/solarsystem/planets/mars/map_service_configs/Utah/MolaCTX_Elevation.wms index ea53ebdead..7671ec557a 100644 --- a/data/assets/scene/solarsystem/planets/mars/map_service_configs/Utah/MolaCTX_Elevation.wms +++ b/data/assets/scene/solarsystem/planets/mars/map_service_configs/Utah/MolaCTX_Elevation.wms @@ -10,6 +10,5 @@ -90.0 bottom - false 5 diff --git a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerBDR.wms b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerBDR.wms index fcf9b62667..3096861ca9 100644 --- a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerBDR.wms +++ b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerBDR.wms @@ -1,20 +1,20 @@ - - http://openspace.sci.utah.edu/Mercury/MessengerBDR/tile/${z}/${y}/${x} - - - -180.0 - 90.0 - 180.0 - -90.0 - 92160 - 46080 - 7 - top - - GEOGCS["GCS_Mercury_2015",DATUM["D_Mercury_2015",SPHEROID["Mercury_2015",2439400.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] - 360 - 360 - 1 - 10 + + http://openspace.sci.utah.edu/Mercury/MessengerBDR/tile/${z}/${y}/${x} + + + -180.0 + 90.0 + 180.0 + -90.0 + 92160 + 46080 + 7 + top + + GEOGCS["GCS_Mercury_2015",DATUM["D_Mercury_2015",SPHEROID["Mercury_2015",2439400.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] + 360 + 360 + 1 + 10 diff --git a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerDEM.wms b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerDEM.wms index 1469c55fec..f97d363efd 100644 --- a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerDEM.wms +++ b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerDEM.wms @@ -1,20 +1,20 @@ - - http://openspace.sci.utah.edu/Mercury/MessengerDEM/tile/${z}/${y}/${x} - - - -180.0 - 90.0 - 180.0 - -90.0 - 23040 - 11520 - 5 - top - - GEOGCS["GCS_Mercury_2015",DATUM["D_Mercury_2015",SPHEROID["Mercury_2015",2439400.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] - 360 - 360 - 1 - 10 + + http://openspace.sci.utah.edu/Mercury/MessengerDEM/tile/${z}/${y}/${x} + + + -180.0 + 90.0 + 180.0 + -90.0 + 23040 + 11520 + 5 + top + + GEOGCS["GCS_Mercury_2015",DATUM["D_Mercury_2015",SPHEROID["Mercury_2015",2439400.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] + 360 + 360 + 1 + 10 diff --git a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerHIE.wms b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerHIE.wms index 78e1ec49db..46d22c3f36 100644 --- a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerHIE.wms +++ b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerHIE.wms @@ -18,4 +18,3 @@ 1 10 - diff --git a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerHIW.wms b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerHIW.wms index 5608802e02..0e60cf0b16 100644 --- a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerHIW.wms +++ b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerHIW.wms @@ -18,4 +18,3 @@ 1 10 - diff --git a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerLOI.wms b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerLOI.wms index 345c2591b2..c0feac0a09 100644 --- a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerLOI.wms +++ b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerLOI.wms @@ -18,4 +18,3 @@ 1 10 - diff --git a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMDR.wms b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMDR.wms index a0b3d1ef7e..51e83b289f 100644 --- a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMDR.wms +++ b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMDR.wms @@ -1,20 +1,20 @@ - - http://openspace.sci.utah.edu/Mercury/MessengerMDR/tile/${z}/${y}/${x} - - - -180.0 - 90.0 - 180.0 - -90.0 - 23040 - 11521 - 5 - top - - PROJCS["Equirectangular Mercury",GEOGCS["GCS_Mercury",DATUM["D_Mercury",SPHEROID["Mercury_localRadius",2439400,0]],PRIMEM["Reference_Meridian",0],UNIT["degree",0.0174532925199433]],PROJECTION["Equirectangular"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",0],PARAMETER["standard_parallel_1",0],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]] - 360 - 360 - 3 - 10 + + http://openspace.sci.utah.edu/Mercury/MessengerMDR/tile/${z}/${y}/${x} + + + -180.0 + 90.0 + 180.0 + -90.0 + 23040 + 11521 + 5 + top + + PROJCS["Equirectangular Mercury",GEOGCS["GCS_Mercury",DATUM["D_Mercury",SPHEROID["Mercury_localRadius",2439400,0]],PRIMEM["Reference_Meridian",0],UNIT["degree",0.0174532925199433]],PROJECTION["Equirectangular"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",0],PARAMETER["standard_parallel_1",0],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]] + 360 + 360 + 3 + 10 diff --git a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMP3.wms b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMP3.wms index a00610c0fe..d1d572ee8a 100644 --- a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMP3.wms +++ b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMP3.wms @@ -1,20 +1,20 @@ - - http://openspace.sci.utah.edu/Mercury/MessengerMP3/tile/${z}/${y}/${x} - - - -180.0 - 90.0 - 180.0 - -90.0 - 46080 - 17122 - 6 - top - - PROJCS["Equirectangular Mercury",GEOGCS["GCS_Mercury",DATUM["D_Mercury",SPHEROID["Mercury_localRadius",2439400,0]],PRIMEM["Reference_Meridian",0],UNIT["degree",0.0174532925199433]],PROJECTION["Equirectangular"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",0],PARAMETER["standard_parallel_1",0],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]] - 360 - 360 - 3 - 10 + + http://openspace.sci.utah.edu/Mercury/MessengerMP3/tile/${z}/${y}/${x} + + + -180.0 + 90.0 + 180.0 + -90.0 + 46080 + 17122 + 6 + top + + PROJCS["Equirectangular Mercury",GEOGCS["GCS_Mercury",DATUM["D_Mercury",SPHEROID["Mercury_localRadius",2439400,0]],PRIMEM["Reference_Meridian",0],UNIT["degree",0.0174532925199433]],PROJECTION["Equirectangular"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",0],PARAMETER["standard_parallel_1",0],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]] + 360 + 360 + 3 + 10 diff --git a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMosaic2.wms b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMosaic2.wms index d72e9369c9..2a5770877a 100644 --- a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMosaic2.wms +++ b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerMosaic2.wms @@ -1,20 +1,20 @@ - - http://openspace.sci.utah.edu/Mercury/MessengerMosaic2/tile/${z}/${y}/${x} - - - -180.0 - 90.0 - 180.0 - -90.0 - 23040 - 11520 - 5 - top - - GEOGCS["GCS_Mercury_2015",DATUM["D_Mercury_2015",SPHEROID["Mercury_2015",2439400.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] - 360 - 360 - 3 - 10 + + http://openspace.sci.utah.edu/Mercury/MessengerMosaic2/tile/${z}/${y}/${x} + + + -180.0 + 90.0 + 180.0 + -90.0 + 23040 + 11520 + 5 + top + + GEOGCS["GCS_Mercury_2015",DATUM["D_Mercury_2015",SPHEROID["Mercury_2015",2439400.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] + 360 + 360 + 3 + 10 diff --git a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerSHADE.wms b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerSHADE.wms index aa2e992a6d..dfbceb4255 100644 --- a/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerSHADE.wms +++ b/data/assets/scene/solarsystem/planets/mercury/map_service_configs/Utah/MessengerSHADE.wms @@ -1,21 +1,20 @@ - - http://openspace.sci.utah.edu/Mercury/MessengerSHADE/tile/${z}/${y}/${x} - - - -180.0 - 90.0 - 180.0 - -90.0 - 7664 - 3832 - 4 - top - - GEOGCS["GCS_Mercury_2015",DATUM["D_Mercury_2015",SPHEROID["Mercury_2015",2439400.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] - 360 - 360 - 3 - 10 + + http://openspace.sci.utah.edu/Mercury/MessengerSHADE/tile/${z}/${y}/${x} + + + -180.0 + 90.0 + 180.0 + -90.0 + 7664 + 3832 + 4 + top + + GEOGCS["GCS_Mercury_2015",DATUM["D_Mercury_2015",SPHEROID["Mercury_2015",2439400.0,0.0]],PRIMEM["Reference_Meridian",0.0],UNIT["Degree",0.0174532925199433]] + 360 + 360 + 3 + 10 - diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index dfbe68b2be..a29596e121 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -59,6 +59,38 @@ namespace { constexpr const char* _loggerCat = "GlobeBrowsingModule"; + constexpr const openspace::properties::Property::PropertyInfo CacheEnabledInfo = { + "CacheEnabled", + "Cache Enabled", + "Determines whether automatic caching of WMS servers is enabled. Changing the " + "value of this property will not affect already created WMS datasets." + }; + + constexpr const openspace::properties::Property::PropertyInfo OfflineModeInfo = { + "OfflineMode", + "Offline Mode", + "Determines whether loaded WMS servers should be used in offline mode, that is " + "not even try to retrieve images through an internet connection. Please note " + "that this setting is only reasonable, if the caching is enabled and there is " + "available cached data. Changing the value of this property will not affect " + "already created WMS datasets." + }; + + constexpr const openspace::properties::Property::PropertyInfo CacheLocationInfo = { + "CacheLocation", + "Cache Location", + "The location of the cache folder for WMS servers. Changing the value of this " + "property will not affect already created WMS datasets." + }; + + constexpr const openspace::properties::Property::PropertyInfo CacheSizeInfo = { + "CacheSize", + "Cache Size", + "The maximum size of the cache for each WMS server. Changing the value of this " + "property will not affect already created WMS datasets." + }; + + openspace::GlobeBrowsingModule::Capabilities parseSubDatasets(char** subDatasets, int nSubdatasets) { @@ -113,11 +145,51 @@ namespace { namespace openspace { -GlobeBrowsingModule::GlobeBrowsingModule() : OpenSpaceModule(Name) {} +GlobeBrowsingModule::GlobeBrowsingModule() + : OpenSpaceModule(Name) + , _cacheEnabled(CacheEnabledInfo, false) + , _offlineMode(OfflineModeInfo, false) + , _cacheLocation(CacheLocationInfo, "${BASE}/cache_gdal") + , _cacheSizeMB(CacheSizeInfo, 1024) +{ + addProperty(_cacheEnabled); + addProperty(_offlineMode); + addProperty(_cacheLocation); + addProperty(_cacheSizeMB); +} -void GlobeBrowsingModule::internalInitialize(const ghoul::Dictionary&) { +void GlobeBrowsingModule::internalInitialize(const ghoul::Dictionary& dict) { using namespace globebrowsing; + if (dict.hasKeyAndValue(CacheEnabledInfo.identifier)) { + _cacheEnabled = dict.value(CacheEnabledInfo.identifier); + } + if (dict.hasKeyAndValue(OfflineModeInfo.identifier)) { + _offlineMode = dict.value(OfflineModeInfo.identifier); + } + if (dict.hasKeyAndValue(CacheLocationInfo.identifier)) { + _cacheLocation = dict.value(CacheLocationInfo.identifier); + } + if (dict.hasKeyAndValue(CacheSizeInfo.identifier)) { + _cacheSizeMB = static_cast(dict.value(CacheSizeInfo.identifier)); + } + + // Sanity check + const bool noWarning = dict.hasKeyAndValue("NoWarning") ? + dict.value("NoWarning") : + false; + + if (!_cacheEnabled && _offlineMode && !noWarning) { + LWARNINGC( + "GlobeBrowsingModule", + "WMS caching is disabled, but offline mode is enabled. Unless you know " + "what you are doing, this will probably cause many servers to stop working. " + "If you want to silence this warning, set the 'NoWarning' parameter to " + "'true'." + ); + } + + // Initialize global::callback::initializeGL.push_back([&]() { _tileCache = std::make_unique(); @@ -127,7 +199,7 @@ void GlobeBrowsingModule::internalInitialize(const ghoul::Dictionary&) { // Convert from MB to Bytes GdalWrapper::create( - 16ULL * 1024ULL * 1024ULL, // 16 MB + 512ULL * 1024ULL * 1024ULL, // 512 MB static_cast(CpuCap.installedMainMemory() * 0.25 * 1024 * 1024) ); addPropertySubOwner(GdalWrapper::ref()); @@ -159,31 +231,38 @@ void GlobeBrowsingModule::internalInitialize(const ghoul::Dictionary&) { fTileProvider->registerClass( layergroupid::LAYER_TYPE_NAMES[static_cast( layergroupid::TypeID::DefaultTileLayer - )]); + )] + ); fTileProvider->registerClass( layergroupid::LAYER_TYPE_NAMES[static_cast( layergroupid::TypeID::SingleImageTileLayer - )]); + )] + ); fTileProvider->registerClass( layergroupid::LAYER_TYPE_NAMES[static_cast( layergroupid::TypeID::TemporalTileLayer - )]); + )] + ); fTileProvider->registerClass( layergroupid::LAYER_TYPE_NAMES[static_cast( layergroupid::TypeID::TileIndexTileLayer - )]); + )] + ); fTileProvider->registerClass( layergroupid::LAYER_TYPE_NAMES[static_cast( layergroupid::TypeID::SizeReferenceTileLayer - )]); + )] + ); fTileProvider->registerClass( layergroupid::LAYER_TYPE_NAMES[static_cast( layergroupid::TypeID::ByLevelTileLayer - )]); + )] + ); fTileProvider->registerClass( layergroupid::LAYER_TYPE_NAMES[static_cast( layergroupid::TypeID::ByIndexTileLayer - )]); + )] + ); FactoryManager::ref().addFactory(std::move(fTileProvider)); @@ -191,7 +270,6 @@ void GlobeBrowsingModule::internalInitialize(const ghoul::Dictionary&) { ghoul_assert(fDashboard, "Dashboard factory was not created"); fDashboard->registerClass("DashboardItemGlobeLocation"); - } globebrowsing::cache::MemoryAwareTileCache* GlobeBrowsingModule::tileCache() { @@ -609,4 +687,22 @@ bool GlobeBrowsingModule::hasUrlInfo(const std::string& globe) const { return _urlList.find(globe) != _urlList.end(); } +bool GlobeBrowsingModule::isCachingEnabled() const { + return _cacheEnabled; +} + +bool GlobeBrowsingModule::isInOfflineMode() const { + return _offlineMode; +} + +std::string GlobeBrowsingModule::cacheLocation() const { + return _cacheLocation; +} + +uint64_t GlobeBrowsingModule::cacheSize() const { + uint64_t size = _cacheSizeMB; + return size * 1024 * 1024; +} + + } // namespace openspace diff --git a/modules/globebrowsing/globebrowsingmodule.h b/modules/globebrowsing/globebrowsingmodule.h index e7d62e7c12..b5981d5361 100644 --- a/modules/globebrowsing/globebrowsingmodule.h +++ b/modules/globebrowsing/globebrowsingmodule.h @@ -25,6 +25,9 @@ #ifndef __OPENSPACE_MODULE_GLOBEBROWSING___GLOBEBROWSING_MODULE___H__ #define __OPENSPACE_MODULE_GLOBEBROWSING___GLOBEBROWSING_MODULE___H__ +#include +#include +#include #include #include @@ -82,6 +85,11 @@ public: void removeWMSServer(const std::string& name); + bool isCachingEnabled() const; + bool isInOfflineMode() const; + std::string cacheLocation() const; + uint64_t cacheSize() const; // bytes + protected: void internalInitialize(const ghoul::Dictionary&) override; @@ -104,6 +112,12 @@ private: */ static std::string layerTypeNamesList(); + + properties::BoolProperty _cacheEnabled; + properties::BoolProperty _offlineMode; + properties::StringProperty _cacheLocation; + properties::UIntProperty _cacheSizeMB; + std::unique_ptr _tileCache; // name -> capabilities diff --git a/modules/globebrowsing/src/rawtiledatareader.cpp b/modules/globebrowsing/src/rawtiledatareader.cpp index 413a478d85..e1ae24819c 100644 --- a/modules/globebrowsing/src/rawtiledatareader.cpp +++ b/modules/globebrowsing/src/rawtiledatareader.cpp @@ -24,8 +24,13 @@ #include +#include #include +#include +#include #include +#include +#include #include #include @@ -46,6 +51,7 @@ #endif // _MSC_VER #include +#include namespace openspace::globebrowsing { @@ -381,7 +387,73 @@ void RawTileDataReader::initialize() { if (_datasetFilePath.empty()) { throw ghoul::RuntimeError("File path must not be empty"); } - _dataset = static_cast(GDALOpen(_datasetFilePath.c_str(), GA_ReadOnly)); + + GlobeBrowsingModule& module = *global::moduleEngine.module(); + + std::string content = _datasetFilePath; + if (module.isCachingEnabled() && FileSys.fileExists(_datasetFilePath)) { + // Only replace the 'content' if the dataset is an XML file and we want to do + // caching + std::ifstream t(_datasetFilePath); + std::string c( + (std::istreambuf_iterator(t)), + std::istreambuf_iterator() + ); + + if (c.size() > 10 && c.substr(0, 10) == "") { + // We know that _datasetFilePath is an XML file, so now we add a Cache line + // into it iff there isn't already one in the XML and if the configuration + // says we should + + // 1. Parse XML + // 2. Inject Cache tag if it isn't already there + // 3. Serialize XML to pass into GDAL + + LDEBUGC(_datasetFilePath, "Inserting caching tag"); + + bool shouldSerializeXml = false; + + CPLXMLNode* root = CPLParseXMLString(c.c_str()); + CPLXMLNode* cache = CPLSearchXMLNode(root, "Cache"); + if (!cache) { + // If there already is a cache, we don't want to modify it + cache = CPLCreateXMLNode(root, CXT_Element, "Cache"); + + CPLCreateXMLElementAndValue( + cache, + "Path", + absPath(module.cacheLocation()).c_str() + ); + CPLCreateXMLElementAndValue(cache, "Depth", "4"); + CPLCreateXMLElementAndValue(cache, "Expires", "315576000"); // 10 years + CPLCreateXMLElementAndValue( + cache, + "MaxSize", + std::to_string(module.cacheSize()).c_str() + ); + + // The serialization only needs to be one if the cache didn't exist + // already + shouldSerializeXml = true; + } + + if (module.isInOfflineMode()) { + CPLXMLNode* offlineMode = CPLSearchXMLNode(root, "OfflineMode"); + if (!offlineMode) { + CPLCreateXMLElementAndValue(root, "OfflineMode", "true"); + shouldSerializeXml = true; + } + } + + + if (shouldSerializeXml) { + content = std::string(CPLSerializeXMLTree(root)); + //CPLSerializeXMLTreeToFile(root, (_datasetFilePath + ".xml").c_str()); + } + } + } + + _dataset = static_cast(GDALOpen(content.c_str(), GA_ReadOnly)); if (!_dataset) { throw ghoul::RuntimeError("Failed to load dataset: " + _datasetFilePath); } diff --git a/openspace.cfg b/openspace.cfg index e87a377be8..070b0ed7c1 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -68,12 +68,30 @@ Paths = { SCRIPTS = "${BASE}/scripts", SHADERS = "${BASE}/shaders" } + +ModuleConfigurations = { + GlobeBrowsing = { + CacheEnabled = false, + -- OfflineMode = true, + -- NoWarning = true, + CacheLocation = "${BASE}/cache_gdal", + CacheSize = 1024 -- in megabytes PER DATASET + }, + Sync = { + SynchronizationRoot = "${SYNC}", + HttpSynchronizationRepositories = { + "data.openspaceproject.com/request" + } + } +} + Fonts = { Mono = "${FONTS}/Bitstream-Vera-Sans-Mono/VeraMono.ttf", Light = "${FONTS}/Roboto/Roboto-Regular.ttf", Console = "${FONTS}/Inconsolata/Inconsolata-Regular.ttf", Loading = "${FONTS}/Roboto/Roboto-Regular.ttf" } + Logging = { LogDir = "${LOGS}", -- LogLevel = "Trace", @@ -112,14 +130,6 @@ ScreenshotUseDate = true -- DisableRenderingOnMaster = true -- DisableSceneOnMaster = true -- DisableInGameConsole = true -ModuleConfigurations = { - Sync = { - SynchronizationRoot = "${SYNC}", - HttpSynchronizationRepositories = { - "data.openspaceproject.com/request" - } - } -} RenderingMethod = "Framebuffer" OpenGLDebugContext = { Activate = false,