Histogram eq with group dataprocessor

This commit is contained in:
Sebastian Piwell
2016-05-20 16:46:33 -04:00
parent a1188c3895
commit c983ecfb89
11 changed files with 368 additions and 186 deletions

View File

@@ -30,18 +30,18 @@ function postInitialization()
openspace.printInfo("Done setting default values")
openspace.iswa.addCygnet(0,"x", "Kameleon");
openspace.iswa.addCygnet(0,"y", "Kameleon");
openspace.iswa.addCygnet(0,"z", "Kameleon");
openspace.iswa.addCygnet(0,"y", "Kameleon");
openspace.iswa.addCygnet(0,"x", "Kameleon");
--openspace.iswa.addCygnet(-4,"Data");
--penspace.iswa.addCygnet(-1,"Data");
--openspace.iswa.addCygnet(-1,"Data");
--openspace.iswa.addCygnet(-2,"Data");
--openspace.iswa.addCygnet(-3,"Data");
--openspace.iswa.addCygnet(-2,"Data","GM");
--openspace.iswa.addCygnet(-1,"Data","GM");
--openspace.iswa.addCygnet(-2,"Data","GM");
--openspace.iswa.addCygnet(-3,"Data","GM");

View File

@@ -74,6 +74,8 @@ public:
float highestBinValue(bool equalized);
float binWidth();
void changeRange(float minValue, float maxValue);
private:
int _numBins;
float _minValue;

View File

@@ -150,7 +150,7 @@ bool DataPlane::loadTexture() {
if(data.empty())
return false;
// _backgroundValues.setValue(_dataProcessor->filterValues());
_backgroundValues.setValue(_dataProcessor->filterValues());
bool texturesReady = false;
std::vector<int> selectedOptions = _dataOptions.value();

View File

@@ -142,9 +142,6 @@ bool DataSphere::loadTexture(){
if(data.empty())
return false;
// auto v = _dataProcessor->filterValues();
// std::cout << std::to_string(v) << std::endl;
_backgroundValues.setValue(_dataProcessor->filterValues());
bool texturesReady = false;

View File

@@ -50,7 +50,7 @@ namespace openspace {
KameleonPlane::KameleonPlane(const ghoul::Dictionary& dictionary)
:CygnetPlane(dictionary)
,_useLog("useLog","Use Logarithm", false)
,_useHistogram("useHistogram", "Use Histogram", true)
,_useHistogram("useHistogram", "Use Histogram", 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")
@@ -95,17 +95,17 @@ KameleonPlane::KameleonPlane(const ghoul::Dictionary& dictionary)
_data->scale.x = 0;
_data->offset.x = 0;
_slice.setValue((_data->offset.x - _data->gridMin.x)/_scale);
_slice.setValue(0.8);
}else if(axis == "y"){
_scale = _data->scale.y;
_data->scale.y = 0;
_data->offset.y = 0;
// _data->offset.y = 0;
_slice.setValue((_data->offset.y -_data->gridMin.y)/_scale);
}else{
_scale = _data->scale.z;
_data->scale.z = 0;
_data->offset.z = 0;
// _data->offset.z = 0;
_slice.setValue((_data->offset.z - _data->gridMin.z)/_scale);
}
@@ -188,8 +188,6 @@ void KameleonPlane::transferFunctionsFile(std::string tfPath){ _transferFunction
void KameleonPlane::backgroundValues(glm::vec2 backgroundValues){ _backgroundValues.setValue(backgroundValues); };
bool KameleonPlane::loadTexture() {
std::cout << "loadTexture()" << std::endl;
ghoul::opengl::Texture::FilterMode filtermode = ghoul::opengl::Texture::FilterMode::Linear;
ghoul::opengl::Texture::WrappingMode wrappingmode = ghoul::opengl::Texture::WrappingMode::ClampToEdge;
@@ -206,7 +204,7 @@ bool KameleonPlane::loadTexture() {
getline(memorystream, optionName, '/');
// std::cout << options[option].description << std::endl;
_dataSlices[option] = _kw->getUniformSliceValues(optionName, _dimensions, _slice.value());
_dataProcessor->addValuesFromKameleonData(_dataSlices[option], _dimensions, options.size(), option);
// _dataProcessor->addValuesFromKameleonData(_dataSlices[option], _dimensions, options.size(), option);
}
}
@@ -215,8 +213,10 @@ bool KameleonPlane::loadTexture() {
if(data.empty())
return false;
// _backgroundValues.setValue(_dataProcessor->filterValues());
_backgroundValues.setValue(_dataProcessor->filterValues());
// std::cout << std::to_string(_backgroundValues.value()) << std::endl;
bool texturesReady = false;
for(int option: selectedOptions){
@@ -255,10 +255,6 @@ bool KameleonPlane::updateTexture(){
_kw = std::make_shared<KameleonWrapper>(absPath(_kwPath));
}
if(!_dataOptions.options().size()){
fillOptions();
}
_dimensions = glm::size3_t(_resolution.value()*100);
if(_data->scale.x == 0){
_dimensions.x = 1;
@@ -280,6 +276,23 @@ bool KameleonPlane::updateTexture(){
_data->offset.z = _data->gridMin.z+_slice.value()*_scale;
}
if(!_dataOptions.options().size()){
fillOptions();
auto options = _dataOptions.options();
for(auto option : options){
std::stringstream memorystream(option.description);
std::string optionName;
getline(memorystream, optionName, '/');
getline(memorystream, optionName, '/');
float* data = _kw->getUniformSliceValues(optionName, _dimensions, _slice.value());
_dataProcessor->addValuesFromKameleonData(data, _dimensions, options.size(), option.value);
}
}
// std::cout << "Dimensions: " << _dimensions.x << " " << _dimensions.y << " " << _dimensions.z << std::endl;
// std::cout << "Offset: " << std::to_string(_data->offset) << std::endl;
// std::cout << _slice << std::endl;

View File

@@ -158,17 +158,25 @@ void DataProcessor::addValues(std::string& dataBuffer, properties::SelectionProp
}
for(int i=0; i<numOptions; i++){
if(!_histograms[i]){
_histograms[i] = std::make_shared<Histogram>(_min[i], _max[i], 512);
}else{
_histograms[i]->changeRange(_min[i], _max[i]);
}
int numValues = values[i].size();
float mean = (1.0/numValues)*sum[i];
float var = 0;
for(int j=0; j<numValues; j++){
var += pow(values[i][j] - mean, 2);
_histograms[i]->add(values[i][j], 1);
}
float sd = sqrt(var / numValues);
_sum[i] += sum[i];
_sd[i] = sqrt(pow(_sd[i],2) + pow(sd, 2));
_numValues[i] += numValues;
std::cout << i << " " << _numValues[i] << " " << _sum[i] << " " << _sd[i] << std::endl;
_histograms[i]->generateEqualizer();
}
}
}
@@ -306,7 +314,33 @@ std::vector<float*> DataProcessor::readData2(std::string& dataBuffer, properties
LWARNING("Number of values read and expected are not the same");
return std::vector<float*>();
}
_filterValues = glm::vec2(0.0f);
if(!_histograms.empty()){
for(int option : selectedOptions){
std::shared_ptr<Histogram> histogram = _histograms[option];
float mean = (1.0 / _numValues[option]) * _sum[option];
float sd = _sd[option];
float filterMid = histogram->highestBinValue(_useHistogram);
float filterWidth = mean+histogram->binWidth()/2.0;
if(_useHistogram) {
sd = histogram->equalize(sd);
mean = histogram->equalize(mean);
filterWidth = mean+0.5;
}
filterMid = normalizeWithStandardScore(filterMid, mean, sd);
filterWidth = fabs(0.5-normalizeWithStandardScore(filterWidth, mean, sd));
_filterValues += glm::vec2(filterMid, filterWidth);
}
}
_filterValues.x /= numSelected;
_filterValues.y /= numSelected;
return data;
}else{
@@ -424,20 +458,50 @@ void DataProcessor::addValuesFromJSON(std::string& dataBuffer, properties::Selec
}
}
}
// // for(int i=0; i<numOptions; i++){
// // if(!_histograms[i]){
// // _histograms[i] = std::make_shared<Histogram>(_min[i], _max[i], 512);
// // }else{
// // //_histogram[option]->changeRange();
// // }
// // int numValues = values[i].size();
// // float mean = (1.0/numValues)*sum[i];
for(int i=0; i<numOptions; i++){
// // float var = 0;
// // for(int j=0; j<numValues; j++){
// // var += pow(values[i][j] - mean, 2);
// // _histograms[i]->add(values[i][j], 1);
// // }
// // float sd = sqrt(var / numValues);
// // _sum[i] += sum[i];
// // _sd[i] = sqrt(pow(_sd[i],2) + pow(sd, 2));
// // _numValues[i] += numValues;
// // _histograms[i]->generateEqualizer();
// // }
for(int i=0; i<numOptions; i++){
if(!_histograms[i]){
_histograms[i] = std::make_shared<Histogram>(_min[i], _max[i], 512);
}else{
_histograms[i]->changeRange(_min[i], _max[i]);
}
int numValues = values[i].size();
float mean = (1.0/numValues)*sum[i];
float var = 0;
for(int j=0; j<numValues; j++){
var += pow(values[i][j] - mean, 2);
_histograms[i]->add(values[i][j], 1);
}
float sd = sqrt(var / numValues);
_sum[i] += sum[i];
_sd[i] = sqrt(pow(_sd[i],2) + pow(sd, 2));
_numValues[i] += numValues;
_histograms[i]->generateEqualizer();
}
}
}
@@ -456,6 +520,9 @@ std::vector<float*> DataProcessor::readJSONData2(std::string& dataBuffer, proper
auto options = dataOptions.options();
std::vector<float*> data(options.size(), nullptr);
_filterValues = glm::vec2(0.0f);
for(int option : selectedOptions){
data[option] = new float[_dimensions.x*_dimensions.y]{0.0f};
@@ -477,12 +544,34 @@ std::vector<float*> DataProcessor::readJSONData2(std::string& dataBuffer, proper
}
}
if(!_histograms.empty()){
float mean = (1.0 / _numValues[option]) * _sum[option];
float sd = _sd[option];
std::shared_ptr<Histogram> histogram = _histograms[option];
float filterMid = histogram->highestBinValue(_useHistogram);
float filterWidth = mean+histogram->binWidth()/2.0;
if(_useHistogram) {
sd = histogram->equalize(sd);
mean = histogram->equalize(mean);
filterWidth = mean+0.5;
}
filterMid = normalizeWithStandardScore(filterMid, mean, sd);
filterWidth = fabs(0.5-normalizeWithStandardScore(filterWidth, mean, sd));
_filterValues += glm::vec2(filterMid, filterWidth);
}
}
_filterValues.x /= numSelected;
_filterValues.y /= numSelected;
return data;
}
else {
// LWARNING("Nothing in memory buffer, are you connected to the information super highway?");
// LWARNING("Nothing in memory buffer, are you connected to the information super highway?");
return std::vector<float*>();
}
}
@@ -507,16 +596,40 @@ void DataProcessor::addValuesFromKameleonData(float* kdata, glm::size3_t dimensi
sum += v;
}
float mean = (1.0 / numValues) * sum;
float var = 0;
for(int i=0; i<numValues; i++){
var += pow(kdata[i] - mean, 2);
int i = option;
// for(int i=0; i<numOptions; i++){
if(!_histograms[i]){
_histograms[i] = std::make_shared<Histogram>(_min[i], _max[i], 512);
}else{
_histograms[i]->changeRange(_min[i], _max[i]);
}
float sd = sqrt ( var / numValues );
// int numValues = values[i].size();
float mean = (1.0/numValues)*sum;
_sum[option] += sum;
_sd[option] = sqrt(pow(_sd[option],2)+ pow(sd,2));
_numValues[option] += numValues;
float var = 0;
for(int j=0; j<numValues; j++){
var += pow(kdata[j] - mean, 2);
_histograms[i]->add(kdata[j], 1);
}
float sd = sqrt(var / numValues);
_sum[i] += sum;
_sd[i] = sqrt(pow(_sd[i],2) + pow(sd, 2));
_numValues[i] += numValues;
_histograms[i]->generateEqualizer();
// }
// float mean = (1.0 / numValues) * sum;
// float var = 0;
// for(int i=0; i<numValues; i++){
// var += pow(kdata[i] - mean, 2);
// }
// float sd = sqrt ( var / numValues );
// _sum[option] += sum;
// _sd[option] = sqrt(pow(_sd[option],2)+ pow(sd,2));
// _numValues[option] += numValues;
}
std::vector<float*> DataProcessor::processKameleonData2(std::vector<float*> kdata, glm::size3_t dimensions, properties::SelectionProperty dataOptions){
@@ -527,15 +640,37 @@ std::vector<float*> DataProcessor::processKameleonData2(std::vector<float*> kdat
std::vector<float*> data(dataOptions.options().size(), nullptr);
int numValues = dimensions.x*dimensions.y*dimensions.z;
_filterValues = glm::vec2(0.0f);
for(int option : selectedOptions){
data[option] = new float[numValues]{0.0f};
float mean = (1.0 / _numValues[option]) * _sum[option];
float sd = _sd[option];
for(int i=0; i<numValues; i++){
float v = kdata[option][i];
data[option][i] = processDataPoint(v, option);
}
std::shared_ptr<Histogram> histogram = _histograms[option];
float filterMid = histogram->highestBinValue(_useHistogram);
float filterWidth = mean+histogram->binWidth()/2.0;
if(_useHistogram) {
sd = histogram->equalize(sd);
mean = histogram->equalize(mean);
filterWidth = mean+0.5;
}
filterMid = normalizeWithStandardScore(filterMid, mean, sd);
filterWidth = fabs(0.5-normalizeWithStandardScore(filterWidth, mean, sd));
_filterValues += glm::vec2(filterMid, filterWidth);
}
_filterValues.x /= numSelected;
_filterValues.y /= numSelected;
return data;
}
@@ -669,9 +804,19 @@ void DataProcessor::processData(float* outputData, std::vector<float>& inputData
float DataProcessor::processDataPoint(float value, int option){
if(_numValues.empty()) return 0.0f;
std::shared_ptr<Histogram> histogram = _histograms[option];
float mean = (1.0 / _numValues[option]) * _sum[option];
float v = normalizeWithStandardScore(value, mean, _sd[option]);
float sd = _sd[option];
if(_useHistogram){
// std::cout << sd << " " <<
sd = histogram->equalize(sd);
mean = histogram->equalize(mean);
value = histogram->equalize(value);
}
float v = normalizeWithStandardScore(value, mean, sd);
return v;
}

View File

@@ -32,15 +32,15 @@
using namespace openspace::properties;
void executeScript(const std::string& id, const std::string& value);
void renderBoolProperty(Property* prop);
void renderOptionProperty(Property* prop);
void renderSelectionProperty(Property* prop);
void renderStringProperty(Property* prop);
void renderIntProperty(Property* prop);
void renderFloatProperty(Property* prop);
void renderVec2Property(Property* prop);
void renderVec3Property(Property* prop);
void renderVec4Property(Property* prop);
void renderTriggerProperty(Property* prop);
void renderBoolProperty(Property* prop, const std::string& ownerName);
void renderOptionProperty(Property* prop, const std::string& ownerName);
void renderSelectionProperty(Property* prop, const std::string& ownerName);
void renderStringProperty(Property* prop, const std::string& ownerName);
void renderIntProperty(Property* prop, const std::string& ownerName);
void renderFloatProperty(Property* prop, const std::string& ownerName);
void renderVec2Property(Property* prop, const std::string& ownerName);
void renderVec3Property(Property* prop, const std::string& ownerName);
void renderVec4Property(Property* prop, const std::string& ownerName);
void renderTriggerProperty(Property* prop, const std::string& ownerName);
#endif __RENDERPROPERTIES_H__

View File

@@ -112,52 +112,52 @@ void GuiIswaComponent::render() {
if (ImGui::CollapsingHeader(p.first.c_str())) {
for (properties::Property* prop : p.second) {
if (_boolProperties.find(prop) != _boolProperties.end()) {
renderBoolProperty(prop);
renderBoolProperty(prop, p.first);
continue;
}
if (_intProperties.find(prop) != _intProperties.end()) {
renderIntProperty(prop);
renderIntProperty(prop, p.first);
continue;
}
if (_floatProperties.find(prop) != _floatProperties.end()) {
renderFloatProperty(prop);
renderFloatProperty(prop, p.first);
continue;
}
if (_vec2Properties.find(prop) != _vec2Properties.end()) {
renderVec2Property(prop);
renderVec2Property(prop, p.first);
continue;
}
if (_vec3Properties.find(prop) != _vec3Properties.end()) {
renderVec3Property(prop);
renderVec3Property(prop, p.first);
continue;
}
if (_vec4Properties.find(prop) != _vec4Properties.end()) {
renderVec4Property(prop);
renderVec4Property(prop, p.first);
continue;
}
if (_optionProperties.find(prop) != _optionProperties.end()) {
renderOptionProperty(prop);
renderOptionProperty(prop, p.first);
continue;
}
if (_triggerProperties.find(prop) != _triggerProperties.end()) {
renderTriggerProperty(prop);
renderTriggerProperty(prop, p.first);
continue;
}
if (_selectionProperties.find(prop) != _selectionProperties.end()) {
renderSelectionProperty(prop);
renderSelectionProperty(prop, p.first);
continue;
}
if (_stringProperties.find(prop) != _stringProperties.end()) {
renderStringProperty(prop);
renderStringProperty(prop, p.first);
continue;
}
}

View File

@@ -290,52 +290,52 @@ void GuiPropertyComponent::render() {
if (ImGui::CollapsingHeader(p.first.c_str())) {
for (properties::Property* prop : p.second) {
if (_boolProperties.find(prop) != _boolProperties.end()) {
renderBoolProperty(prop);
renderBoolProperty(prop, p.first);
continue;
}
if (_intProperties.find(prop) != _intProperties.end()) {
renderIntProperty(prop);
renderIntProperty(prop, p.first);
continue;
}
if (_floatProperties.find(prop) != _floatProperties.end()) {
renderFloatProperty(prop);
renderFloatProperty(prop, p.first);
continue;
}
if (_vec2Properties.find(prop) != _vec2Properties.end()) {
renderVec2Property(prop);
renderVec2Property(prop, p.first);
continue;
}
if (_vec3Properties.find(prop) != _vec3Properties.end()) {
renderVec3Property(prop);
renderVec3Property(prop, p.first);
continue;
}
if (_vec4Properties.find(prop) != _vec4Properties.end()) {
renderVec4Property(prop);
renderVec4Property(prop, p.first);
continue;
}
if (_optionProperties.find(prop) != _optionProperties.end()) {
renderOptionProperty(prop);
renderOptionProperty(prop, p.first);
continue;
}
if (_triggerProperties.find(prop) != _triggerProperties.end()) {
renderTriggerProperty(prop);
renderTriggerProperty(prop, p.first);
continue;
}
if (_selectionProperties.find(prop) != _selectionProperties.end()) {
renderSelectionProperty(prop);
renderSelectionProperty(prop, p.first);
continue;
}
if (_stringProperties.find(prop) != _stringProperties.end()) {
renderStringProperty(prop);
renderStringProperty(prop, p.first);
continue;
}
}

View File

@@ -40,158 +40,158 @@
using namespace openspace::properties;
void executeScript(const std::string& id, const std::string& value) {
std::string script =
"openspace.setPropertyValue('" + id + "', " + value + ");";
OsEng.scriptEngine().queueScript(script);
}
void renderBoolProperty(Property* prop) {
BoolProperty* p = static_cast<BoolProperty*>(prop);
std::string name = p->guiName();
BoolProperty::ValueType value = *p;
ImGui::Checkbox((name).c_str(), &value);
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), value ? "true": "false");
}
void renderOptionProperty(Property* prop) {
OptionProperty* p = static_cast<OptionProperty*>(prop);
std::string name = p->guiName();
int value = *p;
std::vector<OptionProperty::Option> options = p->options();
for (const OptionProperty::Option& o : options) {
ImGui::RadioButton((name).c_str(), &value, o.value);
ImGui::SameLine();
ImGui::Text(o.description.c_str());
void executeScript(const std::string& id, const std::string& value) {
std::string script =
"openspace.setPropertyValue('" + id + "', " + value + ");";
OsEng.scriptEngine().queueScript(script);
}
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value));
}
void renderSelectionProperty(Property* prop) {
SelectionProperty* p = static_cast<SelectionProperty*>(prop);
std::string name = p->guiName();
if (ImGui::CollapsingHeader((name).c_str())) {
const std::vector<SelectionProperty::Option>& options = p->options();
std::vector<int> newSelectedIndices;
void renderBoolProperty(Property* prop, const std::string& ownerName) {
BoolProperty* p = static_cast<BoolProperty*>(prop);
std::string name = p->guiName();
std::vector<int> selectedIndices = p->value();
for (int i = 0; i < options.size(); ++i) {
std::string description = options[i].description;
bool selected = std::find(selectedIndices.begin(), selectedIndices.end(), i) != selectedIndices.end();
ImGui::Checkbox(description.c_str(), &selected);
BoolProperty::ValueType value = *p;
ImGui::Checkbox((ownerName + "." + name).c_str(), &value);
if (selected)
newSelectedIndices.push_back(i);
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), value ? "true": "false");
}
void renderOptionProperty(Property* prop, const std::string& ownerName) {
OptionProperty* p = static_cast<OptionProperty*>(prop);
std::string name = p->guiName();
int value = *p;
std::vector<OptionProperty::Option> options = p->options();
for (const OptionProperty::Option& o : options) {
ImGui::RadioButton((ownerName + "." + name).c_str(), &value, o.value);
ImGui::SameLine();
ImGui::Text(o.description.c_str());
}
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value));
}
if (newSelectedIndices != p->value()) {
std::string parameters = "{";
for (int i : newSelectedIndices)
parameters += std::to_string(i) + ",";
parameters += "}";
executeScript(p->fullyQualifiedIdentifier(), parameters);
void renderSelectionProperty(Property* prop, const std::string& ownerName) {
SelectionProperty* p = static_cast<SelectionProperty*>(prop);
std::string name = p->guiName();
if (ImGui::CollapsingHeader((ownerName + "." + name).c_str())) {
const std::vector<SelectionProperty::Option>& options = p->options();
std::vector<int> newSelectedIndices;
std::vector<int> selectedIndices = p->value();
for (int i = 0; i < options.size(); ++i) {
std::string description = options[i].description;
bool selected = std::find(selectedIndices.begin(), selectedIndices.end(), i) != selectedIndices.end();
ImGui::Checkbox(description.c_str(), &selected);
if (selected)
newSelectedIndices.push_back(i);
}
if (newSelectedIndices != p->value()) {
std::string parameters = "{";
for (int i : newSelectedIndices)
parameters += std::to_string(i) + ",";
parameters += "}";
executeScript(p->fullyQualifiedIdentifier(), parameters);
}
}
}
}
void renderStringProperty(Property* prop) {
StringProperty* p = static_cast<StringProperty*>(prop);
std::string name = p->guiName();
void renderStringProperty(Property* prop, const std::string& ownerName) {
StringProperty* p = static_cast<StringProperty*>(prop);
std::string name = p->guiName();
static const int bufferSize = 256;
static char buffer[bufferSize];
static const int bufferSize = 256;
static char buffer[bufferSize];
#ifdef _MSC_VER
strcpy_s(buffer, p->value().length() + 1, p->value().c_str());
strcpy_s(buffer, p->value().length() + 1, p->value().c_str());
#else
strcpy(buffer, p->value().c_str());
strcpy(buffer, p->value().c_str());
#endif
ImGui::InputText((name).c_str(), buffer, bufferSize);
std::string newValue(buffer);
ImGui::InputText((ownerName + "." + name).c_str(), buffer, bufferSize);
std::string newValue(buffer);
if (newValue != p->value() && FileSys.fileExists(newValue))
executeScript(p->fullyQualifiedIdentifier(), "'" + newValue + "'");
}
if (newValue != p->value() && FileSys.fileExists(newValue))
executeScript(p->fullyQualifiedIdentifier(), "'" + newValue + "'");
}
void renderIntProperty(Property* prop) {
IntProperty* p = static_cast<IntProperty*>(prop);
std::string name = p->guiName();
void renderIntProperty(Property* prop, const std::string& ownerName) {
IntProperty* p = static_cast<IntProperty*>(prop);
std::string name = p->guiName();
IntProperty::ValueType value = *p;
ImGui::SliderInt((name).c_str(), &value, p->minValue(), p->maxValue());
IntProperty::ValueType value = *p;
ImGui::SliderInt((ownerName + "." + name).c_str(), &value, p->minValue(), p->maxValue());
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value));
}
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value));
}
void renderFloatProperty(Property* prop) {
FloatProperty* p = static_cast<FloatProperty*>(prop)
; std::string name = p->guiName();
void renderFloatProperty(Property* prop, const std::string& ownerName) {
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());
FloatProperty::ValueType value = *p;
ImGui::SliderFloat((ownerName + "." + name).c_str(), &value, p->minValue(), p->maxValue());
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value));
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(), std::to_string(value));
}
}
void renderVec2Property(Property* prop) {
Vec2Property* p = static_cast<Vec2Property*>(prop);
std::string name = p->guiName();
void renderVec2Property(Property* prop, const std::string& ownerName) {
Vec2Property* p = static_cast<Vec2Property*>(prop);
std::string name = p->guiName();
Vec2Property::ValueType value = *p;
Vec2Property::ValueType value = *p;
ImGui::SliderFloat2((name).c_str(), &value.x, std::min(p->minValue().x, p->minValue().y), std::max(p->maxValue().x, p->maxValue().y));
ImGui::SliderFloat2((ownerName + "." + name).c_str(), &value.x, std::min(p->minValue().x, p->minValue().y), std::max(p->maxValue().x, p->maxValue().y));
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," + std::to_string(value.y) + "}");
}
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," + std::to_string(value.y) + "}");
}
void renderVec3Property(Property* prop) {
Vec3Property* p = static_cast<Vec3Property*>(prop);
std::string name = p->guiName();
void renderVec3Property(Property* prop, const std::string& ownerName) {
Vec3Property* p = static_cast<Vec3Property*>(prop);
std::string name = p->guiName();
Vec3Property::ValueType value = *p;
Vec3Property::ValueType value = *p;
ImGui::SliderFloat3((name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
ImGui::SliderFloat3((ownerName + "." + name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "}");
}
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "}");
}
void renderVec4Property(Property* prop) {
Vec4Property* p = static_cast<Vec4Property*>(prop);
std::string name = p->guiName();
void renderVec4Property(Property* prop, const std::string& ownerName) {
Vec4Property* p = static_cast<Vec4Property*>(prop);
std::string name = p->guiName();
Vec4Property::ValueType value = *p;
Vec4Property::ValueType value = *p;
ImGui::SliderFloat4((name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
ImGui::SliderFloat4((ownerName + "." + name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "," +
std::to_string(value.w) + "}");
}
if (value != p->value())
executeScript(p->fullyQualifiedIdentifier(),
"{" + std::to_string(value.x) + "," +
std::to_string(value.y) + "," +
std::to_string(value.z) + "," +
std::to_string(value.w) + "}");
}
void renderTriggerProperty(Property* prop) {
std::string name = prop->guiName();
bool pressed = ImGui::Button((name).c_str());
if (pressed)
executeScript(prop->fullyQualifiedIdentifier(), "nil");
}
void renderTriggerProperty(Property* prop, const std::string& ownerName) {
std::string name = prop->guiName();
bool pressed = ImGui::Button((ownerName + "." + name).c_str());
if (pressed)
executeScript(prop->fullyQualifiedIdentifier(), "nil");
}
//void renderBoolProperty(Property* prop, const std::string& ownerName) {
// BoolProperty* p = static_cast<BoolProperty*>(prop);

View File

@@ -120,6 +120,30 @@ bool Histogram::add(float value, float repeat) {
return true;
}
void Histogram::changeRange(float minValue, float maxValue){\
if(minValue > _minValue && maxValue < _maxValue) return;
float* oldData = _data;
float oldMin = _minValue;
float oldMax = _maxValue;
float* newData = new float[_numBins]{0.0};
for(int i=0; i<_numBins; i++){
float unNormalizedValue = i*(oldMax-oldMin)+oldMin;
float normalizedValue = (unNormalizedValue - _minValue) / (_maxValue - _minValue); // [0.0, 1.0]
int binIndex = std::min( floor(normalizedValue * _numBins), _numBins - 1.0 ); // [0, _numBins - 1]
newData[binIndex] = oldData[i];
}
_data = newData;
delete oldData;
_minValue = minValue;
_maxValue = maxValue;
}
bool Histogram::add(const Histogram& histogram) {
if (_minValue == histogram.minValue() && _maxValue == histogram.maxValue() && _numBins == histogram.numBins()) {
@@ -250,14 +274,15 @@ Histogram Histogram::equalize(){
* this method will use its equalizer to return a histogram equalized result.
*/
float Histogram::equalize(float value){
if (value < _minValue || value > _maxValue) {
LWARNING("Equalized value is is not within domain of histogram. min: " + std::to_string(_minValue) + " max: " + std::to_string(_maxValue) + " val: " + std::to_string(value));
}
// if (value < _minValue || value > _maxValue) {
// LWARNING("Equalized value is is not within domain of histogram. min: " + std::to_string(_minValue) + " max: " + std::to_string(_maxValue) + " val: " + std::to_string(value));
// }
float normalizedValue = (value-_minValue)/(_maxValue-_minValue);
int bin = floor(normalizedValue * _numBins);
// If value == _maxValues then bin == _numBins, which is a invalid index.
bin = std::min(_numBins-1, bin);
bin = std::max(0 , bin);
return _equalizer[bin];
}