From 7ced6897a5701ff1ba0edec8a4c40b52347c9fe2 Mon Sep 17 00:00:00 2001 From: Antoine Lorence <antoine.lorence@insa-rennes.fr> Date: Mon, 17 Nov 2014 17:24:52 +0100 Subject: [PATCH] [Quantif] Members set to private, getters & setters added --- app/Operations/MICD.cpp | 20 +++++----- app/Operations/Quantification.cpp | 52 ++++++++++++------------- app/Operations/Quantification.h | 21 +++++++--- app/Operations/QuantificationDialog.cpp | 2 +- app/Operations/QuantificationOp.cpp | 8 ++-- app/Operations/QuantificationWidget.cpp | 18 ++++----- 6 files changed, 66 insertions(+), 55 deletions(-) diff --git a/app/Operations/MICD.cpp b/app/Operations/MICD.cpp index 97b79e6..be8e85b 100644 --- a/app/Operations/MICD.cpp +++ b/app/Operations/MICD.cpp @@ -209,19 +209,19 @@ void MICD::codec(int nlq,int ier,int *icode,int *ireco) { void MICD::set_levels() { // Fills in iloiqu with the specified values - if( quantdef->size - 1 > N_MAX_THRESHOLD || quantdef->size - 1 < 1 ) { + if( quantdef->nbThresholds() > N_MAX_THRESHOLD || quantdef->nbThresholds() < 1 ) { char buffer[255]; - sprintf( buffer, "Error in MICD::set_levels:\nquantdef->GetNumThresholds() = %d", quantdef->size - 1 ); + sprintf( buffer, "Error in MICD::set_levels:\nquantdef->GetNumThresholds() = %d", quantdef->nbThresholds() ); throw buffer; } int counter; - iloiqu[0] = quantdef->size; - for( counter=0; counter< quantdef->size - 1; counter++ ) { - iloiqu[ counter * 2 + 1 ] = quantdef->threshold[ counter ]; - iloiqu[ counter * 2 + 2 ] = quantdef->values[ counter ]; + iloiqu[0] = quantdef->nbValues(); + for( counter=0; counter< quantdef->nbThresholds(); counter++ ) { + iloiqu[ counter * 2 + 1 ] = quantdef->threshold(counter); + iloiqu[ counter * 2 + 2 ] = quantdef->value(counter); } - iloiqu[ (quantdef->size - 1) * 2 + 1 ] = iloiqu[ (quantdef->size - 1) * 2 - 1 ] + 1; - iloiqu[ (quantdef->size - 1) * 2 + 2 ] = quantdef->values[ quantdef->size - 1 ]; + iloiqu[quantdef->nbThresholds() * 2 + 1 ] = iloiqu[quantdef->nbThresholds() * 2 - 1 ] + 1; + iloiqu[quantdef->nbThresholds() * 2 + 2 ] = quantdef->value(quantdef->nbThresholds()); } string MICD::print_iloiqu() { @@ -247,9 +247,9 @@ void MICD::setQuantification( Quantification *tquantdef ) { if( tquantdef == NULL ) { throw "Error in MICD::setQuantDef:\ntquantdef = NULL"; } - if( tquantdef->size - 1 > N_MAX_THRESHOLD || tquantdef->size - 1 < 1 ) { + if( tquantdef->nbThresholds() > N_MAX_THRESHOLD || tquantdef->nbThresholds() < 1 ) { char buffer[255]; - sprintf( buffer, "Error in MICD::setQuantDef:\ntquantdef->GetNumThresholds() = %d", tquantdef->size - 1 ); + sprintf( buffer, "Error in MICD::setQuantDef:\ntquantdef->GetNumThresholds() = %d", tquantdef->nbThresholds() ); throw buffer; } quantdef = tquantdef; diff --git a/app/Operations/Quantification.cpp b/app/Operations/Quantification.cpp index e297304..c8da7c3 100644 --- a/app/Operations/Quantification.cpp +++ b/app/Operations/Quantification.cpp @@ -25,8 +25,8 @@ using namespace imagein; Quantification::Quantification(int size) { this->size = size; - threshold = new int[this->size - 1]; - values = new int[this->size]; + _threshold = new int[this->size - 1]; + _values = new int[this->size]; } Quantification::Quantification(std::string filename) { @@ -38,19 +38,19 @@ Quantification::Quantification(std::string filename) { file >> this->size; this->size++; if(this->size < 2) throw exception(); - threshold = new int[this->size - 1]; - values = new int[this->size]; + _threshold = new int[this->size - 1]; + _values = new int[this->size]; for(int i = 0; i < size - 1; ++i) { double n; file >> n; cout << n << endl; - threshold[i] = n; + _threshold[i] = n; } for(int i = 0; i < size; ++i) { double n; file >> n; cout << n << endl; - values[i] = n; + _values[i] = n; } } @@ -59,11 +59,11 @@ void Quantification::saveAs(std::string filename) { file << "Quant_Level_File" << endl; file << (this->size - 1) << endl; for(int i = 0; i < size - 1; ++i) { - double n = threshold[i]; + double n = _threshold[i]; file << n << endl; } for(int i = 0; i < size; ++i) { - double n = values[i]; + double n = _values[i]; file << n << endl; } } @@ -73,14 +73,14 @@ Quantification Quantification::linearQuant(int size) { Quantification quant(size); for(int i = 0; i < size - 1; ++i) { - quant.threshold[i] = floor( (i + 1) * (float)N_MAX_THRESHOLD / size + 0.5); + quant._threshold[i] = floor( (i + 1) * (float)N_MAX_THRESHOLD / size + 0.5); } if(size > 0) { - quant.values[0] = floor( quant.threshold[0] / 2. + 0.5 ); - quant.values[size - 1] = floor( ((float)N_MAX_THRESHOLD + quant.threshold[size - 2]) / 2. + 0.5 ); + quant._values[0] = floor( quant._threshold[0] / 2. + 0.5 ); + quant._values[size - 1] = floor( ((float)N_MAX_THRESHOLD + quant._threshold[size - 2]) / 2. + 0.5 ); } for(int i = 1; i < size - 1; ++i) { - quant.values[i] = floor( (double)(quant.threshold[i] + quant.threshold[i-1]) / 2. + 0.5 ); + quant._values[i] = floor( (double)(quant._threshold[i] + quant._threshold[i-1]) / 2. + 0.5 ); } return quant; @@ -101,15 +101,15 @@ Quantification Quantification::nonLinearQuant(int size, const Image* image, unsi histogramSum += histogram[value]; ++value; } - quant.threshold[i] = value - 1; + quant._threshold[i] = value - 1; } if(size > 0) { - quant.values[0] = floor( quant.threshold[0] / 2. + 0.5 ); - quant.values[size - 1] = floor( ((float)N_MAX_THRESHOLD + quant.threshold[size - 2]) / 2. + 0.5 ); + quant._values[0] = floor( quant._threshold[0] / 2. + 0.5 ); + quant._values[size - 1] = floor( ((float)N_MAX_THRESHOLD + quant._threshold[size - 2]) / 2. + 0.5 ); } for(int i = 1; i < size - 1; ++i) { - quant.values[i] = floor( (double)(quant.threshold[i] + quant.threshold[i-1]) / 2. + 0.5 ); + quant._values[i] = floor( (double)(quant._threshold[i] + quant._threshold[i-1]) / 2. + 0.5 ); } return quant; } @@ -129,45 +129,45 @@ Quantification Quantification::nonLinearQuantOptimized(int size, const Image* im histogramSum += histogram[value]; ++value; } - quant.threshold[i] = value - 1; + quant._threshold[i] = value - 1; } if(size > 0) { - quant.values[0] = floor( quant.threshold[0] / 2. + 0.5 ); - quant.values[size - 1] = floor( ((float)N_MAX_THRESHOLD + quant.threshold[size - 2]) / 2. + 0.5 ); + quant._values[0] = floor( quant._threshold[0] / 2. + 0.5 ); + quant._values[size - 1] = floor( ((float)N_MAX_THRESHOLD + quant._threshold[size - 2]) / 2. + 0.5 ); } for(int i = 1; i < size - 1; ++i) { - quant.values[i] = floor( (double)(quant.threshold[i] + quant.threshold[i-1]) / 2. + 0.5 ); + quant._values[i] = floor( (double)(quant._threshold[i] + quant._threshold[i-1]) / 2. + 0.5 ); } double som_lum = 0; int nb_points = 0; - for(int j = 0; j < quant.threshold[0]; j++){ + for(int j = 0; j < quant._threshold[0]; j++){ som_lum += histogram[j] * j; nb_points += histogram[j]; } - quant.values[0] = som_lum / nb_points + 0.5; + quant._values[0] = som_lum / nb_points + 0.5; for(int i = 0; i < size - 2; ++i){ som_lum = 0; nb_points = 0; - for(int j = quant.threshold[i]; j < quant.threshold[i+1]; ++j) { + for(int j = quant._threshold[i]; j < quant._threshold[i+1]; ++j) { som_lum += histogram[j] * j; nb_points += histogram[j]; } - quant.values[i+1] = som_lum / nb_points + 0.5; + quant._values[i+1] = som_lum / nb_points + 0.5; } som_lum = 0; nb_points = 0; - for(int j = quant.threshold[size-2]; j < N_MAX_THRESHOLD; ++j) { + for(int j = quant._threshold[size-2]; j < N_MAX_THRESHOLD; ++j) { som_lum += histogram[j] * j; nb_points += histogram[j]; } - quant.values[size-1] = som_lum / nb_points + 0.5; + quant._values[size-1] = som_lum / nb_points + 0.5; return quant; } diff --git a/app/Operations/Quantification.h b/app/Operations/Quantification.h index a42d195..8ea3ff7 100644 --- a/app/Operations/Quantification.h +++ b/app/Operations/Quantification.h @@ -33,20 +33,31 @@ public: inline int valueOf(int value) const { for(int i = 0; i < this->size - 1; ++i) { - if(value < this->threshold[i]) { - return this->values[i]; + if(value < this->_threshold[i]) { + return this->_values[i]; } } - return this->values[this->size - 1]; + return this->_values[this->size - 1]; } + inline int nbValues() {return size;} + + inline int nbThresholds() {return size - 1;} + + inline int value(int i) {return _values[i];} + inline void setValue(int i, int v) {_values[i] = v;} + + inline int threshold(int i) {return _threshold[i];} + inline void setThreshold(int i, int v) {_threshold[i] = v;} + static Quantification linearQuant(int size); static Quantification nonLinearQuant(int size, const imagein::Image *image, unsigned int c); static Quantification nonLinearQuantOptimized(int size, const imagein::Image *image, unsigned int c); +private: int size; - int* threshold; - int* values; + int* _threshold; + int* _values; }; class Quantifier { diff --git a/app/Operations/QuantificationDialog.cpp b/app/Operations/QuantificationDialog.cpp index 8948eca..bb0538f 100644 --- a/app/Operations/QuantificationDialog.cpp +++ b/app/Operations/QuantificationDialog.cpp @@ -122,7 +122,7 @@ void QuantificationDialog::open() { if(filename.isEmpty()) return; Quantification q(filename.toStdString()); _quantWidget->setQuantif(q); - _sizeBox->setValue(q.size); + _sizeBox->setValue(q.nbValues()); _quantBox->setCurrentIndex(_editorOnly ? 1 : 3); } diff --git a/app/Operations/QuantificationOp.cpp b/app/Operations/QuantificationOp.cpp index e73dba9..051b2d4 100644 --- a/app/Operations/QuantificationOp.cpp +++ b/app/Operations/QuantificationOp.cpp @@ -56,12 +56,12 @@ void QuantificationOp::operator()(const imagein::Image* image, const std::map<co Image* resImg = new Image(image->getWidth(), image->getHeight(), image->getNbChannels()); for(unsigned int c = 0; c < image->getNbChannels(); ++c) { Quantification quantification = dialog->getQuantif(image, c); - for(int i = 0; i < quantification.size; ++i) { - cout << (int)quantification.values[i] << "."; + for(int i = 0; i < quantification.nbValues(); ++i) { + cout << (int)quantification.value(i) << "."; } cout << endl; - for(int i = 0; i < quantification.size-1; ++i) { - cout << quantification.threshold[i] << "."; + for(int i = 0; i < quantification.nbThresholds(); ++i) { + cout << quantification.threshold(i) << "."; } cout << endl; Quantifier quantifier = Quantifier(quantification); diff --git a/app/Operations/QuantificationWidget.cpp b/app/Operations/QuantificationWidget.cpp index 076ffab..f5e96dd 100644 --- a/app/Operations/QuantificationWidget.cpp +++ b/app/Operations/QuantificationWidget.cpp @@ -120,12 +120,12 @@ void QuantificationWidget::setQuantif(Quantification q) { void QuantificationWidget::CentralWidget::setQuantif(Quantification q) { - this->_nThreshold = q.size - 1; - for(int i = 0; i < q.size - 1; ++i) { - _thresholdBoxes[i]->setValue(q.threshold[i]); + this->_nThreshold = q.nbThresholds(); + for(int i = 0; i < q.nbThresholds(); ++i) { + _thresholdBoxes[i]->setValue(q.threshold(i)); } - for(int i = 0; i < q.size; ++i) { - _valueBoxes[i]->setValue(q.values[i]); + for(int i = 0; i < q.nbValues(); ++i) { + _valueBoxes[i]->setValue(q.value(i)); } for(int i = 0; i < N_MAX_THRESHOLD; ++i) { _thresholdBoxes[i]->setVisible(i < _nThreshold); @@ -142,11 +142,11 @@ Quantification QuantificationWidget::getQuantif() const { Quantification QuantificationWidget::CentralWidget::getQuantif() const { Quantification q(_nThreshold + 1); - for(int i = 0; i < q.size - 1; ++i) { - q.threshold[i] = _thresholdBoxes[i]->value(); + for(int i = 0; i < q.nbThresholds(); ++i) { + q.setThreshold(i, _thresholdBoxes[i]->value()); } - for(int i = 0; i < q.size; ++i) { - q.values[i] = _valueBoxes[i]->value(); + for(int i = 0; i < q.nbValues(); ++i) { + q.setValue(i, _valueBoxes[i]->value()); } return q; } -- GitLab