From a4d90fb6679e8a9c30a467f2d60925a85cfd54f0 Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Tue, 24 May 2016 14:42:38 -0400 Subject: [PATCH] Load cdf files at start up --- data/cdflist.json | 32 +++++ data/cdflist.txt | 45 ++++++- data/scene/default.scene | 2 +- modules/iswa/rendering/iswagroup.cpp | 2 +- modules/iswa/util/iswamanager.cpp | 126 +++++++++++++----- modules/iswa/util/iswamanager.h | 18 ++- modules/iswa/util/iswamanager_lua.inl | 42 ++++-- .../onscreengui/include/guiiswacomponent.h | 5 +- modules/onscreengui/src/guiiswacomponent.cpp | 99 +++++--------- 9 files changed, 250 insertions(+), 121 deletions(-) create mode 100644 data/cdflist.json diff --git a/data/cdflist.json b/data/cdflist.json new file mode 100644 index 0000000000..7046bc502f --- /dev/null +++ b/data/cdflist.json @@ -0,0 +1,32 @@ +[ + {"group" : "CCMC-3D-CDF", + "fieldlinefile" : "${OPENSPACE_DATA}/scene/iswa/cdf/fieldlines.json", + "cdfs" : [ + { + "name" : "CCMC-00:00:00", + "path" : "../../GM_CDF/3d__var_1_e20000101-000000-000.out.cdf", + "date" : "2000-01-01T00:00:00.00" + }, + { + "name" : "CCMC-00:30:00", + "path" : "../../GM_CDF/3d__var_1_e20000101-003000-000.out.cdf", + "date" : "2000-01-01T00:30:00.00" + }, + { + "name" : "CCMC-01:00:00", + "path" : "../../GM_CDF/3d__var_1_e20000101-010000-000.out.cdf", + "date" : "2000-01-01T10:00:00.00" + }, + { + "name" : "CCMC-01:30:00", + "path" : "../../GM_CDF/3d__var_1_e20000101-013000-000.out.cdf", + "date" : "2000-01-01T01:30:00.00" + }, + { + "name" : "CCMC-02:00:00", + "path" : "../../GM_CDF/3d__var_1_e20000101-020000-000.out.cdf", + "date" : "2000-01-01T02:00:00.00" + } + ] + } +] \ No newline at end of file diff --git a/data/cdflist.txt b/data/cdflist.txt index 4206574687..b0f0feaf60 100644 --- a/data/cdflist.txt +++ b/data/cdflist.txt @@ -1,5 +1,40 @@ -../../GM_CDF/3d__var_1_e20000101-000000-000.out.cdf 2000-01-01T00:00:00.00 -../../GM_CDF/3d__var_1_e20000101-003000-000.out.cdf 2000-01-01T00:30:00.00 -../../GM_CDF/3d__var_1_e20000101-010000-000.out.cdf 2000-01-01T01:00:00.00 -../../GM_CDF/3d__var_1_e20000101-013000-000.out.cdf 2000-01-01T01:30:00.00 -../../GM_CDF/3d__var_1_e20000101-020000-000.out.cdf 2000-01-01T02:00:00.00 \ No newline at end of file +{"cdfgroups" : [{ + "group" : "CCMC-3D-CDF", + "fieldlinefile" : "${OPENSPACE_DATA}/scene/iswa/cdf/fieldlines.json", + "cdfs" : [ + { + "name" : "CCMC-00:00:00", + "path" : "../../GM_CDF/3d__var_1_e20000101-000000-000.out.cdf" + "time" : "2000-01-01T00:00:00.00" + }, + { + "name" : "CCMC-00:30:00", + "path" : "../../GM_CDF/3d__var_1_e20000101-003000-000.out.cdf" + "time" : "2000-01-01T00:00:00.00" + }, + { + "name" : "CCMC-01:00:00", + "path" : "../../GM_CDF/3d__var_1_e20000101-010000-000.out.cdf" + "time" : "2000-01-01T10:00:00.00" + }, + { + "name" : "CCMC-01:30:00", + "path" : "../../GM_CDF/3d__var_1_e20000101-013000-000.out.cdf" + "time" : "2000-01-01T01:30:00.00" + }, + { + "name" : "CCMC-02:00:00", + "path" : "../../GM_CDF/3d__var_1_e20000101-020000-000.out.cdf" + "time" : "2000-01-01T02:00:00.00" + }, + ] + } + ] +} +CCMC-3D-CDF +${OPENSPACE_DATA}/scene/iswa/cdf/fieldlines.json +CCMC-00:00:00 ../../GM_CDF/3d__var_1_e20000101-000000-000.out.cdf 2000-01-01T00:00:00.00 +CCMC-00:30:00 ../../GM_CDF/3d__var_1_e20000101-003000-000.out.cdf 2000-01-01T00:30:00.00 +CCMC-01:00:00 ../../GM_CDF/3d__var_1_e20000101-010000-000.out.cdf 2000-01-01T01:00:00.00 +CCMC-01:30:00 ../../GM_CDF/3d__var_1_e20000101-013000-000.out.cdf 2000-01-01T01:30:00.00 +CCMC-02:00:00 ../../GM_CDF/3d__var_1_e20000101-020000-000.out.cdf 2000-01-01T02:00:00.00 \ No newline at end of file diff --git a/data/scene/default.scene b/data/scene/default.scene index 5100e53e33..5c5a573f9f 100644 --- a/data/scene/default.scene +++ b/data/scene/default.scene @@ -44,7 +44,7 @@ function postInitialization() --openspace.iswa.addCygnet(-2,"Data","GM"); --openspace.iswa.addCygnet(-3,"Data","GM"); - + openspace.iswa.addCdfFiles("${OPENSPACE_DATA}/cdflist.json"); --[[ openspace.iswa.addScreenSpaceCygnet( diff --git a/modules/iswa/rendering/iswagroup.cpp b/modules/iswa/rendering/iswagroup.cpp index 23e3b3b32f..236041f986 100644 --- a/modules/iswa/rendering/iswagroup.cpp +++ b/modules/iswa/rendering/iswagroup.cpp @@ -33,7 +33,7 @@ namespace openspace { IswaGroup::IswaGroup(std::string name) :_enabled("enabled", "Enabled", true) ,_useLog("useLog","Use Logarithm", false) - ,_useHistogram("_useHistogram", "Use Histogram", true) + ,_useHistogram("_useHistogram", "Use Histogram", false) ,_normValues("normValues", "Normalize Values", glm::vec2(1.0,1.0), glm::vec2(0), glm::vec2(5.0)) ,_backgroundValues("backgroundValues", "Background Values", glm::vec2(0.0), glm::vec2(0), glm::vec2(1.0)) ,_transferFunctionsFile("transferfunctions", "Transfer Functions", "${SCENE}/iswa/tfs/hot.tf") diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index 6610956b32..0d6e913241 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -143,15 +143,24 @@ void IswaManager::addIswaCygnet(int id, std::string type, std::string group){ LDEBUG("Download to memory was aborted for data cygnet with id "+ std::to_string(id)+": " + err); } ); - }else{ - // Kameleonplane? - // LERROR("No cygnet with id 0"); - std::string kwPath = "${OPENSPACE_DATA}/BATSRUS.cdf"; - if(type == "x" || type == "y" || type == "z") - createKameleonPlane(kwPath, type, group); - else - createKameleonPlane(kwPath, "z", group); } + // else{ + // // Kameleonplane? + // // LERROR("No cygnet with id 0"); + // std::string kwPath = "${OPENSPACE_DATA}/BATSRUS.cdf"; + // if(type == "x" || type == "y" || type == "z") + // createKameleonPlane(kwPath, type, group); + // else + // createKameleonPlane(kwPath, "z", group); + // } +} + +void IswaManager::addKameleonCdf(std::string group, int pos){ + // auto info = _cdfInformation[group][pos]; + // std::cout << group << " " << pos << std::endl; + createKameleonPlane(_cdfInformation[group][pos], "z"); + createKameleonPlane(_cdfInformation[group][pos], "y"); + createKameleonPlane(_cdfInformation[group][pos], "x"); } std::future IswaManager::fetchImageCygnet(int id){ @@ -225,11 +234,6 @@ void IswaManager::registerOptionsToGroup(std::string name, const std::vector IswaManager::iswaGroup(std::string name){ - // for(auto group : _groups){ - // if(group.second->name() == name){ - // return group.second; - // } - // } if(_groups.find(name) != _groups.end()){ return _groups[name]; } @@ -245,6 +249,10 @@ std::map>& IswaManager::groups(){ return _groups; } +std::map>& IswaManager::cdfInformation(){ + return _cdfInformation; +} + std::shared_ptr IswaManager::downloadMetadata(int id){ std::shared_ptr metaFuture = std::make_shared(); @@ -317,11 +325,11 @@ std::string IswaManager::jsonPlaneToLuaTable(std::shared_ptr dat return ""; } -std::string IswaManager::parseKWToLuaTable(std::string kwPath, std::string cut, std::string group){ - if(kwPath != ""){ - const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension(); +std::string IswaManager::parseKWToLuaTable(CdfInfo info, std::string cut){ + if(info.path != ""){ + const std::string& extension = ghoul::filesystem::File(absPath(info.path)).fileExtension(); if(extension == "cdf"){ - KameleonWrapper kw = KameleonWrapper(absPath(kwPath)); + KameleonWrapper kw = KameleonWrapper(absPath(info.path)); std::string parent = kw.getParent(); std::string frame = kw.getFrame(); @@ -346,7 +354,7 @@ std::string IswaManager::parseKWToLuaTable(std::string kwPath, std::string cut, } std::string table = "{" - "Name = 'KameleonPlane-"+cut+"'," + "Name = '"+info.name+"-"+cut+"_"+info.group+"'," "Parent = '" + parent + "', " "Renderable = {" "Type = 'KameleonPlane', " @@ -356,11 +364,11 @@ std::string IswaManager::parseKWToLuaTable(std::string kwPath, std::string cut, "GridMax = " + std::to_string(max) + ", " "SpatialScale = " + std::to_string(spatialScale) + ", " "UpdateTime = 0, " - "kwPath = '" + kwPath + "' ," + "kwPath = '" + info.path + "' ," "axisCut = '"+cut+"'," "CoordinateType = '" + coordinateType + "', " - "Group = '"+ group + "'," - "fieldlineSeedsIndexFile = '${OPENSPACE_DATA}/scene/iswa/cdf/fieldlines.json'" + "Group = '"+ info.group + "'," + "fieldlineSeedsIndexFile = '"+info.fieldlineSeedsIndexFile+"'" "}" "}" ; @@ -472,18 +480,20 @@ void IswaManager::createSphere(std::shared_ptr data){ } } -void IswaManager::createKameleonPlane(std::string kwPath, std::string cut, std::string group){ - const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension(); +void IswaManager::createKameleonPlane(CdfInfo info, std::string cut){ + std::cout << info.name << " " << cut << std::endl; - if(FileSys.fileExists(absPath(kwPath)) && extension == "cdf"){ - std::string luaTable = parseKWToLuaTable(kwPath, cut, group); + const std::string& extension = ghoul::filesystem::File(absPath(info.path)).fileExtension(); + + if(FileSys.fileExists(absPath(info.path)) && extension == "cdf"){ + std::string luaTable = parseKWToLuaTable(info, cut); if(!luaTable.empty()){ - // std::cout << luaTable << std::endl; + // // std::cout << luaTable << std::endl; std::string script = "openspace.addSceneGraphNode(" + luaTable + ");"; OsEng.scriptEngine().queueScript(script); } }else{ - LWARNING( absPath(kwPath) + " is not a cdf file or can't be found."); + LWARNING( absPath(info.path) + " is not a cdf file or can't be found."); } } @@ -549,6 +559,46 @@ void IswaManager::fillCygnetInfo(std::string jsonString){ } } +void IswaManager::addCdfFiles(std::string path){ + path = absPath(path); + if(FileSys.fileExists(path)){ + + std::string basePath = path.substr(0, path.find_last_of("/\\")); + std::ifstream jsonFile(path); + + if (jsonFile.is_open()){ + json cdfGroups = json::parse(jsonFile); + for(int i=0; i(); + + json cdfs = cdfGroup["cdfs"]; + for(int j=0; j fetchImageCygnet(int id); @@ -91,6 +100,8 @@ public: std::map>& cygnetInformation(); std::map>& groups(); + // std::vector& cdfInformation(); + std::map>& cdfInformation(); static scripting::ScriptEngine::LuaLibrary luaLibrary(); @@ -98,16 +109,17 @@ public: return _iswaEvent; } - void createKameleonPlane(std::string kwPath, std::string cut="z", std::string group=""); + void addCdfFiles(std::string path); private: std::shared_ptr downloadMetadata(int id); std::string jsonPlaneToLuaTable(std::shared_ptr data); std::string jsonSphereToLuaTable(std::shared_ptr data); - std::string parseKWToLuaTable(std::string kwPath, std::string cut="z", std::string group=""); + std::string parseKWToLuaTable(CdfInfo info, std::string cut="z"); void createScreenSpace(int id); void createPlane(std::shared_ptr data); void createSphere(std::shared_ptr data); + void createKameleonPlane(CdfInfo info, std::string cut); void fillCygnetInfo(std::string jsonString); @@ -120,6 +132,8 @@ private: std::map> _groups; std::map> _cygnetInformation; + // std::vector _cdfInformation; + std::map> _cdfInformation; ghoul::Event _iswaEvent; diff --git a/modules/iswa/util/iswamanager_lua.inl b/modules/iswa/util/iswamanager_lua.inl index 7bd5e76c8c..8e44701ca5 100644 --- a/modules/iswa/util/iswamanager_lua.inl +++ b/modules/iswa/util/iswamanager_lua.inl @@ -92,25 +92,25 @@ int iswa_addScreenSpaceCygnet(lua_State* L){ return 0; } -int iswa_addKameleonPlane(lua_State* L){ - int nArguments = lua_gettop(L); +// int iswa_addKameleonPlane(lua_State* L){ +// int nArguments = lua_gettop(L); - std::string kwPath = ""; - std::string type = "x"; - std::string group = ""; +// std::string kwPath = ""; +// std::string type = "x"; +// std::string group = ""; - if(nArguments > 0) - kwPath = luaL_checkstring(L, 1); +// if(nArguments > 0) +// kwPath = luaL_checkstring(L, 1); - if(nArguments > 1) - type = luaL_checkstring(L, 2); +// if(nArguments > 1) +// type = luaL_checkstring(L, 2); - if(nArguments > 2) - group = luaL_checkstring(L, 3); +// if(nArguments > 2) +// group = luaL_checkstring(L, 3); - IswaManager::ref().createKameleonPlane(kwPath, type, group); - return 0; -} +// IswaManager::ref().createKameleonPlane(kwPath, type, group); +// return 0; +// } int iswa_removeCygnet(lua_State* L){ std::string name = luaL_checkstring(L, -1); @@ -149,6 +149,20 @@ int iswa_removeGroup(lua_State* L){ return 0; } +int iswa_addCdfFiles(lua_State* L){ + std::string path = luaL_checkstring(L, 1); + IswaManager::ref().addCdfFiles(path); + + return 0; +} + +int iswa_addKameleonPlanes(lua_State* L){ + std::string group = luaL_checkstring(L, 1); + int pos = lua_tonumber(L, 2); + IswaManager::ref().addKameleonCdf(group, pos); + // auto cdfInfo = + return 0; +} }// namespace luascriptfunctions diff --git a/modules/onscreengui/include/guiiswacomponent.h b/modules/onscreengui/include/guiiswacomponent.h index a73da644ac..2aeaef3b18 100644 --- a/modules/onscreengui/include/guiiswacomponent.h +++ b/modules/onscreengui/include/guiiswacomponent.h @@ -39,16 +39,17 @@ struct RadioOption { class GuiIswaComponent : public GuiPropertyComponent { public: + GuiIswaComponent(); virtual void render() override; private: bool gmdata; bool gmimage; bool iondata; - bool kameleon; - std::vector _cdfOptions; int _cdfOption; + std::vector _cdfOptions; + std::map _cdfOptionsMap; }; diff --git a/modules/onscreengui/src/guiiswacomponent.cpp b/modules/onscreengui/src/guiiswacomponent.cpp index e52917784e..52ecdfb18c 100644 --- a/modules/onscreengui/src/guiiswacomponent.cpp +++ b/modules/onscreengui/src/guiiswacomponent.cpp @@ -57,12 +57,15 @@ namespace { namespace openspace { namespace gui { +GuiIswaComponent::GuiIswaComponent() + :GuiPropertyComponent() + ,_cdfOption(-1) +{} void GuiIswaComponent::render() { bool gmdatavalue = gmdata; bool gmimagevalue = gmimage; bool iondatavalue = iondata; - bool kameleonvalue = kameleon; ImGui::Begin("ISWA", &_isEnabled, size, 0.5f); ImGui::Text("Global Magnetosphere"); @@ -72,8 +75,6 @@ void GuiIswaComponent::render() { ImGui::Text("Ionosphere"); ImGui::Checkbox("Ion From Data", &iondata); - ImGui::Text("Kameleon"); - ImGui::Checkbox("BATSRUS.cdf", &kameleon); ImGui::Spacing(); static const int addCygnetBufferSize = 256; @@ -83,41 +84,6 @@ void GuiIswaComponent::render() { if(ImGui::SmallButton("Add Cygnet")) OsEng.scriptEngine().queueScript("openspace.iswa.addCygnet("+std::string(addCygnetBuffer)+");"); - static const int cdfListSize = 256; - static char cdfList[cdfListSize]; - - std::string startPath = absPath("${OPENSPACE_DATA}/cdflist.txt"); - std::copy(startPath.begin(), startPath.end(),cdfList); - - ImGui::InputText("cdf list", cdfList, cdfListSize); - if(ImGui::SmallButton("Add Cdf files")){ - _cdfOption = -1; - if(FileSys.fileExists(cdfList)){ - std::string list = std::string(cdfList); - - std::string line; - std::string basePath = list.substr(0, list.find_last_of("/\\")); - - std::ifstream cdfListFile(list); - int i = 0; - if(cdfListFile.is_open()){ - while(getline(cdfListFile, line)){ - std::string path = line.substr(0, line.find_first_of(" ")); - std::string date = line.substr(line.find_first_of(" ")+1); - - - _cdfOptions.push_back({i, basePath+"/"+path, date}); - i++; - } - } - - }else{ - LWARNING( std::string(cdfList) + " is not a cdf file or can't be found."); - } - - - } - if(gmdata != gmdatavalue){ if(gmdata){ std::string x = "openspace.iswa.addCygnet(-1,'Data','GMData');"; @@ -148,38 +114,41 @@ void GuiIswaComponent::render() { } } - if(kameleon != kameleonvalue){ - if(kameleon){ - OsEng.scriptEngine().queueScript("openspace.iswa.addKameleonPlane('${OPENSPACE_DATA}/BATSRUS.cdf','z','BATSRUS');"); - OsEng.scriptEngine().queueScript("openspace.iswa.addKameleonPlane('${OPENSPACE_DATA}/BATSRUS.cdf','y','BATSRUS');"); - OsEng.scriptEngine().queueScript("openspace.iswa.addKameleonPlane('${OPENSPACE_DATA}/BATSRUS.cdf','x','BATSRUS');"); - }else{ - OsEng.scriptEngine().queueScript("openspace.iswa.removeGroup('BATSRUS');"); - } - } - if(ImGui::CollapsingHeader("Cdf files")){ - int cdfOptionValue = _cdfOption; + auto cdfInfo = IswaManager::ref().cdfInformation(); - for(auto radioOption : _cdfOptions){ - std::string path = radioOption.path; - std::string cdfName = path.substr(path.find_last_of("/\\")+1); - ImGui::RadioButton(cdfName.c_str(), &_cdfOption, radioOption.value); - // ImGui::Text(cdfName.c_str()); - } + for(auto group : cdfInfo){ + std::string groupName = group.first; + if(_cdfOptionsMap.find(groupName) == _cdfOptionsMap.end()){ + _cdfOptionsMap[groupName] = -1; + } - if(_cdfOption != cdfOptionValue){ - OsEng.scriptEngine().queueScript("openspace.iswa.removeGroup('Kameleon');"); + if(ImGui::CollapsingHeader(groupName.c_str())){ + int cdfOptionValue = _cdfOptionsMap[groupName]; + auto cdfs = group.second; - std::string path = _cdfOptions[_cdfOption].path; - std::string date = _cdfOptions[_cdfOption].date; + for(int i=0; i 0){ + groupName = cdfs[cdfOptionValue].group; + // std::cout << groupName << std::endl; + OsEng.scriptEngine().queueScript("openspace.iswa.removeGroup('"+groupName+"');"); + } + + std::string path = cdfs[cdfOption].path; + std::string date = cdfs[cdfOption].date; + groupName = cdfs[cdfOption].group; + // std::cout << path << ", " << date << ", " << groupName << std::endl; + OsEng.scriptEngine().queueScript("openspace.iswa.addKameleonPlanes('"+groupName+"',"+std::to_string(cdfOption)+");"); + OsEng.scriptEngine().queueScript("openspace.time.setTime('"+date+"');"); + OsEng.scriptEngine().queueScript("openspace.time.setDeltaTime(0);"); + } + } } }