From bba419fcf11586ab21919039cd5204ed8c77a780 Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Wed, 1 Jun 2016 15:08:29 -0400 Subject: [PATCH] IswaKameleonGroup --- modules/iswa/CMakeLists.txt | 2 + modules/iswa/rendering/iswacygnet.h | 1 + modules/iswa/rendering/iswadatagroup.cpp | 99 +------------ modules/iswa/rendering/iswadatagroup.h | 21 +-- modules/iswa/rendering/iswakameleongroup.cpp | 146 +++++++++++++++++++ modules/iswa/rendering/iswakameleongroup.h | 54 +++++++ modules/iswa/rendering/kameleonplane.cpp | 6 +- modules/iswa/util/iswamanager.cpp | 15 +- 8 files changed, 225 insertions(+), 119 deletions(-) create mode 100644 modules/iswa/rendering/iswakameleongroup.cpp create mode 100644 modules/iswa/rendering/iswakameleongroup.h diff --git a/modules/iswa/CMakeLists.txt b/modules/iswa/CMakeLists.txt index 68680848c0..ee85bb53a5 100644 --- a/modules/iswa/CMakeLists.txt +++ b/modules/iswa/CMakeLists.txt @@ -40,6 +40,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspacecygnet.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswagroup.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswadatagroup.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswakameleongroup.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/texturecygnet.h ) source_group("Header Files" FILES ${HEADER_FILES}) @@ -60,6 +61,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspacecygnet.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswagroup.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswadatagroup.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswakameleongroup.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/texturecygnet.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/iswa/rendering/iswacygnet.h b/modules/iswa/rendering/iswacygnet.h index 46a15fc836..925d1353f8 100644 --- a/modules/iswa/rendering/iswacygnet.h +++ b/modules/iswa/rendering/iswacygnet.h @@ -49,6 +49,7 @@ #include #include +#include namespace openspace{ class IswaGroup; diff --git a/modules/iswa/rendering/iswadatagroup.cpp b/modules/iswa/rendering/iswadatagroup.cpp index 086f74239b..a402237eb4 100644 --- a/modules/iswa/rendering/iswadatagroup.cpp +++ b/modules/iswa/rendering/iswadatagroup.cpp @@ -49,8 +49,8 @@ IswaDataGroup::IswaDataGroup(std::string name, std::string type) ,_backgroundValues("backgroundValues", "Background Values", glm::vec2(0.0), glm::vec2(0), glm::vec2(1.0)) ,_transferFunctionsFile("transferfunctions", "Transfer Functions", "${SCENE}/iswa/tfs/hot.tf") ,_dataOptions("dataOptions", "Data Options") - ,_fieldlines("fieldlineSeedsIndexFile", "Fieldline Seedpoints") - ,_fieldlineIndexFile("") + // ,_fieldlines("fieldlineSeedsIndexFile", "Fieldline Seedpoints") + // ,_fieldlineIndexFile("") { addProperty(_useLog); addProperty(_useHistogram); @@ -59,24 +59,18 @@ IswaDataGroup::IswaDataGroup(std::string name, std::string type) addProperty(_backgroundValues); addProperty(_transferFunctionsFile); addProperty(_dataOptions); - addProperty(_fieldlines); std::cout << "DataGroup" << std::endl; createDataProcessor(); registerProperties(); } - IswaDataGroup::~IswaDataGroup(){} - -void IswaDataGroup::clearGroup(){ - IswaGroup::clearGroup(); - clearFieldlines(); -} +IswaDataGroup::~IswaDataGroup(){} void IswaDataGroup::registerProperties(){ // IswaGroup::registerProperties(); - std::cout << "register properties" << std::endl; + // std::cout << "register properties" << std::endl; OsEng.gui()._iswa.registerProperty(&_useLog); OsEng.gui()._iswa.registerProperty(&_useHistogram); OsEng.gui()._iswa.registerProperty(&_autoFilter); @@ -119,16 +113,6 @@ void IswaDataGroup::registerProperties(){ LDEBUG("Group " + name() + " published dataOptionsChanged"); _groupEvent->publish("dataOptionsChanged", ghoul::Dictionary({{"dataOptions", std::make_shared >(_dataOptions.value())}})); }); - - if(_type == typeid(KameleonPlane).name()){ - OsEng.gui()._iswa.registerProperty(&_fieldlines); - - _fieldlines.onChange([this]{ - updateFieldlineSeeds(); - // LDEBUG("Group " + name() + " published fieldlinesChanged"); - // _groupEvent->publish("fieldlinesChanged", ghoul::Dictionary({{"fieldlines", std::make_shared >(_fieldlines.value())}})); - }); - } } void IswaDataGroup::registerOptions(const std::vector& options){ @@ -143,81 +127,6 @@ void IswaDataGroup::registerOptions(const std::vector selectedOptions = _fieldlines.value(); - - // SeedPath == map > - for (auto& seedPath: _fieldlineState) { - // if this option was turned off - if( std::find(selectedOptions.begin(), selectedOptions.end(), seedPath.first)==selectedOptions.end() && std::get<2>(seedPath.second)){ - LDEBUG("Removed fieldlines: " + std::get<0>(seedPath.second)); - OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + std::get<0>(seedPath.second) + "')"); - std::get<2>(seedPath.second) = false; - // if this option was turned on - } else if( std::find(selectedOptions.begin(), selectedOptions.end(), seedPath.first)!=selectedOptions.end() && !std::get<2>(seedPath.second)) { - LDEBUG("Created fieldlines: " + std::get<0>(seedPath.second)); - IswaManager::ref().createFieldline(std::get<0>(seedPath.second), _kameleonPath, std::get<1>(seedPath.second)); - std::get<2>(seedPath.second) = true; - } - } -} - -void IswaDataGroup::readFieldlinePaths(std::string indexFile){ - LINFO("Reading seed points paths from file '" << indexFile << "'"); - - // Read the index file from disk - std::ifstream seedFile(indexFile); - if (!seedFile.good()) - LERROR("Could not open seed points file '" << indexFile << "'"); - else { - std::string line; - std::string fileContent; - while (std::getline(seedFile, line)) { - fileContent += line; - } - - try{ - //Parse and add each fieldline as an selection - json fieldlines = json::parse(fileContent); - int i = 0; - - for (json::iterator it = fieldlines.begin(); it != fieldlines.end(); ++it) { - _fieldlines.addOption({i, name()+"/"+it.key()}); - _fieldlineState[i] = std::make_tuple(name()+"/"+it.key(), it.value(), false); - i++; - } - - } catch(const std::exception& e) { - LERROR("Error when reading json file with paths to seedpoints: " + std::string(e.what())); - } - } -} - -void IswaDataGroup::clearFieldlines(){ - // SeedPath == map > - for (auto& seedPath: _fieldlineState) { - if(std::get<2>(seedPath.second)){ - LDEBUG("Removed fieldlines: " + std::get<0>(seedPath.second)); - OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + std::get<0>(seedPath.second) + "')"); - std::get<2>(seedPath.second) = false; - } - } -} - void IswaDataGroup::createDataProcessor(){ if(_type == typeid(DataPlane).name()){ _dataProcessor = std::make_shared(); diff --git a/modules/iswa/rendering/iswadatagroup.h b/modules/iswa/rendering/iswadatagroup.h index 8739620be8..47a34c12cf 100644 --- a/modules/iswa/rendering/iswadatagroup.h +++ b/modules/iswa/rendering/iswadatagroup.h @@ -31,23 +31,22 @@ public: IswaDataGroup(std::string name, std::string type); ~IswaDataGroup(); - virtual void clearGroup() override; + // virtual void clearGroup() override; void registerOptions(const std::vector& options); - void registerFieldLineOptions(const std::vector& options); + // void registerFieldLineOptions(const std::vector& options); std::vector dataOptionsValue(); - std::vector fieldlineValue(); - void setFieldlineInfo(std::string fieldlineIndexFile, std::string kameleonPath); + // std::vector fieldlineValue(); + // void setFieldlineInfo(std::string fieldlineIndexFile, std::string kameleonPath); -private: +protected: void registerProperties(); - void createDataProcessor(); - void readFieldlinePaths(std::string indexFile); - void updateFieldlineSeeds(); - void clearFieldlines(); + // void readFieldlinePaths(std::string indexFile); + // void updateFieldlineSeeds(); + // void clearFieldlines(); properties::BoolProperty _useLog; properties::BoolProperty _useHistogram; @@ -56,11 +55,7 @@ private: properties::Vec2Property _backgroundValues; properties::StringProperty _transferFunctionsFile; properties::SelectionProperty _dataOptions; - properties::SelectionProperty _fieldlines; - std::string _fieldlineIndexFile; - std::string _kameleonPath; - std::map > _fieldlineState; }; } //namespace openspace diff --git a/modules/iswa/rendering/iswakameleongroup.cpp b/modules/iswa/rendering/iswakameleongroup.cpp new file mode 100644 index 0000000000..76294505c0 --- /dev/null +++ b/modules/iswa/rendering/iswakameleongroup.cpp @@ -0,0 +1,146 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* 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 + +#include +#include + +#include +#include +#include + +#include +#include +#include + +namespace { + const std::string _loggerCat = "IswaDataGroup"; + using json = nlohmann::json; +} + +namespace openspace{ +IswaKameleonGroup::IswaKameleonGroup(std::string name, std::string type) + :IswaDataGroup(name, type) + ,_fieldlines("fieldlineSeedsIndexFile", "Fieldline Seedpoints") + ,_fieldlineIndexFile("") +{ + addProperty(_fieldlines); + registerProperties(); +} + +IswaKameleonGroup::~IswaKameleonGroup(){} + +void IswaKameleonGroup::clearGroup(){ + IswaGroup::clearGroup(); + clearFieldlines(); +} + +std::vector IswaKameleonGroup::fieldlineValue(){ + return _fieldlines.value(); +} + +void IswaKameleonGroup::setFieldlineInfo(std::string fieldlineIndexFile, std::string kameleonPath){ + if(fieldlineIndexFile != _fieldlineIndexFile){ + _fieldlineIndexFile = fieldlineIndexFile; + readFieldlinePaths(_fieldlineIndexFile); + } + + if(kameleonPath != _kameleonPath){ + _kameleonPath = kameleonPath; + clearFieldlines(); + updateFieldlineSeeds(); + } +} + + +void IswaKameleonGroup::registerProperties(){ + OsEng.gui()._iswa.registerProperty(&_fieldlines); + + _fieldlines.onChange([this]{ + updateFieldlineSeeds(); + }); +} + +void IswaKameleonGroup::readFieldlinePaths(std::string indexFile){ + LINFO("Reading seed points paths from file '" << indexFile << "'"); + + // Read the index file from disk + std::ifstream seedFile(indexFile); + if (!seedFile.good()) + LERROR("Could not open seed points file '" << indexFile << "'"); + else { + std::string line; + std::string fileContent; + while (std::getline(seedFile, line)) { + fileContent += line; + } + + try{ + //Parse and add each fieldline as an selection + json fieldlines = json::parse(fileContent); + int i = 0; + + for (json::iterator it = fieldlines.begin(); it != fieldlines.end(); ++it) { + _fieldlines.addOption({i, name()+"/"+it.key()}); + _fieldlineState[i] = std::make_tuple(name()+"/"+it.key(), it.value(), false); + i++; + } + + } catch(const std::exception& e) { + LERROR("Error when reading json file with paths to seedpoints: " + std::string(e.what())); + } + } +} + +void IswaKameleonGroup::updateFieldlineSeeds(){ + std::vector selectedOptions = _fieldlines.value(); + + // SeedPath == map > + for (auto& seedPath: _fieldlineState) { + // if this option was turned off + if( std::find(selectedOptions.begin(), selectedOptions.end(), seedPath.first)==selectedOptions.end() && std::get<2>(seedPath.second)){ + LDEBUG("Removed fieldlines: " + std::get<0>(seedPath.second)); + OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + std::get<0>(seedPath.second) + "')"); + std::get<2>(seedPath.second) = false; + // if this option was turned on + } else if( std::find(selectedOptions.begin(), selectedOptions.end(), seedPath.first)!=selectedOptions.end() && !std::get<2>(seedPath.second)) { + LDEBUG("Created fieldlines: " + std::get<0>(seedPath.second)); + IswaManager::ref().createFieldline(std::get<0>(seedPath.second), _kameleonPath, std::get<1>(seedPath.second)); + std::get<2>(seedPath.second) = true; + } + } +} + +void IswaKameleonGroup::clearFieldlines(){ + // SeedPath == map > + for (auto& seedPath: _fieldlineState) { + if(std::get<2>(seedPath.second)){ + LDEBUG("Removed fieldlines: " + std::get<0>(seedPath.second)); + OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + std::get<0>(seedPath.second) + "')"); + std::get<2>(seedPath.second) = false; + } + } +} + +}//namespace openspace \ No newline at end of file diff --git a/modules/iswa/rendering/iswakameleongroup.h b/modules/iswa/rendering/iswakameleongroup.h new file mode 100644 index 0000000000..950f23fcaa --- /dev/null +++ b/modules/iswa/rendering/iswakameleongroup.h @@ -0,0 +1,54 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* 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. * +****************************************************************************************/ +#ifndef __ISWAKAMELEONGROUP_H__ +#define __ISWAKAMELEONGROUP_H__ +#include + +namespace openspace{ +class IswaKameleonGroup : public IswaDataGroup{ +public: + IswaKameleonGroup(std::string name, std::string type); + ~IswaKameleonGroup(); + + virtual void clearGroup(); + + std::vector fieldlineValue(); + void setFieldlineInfo(std::string fieldlineIndexFile, std::string kameleonPath); + +protected: + void registerProperties(); + + void readFieldlinePaths(std::string indexFile); + void updateFieldlineSeeds(); + void clearFieldlines(); + + properties::SelectionProperty _fieldlines; + + std::string _fieldlineIndexFile; + std::string _kameleonPath; + std::map > _fieldlineState; +}; + +}//namespace openspace +#endif \ No newline at end of file diff --git a/modules/iswa/rendering/kameleonplane.cpp b/modules/iswa/rendering/kameleonplane.cpp index d876b918b5..94a58331bd 100644 --- a/modules/iswa/rendering/kameleonplane.cpp +++ b/modules/iswa/rendering/kameleonplane.cpp @@ -37,10 +37,8 @@ #include #include #include -#include #include - namespace { using json = nlohmann::json; const std::string _loggerCat = "KameleonPlane"; @@ -439,7 +437,7 @@ void KameleonPlane::fillOptions(){ } } if(_group){ - std::dynamic_pointer_cast (_group)->registerOptions(_dataOptions.options()); + std::dynamic_pointer_cast (_group)->registerOptions(_dataOptions.options()); // _dataOptions.setValue(_group->dataOptionsValue()); }else{ _dataOptions.setValue(std::vector(1,0)); @@ -477,7 +475,7 @@ void KameleonPlane::updateFieldlineSeeds(){ void KameleonPlane::readFieldlinePaths(std::string indexFile){ LINFO("Reading seed points paths from file '" << indexFile << "'"); if(_group){ - std::dynamic_pointer_cast(_group)->setFieldlineInfo(indexFile, _kwPath); + std::dynamic_pointer_cast(_group)->setFieldlineInfo(indexFile, _kwPath); return; } diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index 462d961a27..fdaa865bac 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -221,15 +222,15 @@ std::string IswaManager::iswaUrl(int id, std::string type){ void IswaManager::registerGroup(std::string groupName, std::string type){ if(_groups.find(groupName) == _groups.end()){ - bool dataGroup = (type == typeid(DataPlane).name()) || - (type == typeid(DataSphere).name()) || - (type == typeid(KameleonPlane).name()); - + bool dataGroup = (type == typeid(DataPlane).name()) || + (type == typeid(DataSphere).name()); + + bool kameleonGroup = (type == typeid(KameleonPlane).name()); if(dataGroup){ - std::cout << "Register data group" << std::endl; _groups.insert(std::pair>(groupName, std::make_shared(groupName, type))); - } - else{ + }else if(kameleonGroup){ + _groups.insert(std::pair>(groupName, std::make_shared(groupName, type))); + }else{ _groups.insert(std::pair>(groupName, std::make_shared(groupName, type))); } } else if(!_groups[groupName]->isType(type)){