Process Kameleon data

This commit is contained in:
Sebastian Piwell
2016-05-18 15:06:35 -04:00
parent 9387e6d993
commit 100a1e8749
4 changed files with 97 additions and 15 deletions

View File

@@ -86,6 +86,7 @@ DataPlane::DataPlane(const ghoul::Dictionary& dictionary)
_dataProcessor->normValues(_normValues.value());
loadTexture();
});
_useLog.onChange([this](){
_dataProcessor->useLog(_useLog.value());
loadTexture();

View File

@@ -85,6 +85,27 @@ KameleonPlane::KameleonPlane(const ghoul::Dictionary& dictionary)
_dataOptions.onChange([this](){updateTexture();});
_normValues.onChange([this](){
_dataProcessor->normValues(_normValues.value());
loadTexture();
});
_useLog.onChange([this](){
_dataProcessor->useLog(_useLog.value());
loadTexture();
});
_useHistogram.onChange([this](){
_dataProcessor->useHistogram(_useHistogram.value());
loadTexture();
});
_transferFunctionsFile.onChange([this](){
setTransferFunctions(_transferFunctionsFile.value());
});
_type = IswaManager::CygnetType::Data;
dictionary.getValue("kwPath", _kwPath);
std::string axis;
@@ -150,31 +171,44 @@ bool KameleonPlane::loadTexture() {
ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear;
ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge;
std::vector<float*> data = _dataProcessor->processKameleonData(_dataSlices, _dimensions, _dataOptions);
if(data.empty())
return false;
_backgroundValues.setValue(_dataProcessor->filterValues());
bool texturesReady = false;
std::vector<int> selectedOptions = _dataOptions.value();
auto options = _dataOptions.options();
for(int option : selectedOptions){
if(_dataSlices[option]){
if(!_textures[option]){
std::unique_ptr<ghoul::opengl::Texture> texture =
std::make_unique<ghoul::opengl::Texture>(_dataSlices[option], _dimensions, ghoul::opengl::Texture::Format::Red, GL_RED, GL_FLOAT, filtermode, wrappingmode);
for(int option: selectedOptions){
float* values = data[option];
if(!values) continue;
if (!texture){
std::cout << "Could not create texture" << std::endl;
return false;
}
if(!_textures[option]){
std::unique_ptr<ghoul::opengl::Texture> texture = std::make_unique<ghoul::opengl::Texture>(
values,
_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[selected]->setPixelData(values);
// _textures[selected]->uploadTexture();
_textures[option] = std::move(texture);
}
}else{
_textures[option]->setPixelData(values);
_textures[option]->uploadTexture();
}
texturesReady = true;
}
return true;
return texturesReady;
}
bool KameleonPlane::updateTexture(){

View File

@@ -279,6 +279,51 @@ std::vector<float*> DataProcessor::readJSONData(std::string& dataBuffer, propert
}
}
std::vector<float*> DataProcessor::processKameleonData(std::vector<float*> kdata, glm::size3_t dimensions, properties::SelectionProperty dataOptions){
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>());
auto options = dataOptions.options();
std::vector<float*> data(options.size(), nullptr);
int numValues = dimensions.x*dimensions.y*dimensions.z;
int i = 0;
for(int option : selectedOptions){
data[option] = new float[numValues]{0.0f};
for(int j=0; j<numValues; j++){
float v = kdata[option][j];
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;
}
i++;
}
for(int i=0; i<numSelected; i++){
processData(data[ selectedOptions[i] ], optionValues[i], min[i], max[i], sum[i]);
}
return data;
}
void DataProcessor::processData(float* outputData, std::vector<float>& inputData, float min, float max,float sum){
const int numValues = inputData.size();

View File

@@ -61,6 +61,8 @@ public:
std::vector<std::string> readJSONHeader(std::string& dataBuffer);
std::vector<float*> readJSONData(std::string& dataBuffer, properties::SelectionProperty dataOptions);
std::vector<float*> processKameleonData(std::vector<float*> kdata, glm::size3_t dimensions, properties::SelectionProperty dataOptions);
glm::vec2 filterValues();
private: