Merge branch 'feature/iSWA' of github.com:OpenSpace/OpenSpace-Development into feature/iSWA

This commit is contained in:
Michael Nilsson
2016-05-13 15:32:51 -04:00
10 changed files with 232224 additions and 60 deletions

231917
data/ionosphere_variables.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -30,7 +30,7 @@ function postInitialization()
openspace.printInfo("Done setting default values")
--openspace.iswa.addCygnet("0");
openspace.iswa.addCygnet("0,Data,1");
--openspace.iswa.addCygnet("-1,Data,1");
--openspace.iswa.addCygnet("-2,Data,1");
--openspace.iswa.addCygnet("-3,Data,1");

View File

@@ -43,7 +43,7 @@ namespace openspace {
DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
:CygnetPlane(dictionary)
,_useLog("useLog","Use Logarithm", false)
,_useHistogram("_useHistogram", "Use Histogram", true)
,_useHistogram("useHistogram", "Use Histogram", 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")
@@ -71,6 +71,14 @@ DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
OsEng.gui()._iswa.registerProperty(&_dataOptions);
}
setTransferFunctions(_transferFunctionsFile.value());
_dataProcessor = std::make_shared<DataProcessor>(
_useLog.value(),
_useHistogram.value(),
_normValues
);
_normValues.onChange([this](){
// FOR TESTING (should be done on all onChange)
// _avgBenchmarkTime = 0.0;
@@ -96,13 +104,6 @@ DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
_type = IswaManager::CygnetType::Data;
setTransferFunctions(_transferFunctionsFile.value());
_dataProcessor = std::make_shared<DataProcessor>(
_useLog.value(),
_useHistogram.value(),
_normValues
);
}
DataPlane::~DataPlane(){}
@@ -183,7 +184,6 @@ bool DataPlane::loadTexture() {
}
bool DataPlane::updateTexture(){
if(_futureObject.valid())
return false;
@@ -201,8 +201,7 @@ bool DataPlane::readyToRender(){
return (!_textures.empty());
}
void DataPlane::setUniformAndTextures(){
void DataPlane::setUniformAndTextures(){
std::vector<int> selectedOptions = _dataOptions.value();
int activeTextures = selectedOptions.size();
@@ -248,7 +247,6 @@ void DataPlane::setUniformAndTextures(){
}
}
_shader->setUniform("numTextures", activeTextures);
_shader->setUniform("numTransferFunctions", activeTransferfunctions);
_shader->setUniform("backgroundValues", _backgroundValues.value());
@@ -275,8 +273,9 @@ void DataPlane::setTransferFunctions(std::string tfPath){
if(tfFile.is_open()){
while(getline(tfFile, line)){
std::shared_ptr<TransferFunction> tf = std::make_shared<TransferFunction>(absPath(line));
if(tf)
if(tf){
tfs.push_back(tf);
}
}
}

View File

@@ -41,12 +41,12 @@ friend class IswaGroup;
~DataPlane();
protected:
void useLog(bool useLog);
void normValues(glm::vec2 normValues);
void useHistogram(bool useHistogram);
void dataOptions(std::vector<int> options);
void transferFunctionsFile(std::string tfPath);
void backgroundValues(glm::vec2 backgroundValues);
virtual void useLog(bool useLog) override;
virtual void normValues(glm::vec2 normValues) override;
virtual void useHistogram(bool useHistogram) override;
virtual void dataOptions(std::vector<int> options) override;
virtual void transferFunctionsFile(std::string tfPath) override;
virtual void backgroundValues(glm::vec2 backgroundValues) override;
private:
virtual bool loadTexture() override;

View File

@@ -26,45 +26,170 @@
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/filesystem/filesystem.h>
#include <modules/base/rendering/planetgeometry.h>
#include <fstream>
namespace openspace {
DataSphere::DataSphere(const ghoul::Dictionary& dictionary)
:CygnetSphere(dictionary)
,_useLog("useLog","Use Logarithm", false)
,_useHistogram("useHistogram", "Use Histogram", 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")
{
std::string name;
dictionary.getValue("Name", name);
setName(name);
registerProperties();
addProperty(_useLog);
addProperty(_useHistogram);
addProperty(_normValues);
addProperty(_backgroundValues);
addProperty(_transferFunctionsFile);
addProperty(_dataOptions);
if(_data->groupId < 0){
OsEng.gui()._iswa.registerProperty(&_useLog);
OsEng.gui()._iswa.registerProperty(&_useHistogram);
OsEng.gui()._iswa.registerProperty(&_normValues);
OsEng.gui()._iswa.registerProperty(&_backgroundValues);
OsEng.gui()._iswa.registerProperty(&_transferFunctionsFile);
OsEng.gui()._iswa.registerProperty(&_dataOptions);
}
setTransferFunctions(_transferFunctionsFile.value());
_dataProcessor = std::make_shared<DataProcessor>(
_useLog.value(),
_useHistogram.value(),
_normValues
);
_normValues.onChange([this](){
// FOR TESTING (should be done on all onChange)
// _avgBenchmarkTime = 0.0;
// _numOfBenchmarks = 0;
_dataProcessor->normValues(_normValues.value());
loadTexture();
});
_useLog.onChange([this](){
_dataProcessor->useLog(_useLog.value());
loadTexture();
});
_useHistogram.onChange([this](){
_dataProcessor->useHistogram(_useHistogram.value());
loadTexture();
});
_dataOptions.onChange([this](){ loadTexture();} );
_transferFunctionsFile.onChange([this](){
setTransferFunctions(_transferFunctionsFile.value());
});
_type = IswaManager::CygnetType::Data;
}
DataSphere::~DataSphere(){}
void DataSphere::useLog(bool useLog){ _useLog.setValue(useLog); };
void DataSphere::normValues(glm::vec2 normValues){ _normValues.setValue(normValues); };
void DataSphere::useHistogram(bool useHistogram){ _useHistogram.setValue(useHistogram); };
void DataSphere::dataOptions(std::vector<int> options){ _dataOptions.setValue(options); };
void DataSphere::transferFunctionsFile(std::string tfPath){ _transferFunctionsFile.setValue(tfPath); };
void DataSphere::backgroundValues(glm::vec2 backgroundValues){ _backgroundValues.setValue(backgroundValues); };
bool DataSphere::loadTexture(){
std::string texturepath = "${OPENSPACE_DATA}/scene/mars/textures/mars.jpg";
auto texture = ghoul::io::TextureReader::ref().loadTexture(absPath(texturepath));
if(texture){
texture->uploadTexture();
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_textures[0] = std::move(texture);
}
// if The future is done then get the new dataFile
if(_futureObject.valid() && DownloadManager::futureReady(_futureObject)){
DownloadManager::MemoryFile dataFile = _futureObject.get();
return true;
if(dataFile.corrupted)
return false;
_dataBuffer = "";
_dataBuffer.append(dataFile.buffer, dataFile.size);
}
// if the buffer in the datafile is empty, do not proceed
if(_dataBuffer.empty())
return false;
if(!_dataOptions.options().size()){ // load options for value selection
std::vector<std::string> options = _dataProcessor->readHeader(_dataBuffer);
for(int i=0; i<options.size(); i++){
_dataOptions.addOption({i, name()+"_"+options[i]});
_textures.push_back(nullptr);
}
_dataOptions.setValue(std::vector<int>(1,0));
if(_data->groupId > 0)
IswaManager::ref().registerOptionsToGroup(_data->groupId, _dataOptions.options());
}
std::vector<float*> data = _dataProcessor->readData(_dataBuffer, _dataOptions);
if(data.empty())
return false;
bool texturesReady = false;
std::vector<int> selectedOptions = _dataOptions.value();
for(int option: selectedOptions){
float* values = data[option];
if(!values) continue;
if(!_textures[option]){
std::unique_ptr<ghoul::opengl::Texture> texture = std::make_unique<ghoul::opengl::Texture>(
values,
_dataProcessor->dimensions(),
ghoul::opengl::Texture::Format::Red,
GL_RED,
GL_FLOAT,
ghoul::opengl::Texture::FilterMode::Linear,
ghoul::opengl::Texture::WrappingMode::ClampToEdge
);
if(texture){
texture->uploadTexture();
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_textures[option] = std::move(texture);
}
}else{
_textures[option]->setPixelData(values);
_textures[option]->uploadTexture();
}
texturesReady = true;
}
return texturesReady;
}
bool DataSphere::updateTexture(){
if(_textures.empty())
_textures.push_back(nullptr);
if(!_textures[0])
loadTexture();
return true;
if(_futureObject.valid())
return false;
std::future<DownloadManager::MemoryFile> future = IswaManager::ref().fetchDataCygnet(_data->id);
if(future.valid()){
_futureObject = std::move(future);
return true;
}
return false;
}
bool DataSphere::readyToRender(){
return (!_textures.empty());
bool ready = isReady();
ready &= (!_textures.empty() && _textures[0]);
ready &= (_sphere != nullptr);
@@ -73,12 +198,54 @@ bool DataSphere::readyToRender(){
void DataSphere::setUniformAndTextures(){
_shader->setUniform("transparency",0.5f);
ghoul::opengl::TextureUnit unit;
unit.activate();
_textures[0]->bind();
_shader->setUniform("texture1", unit);
std::vector<int> selectedOptions = _dataOptions.value();
int activeTextures = selectedOptions.size();
int activeTransferfunctions = _transferFunctions.size();
ghoul::opengl::TextureUnit txUnits[10];
int j = 0;
for(int option : selectedOptions){
if(_textures[option]){
txUnits[j].activate();
_textures[option]->bind();
_shader->setUniform(
"textures[" + std::to_string(j) + "]",
txUnits[j]
);
j++;
}
}
ghoul::opengl::TextureUnit tfUnits[10];
j = 0;
if((activeTransferfunctions == 1) && (_textures.size() != _transferFunctions.size())){
tfUnits[0].activate();
_transferFunctions[0]->bind();
_shader->setUniform(
"transferFunctions[0]",
tfUnits[0]
);
}else{
for(int option : selectedOptions){
if(_transferFunctions[option]){
tfUnits[j].activate();
_transferFunctions[option]->bind();
_shader->setUniform(
"transferFunctions[" + std::to_string(j) + "]",
tfUnits[j]
);
j++;
}
}
}
_shader->setUniform("numTextures", activeTextures);
_shader->setUniform("numTransferFunctions", activeTransferfunctions);
_shader->setUniform("backgroundValues", _backgroundValues.value());
}
@@ -96,5 +263,26 @@ bool DataSphere::createShader(){
return true;
}
void DataSphere::setTransferFunctions(std::string tfPath){
std::string line;
std::ifstream tfFile(absPath(tfPath));
std::vector<std::shared_ptr<TransferFunction>> tfs;
if(tfFile.is_open()){
while(getline(tfFile, line)){
std::shared_ptr<TransferFunction> tf = std::make_shared<TransferFunction>(absPath(line));
if(tf){
tfs.push_back(tf);
}
}
}
if(!tfs.empty()){
_transferFunctions.clear();
_transferFunctions = tfs;
}
}
} //namespace openspace

View File

@@ -26,15 +26,26 @@
#define __DATASPHERE_H__
#include <modules/iswa/rendering/cygnetsphere.h>
#include <openspace/properties/vectorproperty.h>
#include <openspace/properties/selectionproperty.h>
#include <modules/iswa/util/dataprocessor.h>
namespace openspace{
class PowerScaledSphere;
class DataSphere : public CygnetSphere {
friend class IswaGroup;
public:
DataSphere(const ghoul::Dictionary& dictionary);
~DataSphere();
protected:
virtual void useLog(bool useLog) override;
virtual void normValues(glm::vec2 normValues) override;
virtual void useHistogram(bool useHistogram) override;
virtual void dataOptions(std::vector<int> options) override;
virtual void transferFunctionsFile(std::string tfPath) override;
virtual void backgroundValues(glm::vec2 backgroundValues) override;
private:
virtual bool loadTexture() override;
@@ -43,6 +54,19 @@ private:
virtual bool readyToRender() override;
virtual void setUniformAndTextures() override;
virtual bool createShader() override;
void setTransferFunctions(std::string tfPath);
properties::SelectionProperty _dataOptions;
properties::StringProperty _transferFunctionsFile;
properties::Vec2Property _backgroundValues;
properties::Vec2Property _normValues;
properties::BoolProperty _useLog;
properties::BoolProperty _useHistogram;
std::string _dataBuffer;
std::shared_ptr<DataProcessor> _dataProcessor;
};

View File

@@ -67,7 +67,6 @@ struct Metadata {
};
class IswaCygnet : public Renderable, public std::enable_shared_from_this<IswaCygnet> {
friend class IswaGroup;
@@ -82,6 +81,14 @@ public:
void update(const UpdateData& data) override;
protected:
virtual void useLog(bool useLog){};
virtual void normValues(glm::vec2 normValues){};
virtual void useHistogram(bool useHistogram){};
virtual void dataOptions(std::vector<int> options){};
virtual void transferFunctionsFile(std::string tfPath){};
virtual void backgroundValues(glm::vec2 backgroundValues){};
void enabled(bool enabled){_enabled.setValue(enabled);};
void registerProperties();

View File

@@ -136,33 +136,33 @@ void IswaGroup::registerProperties(){
_useLog.onChange([this]{
for(auto cygnet : _cygnets)
static_cast<DataPlane*>(cygnet)->useLog(_useLog.value());
cygnet->useLog(_useLog.value());
});
_useHistogram.onChange([this]{
for(auto cygnet : _cygnets)
static_cast<DataPlane*>(cygnet)->useHistogram(_useHistogram.value());
cygnet->useHistogram(_useHistogram.value());
});
_normValues.onChange([this]{
for(auto cygnet : _cygnets)
static_cast<DataPlane*>(cygnet)->normValues(_normValues.value());
cygnet->normValues(_normValues.value());
});
_backgroundValues.onChange([this]{
for(auto cygnet : _cygnets)
static_cast<DataPlane*>(cygnet)->backgroundValues(_backgroundValues.value());
cygnet->backgroundValues(_backgroundValues.value());
});
_transferFunctionsFile.onChange([this]{
for(auto cygnet : _cygnets)
static_cast<DataPlane*>(cygnet)->transferFunctionsFile(_transferFunctionsFile.value());
cygnet->transferFunctionsFile(_transferFunctionsFile.value());
});
_dataOptions.onChange([this]{
for(auto cygnet : _cygnets)
static_cast<DataPlane*>(cygnet)->dataOptions(_dataOptions.value());
cygnet->dataOptions(_dataOptions.value());
});
}

View File

@@ -2,7 +2,7 @@
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* 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 *
@@ -21,15 +21,22 @@
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
uniform vec4 campos;
uniform vec4 objpos;
uniform float time;
uniform float transparency;
uniform sampler2D texture1;
in vec2 vs_st;
// uniform sampler2D texture1;
uniform sampler2D textures[6];
uniform sampler2D transferFunctions[6];
// uniform sampler2D tf;
// uniform sampler2D tfs[6];
uniform int numTextures;
uniform int numTransferFunctions;
uniform bool averageValues;
uniform vec2 backgroundValues;
// uniform float background;
in vec2 vs_st;
in vec4 vs_position;
#include "PowerScaling/powerScaling_fs.hglsl"
@@ -38,14 +45,37 @@ in vec4 vs_position;
Fragment getFragment() {
vec4 position = vs_position;
float depth = pscDepth(position);
vec4 diffuse = texture(texture1, vs_st);
vec4 transparent = vec4(0.0f);
vec4 diffuse = transparent;
float v = 0;
diffuse.w = transparency;
if((numTransferFunctions == 1) || (numTextures > numTransferFunctions)){
for(int i=0; i<numTextures; i++){
v += texture(textures[i], vec2(vs_st.s, 1-vs_st.t)).r;
}
v /= numTextures;
vec4 color = texture(transferFunctions[0], vec2(v,0));
float x = backgroundValues.x;
float y = backgroundValues.y;
if((v<(x+y)) && v>(x-y))
color = mix(transparent, color, clamp(1,0,abs(v-x)));
diffuse = color;
}else{
for(int i=0; i<numTextures; i++){
v = texture(textures[i], vec2(vs_st.s, 1-vs_st.t)).r;
vec4 color = texture(transferFunctions[i], vec2(v,0));
diffuse += color;
}
}
if (diffuse.a <= backgroundValues.y)
discard;
Fragment frag;
frag.color = diffuse;
frag.depth = depth;
return frag;
}
}

View File

@@ -69,7 +69,6 @@ private:
float normalizeWithStandardScore(float value, float mean, float sd);
glm::size3_t _dimensions;
bool _useLog;
bool _useHistogram;