mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-24 22:09:10 -06:00
refactor datasphere
This commit is contained in:
@@ -1,20 +1,26 @@
|
||||
// * Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
// * software and associated documentation files (the "Software"), to deal in the Software *
|
||||
// * without restriction, including without limitation the rights to use, copy, modify, *
|
||||
// * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
// * permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
// * conditions: *
|
||||
// * *
|
||||
// * The above copyright notice and this permission notice shall be included in all copies *
|
||||
// * or substantial portions of the Software. *
|
||||
// * *
|
||||
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
// * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
// * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
// * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
// * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
// * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
// ****************************************************************************************/
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/iswa/rendering/cygnetsphere.h>
|
||||
|
||||
@@ -46,12 +52,12 @@ bool CygnetSphere::createGeometry(){
|
||||
int segments = 100;
|
||||
_sphere = std::make_shared<PowerScaledSphere>(radius, segments);
|
||||
_sphere->initialize();
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CygnetSphere::destroyGeometry(){
|
||||
_sphere = nullptr;
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CygnetSphere::renderGeometry() const {
|
||||
|
||||
@@ -41,6 +41,8 @@ DataCygnet::DataCygnet(const ghoul::Dictionary& dictionary)
|
||||
,_dataOptions("dataOptions", "Data Options")
|
||||
{
|
||||
addProperty(_dataOptions);
|
||||
registerProperties();
|
||||
_type = IswaManager::CygnetType::Data;
|
||||
}
|
||||
|
||||
DataCygnet::~DataCygnet(){}
|
||||
@@ -64,14 +66,29 @@ bool DataCygnet::loadTexture(){
|
||||
|
||||
if(!_dataOptions.options().size()){ // load options for value selection
|
||||
fillOptions();
|
||||
_dataProcessor->addValues(_dataBuffer, _dataOptions);
|
||||
|
||||
if(_group)
|
||||
//Temporary if statements
|
||||
if( className == "DataSphere"){
|
||||
_dataProcessor->addValuesFromJSON(_dataBuffer, _dataOptions);
|
||||
} else if(className == "DataPlane"){
|
||||
_dataProcessor->addValues(_dataBuffer, _dataOptions);
|
||||
}
|
||||
|
||||
// if this datacygnet has added new values then reload texture
|
||||
// for the whole group, including this datacygnet, and return after.
|
||||
if(_group){
|
||||
_group->updateGroup();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<float*> data = _dataProcessor->readData2(_dataBuffer, _dataOptions);
|
||||
|
||||
//Temporary if statements
|
||||
std::vector<float*> data;
|
||||
if( className == "DataSphere"){
|
||||
data = _dataProcessor->readJSONData2(_dataBuffer, _dataOptions);
|
||||
} else if(className == "DataPlane"){
|
||||
data = _dataProcessor->readData2(_dataBuffer, _dataOptions);
|
||||
}
|
||||
|
||||
if(data.empty())
|
||||
return false;
|
||||
|
||||
@@ -104,7 +121,6 @@ bool DataCygnet::loadTexture(){
|
||||
}
|
||||
texturesReady = true;
|
||||
}
|
||||
|
||||
return texturesReady;
|
||||
}
|
||||
|
||||
@@ -215,7 +231,14 @@ void DataCygnet::readTransferFunctions(std::string tfPath){
|
||||
}
|
||||
|
||||
void DataCygnet::fillOptions(){
|
||||
std::vector<std::string> options = _dataProcessor->readHeader(_dataBuffer);
|
||||
std::vector<std::string> options;
|
||||
//Temporary if statements
|
||||
if( className == "DataSphere"){
|
||||
options = _dataProcessor->readJSONHeader(_dataBuffer);
|
||||
} else if(className == "DataPlane"){
|
||||
options = _dataProcessor->readHeader(_dataBuffer);
|
||||
}
|
||||
|
||||
for(int i=0; i<options.size(); i++){
|
||||
_dataOptions.addOption({i, options[i]});
|
||||
_textures.push_back(nullptr);
|
||||
|
||||
@@ -64,7 +64,7 @@ protected:
|
||||
*/
|
||||
void setTextureUniforms();
|
||||
|
||||
// Subclass interface
|
||||
// Subclass interface. Must be protected, called from base class
|
||||
virtual bool createGeometry() = 0;
|
||||
virtual bool destroyGeometry() = 0;
|
||||
virtual void renderGeometry() const = 0;
|
||||
@@ -74,6 +74,9 @@ protected:
|
||||
properties::SelectionProperty _dataOptions;
|
||||
std::shared_ptr<DataProcessor> _dataProcessor;
|
||||
|
||||
// Temporary variable untill dataprocessor is done
|
||||
std::string className;
|
||||
|
||||
private:
|
||||
void fillOptions();
|
||||
|
||||
|
||||
@@ -32,17 +32,12 @@ namespace openspace {
|
||||
DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
|
||||
:DataCygnet(dictionary)
|
||||
,_useLog("useLog","Use Logarithm", false)
|
||||
,_useHistogram("useHistogram", "Use Histogram", false)
|
||||
,_useHistogram("useHistogram", "Auto Contrast", false)
|
||||
,_autoFilter("autoFilter", "Auto Filter", false)
|
||||
,_normValues("normValues", "Normalize Values", glm::vec2(1.0,1.0), glm::vec2(0), glm::vec2(5.0))
|
||||
,_backgroundValues("backgroundValues", "Background Values", glm::vec2(0.0), glm::vec2(0), glm::vec2(1.0))
|
||||
,_transferFunctionsFile("transferfunctions", "Transfer Functions", "${SCENE}/iswa/tfs/hot.tf")
|
||||
{
|
||||
std::string name;
|
||||
dictionary.getValue("Name", name);
|
||||
setName(name);
|
||||
|
||||
registerProperties();
|
||||
|
||||
addProperty(_useLog);
|
||||
addProperty(_useHistogram);
|
||||
@@ -51,11 +46,12 @@ DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_backgroundValues);
|
||||
addProperty(_transferFunctionsFile);
|
||||
|
||||
_type = IswaManager::CygnetType::Data;
|
||||
|
||||
_programName = "DataPlaneProgram";
|
||||
_vsPath = "${MODULE_ISWA}/shaders/dataplane_vs.glsl";
|
||||
_fsPath = "${MODULE_ISWA}/shaders/dataplane_fs.glsl";
|
||||
|
||||
// Temporary
|
||||
className = "DataPlane";
|
||||
}
|
||||
|
||||
DataPlane::~DataPlane(){}
|
||||
@@ -79,6 +75,19 @@ bool DataPlane::initialize(){
|
||||
_useHistogram.value(),
|
||||
_normValues
|
||||
);
|
||||
|
||||
|
||||
//If autofiler is on, background values property should be hidden
|
||||
_autoFilter.onChange([this](){
|
||||
// If autofiler is selected, use _dataProcessor to set backgroundValues
|
||||
// and unregister backgroundvalues property.
|
||||
if(_autoFilter.value()){
|
||||
_backgroundValues.setValue(_dataProcessor->filterValues());
|
||||
// else if autofilter is turned off, register backgroundValues
|
||||
} else {
|
||||
OsEng.gui()._iswa.registerProperty(&_backgroundValues, &_autoFilter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
readTransferFunctions(_transferFunctionsFile.value());
|
||||
@@ -96,6 +105,8 @@ bool DataPlane::initialize(){
|
||||
_useHistogram.onChange([this](){
|
||||
_dataProcessor->useHistogram(_useHistogram.value());
|
||||
loadTexture();
|
||||
if(_autoFilter.value())
|
||||
_backgroundValues.setValue(_dataProcessor->filterValues());
|
||||
});
|
||||
|
||||
_dataOptions.onChange([this](){
|
||||
@@ -108,11 +119,6 @@ bool DataPlane::initialize(){
|
||||
readTransferFunctions(_transferFunctionsFile.value());
|
||||
});
|
||||
|
||||
_autoFilter.onChange([this](){
|
||||
if(_autoFilter.value())
|
||||
_backgroundValues.setValue(_dataProcessor->filterValues());
|
||||
});
|
||||
|
||||
_autoFilter.setValue(true);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
|
||||
namespace openspace{
|
||||
class IswaGroup;
|
||||
|
||||
/**
|
||||
* DataPlane is a concrete IswaCygnet with data files as its input source.
|
||||
|
||||
@@ -23,35 +23,27 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/iswa/rendering/datasphere.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <modules/base/rendering/planetgeometry.h>
|
||||
#include <fstream>
|
||||
#include <modules/iswa/rendering/iswagroup.h>
|
||||
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "DataSphere";
|
||||
const int MAX_TEXTURES = 6;
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
DataSphere::DataSphere(const ghoul::Dictionary& dictionary)
|
||||
:CygnetSphere(dictionary)
|
||||
:DataCygnet(dictionary)
|
||||
,_useLog("useLog","Use Logarithm", false)
|
||||
,_useHistogram("useHistogram", "Use Histogram", true)
|
||||
,_autoFilter("autoFilter", "Auto Filter", true)
|
||||
,_useHistogram("useHistogram", "Auto Contrast", false)
|
||||
,_autoFilter("autoFilter", "Auto Filter", false)
|
||||
,_normValues("normValues", "Normalize Values", glm::vec2(1.0,1.0), glm::vec2(0), glm::vec2(5.0))
|
||||
,_backgroundValues("backgroundValues", "Background Values", glm::vec2(0.0), glm::vec2(0), glm::vec2(1.0))
|
||||
,_transferFunctionsFile("transferfunctions", "Transfer Functions", "${SCENE}/iswa/tfs/hot.tf")
|
||||
,_dataOptions("dataOptions", "Data Options")
|
||||
,_sphere(nullptr)
|
||||
{
|
||||
std::string name;
|
||||
dictionary.getValue("Name", name);
|
||||
setName(name);
|
||||
|
||||
registerProperties();
|
||||
float radius;
|
||||
dictionary.getValue("Radius", radius);
|
||||
_radius = radius;
|
||||
|
||||
addProperty(_useLog);
|
||||
addProperty(_useHistogram);
|
||||
@@ -59,13 +51,13 @@ DataSphere::DataSphere(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_normValues);
|
||||
addProperty(_backgroundValues);
|
||||
addProperty(_transferFunctionsFile);
|
||||
addProperty(_dataOptions);
|
||||
|
||||
_type = IswaManager::CygnetType::Data;
|
||||
|
||||
_programName = "DataSphereProgram";
|
||||
_vsPath = "${MODULE_ISWA}/shaders/datasphere_vs.glsl";
|
||||
_fsPath = "${MODULE_ISWA}/shaders/datasphere_fs.glsl";
|
||||
|
||||
// Temporary
|
||||
className = "DataSphere";
|
||||
}
|
||||
|
||||
DataSphere::~DataSphere(){}
|
||||
@@ -75,65 +67,13 @@ bool DataSphere::initialize(){
|
||||
|
||||
if(_group){
|
||||
_dataProcessor = _group->dataProcessor();
|
||||
|
||||
_groupEvent->subscribe(name(), "useLogChanged", [&](const ghoul::Dictionary& dict){
|
||||
LDEBUG(name() + " Event useLogChanged");
|
||||
_useLog.setValue(dict.value<bool>("useLog"));
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "normValuesChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event normValuesChanged");
|
||||
std::shared_ptr<glm::vec2> values;
|
||||
bool success = dict.getValue("normValues", values);
|
||||
if(success){
|
||||
_normValues.setValue(*values);
|
||||
}
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "useHistogramChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event useHistogramChanged");
|
||||
_useHistogram.setValue(dict.value<bool>("useHistogram"));
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "dataOptionsChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event dataOptionsChanged");
|
||||
std::shared_ptr<std::vector<int> > values;
|
||||
bool success = dict.getValue("dataOptions", values);
|
||||
if(success){
|
||||
_dataOptions.setValue(*values);
|
||||
}
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "transferFunctionsChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event transferFunctionsChanged");
|
||||
_transferFunctionsFile.setValue(dict.value<std::string>("transferFunctions"));
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "backgroundValuesChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event backgroundValuesChanged");
|
||||
std::shared_ptr<glm::vec2> values;
|
||||
bool success = dict.getValue("backgroundValues", values);
|
||||
if(success){
|
||||
_backgroundValues.setValue(*values);
|
||||
}
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "autoFilterChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event autoFilterChanged");
|
||||
_autoFilter.setValue(dict.value<bool>("autoFilter"));
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "updateGroup", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event updateGroup");
|
||||
loadTexture();
|
||||
});
|
||||
|
||||
subscribeToGroup();
|
||||
}else{
|
||||
OsEng.gui()._iswa.registerProperty(&_useLog);
|
||||
OsEng.gui()._iswa.registerProperty(&_useHistogram);
|
||||
OsEng.gui()._iswa.registerProperty(&_autoFilter);
|
||||
OsEng.gui()._iswa.registerProperty(&_normValues);
|
||||
OsEng.gui()._iswa.registerProperty(&_backgroundValues);
|
||||
OsEng.gui()._iswa.registerProperty(&_normValues);
|
||||
OsEng.gui()._iswa.registerProperty(&_transferFunctionsFile);
|
||||
OsEng.gui()._iswa.registerProperty(&_dataOptions);
|
||||
_dataProcessor = std::make_shared<DataProcessor>(
|
||||
@@ -141,9 +81,21 @@ bool DataSphere::initialize(){
|
||||
_useHistogram.value(),
|
||||
_normValues
|
||||
);
|
||||
|
||||
//If autofiler is on, background values property should be hidden
|
||||
_autoFilter.onChange([this](){
|
||||
// If autofiler is selected, use _dataProcessor to set backgroundValues
|
||||
// and unregister backgroundvalues property.
|
||||
if(_autoFilter.value()){
|
||||
_backgroundValues.setValue(_dataProcessor->filterValues());
|
||||
// else if autofilter is turned off, register backgroundValues
|
||||
} else {
|
||||
OsEng.gui()._iswa.registerProperty(&_backgroundValues, &_autoFilter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setTransferFunctions(_transferFunctionsFile.value());
|
||||
readTransferFunctions(_transferFunctionsFile.value());
|
||||
|
||||
_normValues.onChange([this](){
|
||||
_dataProcessor->normValues(_normValues.value());
|
||||
@@ -156,8 +108,10 @@ bool DataSphere::initialize(){
|
||||
});
|
||||
|
||||
_useHistogram.onChange([this](){
|
||||
_dataProcessor->useHistogram(_useHistogram.value());
|
||||
_dataProcessor->useHistogram(_useHistogram.value());
|
||||
loadTexture();
|
||||
if(_autoFilter.value())
|
||||
_backgroundValues.setValue(_dataProcessor->filterValues());
|
||||
});
|
||||
|
||||
_dataOptions.onChange([this](){
|
||||
@@ -167,219 +121,94 @@ bool DataSphere::initialize(){
|
||||
});
|
||||
|
||||
_transferFunctionsFile.onChange([this](){
|
||||
setTransferFunctions(_transferFunctionsFile.value());
|
||||
readTransferFunctions(_transferFunctionsFile.value());
|
||||
});
|
||||
|
||||
_useHistogram.setValue(true);
|
||||
_autoFilter.setValue(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataSphere::loadTexture(){
|
||||
|
||||
// if The future is done then get the new dataFile
|
||||
if(_futureObject.valid() && DownloadManager::futureReady(_futureObject)){
|
||||
DownloadManager::MemoryFile dataFile = _futureObject.get();
|
||||
|
||||
if(dataFile.corrupted)
|
||||
return false;
|
||||
|
||||
_dataBuffer = "";
|
||||
_dataBuffer.append(dataFile.buffer, dataFile.size);
|
||||
delete[] dataFile.buffer;
|
||||
}
|
||||
|
||||
// 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
|
||||
fillOptions();
|
||||
_dataProcessor->addValuesFromJSON(_dataBuffer, _dataOptions);
|
||||
|
||||
if(_group)
|
||||
_group->updateGroup();
|
||||
}
|
||||
|
||||
std::vector<float*> data = _dataProcessor->readJSONData2(_dataBuffer, _dataOptions);
|
||||
|
||||
if(data.empty())
|
||||
return false;
|
||||
|
||||
if(_autoFilter.value())
|
||||
_backgroundValues.setValue(_dataProcessor->filterValues());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// _dataBuffer = "";
|
||||
return texturesReady;
|
||||
bool DataSphere::createGeometry(){
|
||||
PowerScaledScalar radius = PowerScaledScalar(6.371f*_radius, 6.0);
|
||||
int segments = 100;
|
||||
_sphere = std::make_shared<PowerScaledSphere>(radius, segments);
|
||||
_sphere->initialize();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataSphere::updateTexture(){
|
||||
|
||||
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::destroyGeometry(){
|
||||
_sphere = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DataSphere::readyToRender() const {
|
||||
return (!_textures.empty());
|
||||
|
||||
bool ready = isReady();
|
||||
ready &= (!_textures.empty() && _textures[0]);
|
||||
ready &= (_sphere != nullptr);
|
||||
return ready;
|
||||
void DataSphere::renderGeometry() const {
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
_sphere->render();
|
||||
}
|
||||
|
||||
|
||||
void DataSphere::setUniforms(){
|
||||
std::vector<int> selectedOptions = _dataOptions.value();
|
||||
int activeTextures = std::min((int)selectedOptions.size(), MAX_TEXTURES);
|
||||
int activeTransferfunctions = std::min((int)_transferFunctions.size(), MAX_TEXTURES);
|
||||
|
||||
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++;
|
||||
if(j >= MAX_TEXTURES) break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(activeTextures > 0){
|
||||
if(selectedOptions.back()>=activeTransferfunctions)
|
||||
activeTransferfunctions = 1;
|
||||
}
|
||||
|
||||
ghoul::opengl::TextureUnit tfUnits[10];
|
||||
j = 0;
|
||||
|
||||
if((activeTransferfunctions == 1)){
|
||||
tfUnits[0].activate();
|
||||
_transferFunctions[0]->bind();
|
||||
_shader->setUniform(
|
||||
"transferFunctions[0]",
|
||||
tfUnits[0]
|
||||
);
|
||||
}else{
|
||||
for(int option : selectedOptions){
|
||||
// std::cout << option << std::endl;
|
||||
// if(option >= activeTransferfunctions){
|
||||
// // LWARNING("No transfer function for this value.");
|
||||
// break;
|
||||
// }
|
||||
|
||||
if(_transferFunctions[option]){
|
||||
tfUnits[j].activate();
|
||||
_transferFunctions[option]->bind();
|
||||
_shader->setUniform(
|
||||
"transferFunctions[" + std::to_string(j) + "]",
|
||||
tfUnits[j]
|
||||
);
|
||||
|
||||
j++;
|
||||
if(j >= MAX_TEXTURES) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_shader->setUniform("numTextures", activeTextures);
|
||||
_shader->setUniform("numTransferFunctions", activeTransferfunctions);
|
||||
// set both data texture and transfer function texture
|
||||
setTextureUniforms();
|
||||
_shader->setUniform("backgroundValues", _backgroundValues.value());
|
||||
_shader->setUniform("transparency", _alpha.value());
|
||||
}
|
||||
|
||||
void DataSphere::subscribeToGroup(){
|
||||
_groupEvent->subscribe(name(), "useLogChanged", [&](const ghoul::Dictionary& dict){
|
||||
LDEBUG(name() + " Event useLogChanged");
|
||||
_useLog.setValue(dict.value<bool>("useLog"));
|
||||
});
|
||||
|
||||
// bool DataSphere::createShader(){
|
||||
// if (_shader == nullptr) {
|
||||
// // Plane Program
|
||||
// RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
// _shader = renderEngine.buildRenderProgram(
|
||||
// "DataSphereProgram",
|
||||
// "${MODULE_ISWA}/shaders/datasphere_vs.glsl",
|
||||
// "${MODULE_ISWA}/shaders/datasphere_fs.glsl");
|
||||
// if (!_shader)
|
||||
// return false;
|
||||
// }
|
||||
// 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);
|
||||
}
|
||||
_groupEvent->subscribe(name(), "normValuesChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event normValuesChanged");
|
||||
std::shared_ptr<glm::vec2> values;
|
||||
bool success = dict.getValue("normValues", values);
|
||||
if(success){
|
||||
_normValues.setValue(*values);
|
||||
}
|
||||
tfFile.close();
|
||||
}
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "useHistogramChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event useHistogramChanged");
|
||||
_useHistogram.setValue(dict.value<bool>("useHistogram"));
|
||||
});
|
||||
|
||||
if(!tfs.empty()){
|
||||
_transferFunctions.clear();
|
||||
_transferFunctions = tfs;
|
||||
}
|
||||
_groupEvent->subscribe(name(), "dataOptionsChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event dataOptionsChanged");
|
||||
std::shared_ptr<std::vector<int> > values;
|
||||
bool success = dict.getValue("dataOptions", values);
|
||||
if(success){
|
||||
_dataOptions.setValue(*values);
|
||||
}
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "transferFunctionsChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event transferFunctionsChanged");
|
||||
_transferFunctionsFile.setValue(dict.value<std::string>("transferFunctions"));
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "backgroundValuesChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event backgroundValuesChanged");
|
||||
std::shared_ptr<glm::vec2> values;
|
||||
bool success = dict.getValue("backgroundValues", values);
|
||||
if(success){
|
||||
_backgroundValues.setValue(*values);
|
||||
}
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "autoFilterChanged", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event autoFilterChanged");
|
||||
_autoFilter.setValue(dict.value<bool>("autoFilter"));
|
||||
});
|
||||
|
||||
_groupEvent->subscribe(name(), "updateGroup", [&](ghoul::Dictionary dict){
|
||||
LDEBUG(name() + " Event updateGroup");
|
||||
loadTexture();
|
||||
});
|
||||
}
|
||||
|
||||
void DataSphere::fillOptions(){
|
||||
std::vector<std::string> options = _dataProcessor->readJSONHeader(_dataBuffer);
|
||||
for(int i=0; i<options.size(); i++){
|
||||
_dataOptions.addOption({i, options[i]});
|
||||
_textures.push_back(nullptr);
|
||||
}
|
||||
_dataOptions.setValue(std::vector<int>(1,0));
|
||||
if(_group)
|
||||
_group->registerOptions(_dataOptions.options());
|
||||
// IswaManager::ref().registerOptionsToGroup(_data->groupName, _dataOptions.options());
|
||||
}
|
||||
|
||||
} //namespace openspace
|
||||
@@ -25,45 +25,48 @@
|
||||
#ifndef __DATASPHERE_H__
|
||||
#define __DATASPHERE_H__
|
||||
|
||||
#include <modules/iswa/rendering/cygnetsphere.h>
|
||||
#include <modules/iswa/rendering/datacygnet.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;
|
||||
|
||||
/**
|
||||
* DataSphere is a concrete IswaCygnet with data files as its input source.
|
||||
* The class handles creation, destruction and rendering of a sphere geometry.
|
||||
* It also specifies what uniforms to use and what GUI properties it needs.
|
||||
*/
|
||||
class DataSphere : public DataCygnet {
|
||||
public:
|
||||
DataSphere(const ghoul::Dictionary& dictionary);
|
||||
~DataSphere();
|
||||
|
||||
bool initialize() override;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Creates a sphere geometry
|
||||
*/
|
||||
bool createGeometry() override;
|
||||
bool destroyGeometry() override;
|
||||
void renderGeometry() const override;
|
||||
void setUniforms() override;
|
||||
|
||||
private:
|
||||
virtual bool loadTexture() override;
|
||||
virtual bool updateTexture() override;
|
||||
|
||||
virtual bool readyToRender() const override;
|
||||
virtual void setUniforms() override;
|
||||
void subscribeToGroup();
|
||||
|
||||
void setTransferFunctions(std::string tfPath);
|
||||
void fillOptions();
|
||||
|
||||
properties::SelectionProperty _dataOptions;
|
||||
properties::StringProperty _transferFunctionsFile;
|
||||
properties::Vec2Property _backgroundValues;
|
||||
|
||||
properties::Vec2Property _normValues;
|
||||
|
||||
properties::BoolProperty _useLog;
|
||||
properties::BoolProperty _useHistogram;
|
||||
properties::BoolProperty _autoFilter;
|
||||
|
||||
|
||||
std::string _dataBuffer;
|
||||
std::shared_ptr<DataProcessor> _dataProcessor;
|
||||
std::shared_ptr<PowerScaledSphere> _sphere;
|
||||
float _radius;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,10 @@ IswaCygnet::IswaCygnet(const ghoul::Dictionary& dictionary)
|
||||
,_group(nullptr)
|
||||
,_textureDirty(false)
|
||||
{
|
||||
std::string name;
|
||||
dictionary.getValue("Name", name);
|
||||
setName(name);
|
||||
|
||||
_data = std::make_shared<Metadata>();
|
||||
|
||||
// dict.getValue can only set strings in _data directly
|
||||
|
||||
@@ -39,8 +39,8 @@ IswaGroup::IswaGroup(std::string name, IswaManager::CygnetType type)
|
||||
:_enabled("enabled", "Enabled", true)
|
||||
,_alpha("alpha", "Alpha", 0.9f, 0.0f, 1.0f)
|
||||
,_useLog("useLog","Use Logarithm", false)
|
||||
,_useHistogram("useHistogram", "Use Histogram", false)
|
||||
,_autoFilter("autoFilter", "Auto Filter", true)
|
||||
,_useHistogram("useHistogram", "Auto Contrast", false)
|
||||
,_autoFilter("autoFilter", "Auto Filter", false)
|
||||
,_normValues("normValues", "Normalize Values", glm::vec2(1.0,1.0), glm::vec2(0), glm::vec2(5.0))
|
||||
,_backgroundValues("backgroundValues", "Background Values", glm::vec2(0.0), glm::vec2(0), glm::vec2(1.0))
|
||||
,_transferFunctionsFile("transferfunctions", "Transfer Functions", "${SCENE}/iswa/tfs/hot.tf")
|
||||
@@ -74,6 +74,8 @@ IswaGroup::IswaGroup(std::string name, IswaManager::CygnetType type)
|
||||
);
|
||||
_groupEvent = std::make_shared<ghoul::Event<ghoul::Dictionary> >();
|
||||
registerProperties();
|
||||
|
||||
_autoFilter.setValue(true);
|
||||
}
|
||||
|
||||
IswaGroup::~IswaGroup(){}
|
||||
@@ -148,6 +150,16 @@ void IswaGroup::registerProperties(){
|
||||
|
||||
_autoFilter.onChange([this]{
|
||||
LDEBUG("Group " + name() + " published autoFilterChanged");
|
||||
// If autofiler is selected, use _dataProcessor to set backgroundValues
|
||||
// and unregister backgroundvalues property.
|
||||
if(_autoFilter.value()){
|
||||
_backgroundValues.setValue(_dataProcessor->filterValues());
|
||||
OsEng.gui()._iswa.unregisterProperty(&_backgroundValues);
|
||||
// else if autofilter is turned off, only register backgroundValues
|
||||
// if it does not have a group
|
||||
} else {
|
||||
OsEng.gui()._iswa.registerProperty(&_backgroundValues, &_autoFilter);
|
||||
}
|
||||
_groupEvent->publish("autoFilterChanged", ghoul::Dictionary({{"autoFilter", _autoFilter.value()}}));
|
||||
});
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace openspace {
|
||||
KameleonPlane::KameleonPlane(const ghoul::Dictionary& dictionary)
|
||||
:CygnetPlane(dictionary)
|
||||
,_useLog("useLog","Use Logarithm", false)
|
||||
,_useHistogram("useHistogram", "Use Histogram", false)
|
||||
,_useHistogram("useHistogram", "Auto Contrast", false)
|
||||
,_autoFilter("autoFilter", "Auto Filter", 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))
|
||||
@@ -62,9 +62,6 @@ KameleonPlane::KameleonPlane(const ghoul::Dictionary& dictionary)
|
||||
,_resolution("resolution", "Resolutionx100", 1, 1, 5)
|
||||
,_slice("slice", "Slice", 0.0, 0.0, 1.0)
|
||||
{
|
||||
std::string name;
|
||||
dictionary.getValue("Name", name);
|
||||
setName(name);
|
||||
|
||||
registerProperties();
|
||||
|
||||
|
||||
@@ -34,7 +34,10 @@ namespace openspace{
|
||||
|
||||
TextureCygnet::TextureCygnet(const ghoul::Dictionary& dictionary)
|
||||
:IswaCygnet(dictionary)
|
||||
{}
|
||||
{
|
||||
registerProperties();
|
||||
_type = IswaManager::CygnetType::Texture;
|
||||
}
|
||||
|
||||
TextureCygnet::~TextureCygnet(){}
|
||||
|
||||
|
||||
@@ -36,13 +36,6 @@ TexturePlane::TexturePlane(const ghoul::Dictionary& dictionary)
|
||||
,_quad(0)
|
||||
,_vertexPositionBuffer(0)
|
||||
{
|
||||
std::string name;
|
||||
dictionary.getValue("Name", name);
|
||||
setName(name);
|
||||
registerProperties();
|
||||
|
||||
_type = IswaManager::CygnetType::Texture;
|
||||
|
||||
_programName = "PlaneProgram";
|
||||
_vsPath = "${MODULE_ISWA}/shaders/cygnetplane_vs.glsl";
|
||||
_fsPath = "${MODULE_ISWA}/shaders/cygnetplane_fs.glsl";
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <modules/kameleon/include/kameleonwrapper.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/scripting/script_helper.h>
|
||||
|
||||
Reference in New Issue
Block a user