refactor filloptions in kameleonplane, merge conflict

This commit is contained in:
Michael Nilsson
2016-06-02 09:45:14 -04:00
parent a00e29d987
commit 7401595e93
8 changed files with 136 additions and 114 deletions

View File

@@ -226,9 +226,13 @@ void DataCygnet::fillOptions(){
_dataOptions.addOption({i, options[i]});
_textures.push_back(nullptr);
}
_dataOptions.setValue(std::vector<int>(1,0));
if(_group)
std::dynamic_pointer_cast<IswaDataGroup>(_group)->registerOptions(_dataOptions.options());
if(_group){
std::dynamic_pointer_cast<IswaDataGroup>(_group)->registerOptions(_dataOptions.options());
_dataOptions.setValue(std::dynamic_pointer_cast<IswaDataGroup>(_group)->dataOptionsValue());
} else {
_dataOptions.setValue(std::vector<int>(1,0));
}
}

View File

@@ -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);

View File

@@ -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<int> IswaDataGroup::dataOptionsValue(){
return _dataOptions.value();
}
} //namespace openspace

View File

@@ -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 <modules/iswa/rendering/kameleonplane.h>
#include <ghoul/filesystem/filesystem>
@@ -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<bool>("useLog"));
});
groupEvent->subscribe(name(), "normValuesChanged", [&](ghoul::Dictionary dict){
LDEBUG(name() + " Event normValuesChanged");
std::shared_ptr<glm::vec2> 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<bool>("useHistogram"));
});
groupEvent->subscribe(name(), "dataOptionsChanged", [&](ghoul::Dictionary dict){
LDEBUG(name() + " Event dataOptionsChanged");
std::shared_ptr<std::vector<int> > 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<std::string>("transferFunctions"));
});
groupEvent->subscribe(name(), "backgroundValuesChanged", [&](ghoul::Dictionary dict){
LDEBUG(name() + " Event backgroundValuesChanged");
std::shared_ptr<glm::vec2> 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<bool>("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<DataProcessorKameleon>(_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<std::string> 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<options.size(); i++){
_dataOptions.addOption({i, options[i]});
_textures.push_back(nullptr);
}
if(_group){
std::dynamic_pointer_cast<IswaKameleonGroup> (_group)->registerOptions(_dataOptions.options());
// _dataOptions.setValue(_group->dataOptionsValue());
}else{
_dataOptions.setValue(std::dynamic_pointer_cast<IswaKameleonGroup> (_group)->dataOptionsValue());
} else {
_dataOptions.setValue(std::vector<int>(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<bool>("useLog"));
});
groupEvent->subscribe(name(), "normValuesChanged", [&](ghoul::Dictionary dict){
LDEBUG(name() + " Event normValuesChanged");
std::shared_ptr<glm::vec2> 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<bool>("useHistogram"));
});
groupEvent->subscribe(name(), "dataOptionsChanged", [&](ghoul::Dictionary dict){
LDEBUG(name() + " Event dataOptionsChanged");
std::shared_ptr<std::vector<int> > 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<std::string>("transferFunctions"));
});
groupEvent->subscribe(name(), "backgroundValuesChanged", [&](ghoul::Dictionary dict){
LDEBUG(name() + " Event backgroundValuesChanged");
std::shared_ptr<glm::vec2> 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<bool>("autoFilter"));
});
groupEvent->subscribe(name(), "updateGroup", [&](ghoul::Dictionary dict){
LDEBUG(name() + " Event updateGroup");
loadTexture();
});
}
}// namespace openspace

View File

@@ -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;

View File

@@ -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<DownloadManager::MemoryFile> future = IswaManager::ref().fetchImageCygnet(_data->id);
if(future.valid()){

View File

@@ -43,17 +43,22 @@ DataProcessorKameleon::~DataProcessorKameleon(){}
std::vector<std::string> 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<std::string> 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<std::string>();

View File

@@ -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) +"&timestamp=";
url = "http://iswa3.ccmc.gsfc.nasa.gov/IswaSystemWebApp/iSWACygnetStreamer?window=-1&cygnetId="+ std::to_string(id) +"&timestamp=";
}
std::string t = Time::ref().currentTimeUTC();
@@ -442,7 +442,6 @@ void IswaManager::createScreenSpace(int id){
void IswaManager::createPlane(std::shared_ptr<MetadataFuture> 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);