From 7401595e93bdb6ff6d233abcd820b3e28f5560bf Mon Sep 17 00:00:00 2001 From: Michael Nilsson Date: Thu, 2 Jun 2016 09:45:14 -0400 Subject: [PATCH] refactor filloptions in kameleonplane, merge conflict --- modules/iswa/rendering/datacygnet.cpp | 10 +- modules/iswa/rendering/dataplane.cpp | 3 +- modules/iswa/rendering/iswadatagroup.cpp | 20 ++- modules/iswa/rendering/kameleonplane.cpp | 187 ++++++++++---------- modules/iswa/rendering/kameleonplane.h | 4 +- modules/iswa/rendering/texturecygnet.cpp | 6 +- modules/iswa/util/dataprocessorkameleon.cpp | 15 +- modules/iswa/util/iswamanager.cpp | 5 +- 8 files changed, 136 insertions(+), 114 deletions(-) diff --git a/modules/iswa/rendering/datacygnet.cpp b/modules/iswa/rendering/datacygnet.cpp index 11c0e8efb6..504bb182e8 100644 --- a/modules/iswa/rendering/datacygnet.cpp +++ b/modules/iswa/rendering/datacygnet.cpp @@ -226,9 +226,13 @@ void DataCygnet::fillOptions(){ _dataOptions.addOption({i, options[i]}); _textures.push_back(nullptr); } - _dataOptions.setValue(std::vector(1,0)); - if(_group) - std::dynamic_pointer_cast(_group)->registerOptions(_dataOptions.options()); + + if(_group){ + std::dynamic_pointer_cast(_group)->registerOptions(_dataOptions.options()); + _dataOptions.setValue(std::dynamic_pointer_cast(_group)->dataOptionsValue()); + } else { + _dataOptions.setValue(std::vector(1,0)); + } } diff --git a/modules/iswa/rendering/dataplane.cpp b/modules/iswa/rendering/dataplane.cpp index 83abdcd7a4..6ca3ca9225 100644 --- a/modules/iswa/rendering/dataplane.cpp +++ b/modules/iswa/rendering/dataplane.cpp @@ -55,8 +55,6 @@ DataPlane::DataPlane(const ghoul::Dictionary& dictionary) DataPlane::~DataPlane(){} bool DataPlane::initialize(){ - std::cout << "DataPlane: " << typeid(this).name() << std::endl; - IswaCygnet::initialize(); if(_group){ @@ -78,6 +76,7 @@ bool DataPlane::initialize(){ // and unregister backgroundvalues property. if(_autoFilter.value()){ _backgroundValues.setValue(_dataProcessor->filterValues()); + OsEng.gui()._iswa.unregisterProperty(&_backgroundValues); // else if autofilter is turned off, register backgroundValues } else { OsEng.gui()._iswa.registerProperty(&_backgroundValues, &_autoFilter); diff --git a/modules/iswa/rendering/iswadatagroup.cpp b/modules/iswa/rendering/iswadatagroup.cpp index ec83bbef8f..fc3e4a3e67 100644 --- a/modules/iswa/rendering/iswadatagroup.cpp +++ b/modules/iswa/rendering/iswadatagroup.cpp @@ -44,7 +44,7 @@ IswaDataGroup::IswaDataGroup(std::string name, std::string type) :IswaBaseGroup(name, type) ,_useLog("useLog","Use Logarithm", false) ,_useHistogram("useHistogram", "Use Histogram", false) - ,_autoFilter("autoFilter", "Auto Filter", true) + ,_autoFilter("autoFilter", "Auto Filter", 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") @@ -68,8 +68,8 @@ void IswaDataGroup::registerProperties(){ 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(&_normValues); OsEng.gui()._iswa.registerProperty(&_transferFunctionsFile); OsEng.gui()._iswa.registerProperty(&_dataOptions); @@ -83,8 +83,18 @@ void IswaDataGroup::registerProperties(){ _groupEvent->publish("useHistogramChanged", ghoul::Dictionary({{"useHistogram", _useHistogram.value()}})); }); - _autoFilter.onChange([this]{ + //If autofiler is on, background values property should be hidden + _autoFilter.onChange([this](){ LDEBUG("Group " + name() + " published autoFilterChanged"); + // If autofiler is selected, use _dataProcessor to set backgroundValues + // and unregister backgroundvalues property. + if(_autoFilter.value()){ + _backgroundValues.setValue(_dataProcessor->filterValues()); + OsEng.gui()._iswa.unregisterProperty(&_backgroundValues); + // else if autofilter is turned off, register backgroundValues + } else { + OsEng.gui()._iswa.registerProperty(&_backgroundValues, &_autoFilter); + } _groupEvent->publish("autoFilterChanged", ghoul::Dictionary({{"autoFilter", _autoFilter.value()}})); }); @@ -131,4 +141,8 @@ void IswaDataGroup::createDataProcessor(){ } } +std::vector IswaDataGroup::dataOptionsValue(){ + return _dataOptions.value(); +} + } //namespace openspace diff --git a/modules/iswa/rendering/kameleonplane.cpp b/modules/iswa/rendering/kameleonplane.cpp index c8cd787119..8fe443d433 100644 --- a/modules/iswa/rendering/kameleonplane.cpp +++ b/modules/iswa/rendering/kameleonplane.cpp @@ -1,26 +1,26 @@ -// /***************************************************************************************** -// * * -// * OpenSpace * -// * * -// * Copyright (c) 2014-2016 * -// * * -// * 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. * -// ****************************************************************************************/ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * 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 @@ -43,7 +43,6 @@ namespace { using json = nlohmann::json; const std::string _loggerCat = "KameleonPlane"; const int MAX_TEXTURES = 6; - } namespace openspace { @@ -134,59 +133,7 @@ bool KameleonPlane::initialize(){ if(_group){ _dataProcessor = _group->dataProcessor(); - auto groupEvent = _group->groupEvent(); - - groupEvent->subscribe(name(), "useLogChanged", [&](const ghoul::Dictionary& dict){ - LDEBUG(name() + " Event useLogChanged"); - _useLog.setValue(dict.value("useLog")); - }); - - groupEvent->subscribe(name(), "normValuesChanged", [&](ghoul::Dictionary dict){ - LDEBUG(name() + " Event normValuesChanged"); - std::shared_ptr values; - bool success = dict.getValue("normValues", values); - if(success){ - _normValues.setValue(*values); - } - }); - - groupEvent->subscribe(name(), "useHistogramChanged", [&](ghoul::Dictionary dict){ - LDEBUG(name() + " Event useHistogramChanged"); - _useHistogram.setValue(dict.value("useHistogram")); - }); - - groupEvent->subscribe(name(), "dataOptionsChanged", [&](ghoul::Dictionary dict){ - LDEBUG(name() + " Event dataOptionsChanged"); - std::shared_ptr > values; - bool success = dict.getValue("dataOptions", values); - if(success){ - _dataOptions.setValue(*values); - } - }); - - groupEvent->subscribe(name(), "transferFunctionsChanged", [&](ghoul::Dictionary dict){ - LDEBUG(name() + " Event transferFunctionsChanged"); - _transferFunctionsFile.setValue(dict.value("transferFunctions")); - }); - - groupEvent->subscribe(name(), "backgroundValuesChanged", [&](ghoul::Dictionary dict){ - LDEBUG(name() + " Event backgroundValuesChanged"); - std::shared_ptr values; - bool success = dict.getValue("backgroundValues", values); - if(success){ - _backgroundValues.setValue(*values); - } - }); - - groupEvent->subscribe(name(), "autoFilterChanged", [&](ghoul::Dictionary dict){ - LDEBUG(name() + " Event autoFilterChanged"); - _autoFilter.setValue(dict.value("autoFilter")); - }); - - groupEvent->subscribe(name(), "updateGroup", [&](ghoul::Dictionary dict){ - LDEBUG(name() + " Event updateGroup"); - loadTexture(); - }); + subscribeToGroup(); }else{ OsEng.gui()._iswa.registerProperty(&_useLog); OsEng.gui()._iswa.registerProperty(&_useHistogram); @@ -261,6 +208,14 @@ bool KameleonPlane::initialize(){ } fillOptions(); + + // Has to be done after fillOptions() + _dataOptions.onChange([this](){ + if(_dataOptions.value().size() > MAX_TEXTURES) + LWARNING("Too many options chosen, max is " + std::to_string(MAX_TEXTURES)); + loadTexture(); + }); + std::dynamic_pointer_cast(_dataProcessor)->dimensions(_dimensions); _dataProcessor->addDataValues(_kwPath, _dataOptions); @@ -413,30 +368,18 @@ void KameleonPlane::setTransferFunctions(std::string tfPath){ } void KameleonPlane::fillOptions(){ - std::cout << "Time to fill options" << std::endl; std::vector options = _dataProcessor->readMetadata(_kwPath); - int numOptions = 0; - for(std::string option : options){ - if(option.size() < 4 && option != "x" && option != "y" && option != "z"){ - _dataOptions.addOption({numOptions, option}); - _dataSlices.push_back(nullptr); - _textures.push_back(nullptr); - numOptions++; - } + for(int i=0; i (_group)->registerOptions(_dataOptions.options()); - // _dataOptions.setValue(_group->dataOptionsValue()); - }else{ + _dataOptions.setValue(std::dynamic_pointer_cast (_group)->dataOptionsValue()); + } else { _dataOptions.setValue(std::vector(1,0)); - // IswaManager::ref().registerOptionsToGroup(_data->groupName, _dataOptions.options()); } - _dataOptions.onChange([this](){ - if(_dataOptions.value().size() > MAX_TEXTURES) - LWARNING("Too many options chosen, max is " + std::to_string(MAX_TEXTURES)); - loadTexture(); - }); } void KameleonPlane::updateFieldlineSeeds(){ @@ -503,4 +446,60 @@ void KameleonPlane::readFieldlinePaths(std::string indexFile){ } } +void KameleonPlane::subscribeToGroup(){ + auto groupEvent = _group->groupEvent(); + + groupEvent->subscribe(name(), "useLogChanged", [&](const ghoul::Dictionary& dict){ + LDEBUG(name() + " Event useLogChanged"); + _useLog.setValue(dict.value("useLog")); + }); + + groupEvent->subscribe(name(), "normValuesChanged", [&](ghoul::Dictionary dict){ + LDEBUG(name() + " Event normValuesChanged"); + std::shared_ptr values; + bool success = dict.getValue("normValues", values); + if(success){ + _normValues.setValue(*values); + } + }); + + groupEvent->subscribe(name(), "useHistogramChanged", [&](ghoul::Dictionary dict){ + LDEBUG(name() + " Event useHistogramChanged"); + _useHistogram.setValue(dict.value("useHistogram")); + }); + + groupEvent->subscribe(name(), "dataOptionsChanged", [&](ghoul::Dictionary dict){ + LDEBUG(name() + " Event dataOptionsChanged"); + std::shared_ptr > values; + bool success = dict.getValue("dataOptions", values); + if(success){ + _dataOptions.setValue(*values); + } + }); + + groupEvent->subscribe(name(), "transferFunctionsChanged", [&](ghoul::Dictionary dict){ + LDEBUG(name() + " Event transferFunctionsChanged"); + _transferFunctionsFile.setValue(dict.value("transferFunctions")); + }); + + groupEvent->subscribe(name(), "backgroundValuesChanged", [&](ghoul::Dictionary dict){ + LDEBUG(name() + " Event backgroundValuesChanged"); + std::shared_ptr values; + bool success = dict.getValue("backgroundValues", values); + if(success){ + _backgroundValues.setValue(*values); + } + }); + + groupEvent->subscribe(name(), "autoFilterChanged", [&](ghoul::Dictionary dict){ + LDEBUG(name() + " Event autoFilterChanged"); + _autoFilter.setValue(dict.value("autoFilter")); + }); + + groupEvent->subscribe(name(), "updateGroup", [&](ghoul::Dictionary dict){ + LDEBUG(name() + " Event updateGroup"); + loadTexture(); + }); +} + }// namespace openspace \ No newline at end of file diff --git a/modules/iswa/rendering/kameleonplane.h b/modules/iswa/rendering/kameleonplane.h index b1bf47ddd3..69661eb913 100644 --- a/modules/iswa/rendering/kameleonplane.h +++ b/modules/iswa/rendering/kameleonplane.h @@ -2,7 +2,7 @@ * * * OpenSpace * * * -* Copyright (c) 2014-2015 * +* Copyright (c) 2014-2016 * * * * 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 * @@ -67,6 +67,8 @@ void setTransferFunctions(std::string tfPath); void fillOptions(); + void subscribeToGroup(); + static int id(); properties::IntProperty _resolution; diff --git a/modules/iswa/rendering/texturecygnet.cpp b/modules/iswa/rendering/texturecygnet.cpp index 649c94fa72..5556df1a4b 100644 --- a/modules/iswa/rendering/texturecygnet.cpp +++ b/modules/iswa/rendering/texturecygnet.cpp @@ -73,12 +73,12 @@ bool TextureCygnet::loadTexture() { bool TextureCygnet::updateTexture(){ - if(_textures.empty()) - _textures.push_back(nullptr); - if(_futureObject.valid()) return false; + if(_textures.empty()) + _textures.push_back(nullptr); + std::future future = IswaManager::ref().fetchImageCygnet(_data->id); if(future.valid()){ diff --git a/modules/iswa/util/dataprocessorkameleon.cpp b/modules/iswa/util/dataprocessorkameleon.cpp index 518a6ef47c..c9dc5e8897 100644 --- a/modules/iswa/util/dataprocessorkameleon.cpp +++ b/modules/iswa/util/dataprocessorkameleon.cpp @@ -43,17 +43,22 @@ DataProcessorKameleon::~DataProcessorKameleon(){} std::vector DataProcessorKameleon::readMetadata(std::string path){ - std::cout << "The path! " << path << std::endl; + if(!path.empty()){ - std::cout << "not empty!"; if(path != _kwPath || !_kw){ - std::cout << "tmie to create!"; initializeKameleonWrapper(path); } - std::cout << "return variables!"; - return _kw->getVariables(); + std::vector opts = _kw->getVariables(); + opts.erase( std::remove_if( + opts.begin(), + opts.end(), + [](std::string opt){ return (opt.size() > 3 || opt == "x" || opt == "y" || opt == "z");} + ), + opts.end() + ); + return opts; } return std::vector(); diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index 3efcdd5011..7648f94fa8 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -83,7 +83,7 @@ IswaManager::IswaManager() _geom[CygnetGeometry::Sphere] = "Sphere"; DlManager.fetchFile( - "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/CygnetHealthServlet", + "http://iswa3.ccmc.gsfc.nasa.gov/IswaSystemWebApp/CygnetHealthServlet", [this](const DownloadManager::MemoryFile& file){ fillCygnetInfo(std::string(file.buffer)); }, @@ -202,7 +202,7 @@ std::string IswaManager::iswaUrl(int id, std::string type){ url = "http://128.183.168.116:3000/"+type+"/" + std::to_string(-id) + "/"; // url = "http://10.0.0.76:3000/"+type+"/" + std::to_string(-id) + "/"; } else{ - url = "http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?window=-1&cygnetId="+ std::to_string(id) +"×tamp="; + url = "http://iswa3.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?window=-1&cygnetId="+ std::to_string(id) +"×tamp="; } std::string t = Time::ref().currentTimeUTC(); @@ -442,7 +442,6 @@ void IswaManager::createScreenSpace(int id){ void IswaManager::createPlane(std::shared_ptr data){ // check if this plane already exist - std::cout << "IswaManager: " << typeid(DataPlane).name() << std::endl; std::string name = _type[data->type] + _geom[data->geom] + std::to_string(data->id);