mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 12:10:52 -06:00
solve merge conflict
This commit is contained in:
@@ -34,10 +34,15 @@ function postInitialization()
|
||||
--openspace.iswa.addCygnet("-1,Data,1");
|
||||
--openspace.iswa.addCygnet("-2,Data,1");
|
||||
--openspace.iswa.addCygnet("-3,Data,1");
|
||||
--[[
|
||||
openspace.registerScreenSpaceRenderable(
|
||||
|
||||
openspace.iswa.addScreenSpaceCygnet(
|
||||
{
|
||||
CygnetId = 2,
|
||||
Position = {-0.8, 0.3},
|
||||
Scale = 0.2
|
||||
});
|
||||
--[[
|
||||
{
|
||||
Name = "iSWACygnet7",
|
||||
Type = "ScreenSpaceCygnet",
|
||||
CygnetId = 7,
|
||||
Position = {0.0, 0.0},
|
||||
|
||||
8236
ext/json/json.hpp
Normal file
8236
ext/json/json.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -26,6 +26,7 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
|
||||
set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/iswamanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/dataprocessor.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/cygnetplane.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswacygnet.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/dataplane.h
|
||||
@@ -34,13 +35,13 @@ set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/cygnetsphere.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasphere.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspacecygnet.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/colorbar.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswagroup.h
|
||||
)
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/iswamanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/dataprocessor.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswacygnet.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/cygnetplane.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/dataplane.cpp
|
||||
@@ -49,7 +50,6 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/cygnetsphere.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/datasphere.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspacecygnet.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/colorbar.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/iswagroup.cpp
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
@@ -59,8 +59,6 @@ set(SHADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/cygnetplane_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/dataplane_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/dataplane_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/colorbar_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/colorbar_vs.glsl
|
||||
)
|
||||
|
||||
source_group("Shader Files" FILES ${SHADER_FILES})
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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/colorbar.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
namespace openspace{
|
||||
ColorBar::ColorBar()
|
||||
:_shader(nullptr)
|
||||
,_texture(nullptr)
|
||||
,_quad(0)
|
||||
,_vertexPositionBuffer(0)
|
||||
{}
|
||||
|
||||
bool ColorBar::initialize(){
|
||||
std::cout << "initializeing colorbar" << std::endl;
|
||||
if (_shader == nullptr) {
|
||||
// DatePlane Program
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_shader = renderEngine.buildRenderProgram("ColorBarProgram",
|
||||
"${MODULE_ISWA}/shaders/colorbar_vs.glsl",
|
||||
"${MODULE_ISWA}/shaders/colorbar_fs.glsl"
|
||||
);
|
||||
if (!_shader)
|
||||
return false;
|
||||
}
|
||||
|
||||
createPlane();
|
||||
|
||||
glm::size3_t dimensions = glm::size3_t(300,100,1);
|
||||
ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear;
|
||||
ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge;
|
||||
|
||||
_texture =
|
||||
std::make_unique<ghoul::opengl::Texture>(dimensions, ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT, filtermode, wrappingmode);
|
||||
if(_texture){
|
||||
|
||||
std::cout << "Texture created" << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColorBar::deinitialize(){
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
_quad = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ColorBar::render(){
|
||||
|
||||
}
|
||||
|
||||
void ColorBar::render(ColorBarData& data){
|
||||
_shader->activate();
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
|
||||
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_shader->setUniform("ModelTransform", data.transform);
|
||||
|
||||
_shader->setUniform("top", data.top);
|
||||
_shader->setUniform("mid", data.mid);
|
||||
_shader->setUniform("bot", data.bot);
|
||||
_shader->setUniform("tfValues", data.tfValues);
|
||||
|
||||
setPscUniforms(*_shader.get(), data.camera, data.position);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glEnable(GL_CULL_FACE);
|
||||
_shader->deactivate();
|
||||
}
|
||||
|
||||
void ColorBar::setPscUniforms(
|
||||
ghoul::opengl::ProgramObject& program,
|
||||
const Camera& camera,
|
||||
const PowerScaledCoordinate& position)
|
||||
{
|
||||
program.setUniform("campos", camera.position().vec4());
|
||||
program.setUniform("objpos", position.vec4());
|
||||
program.setUniform("camrot", camera.viewRotationMatrix());
|
||||
program.setUniform("scaling", camera.scaling());
|
||||
}
|
||||
|
||||
void ColorBar::createPlane(){
|
||||
glGenVertexArrays(1, &_quad); // generate array
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
|
||||
const GLfloat x = 1;
|
||||
const GLfloat y = 3;
|
||||
const GLfloat w = 7.5;
|
||||
|
||||
const GLfloat vertex_data[] = { // square of two triangles (sigh)
|
||||
// x y z w s t
|
||||
-x, -y, 0, w, 0, 1,
|
||||
x, y, 0, w, 1, 0,
|
||||
-x, y, 0, w, 0, 0,
|
||||
-x, -y, 0, w, 0, 1,
|
||||
x, -y, 0, w, 1, 1,
|
||||
x, y, 0, w, 1, 0,
|
||||
};
|
||||
|
||||
glBindVertexArray(_quad); // bind array
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
|
||||
}
|
||||
|
||||
}//namespace openspace
|
||||
@@ -1,63 +0,0 @@
|
||||
// /*****************************************************************************************
|
||||
// * *
|
||||
// * 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 <openspace/util/powerscaledscalar.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct ColorBarData {
|
||||
const Camera& camera;
|
||||
psc position;
|
||||
glm::mat4 transform;
|
||||
glm::vec4 top;
|
||||
glm::vec4 mid;
|
||||
glm::vec4 bot;
|
||||
glm::vec4 tfValues;
|
||||
};
|
||||
|
||||
|
||||
class ColorBar{
|
||||
public:
|
||||
ColorBar();
|
||||
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
void render();
|
||||
void render(ColorBarData& data);
|
||||
// void update();
|
||||
private:
|
||||
void createPlane();
|
||||
static void setPscUniforms(ghoul::opengl::ProgramObject& program, const Camera& camera, const PowerScaledCoordinate& position);
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
};
|
||||
}
|
||||
@@ -22,7 +22,6 @@
|
||||
// * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
// ****************************************************************************************/
|
||||
#include <modules/iswa/rendering/dataplane.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
@@ -49,7 +48,6 @@ DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
|
||||
,_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")
|
||||
// ,_colorbar(nullptr)
|
||||
{
|
||||
std::string name;
|
||||
dictionary.getValue("Name", name);
|
||||
@@ -77,9 +75,19 @@ DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
|
||||
// FOR TESTING (should be done on all onChange)
|
||||
// _avgBenchmarkTime = 0.0;
|
||||
// _numOfBenchmarks = 0;
|
||||
loadTexture();});
|
||||
_useLog.onChange([this](){ loadTexture(); });
|
||||
_useHistogram.onChange([this](){ loadTexture(); });
|
||||
_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](){
|
||||
@@ -89,10 +97,23 @@ 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(){}
|
||||
|
||||
void DataPlane::useLog(bool useLog){ _useLog.setValue(useLog); };
|
||||
void DataPlane::normValues(glm::vec2 normValues){ _normValues.setValue(normValues); };
|
||||
void DataPlane::useHistogram(bool useHistogram){ _useHistogram.setValue(useHistogram); };
|
||||
void DataPlane::dataOptions(std::vector<int> options){ _dataOptions.setValue(options); };
|
||||
void DataPlane::transferFunctionsFile(std::string tfPath){ _transferFunctionsFile.setValue(tfPath); };
|
||||
void DataPlane::backgroundValues(glm::vec2 backgroundValues){ _backgroundValues.setValue(backgroundValues); };
|
||||
|
||||
bool DataPlane::loadTexture() {
|
||||
|
||||
// if The future is done then get the new dataFile
|
||||
@@ -106,11 +127,23 @@ bool DataPlane::loadTexture() {
|
||||
_dataBuffer.append(dataFile.buffer, dataFile.size);
|
||||
}
|
||||
|
||||
|
||||
// if the buffer in the datafile is empty, do not proceed
|
||||
if(_dataBuffer.empty())
|
||||
return false;
|
||||
|
||||
std::vector<float*> data = readData(_dataBuffer);
|
||||
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;
|
||||
@@ -125,7 +158,7 @@ bool DataPlane::loadTexture() {
|
||||
if(!_textures[option]){
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture = std::make_unique<ghoul::opengl::Texture>(
|
||||
values,
|
||||
_dimensions,
|
||||
_dataProcessor->dimensions(),
|
||||
ghoul::opengl::Texture::Format::Red,
|
||||
GL_RED,
|
||||
GL_FLOAT,
|
||||
@@ -170,9 +203,6 @@ bool DataPlane::readyToRender(){
|
||||
|
||||
void DataPlane::setUniformAndTextures(){
|
||||
|
||||
// _shader->setUniform("textures", 1, units[1]);
|
||||
// _shader->setUniform("textures", 2, units[2]);
|
||||
// }
|
||||
std::vector<int> selectedOptions = _dataOptions.value();
|
||||
int activeTextures = selectedOptions.size();
|
||||
|
||||
@@ -236,203 +266,6 @@ bool DataPlane::createShader(){
|
||||
}
|
||||
}
|
||||
|
||||
void DataPlane::readHeader(std::string& dataBuffer){
|
||||
if(!dataBuffer.empty()){
|
||||
std::stringstream memorystream(dataBuffer);
|
||||
std::string line;
|
||||
|
||||
int numOptions = 0;
|
||||
while(getline(memorystream,line)){
|
||||
if(line.find("#") == 0){
|
||||
if(line.find("# Output data:") == 0){
|
||||
|
||||
line = line.substr(26);
|
||||
std::stringstream ss(line);
|
||||
|
||||
std::string token;
|
||||
getline(ss, token, 'x');
|
||||
int x = std::stoi(token);
|
||||
|
||||
getline(ss, token, '=');
|
||||
int y = std::stoi(token);
|
||||
|
||||
_dimensions = glm::size3_t(x, y, 1);
|
||||
|
||||
getline(memorystream, line);
|
||||
line = line.substr(1);
|
||||
|
||||
ss = std::stringstream(line);
|
||||
std::string option;
|
||||
while(ss >> option){
|
||||
if(option != "x" && option != "y" && option != "z"){
|
||||
_dataOptions.addOption({numOptions, name()+"_"+option});
|
||||
numOptions++;
|
||||
_textures.push_back(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_dataOptions.setValue(std::vector<int>(1,0));
|
||||
|
||||
if(_data->groupId > 0)
|
||||
IswaManager::ref().registerOptionsToGroup(_data->groupId, _dataOptions.options());
|
||||
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<float*> DataPlane::readData(std::string& dataBuffer){
|
||||
if(!dataBuffer.empty()){
|
||||
if(!_dataOptions.options().size()) // load options for value selection
|
||||
readHeader(dataBuffer);
|
||||
|
||||
std::stringstream memorystream(dataBuffer);
|
||||
std::string line;
|
||||
|
||||
std::vector<int> selectedOptions = _dataOptions.value();
|
||||
|
||||
int numSelected = selectedOptions.size();
|
||||
|
||||
std::vector<float> min(numSelected, std::numeric_limits<float>::max());
|
||||
std::vector<float> max(numSelected, std::numeric_limits<float>::min());
|
||||
|
||||
std::vector<float> sum(numSelected, 0.0f);
|
||||
std::vector<std::vector<float>> optionValues(numSelected, std::vector<float>());
|
||||
|
||||
std::vector<float*> data(_dataOptions.options().size(), nullptr);
|
||||
for(int option : selectedOptions){
|
||||
data[option] = new float[_dimensions.x*_dimensions.y]{0.0f};
|
||||
}
|
||||
|
||||
int numValues = 0;
|
||||
while(getline(memorystream, line)){
|
||||
if(line.find("#") == 0){ //part of the header
|
||||
continue;
|
||||
}
|
||||
|
||||
std::stringstream ss(line);
|
||||
std::vector<float> value;
|
||||
float v;
|
||||
while(ss >> v){
|
||||
value.push_back(v);
|
||||
}
|
||||
|
||||
if(value.size()){
|
||||
for(int i=0; i<numSelected; i++){
|
||||
|
||||
float v = value[selectedOptions[i]+3]; //+3 because "options" x, y and z.
|
||||
|
||||
if(_useLog.value()){
|
||||
int sign = (v>0)? 1:-1;
|
||||
if(v != 0){
|
||||
v = sign*log(fabs(v));
|
||||
}
|
||||
}
|
||||
|
||||
optionValues[i].push_back(v);
|
||||
|
||||
min[i] = std::min(min[i], v);
|
||||
max[i] = std::max(max[i], v);
|
||||
|
||||
sum[i] += v;
|
||||
}
|
||||
numValues++;
|
||||
}
|
||||
}
|
||||
|
||||
if(numValues != _dimensions.x*_dimensions.y){
|
||||
LWARNING("Number of values read and expected are not the same");
|
||||
return std::vector<float*>();
|
||||
}
|
||||
|
||||
// FOR TESTING
|
||||
// ===========
|
||||
// std::chrono::time_point<std::chrono::system_clock> start, end;
|
||||
// start = std::chrono::system_clock::now();
|
||||
// ===========
|
||||
|
||||
for(int i=0; i<numSelected; i++){
|
||||
processData(data[ selectedOptions[i] ], optionValues[i], min[i], max[i], sum[i]);
|
||||
}
|
||||
|
||||
// FOR TESTING
|
||||
// ===========
|
||||
// end = std::chrono::system_clock::now();
|
||||
// _numOfBenchmarks++;
|
||||
// std::chrono::duration<double> elapsed_seconds = end-start;
|
||||
// _avgBenchmarkTime = ( (_avgBenchmarkTime * (_numOfBenchmarks-1)) + elapsed_seconds.count() ) / _numOfBenchmarks;
|
||||
// std::cout << " readData():" << std::endl;
|
||||
// std::cout << "avg elapsed time: " << _avgBenchmarkTime << "s\n";
|
||||
// std::cout << "num Benchmarks: " << _numOfBenchmarks << "\n";
|
||||
// ===========
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
else {
|
||||
// LWARNING("Nothing in memory buffer, are you connected to the information super highway?");
|
||||
return std::vector<float*>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DataPlane::processData(float* outputData, std::vector<float>& inputData, float min, float max,float sum){
|
||||
|
||||
const int numValues = inputData.size();
|
||||
Histogram histogram(min, max, 512);
|
||||
|
||||
//Calculate the mean
|
||||
float mean = (1.0 / numValues) * sum;
|
||||
|
||||
//Calculate the Standard Deviation
|
||||
float var = 0;
|
||||
for(auto dataValue : inputData){
|
||||
var += pow(dataValue - mean, 2);
|
||||
}
|
||||
float standardDeviation = sqrt ( var / numValues );
|
||||
|
||||
// Histogram functionality
|
||||
if(_useHistogram.value()){
|
||||
for(auto dataValue : inputData){
|
||||
histogram.add(dataValue, 1);
|
||||
}
|
||||
histogram.generateEqualizer();
|
||||
standardDeviation = histogram.equalize(standardDeviation);
|
||||
mean = histogram.equalize(mean);
|
||||
}
|
||||
|
||||
// Normalize and equalize
|
||||
for(int i=0; i < numValues; i++){
|
||||
float v = inputData[i];
|
||||
if(_useHistogram.value()){
|
||||
v = histogram.equalize(v);
|
||||
}
|
||||
v = normalizeWithStandardScore(v, mean, standardDeviation);
|
||||
outputData[i] += v;
|
||||
}
|
||||
// Histogram equalized = histogram.equalize();
|
||||
// histogram.print();
|
||||
// equalized.print();
|
||||
|
||||
}
|
||||
|
||||
float DataPlane::normalizeWithStandardScore(float value, float mean, float sd){
|
||||
|
||||
float zScoreMin = _normValues.value().x;
|
||||
float zScoreMax = _normValues.value().y;
|
||||
float standardScore = ( value - mean ) / sd;
|
||||
// Clamp intresting values
|
||||
standardScore = glm::clamp(standardScore, -zScoreMin, zScoreMax);
|
||||
//return and normalize
|
||||
return ( standardScore + zScoreMin )/(zScoreMin + zScoreMax );
|
||||
}
|
||||
|
||||
|
||||
void DataPlane::setTransferFunctions(std::string tfPath){
|
||||
std::string line;
|
||||
std::ifstream tfFile(absPath(tfPath));
|
||||
@@ -454,11 +287,4 @@ void DataPlane::setTransferFunctions(std::string tfPath){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}// namespace openspace
|
||||
@@ -28,8 +28,8 @@
|
||||
#include <modules/iswa/rendering/cygnetplane.h>
|
||||
#include <modules/kameleon/include/kameleonwrapper.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <modules/iswa/rendering/colorbar.h>
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
#include <modules/iswa/util/dataprocessor.h>
|
||||
|
||||
namespace openspace{
|
||||
class IswaGroup;
|
||||
@@ -41,12 +41,12 @@ friend class IswaGroup;
|
||||
~DataPlane();
|
||||
|
||||
protected:
|
||||
void useLog(bool useLog){ _useLog.setValue(useLog); };
|
||||
void normValues(glm::vec2 normValues){ _normValues.setValue(normValues); };
|
||||
void useHistogram(bool useHistogram){ _useHistogram.setValue(useHistogram); };
|
||||
void dataOptions(std::vector<int> options){ _dataOptions.setValue(options); };
|
||||
void transferFunctionsFile(std::string tfPath){ _transferFunctionsFile.setValue(tfPath); };
|
||||
void backgroundValues(glm::vec2 backgroundValues){ _backgroundValues.setValue(backgroundValues); };
|
||||
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);
|
||||
|
||||
private:
|
||||
virtual bool loadTexture() override;
|
||||
@@ -56,35 +56,20 @@ friend class IswaGroup;
|
||||
virtual void setUniformAndTextures() override;
|
||||
virtual bool createShader() override;
|
||||
|
||||
void readHeader(std::string&);
|
||||
std::vector<float*> readData(std::string&);
|
||||
void processData(
|
||||
float* outputData, // Where you want your processed data to go
|
||||
std::vector<float>& inputData, //data that needs processing
|
||||
float min, // min value of the input data
|
||||
float max, // max valye of the input data
|
||||
float sum // sum of the input data
|
||||
);
|
||||
|
||||
float normalizeWithStandardScore(float value, float mean, float sd);
|
||||
void setTransferFunctions(std::string tfPath);
|
||||
|
||||
properties::SelectionProperty _dataOptions;
|
||||
properties::StringProperty _transferFunctionsFile;
|
||||
properties::Vec2Property _normValues;
|
||||
properties::Vec2Property _backgroundValues;
|
||||
|
||||
properties::Vec2Property _normValues;
|
||||
properties::BoolProperty _useLog;
|
||||
properties::BoolProperty _useHistogram;
|
||||
|
||||
glm::size3_t _dimensions;
|
||||
std::string _dataBuffer;
|
||||
|
||||
// std::shared_ptr<ColorBar> _colorbar;
|
||||
|
||||
//FOR TESTING
|
||||
// double _avgBenchmarkTime=0.0;
|
||||
// int _numOfBenchmarks = 0;
|
||||
//===========
|
||||
std::shared_ptr<DataProcessor> _dataProcessor;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -98,10 +98,9 @@ IswaCygnet::IswaCygnet(const ghoul::Dictionary& dictionary)
|
||||
// std::cout << std::to_string(_data->min) << std::endl;
|
||||
// std::cout << std::to_string(_data->spatialScale) << std::endl;
|
||||
|
||||
_delete.onChange([this](){IswaManager::ref().deleteIswaCygnet(name());});
|
||||
|
||||
// _textures.push_back(nullptr);
|
||||
// _transferFunctions.push_back(nullptr);
|
||||
_delete.onChange([this](){
|
||||
OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + name() + "')");
|
||||
});
|
||||
}
|
||||
|
||||
IswaCygnet::~IswaCygnet(){}
|
||||
|
||||
@@ -71,7 +71,6 @@ void IswaGroup::registerCygnet(IswaCygnet* cygnet, IswaManager::CygnetType type)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(type == IswaManager::CygnetType::Data){
|
||||
DataPlane* dataplane = static_cast<DataPlane*>(cygnet);
|
||||
|
||||
@@ -171,7 +170,6 @@ void IswaGroup::registerProperties(){
|
||||
OsEng.gui()._iswa.registerProperty(&_delete);
|
||||
_delete.onChange([this]{
|
||||
clearGroup();
|
||||
// IswaManager::ref().unregisterGroup(_id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -183,8 +181,8 @@ void IswaGroup::unregisterProperties(){
|
||||
|
||||
void IswaGroup::clearGroup(){
|
||||
for(auto it = _cygnets.begin(); it != _cygnets.end();){
|
||||
IswaManager::ref().deleteIswaCygnet((*it)->name());
|
||||
it = _cygnets.erase(it);
|
||||
OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + (*it)->name() + "')");
|
||||
it = _cygnets.erase(it);
|
||||
}
|
||||
unregisterProperties();
|
||||
}
|
||||
|
||||
@@ -36,35 +36,49 @@ namespace openspace {
|
||||
|
||||
ScreenSpaceCygnet::ScreenSpaceCygnet(const ghoul::Dictionary& dictionary)
|
||||
: ScreenSpaceImage(dictionary)
|
||||
, _updateInterval("updateInterval", "Update Interval", 1.0, 0.0 , 10.0)
|
||||
{
|
||||
// hacky, have to first get as float and then cast to int.
|
||||
float cygnetid;
|
||||
dictionary.getValue("CygnetId", cygnetid);
|
||||
_cygnetId = (int)cygnetid;
|
||||
|
||||
// setName("iSWACygnet" + std::to_string(_cygnetId));
|
||||
addProperty(_updateInterval);
|
||||
float interval;
|
||||
dictionary.getValue("UpdateInterval", interval);
|
||||
_updateTime = (int) interval;
|
||||
|
||||
_downloadImage = true;
|
||||
|
||||
_url = IswaManager::ref().iswaUrl(_cygnetId);
|
||||
|
||||
_openSpaceTime = Time::ref().currentTime();
|
||||
_lastUpdateOpenSpaceTime = _openSpaceTime;
|
||||
|
||||
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
|
||||
_lastUpdateRealTime = _realTime;
|
||||
_minRealTimeUpdateInterval = 100;
|
||||
|
||||
_delete.onChange([this](){
|
||||
OsEng.scriptEngine().queueScript(
|
||||
"openspace.iswa.removeScreenSpaceCygnet("+std::to_string(_cygnetId)+");"
|
||||
);
|
||||
});
|
||||
// IswaManager::ref().deleteIswaCygnet(name());});
|
||||
|
||||
}
|
||||
|
||||
ScreenSpaceCygnet::~ScreenSpaceCygnet(){}
|
||||
|
||||
void ScreenSpaceCygnet::update(){
|
||||
_openSpaceTime = Time::ref().currentTime();
|
||||
_realTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
|
||||
int updateInterval = (int) (_updateInterval.value()*1000);
|
||||
bool timeToUpdate = ((_realTime.count()-_lastUpdateRealTime.count()) > updateInterval) &&
|
||||
(Time::ref().deltaTime() != 0);
|
||||
|
||||
if(updateInterval != 0 && (Time::ref().timeJumped() || timeToUpdate )){
|
||||
bool timeToUpdate = (fabs(_openSpaceTime-_lastUpdateOpenSpaceTime) >= _updateTime &&
|
||||
(_realTime.count()-_lastUpdateRealTime.count()) > _minRealTimeUpdateInterval);
|
||||
|
||||
if((Time::ref().timeJumped() || timeToUpdate )){
|
||||
_url = IswaManager::ref().iswaUrl(_cygnetId);
|
||||
updateTexture();
|
||||
_lastUpdateRealTime = _realTime;
|
||||
_lastUpdateOpenSpaceTime = _openSpaceTime;
|
||||
}
|
||||
|
||||
if(_futureImage.valid() && DownloadManager::futureReady(_futureImage)) {
|
||||
|
||||
@@ -42,12 +42,16 @@ public:
|
||||
|
||||
virtual void update() override;
|
||||
|
||||
|
||||
private:
|
||||
int _cygnetId;
|
||||
properties::FloatProperty _updateInterval;
|
||||
|
||||
int _updateTime;
|
||||
double _openSpaceTime;
|
||||
double _lastUpdateOpenSpaceTime;
|
||||
|
||||
std::chrono::milliseconds _realTime;
|
||||
std::chrono::milliseconds _lastUpdateRealTime;
|
||||
int _minRealTimeUpdateInterval;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
|
||||
uniform vec4 top;
|
||||
uniform vec4 mid;
|
||||
uniform vec4 bot;
|
||||
uniform vec4 tfValues;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec4 vs_position;
|
||||
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
Fragment getFragment() {
|
||||
vec4 position = vs_position;
|
||||
float depth = pscDepth(position);
|
||||
vec4 diffuse;
|
||||
// diffuse = top;
|
||||
// diffuse = texture(texture1, vs_st);
|
||||
// float v = texture(texture1, vs_st).r;
|
||||
float v = 1-vs_st.t;
|
||||
float x = tfValues.x;
|
||||
float y = tfValues.y;
|
||||
|
||||
// if(y == 0){
|
||||
// v = v-x;
|
||||
// diffuse = mix(bot, top, v);
|
||||
// }else{
|
||||
if(v > (x+y)){
|
||||
v = v - (x+y);
|
||||
v = v / (x-y);
|
||||
diffuse = mix(mid, top, v);
|
||||
}else if( v < (x-y)){
|
||||
v = v / (x-y);
|
||||
diffuse = mix(bot, mid, v);
|
||||
}else{
|
||||
diffuse = mid;
|
||||
}
|
||||
// }
|
||||
|
||||
// diffuse = vec4(vs_st.s, vs_st.t, 0, 1);
|
||||
// vec4 diffuse = vec4(1,vs_st,1);
|
||||
//vec4 diffuse = vec4(1,0,0,1);
|
||||
// if(position.w > 9.0) {
|
||||
// diffuse = vec4(1,0,0,1);
|
||||
// }
|
||||
|
||||
//diffuse.a = diffuse.r;
|
||||
// float tot = diffuse.r + diffuse.g + diffuse.b;
|
||||
// tot /= 3.0;
|
||||
// if (diffuse.a <= 0.05)
|
||||
// discard;
|
||||
|
||||
Fragment frag;
|
||||
frag.color = diffuse;
|
||||
frag.depth = depth;
|
||||
return frag;
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec4 vs_position;
|
||||
out float s;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tmp = in_position;
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
|
||||
vs_position = tmp;
|
||||
vs_st = in_st;
|
||||
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
}
|
||||
235
modules/iswa/util/dataprocessor.cpp
Normal file
235
modules/iswa/util/dataprocessor.cpp
Normal file
@@ -0,0 +1,235 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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/util/dataprocessor.h>
|
||||
#include <modules/multiresvolume/rendering/histogram.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <modules/iswa/util/iswamanager.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "DataPlane";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
DataProcessor::DataProcessor(bool useLog, bool useHistogram, glm::vec2 normValues)
|
||||
:_useLog(useLog)
|
||||
,_useHistogram(useHistogram)
|
||||
,_normValues(normValues)
|
||||
{};
|
||||
DataProcessor::~DataProcessor(){};
|
||||
|
||||
std::vector<std::string> DataProcessor::readHeader(std::string& dataBuffer){
|
||||
std::vector<std::string> options = std::vector<std::string>();
|
||||
if(!dataBuffer.empty()){
|
||||
std::stringstream memorystream(dataBuffer);
|
||||
std::string line;
|
||||
|
||||
while(getline(memorystream,line)){
|
||||
if(line.find("#") == 0){
|
||||
if(line.find("# Output data:") == 0){
|
||||
|
||||
line = line.substr(26);
|
||||
std::stringstream ss(line);
|
||||
|
||||
std::string token;
|
||||
getline(ss, token, 'x');
|
||||
int x = std::stoi(token);
|
||||
|
||||
getline(ss, token, '=');
|
||||
int y = std::stoi(token);
|
||||
|
||||
_dimensions = glm::size3_t(x, y, 1);
|
||||
|
||||
getline(memorystream, line);
|
||||
line = line.substr(1);
|
||||
|
||||
ss = std::stringstream(line);
|
||||
std::string option;
|
||||
while(ss >> option){
|
||||
if(option != "x" && option != "y" && option != "z"){
|
||||
options.push_back(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
std::vector<float*> DataProcessor::readData(std::string& dataBuffer, properties::SelectionProperty dataOptions){
|
||||
if(!dataBuffer.empty()){
|
||||
// if(!_dataOptions.options().size()) // load options for value selection
|
||||
// readHeader(dataBuffer);
|
||||
|
||||
std::stringstream memorystream(dataBuffer);
|
||||
std::string line;
|
||||
|
||||
std::vector<int> selectedOptions = dataOptions.value();
|
||||
|
||||
int numSelected = selectedOptions.size();
|
||||
|
||||
std::vector<float> min(numSelected, std::numeric_limits<float>::max());
|
||||
std::vector<float> max(numSelected, std::numeric_limits<float>::min());
|
||||
|
||||
std::vector<float> sum(numSelected, 0.0f);
|
||||
std::vector<std::vector<float>> optionValues(numSelected, std::vector<float>());
|
||||
|
||||
std::vector<float*> data(dataOptions.options().size(), nullptr);
|
||||
for(int option : selectedOptions){
|
||||
data[option] = new float[_dimensions.x*_dimensions.y]{0.0f};
|
||||
}
|
||||
|
||||
int numValues = 0;
|
||||
while(getline(memorystream, line)){
|
||||
if(line.find("#") == 0){ //part of the header
|
||||
continue;
|
||||
}
|
||||
|
||||
std::stringstream ss(line);
|
||||
std::vector<float> value;
|
||||
float v;
|
||||
while(ss >> v){
|
||||
value.push_back(v);
|
||||
}
|
||||
|
||||
if(value.size()){
|
||||
for(int i=0; i<numSelected; i++){
|
||||
|
||||
float v = value[selectedOptions[i]+3]; //+3 because "options" x, y and z.
|
||||
|
||||
if(_useLog){
|
||||
int sign = (v>0)? 1:-1;
|
||||
if(v != 0){
|
||||
v = sign*log(fabs(v));
|
||||
}
|
||||
}
|
||||
|
||||
optionValues[i].push_back(v);
|
||||
|
||||
min[i] = std::min(min[i], v);
|
||||
max[i] = std::max(max[i], v);
|
||||
|
||||
sum[i] += v;
|
||||
}
|
||||
numValues++;
|
||||
}
|
||||
}
|
||||
// std::cout << "Actual size: " << numValues << " Expected: " << _dimensions.x*_dimensions.y << std::endl;
|
||||
if(numValues != _dimensions.x*_dimensions.y){
|
||||
LWARNING("Number of values read and expected are not the same");
|
||||
return std::vector<float*>();
|
||||
}
|
||||
|
||||
// FOR TESTING
|
||||
// ===========
|
||||
// std::chrono::time_point<std::chrono::system_clock> start, end;
|
||||
// start = std::chrono::system_clock::now();
|
||||
// ===========
|
||||
|
||||
for(int i=0; i<numSelected; i++){
|
||||
processData(data[ selectedOptions[i] ], optionValues[i], min[i], max[i], sum[i]);
|
||||
}
|
||||
|
||||
// FOR TESTING
|
||||
// ===========
|
||||
// end = std::chrono::system_clock::now();
|
||||
// _numOfBenchmarks++;
|
||||
// std::chrono::duration<double> elapsed_seconds = end-start;
|
||||
// _avgBenchmarkTime = ( (_avgBenchmarkTime * (_numOfBenchmarks-1)) + elapsed_seconds.count() ) / _numOfBenchmarks;
|
||||
// std::cout << " readData():" << std::endl;
|
||||
// std::cout << "avg elapsed time: " << _avgBenchmarkTime << "s\n";
|
||||
// std::cout << "num Benchmarks: " << _numOfBenchmarks << "\n";
|
||||
// ===========
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
else {
|
||||
// LWARNING("Nothing in memory buffer, are you connected to the information super highway?");
|
||||
return std::vector<float*>();
|
||||
}
|
||||
}
|
||||
|
||||
void DataProcessor::processData(float* outputData, std::vector<float>& inputData, float min, float max,float sum){
|
||||
|
||||
const int numValues = inputData.size();
|
||||
Histogram histogram(min, max, 512);
|
||||
|
||||
//Calculate the mean
|
||||
float mean = (1.0 / numValues) * sum;
|
||||
|
||||
//Calculate the Standard Deviation
|
||||
float var = 0;
|
||||
for(auto dataValue : inputData){
|
||||
var += pow(dataValue - mean, 2);
|
||||
}
|
||||
float standardDeviation = sqrt ( var / numValues );
|
||||
|
||||
// Histogram functionality
|
||||
if(_useHistogram){
|
||||
for(auto dataValue : inputData){
|
||||
histogram.add(dataValue, 1);
|
||||
}
|
||||
histogram.generateEqualizer();
|
||||
standardDeviation = histogram.equalize(standardDeviation);
|
||||
mean = histogram.equalize(mean);
|
||||
}
|
||||
|
||||
// Normalize and equalize
|
||||
for(int i=0; i < numValues; i++){
|
||||
float v = inputData[i];
|
||||
if(_useHistogram){
|
||||
v = histogram.equalize(v);
|
||||
}
|
||||
v = normalizeWithStandardScore(v, mean, standardDeviation);
|
||||
outputData[i] += v;
|
||||
}
|
||||
// Histogram equalized = histogram.equalize();
|
||||
// histogram.print();
|
||||
// equalized.print();
|
||||
}
|
||||
|
||||
float DataProcessor::normalizeWithStandardScore(float value, float mean, float sd){
|
||||
|
||||
float zScoreMin = _normValues.x;
|
||||
float zScoreMax = _normValues.y;
|
||||
float standardScore = ( value - mean ) / sd;
|
||||
// Clamp intresting values
|
||||
standardScore = glm::clamp(standardScore, -zScoreMin, zScoreMax);
|
||||
//return and normalize
|
||||
return ( standardScore + zScoreMin )/(zScoreMin + zScoreMax );
|
||||
}
|
||||
}
|
||||
80
modules/iswa/util/dataprocessor.h
Normal file
80
modules/iswa/util/dataprocessor.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __DATAPROCESSOR_H__
|
||||
#define __DATAPROCESSOR_H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
|
||||
namespace openspace{
|
||||
class DataProcessor{
|
||||
friend class IswaGroup;
|
||||
public:
|
||||
DataProcessor(bool useLog, bool useHistogram, glm::vec2 normValues);
|
||||
~DataProcessor();
|
||||
|
||||
void useLog(bool useLog){
|
||||
_useLog = useLog;
|
||||
}
|
||||
|
||||
void useHistogram(bool useHistogram){
|
||||
_useHistogram = useHistogram;
|
||||
}
|
||||
|
||||
void normValues(glm::vec2 normValues){
|
||||
_normValues = normValues;
|
||||
}
|
||||
|
||||
glm::size3_t dimensions(){
|
||||
return _dimensions;
|
||||
}
|
||||
|
||||
std::vector<std::string> readHeader(std::string& dataBuffer);
|
||||
std::vector<float*> readData(std::string& dataBuffer, properties::SelectionProperty dataOptions);
|
||||
|
||||
private:
|
||||
void processData(
|
||||
float* outputData, // Where you want your processed data to go
|
||||
std::vector<float>& inputData, //data that needs processing
|
||||
float min, // min value of the input data
|
||||
float max, // max valye of the input data
|
||||
float sum // sum of the input data
|
||||
);
|
||||
|
||||
float normalizeWithStandardScore(float value, float mean, float sd);
|
||||
|
||||
|
||||
glm::size3_t _dimensions;
|
||||
bool _useLog;
|
||||
bool _useHistogram;
|
||||
glm::vec2 _normValues;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
#endif //__DATAPROCESSOR_H__
|
||||
@@ -31,6 +31,8 @@
|
||||
#include <modules/iswa/rendering/iswagroup.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <modules/kameleon/include/kameleonwrapper.h>
|
||||
#include <openspace/util/time.h>
|
||||
@@ -49,8 +51,7 @@ namespace {
|
||||
|
||||
namespace openspace{
|
||||
|
||||
IswaManager::IswaManager()
|
||||
{
|
||||
IswaManager::IswaManager(){
|
||||
_month["JAN"] = "01";
|
||||
_month["FEB"] = "02";
|
||||
_month["MAR"] = "03";
|
||||
@@ -70,10 +71,21 @@ IswaManager::IswaManager()
|
||||
|
||||
_geom[CygnetGeometry::Plane] = "Plane";
|
||||
_geom[CygnetGeometry::Sphere] = "Sphere";
|
||||
|
||||
DlManager.fetchFile(
|
||||
"http://iswa2.ccmc.gsfc.nasa.gov/IswaSystemWebApp/CygnetHealthServlet",
|
||||
[this](const DownloadManager::MemoryFile& file){
|
||||
fillCygnetInfo(std::string(file.buffer));
|
||||
},
|
||||
[](const std::string& err){
|
||||
LWARNING("Download to memory was aborted: " + err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
IswaManager::~IswaManager(){
|
||||
_groups.clear();
|
||||
_cygnetInformation.clear();
|
||||
}
|
||||
|
||||
void IswaManager::addIswaCygnet(std::string info){
|
||||
@@ -136,9 +148,7 @@ void IswaManager::addIswaCygnet(int id, std::string info, int group){
|
||||
metaFuture->json,
|
||||
metadataCallback
|
||||
);
|
||||
}else{
|
||||
//create kameleonplane
|
||||
// createKameleonPlane(info);
|
||||
}else{
|
||||
std::shared_ptr<MetadataFuture> metaFuture = std::make_shared<MetadataFuture>();
|
||||
metaFuture->id = -1;
|
||||
metaFuture->group = group;
|
||||
@@ -159,39 +169,7 @@ void IswaManager::addIswaCygnet(int id, std::string info, int group){
|
||||
metaFuture->json,
|
||||
metadataCallback
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void IswaManager::deleteIswaCygnet(std::string name){
|
||||
OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + name + "')");
|
||||
}
|
||||
|
||||
std::shared_ptr<DownloadManager::FileFuture> IswaManager::downloadImageToMemory(int id, std::string& buffer){
|
||||
return DlManager.downloadToMemory(
|
||||
iswaUrl(id, "image"),
|
||||
buffer,
|
||||
[](const DownloadManager::FileFuture& f){
|
||||
if(f.isFinished){
|
||||
LDEBUG("Download to memory finished");
|
||||
} else if (f.isAborted){
|
||||
LWARNING("Download to memory was aborted: " + f.errorMessage);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<DownloadManager::FileFuture> IswaManager::downloadDataToMemory(int id, std::string& buffer){
|
||||
return DlManager.downloadToMemory(
|
||||
iswaUrl(id, "data"),
|
||||
buffer,
|
||||
[](const DownloadManager::FileFuture& f){
|
||||
if(f.isFinished){
|
||||
LDEBUG("Download to memory finished");
|
||||
} else if (f.isAborted){
|
||||
LWARNING("Download to memory was aborted: " + f.errorMessage);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
std::future<DownloadManager::MemoryFile> IswaManager::fetchImageCygnet(int id){
|
||||
@@ -218,7 +196,6 @@ std::future<DownloadManager::MemoryFile> IswaManager::fetchDataCygnet(int id){
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
std::string IswaManager::iswaUrl(int id, std::string type){
|
||||
std::string url;
|
||||
if(id < 0){
|
||||
@@ -244,6 +221,44 @@ std::string IswaManager::iswaUrl(int id, std::string type){
|
||||
return url;
|
||||
}
|
||||
|
||||
void IswaManager::registerToGroup(int id, CygnetType type, IswaCygnet* cygnet){
|
||||
if(_groups.find(id) == _groups.end()){
|
||||
_groups.insert(std::pair<int, std::shared_ptr<IswaGroup>>(id, std::make_shared<IswaGroup>(id)));
|
||||
}
|
||||
|
||||
_groups[id]->registerCygnet(cygnet, type);
|
||||
}
|
||||
|
||||
void IswaManager::unregisterFromGroup(int id, IswaCygnet* cygnet){
|
||||
if(_groups.find(id) != _groups.end()){
|
||||
_groups[id]->unregisterCygnet(cygnet);
|
||||
}
|
||||
}
|
||||
|
||||
void IswaManager::registerOptionsToGroup(int id, const std::vector<properties::SelectionProperty::Option>& options){
|
||||
if(_groups.find(id) != _groups.end()){
|
||||
_groups[id]->registerOptions(options);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<IswaGroup> IswaManager::iswaGroup(std::string name){
|
||||
for(auto group : _groups){
|
||||
if(group.second->name() == name){
|
||||
return group.second;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::map<int, std::shared_ptr<CygnetInfo>>& IswaManager::cygnetInformation(){
|
||||
return _cygnetInformation;
|
||||
}
|
||||
|
||||
std::map<int, std::shared_ptr<IswaGroup>>& IswaManager::groups(){
|
||||
return _groups;
|
||||
}
|
||||
|
||||
std::shared_ptr<MetadataFuture> IswaManager::downloadMetadata(int id){
|
||||
std::shared_ptr<MetadataFuture> metaFuture = std::make_shared<MetadataFuture>();
|
||||
|
||||
@@ -264,43 +279,6 @@ std::shared_ptr<MetadataFuture> IswaManager::downloadMetadata(int id){
|
||||
return metaFuture;
|
||||
}
|
||||
|
||||
void IswaManager::createScreenSpace(int id){
|
||||
|
||||
std::string name = "iSWACygnet" + std::to_string(id);
|
||||
if(OsEng.renderEngine().screenSpaceRenderable(name)){
|
||||
LERROR("A cygnet with the name \"" + name +"\" already exist");
|
||||
return;
|
||||
}else{
|
||||
std::string luaTable = "{ Name = '" + name + "', Type='ScreenSpaceCygnet', CygnetId = "+std::to_string(id)+"}";
|
||||
std::string script = "openspace.registerScreenSpaceRenderable(" + luaTable + ");";
|
||||
OsEng.scriptEngine().queueScript(script);
|
||||
}
|
||||
}
|
||||
|
||||
void IswaManager::createPlane(std::shared_ptr<MetadataFuture> data){
|
||||
// check if this plane already exist
|
||||
std::string name = _type[data->type] + _geom[data->geom] + std::to_string(data->id);
|
||||
|
||||
if(data->group > 0){
|
||||
auto it = _groups.find(data->group);
|
||||
if(it == _groups.end() || (*it).second->checkType((CygnetType) data->type))
|
||||
name += "_Group" + std::to_string(data->group);
|
||||
}
|
||||
|
||||
data->name = name;
|
||||
|
||||
if( OsEng.renderEngine().scene()->sceneGraphNode(name) ){
|
||||
LERROR("A node with name \"" + name +"\" already exist");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string luaTable = parseJSONToLuaTable(data);
|
||||
if(luaTable != ""){
|
||||
std::string script = "openspace.addSceneGraphNode(" + luaTable + ");";
|
||||
OsEng.scriptEngine().queueScript(script);
|
||||
}
|
||||
}
|
||||
|
||||
std::string IswaManager::parseJSONToLuaTable(std::shared_ptr<MetadataFuture> data){
|
||||
if(data->json != ""){
|
||||
json j = json::parse(data->json);
|
||||
@@ -353,113 +331,56 @@ std::string IswaManager::parseJSONToLuaTable(std::shared_ptr<MetadataFuture> dat
|
||||
return "";
|
||||
}
|
||||
|
||||
// void IswaManager::createKameleonPlane(std::string kwPath, int group){
|
||||
// kwPath = "${OPENSPACE_DATA}/" + kwPath;
|
||||
// const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension();
|
||||
|
||||
// if(FileSys.fileExists(absPath(kwPath)) && extension == "cdf"){
|
||||
// std::string luaTable = parseKWToLuaTable(kwPath, group);
|
||||
// if(!luaTable.empty()){
|
||||
// std::cout << luaTable << std::endl;
|
||||
// std::string script = "openspace.addSceneGraphNode(" + luaTable + ");";
|
||||
// OsEng.scriptEngine().queueScript(script);
|
||||
// }
|
||||
// }else{
|
||||
// LWARNING( kwPath + " is not a cdf file or can't be found.");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// std::string IswaManager::parseKWToLuaTable(std::string kwPath, int group){
|
||||
// if(kwPath != ""){
|
||||
// const std::string& extension = ghoul::filesystem::File(absPath(kwPath)).fileExtension();
|
||||
// if(extension == "cdf"){
|
||||
// KameleonWrapper kw = KameleonWrapper(absPath(kwPath));
|
||||
|
||||
// std::string parent = kw.getParent();
|
||||
// std::string frame = kw.getFrame();
|
||||
// glm::vec3 min = kw.getGridMin();
|
||||
// glm::vec3 max = kw.getGridMax();
|
||||
|
||||
// glm::vec4 spatialScale;
|
||||
// std::string coordinateType;
|
||||
|
||||
// std::tuple < std::string, std::string, std::string > gridUnits = kw.getGridUnits();
|
||||
// if (std::get<0>(gridUnits) == "R" && std::get<1>(gridUnits) == "R" && std::get<2>(gridUnits) == "R") {
|
||||
// spatialScale.x = 6.371f;
|
||||
// spatialScale.y = 6.371f;
|
||||
// spatialScale.z = 6.371f;
|
||||
// spatialScale.w = 6;
|
||||
|
||||
// coordinateType = "Cartesian";
|
||||
// }else{
|
||||
// spatialScale = glm::vec4(1.0);
|
||||
// spatialScale.w = 1; //-log10(1.0f/max.x);
|
||||
|
||||
// coordinateType = "Polar";
|
||||
// }
|
||||
// std::string table = "{"
|
||||
// "Name = 'KameleonPlane0',"
|
||||
// "Parent = '" + parent + "', "
|
||||
// "Renderable = {"
|
||||
// "Type = 'KameleonPlane', "
|
||||
// "Id = 0 ,"
|
||||
// "Frame = '" + frame + "' , "
|
||||
// "GridMin = " + std::to_string(min) + ", "
|
||||
// "GridMax = " + std::to_string(max) + ", "
|
||||
// "SpatialScale = " + std::to_string(spatialScale) + ", "
|
||||
// "UpdateTime = 0, "
|
||||
// "kwPath = '" + kwPath + "' ,"
|
||||
// "axisCut = 'y' ,"
|
||||
// "CoordinateType = '" + coordinateType + "', "
|
||||
// "Group = "+ std::to_string(group) + " ,"
|
||||
// "}"
|
||||
// "}"
|
||||
// ;
|
||||
// // std::cout << table << std::endl;
|
||||
// return table;
|
||||
// }
|
||||
// }
|
||||
// return "";
|
||||
// }
|
||||
|
||||
|
||||
void IswaManager::registerGroup(int id){
|
||||
_groups.insert(std::pair<int, std::shared_ptr<IswaGroup>>(id, std::make_shared<IswaGroup>(id)));
|
||||
void IswaManager::createScreenSpace(int id){
|
||||
std::string script = "openspace.iswa.addScreenSpaceCygnet("
|
||||
"{CygnetId =" + std::to_string(id) + "});";
|
||||
OsEng.scriptEngine().queueScript(script);
|
||||
}
|
||||
|
||||
void IswaManager::unregisterGroup(int id){
|
||||
if(_groups.find(id) != _groups.end())
|
||||
_groups[id]->clearGroup();
|
||||
}
|
||||
void IswaManager::createPlane(std::shared_ptr<MetadataFuture> data){
|
||||
// check if this plane already exist
|
||||
std::string name = _type[data->type] + _geom[data->geom] + std::to_string(data->id);
|
||||
|
||||
void IswaManager::registerToGroup(int id, CygnetType type, IswaCygnet* cygnet){
|
||||
if(_groups.find(id) == _groups.end()){
|
||||
registerGroup(id);
|
||||
if(data->group > 0){
|
||||
auto it = _groups.find(data->group);
|
||||
if(it == _groups.end() || (*it).second->checkType((CygnetType) data->type))
|
||||
name += "_Group" + std::to_string(data->group);
|
||||
}
|
||||
|
||||
_groups[id]->registerCygnet(cygnet, type);
|
||||
}
|
||||
data->name = name;
|
||||
|
||||
void IswaManager::unregisterFromGroup(int id, IswaCygnet* cygnet){
|
||||
if(_groups.find(id) != _groups.end()){
|
||||
_groups[id]->unregisterCygnet(cygnet);
|
||||
if( OsEng.renderEngine().scene()->sceneGraphNode(name) ){
|
||||
LERROR("A node with name \"" + name +"\" already exist");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string luaTable = parseJSONToLuaTable(data);
|
||||
if(luaTable != ""){
|
||||
std::string script = "openspace.addSceneGraphNode(" + luaTable + ");";
|
||||
OsEng.scriptEngine().queueScript(script);
|
||||
}
|
||||
}
|
||||
|
||||
void IswaManager::registerOptionsToGroup(int id, const std::vector<properties::SelectionProperty::Option>& options){
|
||||
if(_groups.find(id) != _groups.end()){
|
||||
_groups[id]->registerOptions(options);
|
||||
}
|
||||
}
|
||||
void IswaManager::fillCygnetInfo(std::string jsonString){
|
||||
if(jsonString != ""){
|
||||
json j = json::parse(jsonString);
|
||||
|
||||
json jCygnets = j["listOfPriorityCygnets"];
|
||||
for(int i=0; i<jCygnets.size(); i++){
|
||||
json jCygnet = jCygnets.at(i);
|
||||
|
||||
std::shared_ptr<IswaGroup> IswaManager::iswaGroup(std::string name){
|
||||
for(auto group : _groups){
|
||||
if(group.second->name() == name){
|
||||
return group.second;
|
||||
std::string name = jCygnet["cygnetDisplayTitle"];
|
||||
std::replace(name.begin(), name.end(),'.', ',');
|
||||
|
||||
CygnetInfo info = {
|
||||
name,
|
||||
jCygnet["cygnetDescription"],
|
||||
jCygnet["cygnetUpdateInterval"],
|
||||
false
|
||||
};
|
||||
_cygnetInformation[jCygnet["cygnetID"]] = std::make_shared<CygnetInfo>(info);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
scripting::ScriptEngine::LuaLibrary IswaManager::luaLibrary() {
|
||||
@@ -473,6 +394,27 @@ scripting::ScriptEngine::LuaLibrary IswaManager::luaLibrary() {
|
||||
"Adds a IswaCygnet",
|
||||
true
|
||||
},
|
||||
{
|
||||
"addScreenSpaceCygnet",
|
||||
&luascriptfunctions::iswa_addScreenSpaceCygnet,
|
||||
"table",
|
||||
"Adds a Screen Space Cygnets",
|
||||
true
|
||||
},
|
||||
{
|
||||
"removeCygnet",
|
||||
&luascriptfunctions::iswa_removeCygnet,
|
||||
"string",
|
||||
"Remove a Cygnets",
|
||||
true
|
||||
},
|
||||
{
|
||||
"removeScreenSpaceCygnet",
|
||||
&luascriptfunctions::iswa_removeScrenSpaceCygnet,
|
||||
"int",
|
||||
"Remove a Screen Space Cygnets",
|
||||
true
|
||||
},
|
||||
{
|
||||
"removeGroup",
|
||||
&luascriptfunctions::iswa_removeGroup,
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
|
||||
// #include <modules/iswa/rendering/iswacygnet.h>
|
||||
// #include <modules/iswa/rendering/iswagroup.h>
|
||||
@@ -46,6 +47,12 @@ namespace openspace {
|
||||
class IswaGroup;
|
||||
class IswaCygnet;
|
||||
|
||||
struct CygnetInfo {
|
||||
std::string name;
|
||||
std::string description;
|
||||
int updateInterval;
|
||||
bool selected;
|
||||
};
|
||||
|
||||
struct MetadataFuture {
|
||||
int id;
|
||||
@@ -58,7 +65,7 @@ struct MetadataFuture {
|
||||
};
|
||||
|
||||
|
||||
class IswaManager : public ghoul::Singleton<IswaManager> {
|
||||
class IswaManager : public ghoul::Singleton<IswaManager>, public properties::PropertyOwner {
|
||||
friend class ghoul::Singleton<IswaManager>;
|
||||
|
||||
public:
|
||||
@@ -70,42 +77,40 @@ public:
|
||||
|
||||
void addIswaCygnet(std::string info);
|
||||
void addIswaCygnet(int id, std::string info = "Texture", int group = -1);
|
||||
void deleteIswaCygnet(std::string);
|
||||
|
||||
std::shared_ptr<DownloadManager::FileFuture> downloadImageToMemory(int id, std::string& buffer);
|
||||
std::shared_ptr<DownloadManager::FileFuture> downloadDataToMemory(int id, std::string& buffer);
|
||||
// void deleteIswaCygnet(std::string);
|
||||
|
||||
std::future<DownloadManager::MemoryFile> fetchImageCygnet(int id);
|
||||
std::future<DownloadManager::MemoryFile> fetchDataCygnet(int id);
|
||||
std::string iswaUrl(int id, std::string type = "image");
|
||||
|
||||
void registerGroup(int id);
|
||||
void unregisterGroup(int id);
|
||||
void registerToGroup(int id, CygnetType type, IswaCygnet* cygnet);
|
||||
void unregisterFromGroup(int id, IswaCygnet* cygnet);
|
||||
void registerOptionsToGroup(int id, const std::vector<properties::SelectionProperty::Option>& options);
|
||||
std::shared_ptr<IswaGroup> iswaGroup(std::string name);
|
||||
|
||||
std::map<int, std::shared_ptr<CygnetInfo>>& cygnetInformation();
|
||||
std::map<int, std::shared_ptr<IswaGroup>>& groups();
|
||||
|
||||
static scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
std::string iswaUrl(int id, std::string type = "image");
|
||||
private:
|
||||
std::shared_ptr<MetadataFuture> downloadMetadata(int id);
|
||||
|
||||
std::string parseJSONToLuaTable(std::shared_ptr<MetadataFuture> data);
|
||||
|
||||
void createScreenSpace(int id);
|
||||
void createPlane(std::shared_ptr<MetadataFuture> data);
|
||||
std::string parseJSONToLuaTable(std::shared_ptr<MetadataFuture> data);
|
||||
|
||||
void createKameleonPlane(std::string kwPath, int group = -1);
|
||||
std::string parseKWToLuaTable(std::string kwPath, int group);
|
||||
void fillCygnetInfo(std::string jsonString);
|
||||
|
||||
std::map<std::string, std::string> _month;
|
||||
std::map<int, std::string> _type;
|
||||
std::map<int, std::string> _geom;
|
||||
|
||||
std::map<int, std::shared_ptr<IswaGroup>> _groups;
|
||||
|
||||
std::shared_ptr<ccmc::Kameleon> _kameleon;
|
||||
std::set<std::string> _kameleonFrames;
|
||||
|
||||
std::map<int, std::shared_ptr<IswaGroup>> _groups;
|
||||
std::map<int, std::shared_ptr<CygnetInfo>> _cygnetInformation;
|
||||
};
|
||||
|
||||
} //namespace openspace
|
||||
|
||||
@@ -32,12 +32,89 @@ int iswa_addCygnet(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iswa_addScreenSpaceCygnet(lua_State* L){
|
||||
static const std::string _loggerCat = "addScreenSpaceCygnet";
|
||||
using ghoul::lua::errorLocation;
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
|
||||
ghoul::Dictionary d;
|
||||
try {
|
||||
ghoul::lua::luaDictionaryFromState(L, d);
|
||||
}
|
||||
catch (const ghoul::lua::LuaFormatException& e) {
|
||||
LERROR(e.what());
|
||||
return 0;
|
||||
}
|
||||
|
||||
float id;
|
||||
d.getValue("CygnetId", id);
|
||||
|
||||
auto cygnetInformation = IswaManager::ref().cygnetInformation();
|
||||
if(cygnetInformation.find((int)id) == cygnetInformation.end()){
|
||||
LWARNING("Could not find Cygnet with id = " + std::to_string(id));
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto info = cygnetInformation[(int)id];
|
||||
std::string name = info->name;
|
||||
int updateInterval = info->updateInterval;
|
||||
info->selected = true;
|
||||
|
||||
if(OsEng.renderEngine().screenSpaceRenderable(name)){
|
||||
LERROR("A cygnet with the name \"" + name +"\" already exist");
|
||||
return 0;
|
||||
}else{
|
||||
d.setValue("Name", name);
|
||||
d.setValue("Type", "ScreenSpaceCygnet");
|
||||
d.setValue("UpdateInterval", (float) updateInterval);
|
||||
|
||||
std::shared_ptr<ScreenSpaceRenderable> s( ScreenSpaceRenderable::createFromDictionary(d) );
|
||||
OsEng.renderEngine().registerScreenSpaceRenderable(s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iswa_removeCygnet(lua_State* L){
|
||||
std::string name = luaL_checkstring(L, -1);
|
||||
OsEng.scriptEngine().queueScript("openspace.removeSceneGraphNode('" + name + "')");
|
||||
// IswaManager::ref().deleteIswaCygnet(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iswa_removeScrenSpaceCygnet(lua_State* L){
|
||||
static const std::string _loggerCat = "removeScreenSpaceCygnet";
|
||||
|
||||
int id = lua_tonumber(L, 1);
|
||||
|
||||
auto cygnetInformation = IswaManager::ref().cygnetInformation();
|
||||
if(cygnetInformation.find(id) == cygnetInformation.end()){
|
||||
LWARNING("Could not find Cygnet with id = " + std::to_string(id));
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto info = cygnetInformation[id];
|
||||
info->selected = false;
|
||||
|
||||
std::string script = "openspace.unregisterScreenSpaceRenderable('" + cygnetInformation[id]->name + "');";
|
||||
OsEng.scriptEngine().queueScript(script);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iswa_removeGroup(lua_State* L){
|
||||
int id = lua_tonumber(L, 1);
|
||||
IswaManager::ref().unregisterGroup(id);
|
||||
// IswaManager::ref().unregisterGroup(id);
|
||||
|
||||
auto groups = IswaManager::ref().groups();
|
||||
if(groups.find(id) != groups.end())
|
||||
groups[id]->clearGroup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}// namespace luascriptfunctions
|
||||
|
||||
}// namespace openspace
|
||||
@@ -37,9 +37,9 @@ public:
|
||||
virtual void render() override;
|
||||
|
||||
private:
|
||||
bool gmdata;
|
||||
bool gmimage;
|
||||
bool iondata;
|
||||
bool gmdata;
|
||||
bool gmimage;
|
||||
bool iondata;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -38,10 +38,18 @@
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <ext/json/json.hpp>
|
||||
#include <openspace/engine/downloadmanager.h>
|
||||
#include <modules/iswa/util/iswamanager.h>
|
||||
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
namespace {
|
||||
// const ImVec2 size = ImVec2(350, 200);
|
||||
using json = nlohmann::json;
|
||||
const std::string _loggerCat = "iSWAComponent";
|
||||
const ImVec2 size = ImVec2(350, 500);
|
||||
|
||||
@@ -138,8 +146,8 @@ namespace {
|
||||
}
|
||||
|
||||
void renderFloatProperty(Property* prop) {
|
||||
FloatProperty* p = static_cast<FloatProperty*>(prop);
|
||||
std::string name = p->guiName();
|
||||
FloatProperty* p = static_cast<FloatProperty*>(prop)
|
||||
; std::string name = p->guiName();
|
||||
|
||||
FloatProperty::ValueType value = *p;
|
||||
ImGui::SliderFloat((name).c_str(), &value, p->minValue(), p->maxValue());
|
||||
@@ -254,13 +262,6 @@ void GuiIswaComponent::render() {
|
||||
OsEng.scriptEngine().queueScript("openspace.iswa.removeGroup(3);");
|
||||
}
|
||||
}
|
||||
// bool gmdata = ImGui::Button("Create Global Magnetosphere from data");
|
||||
// bool gmtext = ImGui::Button("Create Global Magnetosphere from images");
|
||||
// bool iodata = ImGui::Button("Create Ionosphere from data");
|
||||
// ImGui::ShowUserGuide();
|
||||
|
||||
|
||||
ImGui::Spacing();
|
||||
|
||||
for (const auto& p : _propertiesByOwner) {
|
||||
if (ImGui::CollapsingHeader(p.first.c_str())) {
|
||||
@@ -317,6 +318,37 @@ void GuiIswaComponent::render() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ImGui::CollapsingHeader("iSWA screen space cygntes")) {
|
||||
|
||||
auto map = IswaManager::ref().cygnetInformation();
|
||||
for(auto cygnetInfo : map){
|
||||
int id = cygnetInfo.first;
|
||||
auto info = cygnetInfo.second;
|
||||
|
||||
bool selected = info->selected;
|
||||
ImGui::Checkbox(info->name.c_str(), &info->selected);
|
||||
ImGui::SameLine();
|
||||
|
||||
if(ImGui::CollapsingHeader(("Description" + std::to_string(id)).c_str())){
|
||||
ImGui::TextWrapped(info->description.c_str());
|
||||
ImGui::Spacing();
|
||||
}
|
||||
|
||||
if(selected != info->selected){
|
||||
if(info->selected){
|
||||
OsEng.scriptEngine().queueScript("openspace.iswa.addScreenSpaceCygnet("
|
||||
"{CygnetId = "+std::to_string(id)+" });");
|
||||
}else{
|
||||
OsEng.scriptEngine().queueScript("openspace.iswa.removeScreenSpaceCygnet("+std::to_string(id)+");");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
@@ -144,11 +144,6 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName,
|
||||
Time::initialize();
|
||||
ghoul::systemcapabilities::SystemCapabilities::initialize();
|
||||
TransformationManager::initialize();
|
||||
|
||||
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
|
||||
IswaManager::initialize();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
OpenSpaceEngine::~OpenSpaceEngine() {
|
||||
@@ -425,6 +420,10 @@ bool OpenSpaceEngine::initialize() {
|
||||
LINFO("Initializing GUI");
|
||||
_gui->initialize();
|
||||
|
||||
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
|
||||
IswaManager::initialize();
|
||||
#endif
|
||||
|
||||
LINFO("Finished initializing");
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user