From 49d88ab56ba8efc60b809cc1f1a9aa471ee94e37 Mon Sep 17 00:00:00 2001 From: Kollberg Date: Tue, 2 Jul 2019 14:52:27 -0400 Subject: [PATCH] Added webfieldlinesmanager as a member variable to renderable fieldlinessequence --- modules/base/rendering/suntexturemanager.cpp | 2 +- .../renderablefieldlinessequence.cpp | 33 ++++++++-- .../rendering/renderablefieldlinessequence.h | 5 +- .../util/webfieldlinesmanager.cpp | 65 ++++++++++++++----- .../util/webfieldlinesmanager.h | 31 ++++++--- 5 files changed, 103 insertions(+), 33 deletions(-) diff --git a/modules/base/rendering/suntexturemanager.cpp b/modules/base/rendering/suntexturemanager.cpp index 1db8c63b76..bfec2d062e 100644 --- a/modules/base/rendering/suntexturemanager.cpp +++ b/modules/base/rendering/suntexturemanager.cpp @@ -44,7 +44,7 @@ namespace openspace SunTextureManager::SunTextureManager() { - _syncDir = FileSys.relativePath("./sync/magnetograms"); + _syncDir = absPath("${BASE}/sync/magnetograms") + FileSys.PathSeparator; } void SunTextureManager::update(std::unique_ptr &texture) { diff --git a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp index 342042a58b..78ec022b2b 100644 --- a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp +++ b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp @@ -54,6 +54,8 @@ namespace { constexpr const char* KeyInputFileType = "InputFileType"; // [STRING] should be path to folder containing the input files constexpr const char* KeySourceFolder = "SourceFolder"; + // [BOOLEAN] should specify whether field line data should be fetched online or not + constexpr const char* KeyWebFieldline = "WebFieldline"; // ---------------------- MANDATORY INPUT TYPE SPECIFIC KEYS ---------------------- // // [STRING] Path to a .txt file containing seed points @@ -371,8 +373,6 @@ void RenderableFieldlinesSequence::initializeGL() { // Needed for additive blending setRenderBin(Renderable::RenderBin::Overlay); - // ----------------- Initialize Web Fieldlines Manager things ---------------------// - //WebFieldlinesManager webFieldlinesManager(_sourceFiles[0]); } /** @@ -419,9 +419,23 @@ bool RenderableFieldlinesSequence::extractMandatoryInfoFromDictionary( } std::string sourceFolderPath; + bool webFieldLine; if (!_dictionary->getValue(KeySourceFolder, sourceFolderPath)) { - LERROR(fmt::format("{}: The field {} is missing", _identifier, KeySourceFolder)); - return false; + + // If this is a web-fieldline, we don't need no sourcefolder + if (!_dictionary->getValue(KeyWebFieldline, webFieldLine)) { + LERROR(fmt::format("{}: The field {} is missing", _identifier, KeySourceFolder)); + return false; + } + else if (!webFieldLine) { + LERROR(fmt::format("{}: The field {} is missing", _identifier, KeySourceFolder)); + return false; + } + } + + if (webFieldLine) { + initializeWebManager(); + sourceFolderPath = _webFieldlinesManager.getDirectory(); } // Ensure that the source folder exists and then extract @@ -530,7 +544,9 @@ void RenderableFieldlinesSequence::extractOptionalInfoFromDictionary( } } - +// The reason this exists is because some values are read from the properties in the GUI. +// This function may change the default values of those properties, if the user has specified them +// in the asset file void RenderableFieldlinesSequence::extractPropertyInfoFromDictionary() { // Specified weather to use uniform coloring or by specified quantity. std::string coloringMethodDictionary; @@ -1162,6 +1178,10 @@ void RenderableFieldlinesSequence::render(const RenderData& data, RendererTasks& } } +void RenderableFieldlinesSequence::initializeWebManager() { + _webFieldlinesManager(_identifier, "PfssIo"); +} + void RenderableFieldlinesSequence::update(const UpdateData& data) { if (_shaderProgram->isDirty()) { _shaderProgram->rebuildFromFile(); @@ -1172,8 +1192,7 @@ void RenderableFieldlinesSequence::update(const UpdateData& data) { // en liten fuling för att testa att trigga nedladdning if(currentTime > 610056120.0 && currentTime < 610056120.2){ LERROR("downloading is starting"); - WebFieldlinesManager webFieldlinesManager(_sourceFiles[0]); - webFieldlinesManager.downloadFieldlines(_sourceFiles, _startTimes, _nStates); + _webFieldlinesManager.downloadFieldlines(_sourceFiles, _startTimes, _nStates); computeSequenceEndTime(); } diff --git a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.h b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.h index 775f270111..640ffa9c21 100644 --- a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.h +++ b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.h @@ -52,6 +52,7 @@ public: bool isReady() const override; void render(const RenderData& data, RendererTasks& rendererTask) override; + void initializeWebManager(); void update(const UpdateData& data) override; private: @@ -200,7 +201,9 @@ private: // --------------------- Web Fieldlines Manager ----------------------------------- // - //WebFieldlinesManager _webFieldlinesManager; + // Web Fieldlines manager downloads and updates renderable field lines with // + // field lines downloaded from the web. // + WebFieldlinesManager _webFieldlinesManager; // --------------------- FUNCTIONS USED DURING INITIALIZATION --------------------- // diff --git a/modules/fieldlinessequence/util/webfieldlinesmanager.cpp b/modules/fieldlinessequence/util/webfieldlinesmanager.cpp index 738f09a157..8ca01b697d 100644 --- a/modules/fieldlinessequence/util/webfieldlinesmanager.cpp +++ b/modules/fieldlinessequence/util/webfieldlinesmanager.cpp @@ -40,27 +40,21 @@ namespace { namespace openspace{ - WebFieldlinesManager::WebFieldlinesManager(std::string syncDir){ - - // Using constructor for some testing -// ghoul::filesystem::File tempFile = ghoul::filesystem::File(syncDir); - //_syncDir = tempFile.directoryName(); - _syncDir = "/Users/shuy/Offline-dokument/OpenSpace/Spaceweather/OpenSpace/data/assets/testwsa/fl_pfss_io_25"; - _flsType = PFSSIO; - _flsTypeString = "PFSSIO"; - + WebFieldlinesManager::WebFieldlinesManager(std::string identifier, std::string fieldLineModelType): + _flsType(fieldLineModelType) + { + _syncDir = initializeSyncDirectory(identifier); + std::string testTime; triggerTimeInt2String(610056000, testTime); - int testInt; triggerTimeString2Int(testTime, testInt); getAvailableTriggertimes(); LERROR("WebFieldlinesManager initialized"); - - + } // For testing purposes @@ -68,7 +62,7 @@ namespace openspace{ LERROR("starting download"); for (auto& tt : _availableTriggertimes){ - downloadOsfls(_flsType, tt); + downloadOsfls(tt); //add the timetrigger at the right place in the list std::string sub = tt.substr(6, 23); @@ -88,12 +82,38 @@ namespace openspace{ _nStates += 1; } } + + // ------------------------------- OPERATORS ------------------------------- // + + // Operator () + void WebFieldlinesManager::operator()(std::string identifier, std::string fieldLineModelType) + { + _flsType = fieldLineModelType; + _syncDir = initializeSyncDirectory(identifier); + + std::string testTime; + triggerTimeInt2String(610056000, testTime); + + int testInt; + triggerTimeString2Int(testTime, testInt); + + getAvailableTriggertimes(); + + LERROR("WebFieldlinesManager initialized"); + + } + + std::string WebFieldlinesManager::getDirectory(){ + return _syncDir; + } + + // --------------------------- PRIVATE FUNCTIONS --------------------------- // void WebFieldlinesManager::update(){ } - void WebFieldlinesManager::downloadOsfls(FlsType type, std::string triggertime){ + void WebFieldlinesManager::downloadOsfls(std::string triggertime){ std::string url = "http://localhost:3000/WSA/" + triggertime; std::string destinationpath = absPath(_syncDir + '/' + triggertime.substr(6)); AsyncHttpFileDownload ashd = AsyncHttpFileDownload(url, destinationpath, HttpFileDownload::Overwrite::Yes); @@ -108,10 +128,25 @@ namespace openspace{ LERROR("failed: " + destinationpath); } } + + // Make sure that the sync directory exists + // Also creates a new directory in the web_fieldlines directory corresponding to the field line identifier + std::string WebFieldlinesManager::initializeSyncDirectory(std::string identifier) { + std::string path = absPath("${BASE}/sync/http/web_fieldlines") + FileSys.PathSeparator; + + if (!FileSys.directoryExists(path)) { + FileSys.createDirectory(path); + } + path = absPath(path + identifier); + if(!FileSys.directoryExists(path)) { + FileSys.createDirectory(path); + } + return path; + } void WebFieldlinesManager::getAvailableTriggertimes(){ - std::string url = "http://localhost:3000/WSA/available/" + _flsTypeString; + std::string url = "http://localhost:3000/WSA/available/" + _flsType; SyncHttpMemoryDownload mmryDld = SyncHttpMemoryDownload(url); HttpRequest::RequestOptions opt = {}; opt.requestTimeoutSeconds = 0; diff --git a/modules/fieldlinessequence/util/webfieldlinesmanager.h b/modules/fieldlinessequence/util/webfieldlinesmanager.h index 2a537f08a2..c1fe5cd9cc 100644 --- a/modules/fieldlinessequence/util/webfieldlinesmanager.h +++ b/modules/fieldlinessequence/util/webfieldlinesmanager.h @@ -32,23 +32,32 @@ namespace openspace { class WebFieldlinesManager{ public: - WebFieldlinesManager(); - WebFieldlinesManager(std::string syncDir); - - // What model of FieldlinesSequence is this? - enum FlsType { PFSSIO, PFSSOI, SCSOI }; + WebFieldlinesManager() = default; + + // Constructor + WebFieldlinesManager(std::string identifier, std::string fieldLineModelType); // For testing purposes void downloadFieldlines(std::vector& _sourceFile, std::vector& _startTimes, size_t& _nStates); + //---------------- OPERATORS ------------------------- // + + // To replace the constructor, takes the identifier of the field line, is used for storing the field lines mainly + // Also takes a second parameter containing the name of the field line model used. + // These may in the future be the same. + void operator ()(std::string identifier, std::string fieldLineModelType); + + // Returns the sync directory + std::string getDirectory(); private: - // for now, it's the same as user entered i asset-file + + // Directory for saving this specific typ of field line, named by the identifier std::string _syncDir; - FlsType _flsType; - std::string _flsTypeString; + // What model is this field line derived from, may come to be the same as the identifier + std::string _flsType; // List of all triggertimes(field lines states) available for download // ***turn into ints later*** @@ -59,7 +68,11 @@ private: // Download one file, given what model type and triggertime in J2000 // ***turn into ints later*** - void downloadOsfls(FlsType type, std::string triggertime); + void downloadOsfls(std::string triggertime); + + // Checks if there is a sync directory for one specific set of field lines + // If not creates one and returns the string to that directory + std::string initializeSyncDirectory(std::string identifier); // Get list of all triggertimes(field lines states) available form the server void getAvailableTriggertimes();