From 27a046d81d859918c3d7d87a71ebc12353930ecf Mon Sep 17 00:00:00 2001 From: Sebastian Piwell Date: Wed, 1 Jun 2016 14:40:00 -0400 Subject: [PATCH] IswaDataGroup --- modules/iswa/CMakeLists.txt | 2 + modules/iswa/rendering/dataplane.cpp | 2 +- modules/iswa/rendering/datasphere.cpp | 2 +- modules/iswa/rendering/iswacygnet.h | 2 + modules/iswa/rendering/iswadatagroup.cpp | 231 +++++++++++++++++++++++ modules/iswa/rendering/iswadatagroup.h | 67 +++++++ modules/iswa/rendering/iswagroup.cpp | 217 +++------------------ modules/iswa/rendering/iswagroup.h | 33 +--- modules/iswa/rendering/kameleonplane.cpp | 6 +- modules/iswa/util/iswamanager.cpp | 49 ++++- 10 files changed, 373 insertions(+), 238 deletions(-) create mode 100644 modules/iswa/rendering/iswadatagroup.cpp create mode 100644 modules/iswa/rendering/iswadatagroup.h diff --git a/modules/iswa/CMakeLists.txt b/modules/iswa/CMakeLists.txt index ef5b83a613..68680848c0 100644 --- a/modules/iswa/CMakeLists.txt +++ b/modules/iswa/CMakeLists.txt @@ -39,6 +39,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasphere.h ${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/texturecygnet.h ) source_group("Header Files" FILES ${HEADER_FILES}) @@ -58,6 +59,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasphere.cpp ${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/texturecygnet.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/iswa/rendering/dataplane.cpp b/modules/iswa/rendering/dataplane.cpp index e4bee8c6b3..fddd852a12 100644 --- a/modules/iswa/rendering/dataplane.cpp +++ b/modules/iswa/rendering/dataplane.cpp @@ -358,7 +358,7 @@ void DataPlane::fillOptions(){ } _dataOptions.setValue(std::vector(1,0)); if(_group) - _group->registerOptions(_dataOptions.options()); + std::dynamic_pointer_cast (_group)->registerOptions(_dataOptions.options()); } }// namespace openspace \ No newline at end of file diff --git a/modules/iswa/rendering/datasphere.cpp b/modules/iswa/rendering/datasphere.cpp index 216b7127c7..36af34b290 100644 --- a/modules/iswa/rendering/datasphere.cpp +++ b/modules/iswa/rendering/datasphere.cpp @@ -374,7 +374,7 @@ void DataSphere::fillOptions(){ } _dataOptions.setValue(std::vector(1,0)); if(_group) - _group->registerOptions(_dataOptions.options()); + std::dynamic_pointer_cast(_group)->registerOptions(_dataOptions.options()); // IswaManager::ref().registerOptionsToGroup(_data->groupName, _dataOptions.options()); } diff --git a/modules/iswa/rendering/iswacygnet.h b/modules/iswa/rendering/iswacygnet.h index 2c8bee34ba..46a15fc836 100644 --- a/modules/iswa/rendering/iswacygnet.h +++ b/modules/iswa/rendering/iswacygnet.h @@ -47,6 +47,8 @@ #include #include +#include +#include namespace openspace{ class IswaGroup; diff --git a/modules/iswa/rendering/iswadatagroup.cpp b/modules/iswa/rendering/iswadatagroup.cpp new file mode 100644 index 0000000000..086f74239b --- /dev/null +++ b/modules/iswa/rendering/iswadatagroup.cpp @@ -0,0 +1,231 @@ +/***************************************************************************************** +* * +* 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{ +IswaDataGroup::IswaDataGroup(std::string name, std::string type) + :IswaGroup(name, type) + ,_useLog("useLog","Use Logarithm", false) + ,_useHistogram("useHistogram", "Use Histogram", false) + ,_autoFilter("autoFilter", "Auto Filter", true) + ,_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") + ,_dataOptions("dataOptions", "Data Options") + ,_fieldlines("fieldlineSeedsIndexFile", "Fieldline Seedpoints") + ,_fieldlineIndexFile("") +{ + addProperty(_useLog); + addProperty(_useHistogram); + addProperty(_autoFilter); + addProperty(_normValues); + addProperty(_backgroundValues); + addProperty(_transferFunctionsFile); + addProperty(_dataOptions); + addProperty(_fieldlines); + + std::cout << "DataGroup" << std::endl; + createDataProcessor(); + registerProperties(); +} + + IswaDataGroup::~IswaDataGroup(){} + +void IswaDataGroup::clearGroup(){ + IswaGroup::clearGroup(); + clearFieldlines(); +} + +void IswaDataGroup::registerProperties(){ + // IswaGroup::registerProperties(); + + std::cout << "register properties" << std::endl; + OsEng.gui()._iswa.registerProperty(&_useLog); + OsEng.gui()._iswa.registerProperty(&_useHistogram); + OsEng.gui()._iswa.registerProperty(&_autoFilter); + OsEng.gui()._iswa.registerProperty(&_normValues); + OsEng.gui()._iswa.registerProperty(&_backgroundValues); + OsEng.gui()._iswa.registerProperty(&_transferFunctionsFile); + OsEng.gui()._iswa.registerProperty(&_dataOptions); + + _useLog.onChange([this]{ + LDEBUG("Group " + name() + " published useLogChanged"); + _groupEvent->publish("useLogChanged", ghoul::Dictionary({{"useLog", _useLog.value()}})); + }); + + _useHistogram.onChange([this]{ + LDEBUG("Group " + name() + " published useHistogramChanged"); + _groupEvent->publish("useHistogramChanged", ghoul::Dictionary({{"useHistogram", _useHistogram.value()}})); + }); + + _autoFilter.onChange([this]{ + LDEBUG("Group " + name() + " published autoFilterChanged"); + _groupEvent->publish("autoFilterChanged", ghoul::Dictionary({{"autoFilter", _autoFilter.value()}})); + }); + + _normValues.onChange([this]{ + LDEBUG("Group " + name() + " published normValuesChanged"); + _groupEvent->publish("normValuesChanged", ghoul::Dictionary({{"normValues", std::make_shared(_normValues.value())}})); + }); + + _backgroundValues.onChange([this]{ + LDEBUG("Group " + name() + " published backgroundValuesChanged"); + _groupEvent->publish("backgroundValuesChanged", ghoul::Dictionary({{"backgroundValues", std::make_shared(_backgroundValues.value())}})); + }); + + _transferFunctionsFile.onChange([this]{ + LDEBUG("Group " + name() + " published transferFunctionsChanged"); + _groupEvent->publish("transferFunctionsChanged", ghoul::Dictionary({{"transferFunctions", _transferFunctionsFile.value()}})); + }); + + _dataOptions.onChange([this]{ + 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){ + if(!_registered) + registerProperties(); + + if(_dataOptions.options().empty()){ + for(auto option : options){ + _dataOptions.addOption({option.value, option.description}); + } + _dataOptions.setValue(std::vector(1,0)); + } +} + +void IswaDataGroup::setFieldlineInfo(std::string fieldlineIndexFile, std::string kameleonPath){ + + if(fieldlineIndexFile != _fieldlineIndexFile){ + _fieldlineIndexFile = fieldlineIndexFile; + readFieldlinePaths(_fieldlineIndexFile); + } + + if(kameleonPath != _kameleonPath){ + _kameleonPath = kameleonPath; + clearFieldlines(); + updateFieldlineSeeds(); + } +} + +void IswaDataGroup::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 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(); + }else if(_type == typeid(DataSphere).name()){ + _dataProcessor = std::make_shared(); + }else if(_type == typeid(KameleonPlane).name()){ + _dataProcessor = std::make_shared(); + } +} + +} //namespace openspace diff --git a/modules/iswa/rendering/iswadatagroup.h b/modules/iswa/rendering/iswadatagroup.h new file mode 100644 index 0000000000..8739620be8 --- /dev/null +++ b/modules/iswa/rendering/iswadatagroup.h @@ -0,0 +1,67 @@ +/***************************************************************************************** +* * +* 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 __ISWADATAGROUP_H__ +#define __ISWADATAGROUP_H__ +#include + +namespace openspace{ +class IswaDataGroup : public IswaGroup{ +public: + IswaDataGroup(std::string name, std::string type); + ~IswaDataGroup(); + + virtual void clearGroup() override; + + void registerOptions(const std::vector& options); + void registerFieldLineOptions(const std::vector& options); + + std::vector dataOptionsValue(); + std::vector fieldlineValue(); + void setFieldlineInfo(std::string fieldlineIndexFile, std::string kameleonPath); + +private: + void registerProperties(); + + void createDataProcessor(); + + void readFieldlinePaths(std::string indexFile); + void updateFieldlineSeeds(); + void clearFieldlines(); + + properties::BoolProperty _useLog; + properties::BoolProperty _useHistogram; + properties::BoolProperty _autoFilter; + properties::Vec2Property _normValues; + properties::Vec2Property _backgroundValues; + properties::StringProperty _transferFunctionsFile; + properties::SelectionProperty _dataOptions; + properties::SelectionProperty _fieldlines; + + std::string _fieldlineIndexFile; + std::string _kameleonPath; + std::map > _fieldlineState; +}; + +} //namespace openspace +#endif // __ISWADATAGROUP_H__ \ No newline at end of file diff --git a/modules/iswa/rendering/iswagroup.cpp b/modules/iswa/rendering/iswagroup.cpp index c2ac4706c9..16d5df40c2 100644 --- a/modules/iswa/rendering/iswagroup.cpp +++ b/modules/iswa/rendering/iswagroup.cpp @@ -22,7 +22,6 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ #include -#include #include #include @@ -39,82 +38,53 @@ namespace { const std::string _loggerCat = "IswaGroup"; using json = nlohmann::json; - } namespace openspace { IswaGroup::IswaGroup(std::string name, std::string type) :_enabled("enabled", "Enabled", true) ,_alpha("alpha", "Alpha", 0.9f, 0.0f, 1.0f) - ,_useLog("useLog","Use Logarithm", false) - ,_useHistogram("useHistogram", "Use Histogram", false) - ,_autoFilter("autoFilter", "Auto Filter", true) - ,_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") ,_delete("delete", "Delete") - ,_dataOptions("dataOptions", "Data Options") - ,_fieldlines("fieldlineSeedsIndexFile", "Fieldline Seedpoints") - ,_fieldlineIndexFile("") ,_registered(false) ,_type(type) + ,_dataProcessor(nullptr) { setName(name); addProperty(_enabled); addProperty(_alpha); - - addProperty(_useLog); - addProperty(_useHistogram); - addProperty(_autoFilter); - addProperty(_normValues); - addProperty(_backgroundValues); - addProperty(_transferFunctionsFile); - addProperty(_dataOptions); - addProperty(_fieldlines); - addProperty(_delete); - createDataProcessor(); _groupEvent = std::make_shared >(); registerProperties(); + std::cout << "BaseGroup" << std::endl; } IswaGroup::~IswaGroup(){} - -void IswaGroup::registerOptions(const std::vector& options){ - if(!_registered) - registerProperties(); - if(_type == typeid(DataPlane).name() || _type == typeid(DataSphere).name() || - _type == typeid(KameleonPlane).name()){ - if(_dataOptions.options().empty()){ - for(auto option : options){ - _dataOptions.addOption({option.value, option.description}); - } - _dataOptions.setValue(std::vector(1,0)); - } - } -} - -void IswaGroup::setFieldlineInfo(std::string fieldlineIndexFile, std::string kameleonPath){ - - if(fieldlineIndexFile != _fieldlineIndexFile){ - _fieldlineIndexFile = fieldlineIndexFile; - readFieldlinePaths(_fieldlineIndexFile); - } - - if(kameleonPath != _kameleonPath){ - _kameleonPath = kameleonPath; - clearFieldlines(); - updateFieldlineSeeds(); - } -} - bool IswaGroup::isType(std::string type){ return (_type == type); } +void IswaGroup::updateGroup(){ + _groupEvent->publish("updateGroup", ghoul::Dictionary()); +} + +void IswaGroup::clearGroup(){ + _groupEvent->publish("clearGroup", ghoul::Dictionary()); + LDEBUG("Group " + name() + " published clearGroup"); + unregisterProperties(); +} + +std::shared_ptr IswaGroup::dataProcessor(){ + return _dataProcessor; +} + +std::shared_ptr > IswaGroup::groupEvent(){ + return _groupEvent; +}; + + void IswaGroup::registerProperties(){ OsEng.gui()._iswa.registerProperty(&_enabled); OsEng.gui()._iswa.registerProperty(&_alpha); @@ -130,67 +100,11 @@ void IswaGroup::registerProperties(){ }); - if(_type == typeid(DataPlane).name() || _type == typeid(DataSphere).name() || - _type == typeid(KameleonPlane).name() ){ - OsEng.gui()._iswa.registerProperty(&_useLog); - OsEng.gui()._iswa.registerProperty(&_useHistogram); - OsEng.gui()._iswa.registerProperty(&_autoFilter); - OsEng.gui()._iswa.registerProperty(&_normValues); - OsEng.gui()._iswa.registerProperty(&_backgroundValues); - OsEng.gui()._iswa.registerProperty(&_transferFunctionsFile); - OsEng.gui()._iswa.registerProperty(&_dataOptions); - - _useLog.onChange([this]{ - LDEBUG("Group " + name() + " published useLogChanged"); - _groupEvent->publish("useLogChanged", ghoul::Dictionary({{"useLog", _useLog.value()}})); - }); - - _useHistogram.onChange([this]{ - LDEBUG("Group " + name() + " published useHistogramChanged"); - _groupEvent->publish("useHistogramChanged", ghoul::Dictionary({{"useHistogram", _useHistogram.value()}})); - }); - - _autoFilter.onChange([this]{ - LDEBUG("Group " + name() + " published autoFilterChanged"); - _groupEvent->publish("autoFilterChanged", ghoul::Dictionary({{"autoFilter", _autoFilter.value()}})); - }); - - _normValues.onChange([this]{ - LDEBUG("Group " + name() + " published normValuesChanged"); - _groupEvent->publish("normValuesChanged", ghoul::Dictionary({{"normValues", std::make_shared(_normValues.value())}})); - }); - - _backgroundValues.onChange([this]{ - LDEBUG("Group " + name() + " published backgroundValuesChanged"); - _groupEvent->publish("backgroundValuesChanged", ghoul::Dictionary({{"backgroundValues", std::make_shared(_backgroundValues.value())}})); - }); - - _transferFunctionsFile.onChange([this]{ - LDEBUG("Group " + name() + " published transferFunctionsChanged"); - _groupEvent->publish("transferFunctionsChanged", ghoul::Dictionary({{"transferFunctions", _transferFunctionsFile.value()}})); - }); - - _dataOptions.onChange([this]{ - 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())}})); - }); - } - OsEng.gui()._iswa.registerProperty(&_delete); _delete.onChange([this]{ clearGroup(); }); + _registered = true; } @@ -199,91 +113,4 @@ void IswaGroup::unregisterProperties(){ _registered = false; } -void IswaGroup::updateGroup(){ - _groupEvent->publish("updateGroup", ghoul::Dictionary()); -} - -void IswaGroup::clearGroup(){ - _groupEvent->publish("clearGroup", ghoul::Dictionary()); - LDEBUG("Group " + name() + " published clearGroup"); - unregisterProperties(); - clearFieldlines(); - -} - -std::shared_ptr IswaGroup::dataProcessor(){ - return _dataProcessor; -} - -void IswaGroup::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 IswaGroup::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 IswaGroup::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 IswaGroup::createDataProcessor(){ - if(_type == typeid(DataPlane).name()){ - _dataProcessor = std::make_shared(); - }else if(_type == typeid(DataSphere).name()){ - _dataProcessor = std::make_shared(); - }else if(_type == typeid(KameleonPlane).name()){ - _dataProcessor = std::make_shared(); - } -} - } //namespace openspace \ No newline at end of file diff --git a/modules/iswa/rendering/iswagroup.h b/modules/iswa/rendering/iswagroup.h index fbff39a8b2..bd0227fec7 100644 --- a/modules/iswa/rendering/iswagroup.h +++ b/modules/iswa/rendering/iswagroup.h @@ -42,53 +42,28 @@ class IswaCygnet; class IswaGroup : public properties::PropertyOwner{ public: - IswaGroup(std::string name, IswaManager::CygnetType type); IswaGroup(std::string name, std::string type); ~IswaGroup(); - void registerOptions(const std::vector& options); - void registerFieldLineOptions(const std::vector& options); bool isType(std::string type); - void clearGroup(); void updateGroup(); + virtual void clearGroup(); std::shared_ptr dataProcessor(); - std::shared_ptr > groupEvent(){ return _groupEvent; }; - std::vector fieldlineValue() {return _fieldlines.value();} - std::vector dataOptionsValue() {return _dataOptions.value();} - void setFieldlineInfo(std::string fieldlineIndexFile, std::string kameleonPath); - -private: - void createDataProcessor(); + std::shared_ptr > groupEvent(); +protected: void registerProperties(); void unregisterProperties(); - void readFieldlinePaths(std::string indexFile); - void updateFieldlineSeeds(); - void clearFieldlines(); - properties::BoolProperty _enabled; properties::FloatProperty _alpha; - properties::BoolProperty _useLog; - properties::BoolProperty _useHistogram; - properties::BoolProperty _autoFilter; - properties::Vec2Property _normValues; - properties::Vec2Property _backgroundValues; - properties::StringProperty _transferFunctionsFile; - properties::SelectionProperty _dataOptions; - properties::SelectionProperty _fieldlines; - properties::TriggerProperty _delete; + properties::TriggerProperty _delete; - int _id; std::shared_ptr > _groupEvent; std::shared_ptr _dataProcessor; bool _registered; - - std::string _fieldlineIndexFile; - std::string _kameleonPath; - std::map > _fieldlineState; std::string _type; }; diff --git a/modules/iswa/rendering/kameleonplane.cpp b/modules/iswa/rendering/kameleonplane.cpp index bd97c96a73..d876b918b5 100644 --- a/modules/iswa/rendering/kameleonplane.cpp +++ b/modules/iswa/rendering/kameleonplane.cpp @@ -439,8 +439,8 @@ void KameleonPlane::fillOptions(){ } } if(_group){ - _group->registerOptions(_dataOptions.options()); - _dataOptions.setValue(_group->dataOptionsValue()); + std::dynamic_pointer_cast (_group)->registerOptions(_dataOptions.options()); + // _dataOptions.setValue(_group->dataOptionsValue()); }else{ _dataOptions.setValue(std::vector(1,0)); // IswaManager::ref().registerOptionsToGroup(_data->groupName, _dataOptions.options()); @@ -477,7 +477,7 @@ void KameleonPlane::updateFieldlineSeeds(){ void KameleonPlane::readFieldlinePaths(std::string indexFile){ LINFO("Reading seed points paths from file '" << indexFile << "'"); if(_group){ - _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 3384cfdbce..462d961a27 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -26,9 +26,12 @@ #include #include #include +#include + #include #include #include +#include #include #include @@ -163,8 +166,8 @@ 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"); + createKameleonPlane(_cdfInformation[group][pos], "y"); + createKameleonPlane(_cdfInformation[group][pos], "x"); } std::future IswaManager::fetchImageCygnet(int id){ @@ -218,7 +221,17 @@ std::string IswaManager::iswaUrl(int id, std::string type){ void IswaManager::registerGroup(std::string groupName, std::string type){ if(_groups.find(groupName) == _groups.end()){ - _groups.insert(std::pair>(groupName, std::make_shared(groupName, type))); + bool dataGroup = (type == typeid(DataPlane).name()) || + (type == typeid(DataSphere).name()) || + (type == typeid(KameleonPlane).name()); + + if(dataGroup){ + std::cout << "Register data group" << std::endl; + _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)){ LWARNING("Can't add cygnet to groups with diffent type"); } @@ -346,7 +359,7 @@ std::string IswaManager::parseKWToLuaTable(CdfInfo info, std::string cut){ } std::string table = "{" - "Name = '" +info.group+"_"+info.name+"-"+cut+"'," + "Name = '" +info.name+ "'," "Parent = '" + parent + "', " "Renderable = {" "Type = 'KameleonPlane', " @@ -360,12 +373,11 @@ std::string IswaManager::parseKWToLuaTable(CdfInfo info, std::string cut){ "axisCut = '"+cut+"'," "CoordinateType = '" + coordinateType + "', " "Group = '"+ info.group + "'," - "Group = ''," + // "Group = ''," "fieldlineSeedsIndexFile = '"+info.fieldlineSeedsIndexFile+"'" "}" "}" - ; - // std::cout << table << std::endl; + ; return table; } } @@ -494,11 +506,30 @@ void IswaManager::createSphere(std::shared_ptr data){ } void IswaManager::createKameleonPlane(CdfInfo info, std::string cut){ - std::cout << info.name << " " << cut << std::endl; const std::string& extension = ghoul::filesystem::File(absPath(info.path)).fileExtension(); - if(FileSys.fileExists(absPath(info.path)) && extension == "cdf"){ + + + if(!info.group.empty()){ + std::string type = typeid(KameleonPlane).name(); + registerGroup(info.group, type); + + auto it = _groups.find(info.group); + if(it == _groups.end() || (*it).second->isType(type)){ + info.name = info.group +"_"+info.name; + }else{ + info.group=""; + } + } + + info.name = info.name+"-"+cut; + + if( OsEng.renderEngine().scene()->sceneGraphNode(info.name) ){ + LERROR("A node with name \"" + info.name +"\" already exist"); + return; + } + std::string luaTable = parseKWToLuaTable(info, cut); if(!luaTable.empty()){ // // std::cout << luaTable << std::endl;