IswaKameleonGroup

This commit is contained in:
Sebastian Piwell
2016-06-01 15:08:29 -04:00
parent 27a046d81d
commit bba419fcf1
8 changed files with 225 additions and 119 deletions

View File

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

View File

@@ -49,6 +49,7 @@
#include <modules/iswa/rendering/iswagroup.h>
#include <modules/iswa/rendering/iswadatagroup.h>
#include <modules/iswa/rendering/iswakameleongroup.h>
namespace openspace{
class IswaGroup;

View File

@@ -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<std::vector<int> >(_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<std::vector<int> >(_fieldlines.value())}}));
});
}
}
void IswaDataGroup::registerOptions(const std::vector<properties::SelectionProperty::Option>& options){
@@ -143,81 +127,6 @@ void IswaDataGroup::registerOptions(const std::vector<properties::SelectionPrope
}
}
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<int> selectedOptions = _fieldlines.value();
// SeedPath == map<int selectionValue, tuple< string name, string path, bool active > >
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<int selectionValue, tuple< string name, string path, bool active > >
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<DataProcessorText>();

View File

@@ -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<properties::SelectionProperty::Option>& options);
void registerFieldLineOptions(const std::vector<properties::SelectionProperty::Option>& options);
// void registerFieldLineOptions(const std::vector<properties::SelectionProperty::Option>& options);
std::vector<int> dataOptionsValue();
std::vector<int> fieldlineValue();
void setFieldlineInfo(std::string fieldlineIndexFile, std::string kameleonPath);
// std::vector<int> 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<int, std::tuple<std::string, std::string, bool> > _fieldlineState;
};
} //namespace openspace

View File

@@ -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 <modules/iswa/rendering/iswakameleongroup.h>
#include <fstream>
#include <modules/iswa/ext/json/json.hpp>
#include <modules/iswa/util/dataprocessortext.h>
#include <modules/iswa/util/dataprocessorjson.h>
#include <modules/iswa/util/dataprocessorkameleon.h>
#include <modules/iswa/rendering/dataplane.h>
#include <modules/iswa/rendering/datasphere.h>
#include <modules/iswa/rendering/kameleonplane.h>
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<int> 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<int> selectedOptions = _fieldlines.value();
// SeedPath == map<int selectionValue, tuple< string name, string path, bool active > >
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<int selectionValue, tuple< string name, string path, bool active > >
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

View File

@@ -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 <modules/iswa/rendering/iswadatagroup.h>
namespace openspace{
class IswaKameleonGroup : public IswaDataGroup{
public:
IswaKameleonGroup(std::string name, std::string type);
~IswaKameleonGroup();
virtual void clearGroup();
std::vector<int> 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<int, std::tuple<std::string, std::string, bool> > _fieldlineState;
};
}//namespace openspace
#endif

View File

@@ -37,10 +37,8 @@
#include <ghoul/filesystem/filesystem.h>
#include <fstream>
#include <modules/iswa/ext/json/json.hpp>
#include <modules/iswa/rendering/iswagroup.h>
#include <modules/iswa/util/dataprocessorkameleon.h>
namespace {
using json = nlohmann::json;
const std::string _loggerCat = "KameleonPlane";
@@ -439,7 +437,7 @@ void KameleonPlane::fillOptions(){
}
}
if(_group){
std::dynamic_pointer_cast<IswaDataGroup> (_group)->registerOptions(_dataOptions.options());
std::dynamic_pointer_cast<IswaKameleonGroup> (_group)->registerOptions(_dataOptions.options());
// _dataOptions.setValue(_group->dataOptionsValue());
}else{
_dataOptions.setValue(std::vector<int>(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<IswaDataGroup>(_group)->setFieldlineInfo(indexFile, _kwPath);
std::dynamic_pointer_cast<IswaKameleonGroup>(_group)->setFieldlineInfo(indexFile, _kwPath);
return;
}

View File

@@ -32,6 +32,7 @@
#include <modules/iswa/rendering/iswacygnet.h>
#include <modules/iswa/rendering/iswagroup.h>
#include <modules/iswa/rendering/iswadatagroup.h>
#include <modules/iswa/rendering/iswakameleongroup.h>
#include <fstream>
#include <algorithm>
@@ -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<std::string, std::shared_ptr<IswaGroup>>(groupName, std::make_shared<IswaDataGroup>(groupName, type)));
}
else{
}else if(kameleonGroup){
_groups.insert(std::pair<std::string, std::shared_ptr<IswaGroup>>(groupName, std::make_shared<IswaKameleonGroup>(groupName, type)));
}else{
_groups.insert(std::pair<std::string, std::shared_ptr<IswaGroup>>(groupName, std::make_shared<IswaGroup>(groupName, type)));
}
} else if(!_groups[groupName]->isType(type)){