diff --git a/Data/Baseline/OTB-Applications/Files/apTvClDTVectorRegression.sqlite b/Data/Baseline/OTB-Applications/Files/apTvClDTVectorRegression.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..e4eae4a9372461bd14379078bb31d3d47602c5b5 --- /dev/null +++ b/Data/Baseline/OTB-Applications/Files/apTvClDTVectorRegression.sqlite @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:afff9c803aa384fecd0a9b068be71de7c92538cf22767e160478fbcce3b369d5 +size 118784 diff --git a/Data/Input/Classification/apTvClDTVectorRegression.dt b/Data/Input/Classification/apTvClDTVectorRegression.dt new file mode 100644 index 0000000000000000000000000000000000000000..e19000fd7910ad5de62fc0a1d4995240f96d3607 --- /dev/null +++ b/Data/Input/Classification/apTvClDTVectorRegression.dt @@ -0,0 +1,117 @@ +%YAML:1.0 +my_tree: !!opencv-ml-tree + is_classifier: 0 + var_all: 4 + var_count: 4 + ord_var_count: 4 + cat_var_count: 0 + training_params: + use_surrogates: 1 + regression_accuracy: 9.9999997764825821e-03 + max_depth: 25 + min_sample_count: 10 + cross_validation_folds: 0 + var_type: [ 0, 0, 0, 0 ] + best_tree_idx: -1 + nodes: + - + depth: 0 + sample_count: 1185 + value: 2.1434599156118144e+00 + Tn: 0 + complexity: 0 + alpha: 0. + node_risk: 1.3156118143459917e+03 + tree_risk: 0. + tree_error: 0. + splits: + - { var:3, quality:6.5841166992187500e+03, + le:2.3381726074218750e+02 } + - + depth: 1 + sample_count: 593 + value: 1.1635750421585160e+00 + Tn: 0 + complexity: 0 + alpha: 0. + node_risk: 8.9133220910623891e+01 + tree_risk: 0. + tree_error: 0. + splits: + - { var:3, quality:8.8817205810546875e+02, + le:1.6510346984863281e+02 } + - + depth: 2 + sample_count: 500 + value: 1. + Tn: 0 + complexity: 0 + alpha: 0. + node_risk: 0. + tree_risk: 0. + tree_error: 0. + - + depth: 2 + sample_count: 93 + value: 2.0430107526881720e+00 + Tn: 0 + complexity: 0 + alpha: 0. + node_risk: 3.8279569892472978e+00 + tree_risk: 0. + tree_error: 0. + splits: + - { var:0, quality:392., le:2.1638174438476562e+02 } + - + depth: 3 + sample_count: 4 + value: 3. + Tn: 0 + complexity: 0 + alpha: 0. + node_risk: 0. + tree_risk: 0. + tree_error: 0. + - + depth: 3 + sample_count: 89 + value: 2. + Tn: 0 + complexity: 0 + alpha: 0. + node_risk: 0. + tree_risk: 0. + tree_error: 0. + - + depth: 1 + sample_count: 592 + value: 3.1250000000000000e+00 + Tn: 0 + complexity: 0 + alpha: 0. + node_risk: 8.6750000000000000e+01 + tree_risk: 0. + tree_error: 0. + splits: + - { var:1, quality:5.8572387695312500e+03, + le:3.6126699829101562e+02 } + - + depth: 2 + sample_count: 507 + value: 2.9783037475345169e+00 + Tn: 0 + complexity: 0 + alpha: 0. + node_risk: 1.0761341222879309e+01 + tree_risk: 0. + tree_error: 0. + - + depth: 2 + sample_count: 85 + value: 4. + Tn: 0 + complexity: 0 + alpha: 0. + node_risk: 0. + tree_risk: 0. + tree_error: 0. diff --git a/Modules/Applications/AppClassification/app/CMakeLists.txt b/Modules/Applications/AppClassification/app/CMakeLists.txt index 9c9404e94b79763e4105eed288eb5bdf7644c113..c981d9ec5bcf06530dae674b5aefa38c109e411a 100644 --- a/Modules/Applications/AppClassification/app/CMakeLists.txt +++ b/Modules/Applications/AppClassification/app/CMakeLists.txt @@ -115,6 +115,11 @@ otb_create_application( SOURCES otbVectorClassifier.cxx LINK_LIBRARIES ${${otb-module}_LIBRARIES}) +otb_create_application( + NAME VectorRegression + SOURCES otbVectorRegression.cxx + LINK_LIBRARIES ${${otb-module}_LIBRARIES}) + otb_create_application( NAME SampleAugmentation SOURCES otbSampleAugmentation.cxx diff --git a/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx b/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx index 756ea62890030193ea0b2291b78a44b078a7d587..18b9afc2459e9436d06dc6011682e47f42badc8e 100644 --- a/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx +++ b/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx @@ -37,11 +37,6 @@ namespace otb { namespace Wrapper { -/** Utility function to negate std::isalnum */ -bool IsNotAlphaNum(char c) - { - return !std::isalnum(c); - } class ComputeConfusionMatrix : public Application { @@ -198,7 +193,7 @@ private: { std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef(); key = item; - std::string::iterator end = std::remove_if(key.begin(),key.end(),IsNotAlphaNum); + std::string::iterator end = std::remove_if(key.begin(),key.end(), [](char c){return !std::isalnum(c);}); std::transform(key.begin(), end, key.begin(), tolower); OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); diff --git a/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx b/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx index c4ca1ab8346a9c96db6da1370840741934efcc85..db4aca185f9c14cc396465d47bd6e5867e6fa851 100644 --- a/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx +++ b/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx @@ -32,12 +32,6 @@ namespace otb namespace Wrapper { -/** Utility function to negate std::isalnum */ -bool IsNotAlphaNum(char c) - { - return !std::isalnum(c); - } - class PolygonClassStatistics : public Application { public: @@ -141,7 +135,7 @@ private: { std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef(); key = item; - std::string::iterator end = std::remove_if(key.begin(),key.end(),IsNotAlphaNum); + std::string::iterator end = std::remove_if(key.begin(),key.end(), [](char c){return !std::isalnum(c);}); std::transform(key.begin(), end, key.begin(), tolower); OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); diff --git a/Modules/Applications/AppClassification/app/otbSampleExtraction.cxx b/Modules/Applications/AppClassification/app/otbSampleExtraction.cxx index b94130d3f57a68067d035af1de464e55230d397d..473a82b3b0b6750f18a7e9ed2eafda3e6a94347c 100644 --- a/Modules/Applications/AppClassification/app/otbSampleExtraction.cxx +++ b/Modules/Applications/AppClassification/app/otbSampleExtraction.cxx @@ -27,12 +27,6 @@ namespace otb { namespace Wrapper { -/** Utility function to negate std::isalnum */ -bool IsNotAlphaNum(char c) - { - return !std::isalnum(c); - } - class SampleExtraction : public Application { public: @@ -139,7 +133,7 @@ private: { std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef(); key = item; - std::string::iterator end = std::remove_if(key.begin(),key.end(),IsNotAlphaNum); + std::string::iterator end = std::remove_if(key.begin(),key.end(), [](char c){return !std::isalnum(c);}); std::transform(key.begin(), end, key.begin(), tolower); OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); diff --git a/Modules/Applications/AppClassification/app/otbSampleSelection.cxx b/Modules/Applications/AppClassification/app/otbSampleSelection.cxx index c2bc93f144a79313db493355e1b39e024905d487..d4770c4d1dd5bd32dfc8294be9be8c47810a4603 100644 --- a/Modules/Applications/AppClassification/app/otbSampleSelection.cxx +++ b/Modules/Applications/AppClassification/app/otbSampleSelection.cxx @@ -32,13 +32,6 @@ namespace otb { namespace Wrapper { - -/** Utility function to negate std::isalnum */ -bool IsNotAlphaNum(char c) - { - return !std::isalnum(c); - } - class SampleSelection : public Application { public: @@ -243,7 +236,7 @@ private: { std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef(); key = item; - std::string::iterator end = std::remove_if(key.begin(),key.end(),IsNotAlphaNum); + std::string::iterator end = std::remove_if(key.begin(), key.end(), [](char c){return !std::isalnum(c);}); std::transform(key.begin(), end, key.begin(), tolower); OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); diff --git a/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx b/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx index 1f0401aeec3586afc10d2964d60c26fc665ef5df..4308f19ac60d97e949d45a9a22353eaba5e8b132 100644 --- a/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx +++ b/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx @@ -18,419 +18,106 @@ * limitations under the License. */ -#include "otbWrapperApplication.h" -#include "otbWrapperApplicationFactory.h" - -#include "otbOGRDataSourceWrapper.h" -#include "otbOGRFeatureWrapper.h" - -#include "itkVariableLengthVector.h" -#include "otbStatisticsXMLFileReader.h" - -#include "itkListSample.h" -#include "otbShiftScaleSampleListFilter.h" - -#include "otbMachineLearningModelFactory.h" - -#include "otbMachineLearningModel.h" - -#include <time.h> +#include "otbVectorPrediction.h" namespace otb { namespace Wrapper { -/** Utility function to negate std::isalnum */ -bool IsNotAlphaNum(char c) - { - return !std::isalnum(c); - } +using VectorClassifier = VectorPrediction<false>; -class VectorClassifier : public Application +template <> +void VectorClassifier::DoInitSpecialization() { -public: - /** Standard class typedefs. */ - typedef VectorClassifier Self; - typedef Application Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Standard macro */ - itkNewMacro(Self); - - itkTypeMacro(Self, Application) - - /** Filters typedef */ - typedef float ValueType; - typedef unsigned int LabelType; - typedef itk::FixedArray<LabelType,1> LabelSampleType; - typedef itk::Statistics::ListSample<LabelSampleType> LabelListSampleType; - - typedef otb::MachineLearningModel<ValueType,LabelType> MachineLearningModelType; - typedef otb::MachineLearningModelFactory<ValueType, LabelType> MachineLearningModelFactoryType; - typedef MachineLearningModelType::Pointer ModelPointerType; - typedef MachineLearningModelType::ConfidenceListSampleType ConfidenceListSampleType; - - /** Statistics Filters typedef */ - typedef itk::VariableLengthVector<ValueType> MeasurementType; - typedef otb::StatisticsXMLFileReader<MeasurementType> StatisticsReader; - - typedef itk::VariableLengthVector<ValueType> InputSampleType; - typedef itk::Statistics::ListSample<InputSampleType> ListSampleType; - typedef otb::Statistics::ShiftScaleSampleListFilter<ListSampleType, ListSampleType> ShiftScaleFilterType; - - ~VectorClassifier() override - { - MachineLearningModelFactoryType::CleanFactories(); - } - -private: - void DoInit() override - { - SetName("VectorClassifier"); - SetDescription("Performs a classification of the input vector data according to a model file."); + SetName("VectorClassifier"); + SetDescription("Performs a classification of the input vector data according to a model file."); - SetDocAuthors("OTB-Team"); - SetDocLongDescription("This application performs a vector data classification " + SetDocAuthors("OTB-Team"); + SetDocLongDescription( + "This application performs a vector data classification " "based on a model file produced by the TrainVectorClassifier application." "Features of the vector data output will contain the class labels decided by the classifier " "(maximal class label = 65535). \n" "There are two modes: \n" - "1) Update mode: add of the 'cfield' field containing the predicted class in the input file. \n" - "2) Write mode: copies the existing fields of the input file to the output file " - " and add the 'cfield' field containing the predicted class. \n" + "1) Update mode: add of the 'cfield' field containing the predicted class in the input file. \n" + "2) Write mode: copies the existing fields of the input file to the output file " + " and add the 'cfield' field containing the predicted class. \n" "If you have declared the output file, the write mode applies. " "Otherwise, the input file update mode will be applied."); - SetDocLimitations("Shapefiles are supported, but the SQLite format is only supported in update mode."); - SetDocSeeAlso("TrainVectorClassifier"); - AddDocTag(Tags::Learning); - - AddParameter(ParameterType_InputVectorData, "in", "Name of the input vector data"); - SetParameterDescription("in","The input vector data file to classify."); - - AddParameter(ParameterType_InputFilename, "instat", "Statistics file"); - SetParameterDescription("instat", "A XML file containing mean and standard deviation to center" - "and reduce samples before classification, produced by ComputeImagesStatistics application."); - MandatoryOff("instat"); - - AddParameter(ParameterType_InputFilename, "model", "Model file"); - SetParameterDescription("model", "Model file produced by TrainVectorClassifier application."); - - AddParameter(ParameterType_String,"cfield","Field class"); - SetParameterDescription("cfield","Field containing the predicted class." - "Only geometries with this field available will be taken into account.\n" - "The field is added either in the input file (if 'out' off) or in the output file.\n" - "Caution, the 'cfield' must not exist in the input file if you are updating the file."); - SetParameterString("cfield","predicted"); - - AddParameter(ParameterType_ListView, "feat", "Field names to be calculated"); - SetParameterDescription("feat","List of field names in the input vector data used as features for training. " - "Put the same field names as the TrainVectorClassifier application."); - - AddParameter(ParameterType_Bool, "confmap", "Confidence map"); - SetParameterDescription( "confmap", "Confidence map of the produced classification. The confidence index depends on the model: \n\n" - "* LibSVM: difference between the two highest probabilities (needs a model with probability estimates, so that classes probabilities can be computed for each sample)\n" - "* Boost: sum of votes\n" - "* DecisionTree: (not supported)\n" - "* KNearestNeighbors: number of neighbors with the same label\n" - "* NeuralNetwork: difference between the two highest responses\n" - "* NormalBayes: (not supported)\n" - "* RandomForest: Confidence (proportion of votes for the majority class). Margin (normalized difference of the votes of the 2 majority classes) is not available for now.\n" - "* SVM: distance to margin (only works for 2-class models)\n"); - - AddParameter(ParameterType_OutputFilename, "out", "Output vector data file containing class labels"); - SetParameterDescription("out","Output vector data file storing sample values (OGR format)." - "If not given, the input vector data file is updated."); - MandatoryOff("out"); - - // Doc example parameter settings - SetDocExampleParameterValue("in", "vectorData.shp"); - SetDocExampleParameterValue("instat", "meanVar.xml"); - SetDocExampleParameterValue("model", "svmModel.svm"); - SetDocExampleParameterValue("out", "vectorDataLabeledVector.shp"); - SetDocExampleParameterValue("feat", "perimeter area width"); - SetDocExampleParameterValue("cfield", "predicted"); - - SetOfficialDocLink(); - } - - void DoUpdateParameters() override - { - if ( HasValue("in") ) - { - std::string shapefile = GetParameterString("in"); - - otb::ogr::DataSource::Pointer ogrDS; - - OGRSpatialReference oSRS(""); - std::vector<std::string> options; - - ogrDS = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Read); - otb::ogr::Layer layer = ogrDS->GetLayer(0); - OGRFeatureDefn &layerDefn = layer.GetLayerDefn(); - - ClearChoices("feat"); - - for(int iField=0; iField< layerDefn.GetFieldCount(); iField++) - { - std::string item = layerDefn.GetFieldDefn(iField)->GetNameRef(); - std::string key(item); - key.erase( std::remove_if(key.begin(),key.end(),IsNotAlphaNum), key.end()); - std::transform(key.begin(), key.end(), key.begin(), tolower); + SetDocLimitations("Shapefiles are supported, but the SQLite format is only supported in update mode."); + SetDocSeeAlso("TrainVectorClassifier"); + AddDocTag(Tags::Learning); + + AddParameter(ParameterType_InputFilename, "in", "Name of the input vector data"); + SetParameterDescription("in", "The input vector data file to classify."); + + AddParameter(ParameterType_InputFilename, "instat", "Statistics file"); + SetParameterDescription("instat", + "A XML file containing mean and standard deviation to center" + "and reduce samples before classification, produced by ComputeImagesStatistics application."); + MandatoryOff("instat"); + + AddParameter(ParameterType_InputFilename, "model", "Model file"); + SetParameterDescription("model", "Model file produced by TrainVectorClassifier application."); + + AddParameter(ParameterType_String, "cfield", "Output field"); + SetParameterDescription("cfield", + "Field containing the predicted class." + "Only geometries with this field available will be taken into account.\n" + "The field is added either in the input file (if 'out' off) or in the output file.\n" + "Caution, the 'cfield' must not exist in the input file if you are updating the file."); + SetParameterString("cfield", "predicted"); + + AddParameter(ParameterType_ListView, "feat", "Field names to be calculated"); + SetParameterDescription("feat", + "List of field names in the input vector data used as features for training. " + "Put the same field names as the TrainVectorClassifier application."); + + AddParameter(ParameterType_Bool, "confmap", "Confidence map"); + SetParameterDescription("confmap", + "Confidence map of the produced classification. The confidence index depends on the model: \n\n" + "* LibSVM: difference between the two highest probabilities (needs a model with probability estimates, so that classes probabilities " + "can be computed for each sample)\n" + "* Boost: sum of votes\n" + "* DecisionTree: (not supported)\n" + "* KNearestNeighbors: number of neighbors with the same label\n" + "* NeuralNetwork: difference between the two highest responses\n" + "* NormalBayes: (not supported)\n" + "* RandomForest: Confidence (proportion of votes for the majority class). Margin (normalized difference of the votes of the 2 " + "majority classes) is not available for now.\n" + "* SVM: distance to margin (only works for 2-class models)\n"); + + AddParameter(ParameterType_OutputFilename, "out", "Output vector data file"); + MandatoryOff("out"); + SetParameterDescription("out", + "Output vector data file storing sample values (OGR format)." + "If not given, the input vector data file is updated."); + + // Doc example parameter settings + SetDocExampleParameterValue("in", "vectorData.shp"); + SetDocExampleParameterValue("instat", "meanVar.xml"); + SetDocExampleParameterValue("model", "svmModel.svm"); + SetDocExampleParameterValue("out", "vectorDataLabeledVector.shp"); + SetDocExampleParameterValue("feat", "perimeter area width"); + SetDocExampleParameterValue("cfield", "predicted"); + + SetOfficialDocLink(); +} - OGRFieldType fieldType = layerDefn.GetFieldDefn(iField)->GetType(); - if(fieldType == OFTInteger || fieldType == OFTInteger64 || fieldType == OFTReal) - { - std::string tmpKey="feat."+key; - AddChoice(tmpKey,item); - } - } - } - } +template <> +bool VectorClassifier::shouldComputeConfidenceMap() const +{ + bool computeConfidenceMap(GetParameterInt("confmap") && m_Model->HasConfidenceIndex()); - void DoExecute() override + if (!m_Model->HasConfidenceIndex() && GetParameterInt("confmap")) { - clock_t tic = clock(); - - std::string shapefile = GetParameterString("in"); - - otb::ogr::DataSource::Pointer source = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Read); - otb::ogr::Layer layer = source->GetLayer(0); - - ListSampleType::Pointer input = ListSampleType::New(); - - const int nbFeatures = GetSelectedItems("feat").size(); - input->SetMeasurementVectorSize(nbFeatures); - - otb::ogr::Layer::const_iterator it = layer.cbegin(); - otb::ogr::Layer::const_iterator itEnd = layer.cend(); - for( ; it!=itEnd ; ++it) - { - MeasurementType mv; - mv.SetSize(nbFeatures); - for(int idx=0; idx < nbFeatures; ++idx) - { - // Beware that itemIndex differs from ogr layer field index - unsigned int itemIndex = GetSelectedItems("feat")[idx]; - std::string fieldName = GetChoiceNames( "feat" )[itemIndex]; - switch ((*it)[fieldName].GetType()) - { - case OFTInteger: - mv[idx] = static_cast<ValueType>((*it)[fieldName].GetValue<int>()); - break; - case OFTInteger64: - mv[idx] = static_cast<ValueType>((*it)[fieldName].GetValue<int>()); - break; - case OFTReal: - mv[idx] = static_cast<ValueType>((*it)[fieldName].GetValue<double>()); - break; - default: - itkExceptionMacro(<< "incorrect field type: " << (*it)[fieldName].GetType() << "."); - } - - - } - input->PushBack(mv); - } - - // Statistics for shift/scale - MeasurementType meanMeasurementVector; - MeasurementType stddevMeasurementVector; - if (HasValue("instat") && IsParameterEnabled("instat")) - { - StatisticsReader::Pointer statisticsReader = StatisticsReader::New(); - std::string XMLfile = GetParameterString("instat"); - statisticsReader->SetFileName(XMLfile); - meanMeasurementVector = statisticsReader->GetStatisticVectorByName("mean"); - stddevMeasurementVector = statisticsReader->GetStatisticVectorByName("stddev"); - } - else - { - meanMeasurementVector.SetSize(nbFeatures); - meanMeasurementVector.Fill(0.); - stddevMeasurementVector.SetSize(nbFeatures); - stddevMeasurementVector.Fill(1.); - } - - ShiftScaleFilterType::Pointer trainingShiftScaleFilter = ShiftScaleFilterType::New(); - trainingShiftScaleFilter->SetInput(input); - trainingShiftScaleFilter->SetShifts(meanMeasurementVector); - trainingShiftScaleFilter->SetScales(stddevMeasurementVector); - trainingShiftScaleFilter->Update(); - otbAppLogINFO("mean used: " << meanMeasurementVector); - otbAppLogINFO("standard deviation used: " << stddevMeasurementVector); - - otbAppLogINFO("Loading model"); - m_Model = MachineLearningModelFactoryType::CreateMachineLearningModel(GetParameterString("model"), - MachineLearningModelFactoryType::ReadMode); - - if (m_Model.IsNull()) - { - otbAppLogFATAL(<< "Error when loading model " << GetParameterString("model") << " : unsupported model type"); - } - - m_Model->Load(GetParameterString("model")); - otbAppLogINFO("Model loaded"); - - ListSampleType::Pointer listSample = trainingShiftScaleFilter->GetOutput(); - - ConfidenceListSampleType::Pointer quality; - - bool computeConfidenceMap(GetParameterInt("confmap") && m_Model->HasConfidenceIndex() - && !m_Model->GetRegressionMode()); - - if (!m_Model->HasConfidenceIndex() && GetParameterInt("confmap")) - { - otbAppLogWARNING("Confidence map requested but the classifier doesn't support it!"); - } - - LabelListSampleType::Pointer target; - if (computeConfidenceMap) - { - quality = ConfidenceListSampleType::New(); - target = m_Model->PredictBatch(listSample, quality); - } - else - { - target = m_Model->PredictBatch(listSample); - } - - ogr::DataSource::Pointer output; - ogr::DataSource::Pointer buffer = ogr::DataSource::New(); - bool updateMode = false; - if (IsParameterEnabled("out") && HasValue("out")) - { - // Create new OGRDataSource - output = ogr::DataSource::New(GetParameterString("out"), ogr::DataSource::Modes::Overwrite); - otb::ogr::Layer newLayer = output->CreateLayer( - GetParameterString("out"), - const_cast<OGRSpatialReference*>(layer.GetSpatialRef()), - layer.GetGeomType()); - // Copy existing fields - OGRFeatureDefn &inLayerDefn = layer.GetLayerDefn(); - for (int k=0 ; k<inLayerDefn.GetFieldCount() ; k++) - { - OGRFieldDefn fieldDefn(inLayerDefn.GetFieldDefn(k)); - newLayer.CreateField(fieldDefn); - } - } - else - { - // Update mode - updateMode = true; - otbAppLogINFO("Update input vector data."); - // fill temporary buffer for the transfer - otb::ogr::Layer inputLayer = layer; - layer = buffer->CopyLayer(inputLayer, std::string("Buffer")); - // close input data source - source->Clear(); - // Re-open input data source in update mode - output = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Update_LayerUpdate); - } - - otb::ogr::Layer outLayer = output->GetLayer(0); - - OGRErr errStart = outLayer.ogr().StartTransaction(); - if (errStart != OGRERR_NONE) - { - itkExceptionMacro(<< "Unable to start transaction for OGR layer " << outLayer.ogr().GetName() << "."); - } - - // Add the field of prediction in the output layer if field not exist - OGRFeatureDefn &layerDefn = layer.GetLayerDefn(); - int idx = layerDefn.GetFieldIndex(GetParameterString("cfield").c_str()); - if (idx >= 0) - { - if (layerDefn.GetFieldDefn(idx)->GetType() != OFTInteger) - itkExceptionMacro("Field name "<< GetParameterString("cfield") << " already exists with a different type!"); - } - else - { - OGRFieldDefn predictedField(GetParameterString("cfield").c_str(), OFTInteger); - ogr::FieldDefn predictedFieldDef(predictedField); - outLayer.CreateField(predictedFieldDef); - } - - // Add confidence field in the output layer - std::string confFieldName("confidence"); - if (computeConfidenceMap) - { - idx = layerDefn.GetFieldIndex(confFieldName.c_str()); - if (idx >= 0) - { - if (layerDefn.GetFieldDefn(idx)->GetType() != OFTReal) - itkExceptionMacro("Field name "<< confFieldName << " already exists with a different type!"); - } - else - { - OGRFieldDefn confidenceField(confFieldName.c_str(), OFTReal); - confidenceField.SetWidth(confidenceField.GetWidth()); - confidenceField.SetPrecision(confidenceField.GetPrecision()); - ogr::FieldDefn confFieldDefn(confidenceField); - outLayer.CreateField(confFieldDefn); - } - } - - // Fill output layer - unsigned int count=0; - std::string classfieldname = GetParameterString("cfield"); - it = layer.cbegin(); - itEnd = layer.cend(); - for( ; it!=itEnd ; ++it, ++count) - { - ogr::Feature dstFeature(outLayer.GetLayerDefn()); - dstFeature.SetFrom( *it , TRUE); - dstFeature.SetFID(it->GetFID()); - switch (dstFeature[classfieldname].GetType()) - { - case OFTInteger: - dstFeature[classfieldname].SetValue<int>(target->GetMeasurementVector(count)[0]); - break; - case OFTInteger64: - dstFeature[classfieldname].SetValue<int>(target->GetMeasurementVector(count)[0]); - break; - case OFTReal: - dstFeature[classfieldname].SetValue<double>(target->GetMeasurementVector(count)[0]); - break; - case OFTString: - dstFeature[classfieldname].SetValue<std::string>(std::to_string(target->GetMeasurementVector(count)[0])); - break; - default: - itkExceptionMacro(<< "incorrect field type: " << dstFeature[classfieldname].GetType() << "."); - } - if (computeConfidenceMap) - dstFeature[confFieldName].SetValue<double>(quality->GetMeasurementVector(count)[0]); - if (updateMode) - { - outLayer.SetFeature(dstFeature); - } - else - { - outLayer.CreateFeature(dstFeature); - } - } - - if(outLayer.ogr().TestCapability("Transactions")) - { - const OGRErr errCommitX = outLayer.ogr().CommitTransaction(); - if (errCommitX != OGRERR_NONE) - { - itkExceptionMacro(<< "Unable to commit transaction for OGR layer " << outLayer.ogr().GetName() << "."); - } - } - - output->SyncToDisk(); - - clock_t toc = clock(); - otbAppLogINFO( "Elapsed: "<< ((double)(toc - tic) / CLOCKS_PER_SEC)<<" seconds."); - + otbAppLogWARNING("Confidence map requested but the classifier doesn't support it!"); } - ModelPointerType m_Model; -}; - + return computeConfidenceMap; +} } } diff --git a/Modules/Applications/AppClassification/app/otbVectorRegression.cxx b/Modules/Applications/AppClassification/app/otbVectorRegression.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d4e23d4e491a2aa83d21c2f5dde609c2e3eb7d2c --- /dev/null +++ b/Modules/Applications/AppClassification/app/otbVectorRegression.cxx @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "otbVectorPrediction.h" + +namespace otb +{ +namespace Wrapper +{ + +using VectorRegression = VectorPrediction<true>; + +template <> +void VectorRegression::DoInitSpecialization() +{ + SetName("VectorRegression"); + SetDescription("Performs regression on the input vector data according to a model file."); + + SetDocAuthors("OTB-Team"); + SetDocLongDescription( + "This application performs a vector data regression " + "based on a model file produced by the TrainVectorRegression application." + "Features of the vector data output will contain the values predicted by the classifier. \n" + "There are two modes: \n" + "1) Update mode: add of the 'cfield' field containing the predicted value in the input file. \n" + "2) Write mode: copies the existing fields of the input file to the output file " + " and add the 'cfield' field containing the predicted value. \n" + "If you have declared the output file, the write mode applies. " + "Otherwise, the input file update mode will be applied."); + + SetDocLimitations("Shapefiles are supported, but the SQLite format is only supported in update mode."); + SetDocSeeAlso("TrainVectorRegression"); + AddDocTag(Tags::Learning); + + AddParameter(ParameterType_InputFilename, "in", "Name of the input vector data"); + SetParameterDescription("in", "The input vector data file to classify."); + + AddParameter(ParameterType_InputFilename, "instat", "Statistics file"); + SetParameterDescription("instat", + "A XML file containing mean and standard deviation to center" + "and reduce samples before classification, produced by ComputeImagesStatistics application."); + MandatoryOff("instat"); + + AddParameter(ParameterType_InputFilename, "model", "Model file"); + SetParameterDescription("model", "Model file produced by TrainVectorRegression application."); + + AddParameter(ParameterType_String, "cfield", "Output field"); + SetParameterDescription("cfield", + "Field containing the predicted value." + "Only geometries with this field available will be taken into account.\n" + "The field is added either in the input file (if 'out' off) or in the output file.\n" + "Caution, the 'cfield' must not exist in the input file if you are updating the file."); + SetParameterString("cfield", "predicted"); + + AddParameter(ParameterType_ListView, "feat", "Field names to be calculated"); + SetParameterDescription("feat", + "List of field names in the input vector data used as features for training. " + "Put the same field names as the TrainVectorRegression application."); + + AddParameter(ParameterType_OutputFilename, "out", "Output vector data file"); + MandatoryOff("out"); + + SetParameterDescription("out", + "Output vector data file storing sample values (OGR format)." + "If not given, the input vector data file is updated."); + MandatoryOff("out"); + + // Doc example parameter settings + SetDocExampleParameterValue("in", "vectorData.shp"); + SetDocExampleParameterValue("instat", "meanVar.xml"); + SetDocExampleParameterValue("model", "rfModel.rf"); + SetDocExampleParameterValue("out", "vectorDataLabeledVector.shp"); + SetDocExampleParameterValue("feat", "perimeter area width"); + SetDocExampleParameterValue("cfield", "predicted"); + + SetOfficialDocLink(); +} + +// Confidence map computation is not supported for regression. +template <> +bool VectorRegression::shouldComputeConfidenceMap() const +{ + return false; +} +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::VectorRegression) diff --git a/Modules/Applications/AppClassification/include/otbTrainVectorBase.h b/Modules/Applications/AppClassification/include/otbTrainVectorBase.h index 24b731cbd6b09ef5e81bb45388fddbcd43801ca3..d58b536468e3eb5166e246d424664afdacfda812 100644 --- a/Modules/Applications/AppClassification/include/otbTrainVectorBase.h +++ b/Modules/Applications/AppClassification/include/otbTrainVectorBase.h @@ -43,12 +43,6 @@ namespace otb namespace Wrapper { -/** Utility function to negate std::isalnum */ -bool IsNotAlphaNum(char c) -{ - return !std::isalnum( c ); -} - template <class TInputValue, class TOutputValue> class TrainVectorBase : public LearningApplicationBase<TInputValue, TOutputValue> { diff --git a/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx b/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx index eaaa8bee3189933a532c3c21abbde7a65dc77e87..ff2947dc7b757432b6230901eb80a945082f9734 100644 --- a/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx +++ b/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx @@ -124,7 +124,7 @@ TrainVectorBase<TInputValue, TOutputValue> { std::string key, item = feature.ogr().GetFieldDefnRef( iField )->GetNameRef(); key = item; - std::string::iterator end = std::remove_if( key.begin(), key.end(), IsNotAlphaNum ); + std::string::iterator end = std::remove_if( key.begin(), key.end(), [](char c){return !std::isalnum(c);} ); std::transform( key.begin(), end, key.begin(), tolower ); OGRFieldType fieldType = feature.ogr().GetFieldDefnRef( iField )->GetType(); diff --git a/Modules/Applications/AppClassification/include/otbVectorPrediction.h b/Modules/Applications/AppClassification/include/otbVectorPrediction.h new file mode 100644 index 0000000000000000000000000000000000000000..65fe591977d3ac690f860a6c3d74dc4fe9ec7b1f --- /dev/null +++ b/Modules/Applications/AppClassification/include/otbVectorPrediction.h @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otbVectorPrediction_h +#define otbVectorPrediction_h + +#include "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +#include "otbOGRDataSourceWrapper.h" +#include "otbOGRFeatureWrapper.h" + +#include "itkVariableLengthVector.h" +#include "otbStatisticsXMLFileReader.h" + +#include "itkListSample.h" +#include "otbShiftScaleSampleListFilter.h" + +#include "otbMachineLearningModelFactory.h" + +#include "otbMachineLearningModel.h" + +#include <time.h> + +namespace otb +{ +namespace Wrapper +{ + +template <bool RegressionMode> +class VectorPrediction : public Application +{ +public: + /** Standard class typedefs. */ + using Self = VectorPrediction; + using Superclass = Application; + using Pointer = itk::SmartPointer<Self>; + using ConstPointer = itk::SmartPointer<const Self>; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(Self, Application) + + /** Filters typedef */ + using ValueType = float; + // Label type is float for regression and unsigned int for classification + using LabelType = typename std::conditional<RegressionMode, float, unsigned int>::type; + + using LabelSampleType = itk::FixedArray<LabelType, 1>; + using LabelListSampleType = itk::Statistics::ListSample<LabelSampleType>; + + using MachineLearningModelType = otb::MachineLearningModel<ValueType, LabelType>; + using MachineLearningModelFactoryType = otb::MachineLearningModelFactory<ValueType, LabelType>; + using ModelPointerType = typename MachineLearningModelType::Pointer; + using ConfidenceListSampleType = typename MachineLearningModelType::ConfidenceListSampleType; + + /** Statistics Filters typedef */ + using MeasurementType = itk::VariableLengthVector<ValueType>; + using StatisticsReader = otb::StatisticsXMLFileReader<MeasurementType>; + + using InputSampleType = itk::VariableLengthVector<ValueType>; + using ListSampleType = itk::Statistics::ListSample<InputSampleType>; + using ShiftScaleFilterType = otb::Statistics::ShiftScaleSampleListFilter<ListSampleType, ListSampleType>; + + ~VectorPrediction() override + { + MachineLearningModelFactoryType::CleanFactories(); + } + +private: + void DoInit() override; + + /** Method defining the parameters used in the application and their documentation, specialized for RegressionMode=1 and RegrssionMode=0 */ + void DoInitSpecialization(); + + void DoUpdateParameters() override; + + void DoExecute() override; + + /** Method returning whether the confidence map should be computed, depending on the regression mode and input parameters */ + bool shouldComputeConfidenceMap() const; + + /** Method returning the input list sample from the input layer */ + typename ListSampleType::Pointer ReadInputListSample(otb::ogr::Layer const& layer); + + /** Normalize a list sample using the statistic file given */ + typename ListSampleType::Pointer NormalizeListSample(ListSampleType::Pointer input); + + /** Create the output DataSource, in update mode the input layer is buffered and the input + * data source is re opened in update mode. */ + otb::ogr::DataSource::Pointer CreateOutputDataSource(otb::ogr::DataSource::Pointer source, + otb::ogr::Layer & layer, + bool updateMode); + + /** Add a prediction field in the output layer if it does not exist. + * If computeConfidenceMap evaluates to true a confidence field will be + * added. */ + void AddPredictionField(otb::ogr::Layer & outLayer, + otb::ogr::Layer const& layer, + bool computeConfidenceMap); + + /** Fill the output layer with the predicted values and optionnaly the confidence */ + void FillOutputLayer(otb::ogr::Layer & outLayer, + otb::ogr::Layer const& layer, + typename LabelListSampleType::Pointer target, + typename ConfidenceListSampleType::Pointer quality, + bool updateMode, + bool computeConfidenceMap); + + ModelPointerType m_Model; + + /** Name used for the confidence field */ + std::string confFieldName = "confidence"; +}; +} +} + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbVectorPrediction.hxx" +#endif + +#endif diff --git a/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx b/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx new file mode 100644 index 0000000000000000000000000000000000000000..fde557da101a9b1b493027711e6efc7ae14a9578 --- /dev/null +++ b/Modules/Applications/AppClassification/include/otbVectorPrediction.hxx @@ -0,0 +1,345 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otbVectorPrediction_hxx +#define otbVectorPrediction_hxx + +#include "otbVectorPrediction.h" + +namespace otb +{ +namespace Wrapper +{ + +template <bool RegressionMode> +void VectorPrediction<RegressionMode>::DoInit() +{ + DoInitSpecialization(); + + // Assert that the all needed parameters have ben definied in DoInitSpecialization + assert(GetParameterByKey("in") != nullptr); + assert(GetParameterByKey("instat") != nullptr); + assert(GetParameterByKey("model") != nullptr); + assert(GetParameterByKey("cfield") != nullptr); + assert(GetParameterByKey("feat") != nullptr); + assert(GetParameterByKey("out") != nullptr); +} + +template <bool RegressionMode> +void VectorPrediction<RegressionMode>::DoUpdateParameters() +{ + if (HasValue("in")) + { + auto shapefileName = GetParameterString("in"); + + auto ogrDS = otb::ogr::DataSource::New(shapefileName, otb::ogr::DataSource::Modes::Read); + auto layer = ogrDS->GetLayer(0); + OGRFeatureDefn& layerDefn = layer.GetLayerDefn(); + + ClearChoices("feat"); + + for (int iField = 0; iField < layerDefn.GetFieldCount(); iField++) + { + auto fieldDefn = layerDefn.GetFieldDefn(iField); + std::string item = fieldDefn->GetNameRef(); + std::string key(item); + key.erase(std::remove_if(key.begin(), key.end(), [](char c){return !std::isalnum(c);}), key.end()); + std::transform(key.begin(), key.end(), key.begin(), tolower); + auto fieldType = fieldDefn->GetType(); + if (fieldType == OFTInteger || fieldType == OFTInteger64 || fieldType == OFTReal) + { + std::string tmpKey = "feat." + key; + AddChoice(tmpKey, item); + } + } + } +} + +template <bool RegressionMode> +typename VectorPrediction<RegressionMode>::ListSampleType::Pointer +VectorPrediction<RegressionMode> +::ReadInputListSample(otb::ogr::Layer const& layer) +{ + typename ListSampleType::Pointer input = ListSampleType::New(); + + const int nbFeatures = GetSelectedItems("feat").size(); + input->SetMeasurementVectorSize(nbFeatures); + + for (auto const& feature : layer) + { + MeasurementType mv(nbFeatures); + for (int idx = 0; idx < nbFeatures; ++idx) + { + // Beware that itemIndex differs from ogr layer field index + unsigned int itemIndex = GetSelectedItems("feat")[idx]; + std::string fieldName = GetChoiceNames("feat")[itemIndex]; + + auto field = feature[fieldName]; + switch (field.GetType()) + { + case OFTInteger: + case OFTInteger64: + mv[idx] = static_cast<ValueType>(field.template GetValue<int>()); + break; + case OFTReal: + mv[idx] = static_cast<ValueType>(field.template GetValue<double>()); + break; + default: + itkExceptionMacro(<< "incorrect field type: " << field.GetType() << "."); + } + } + input->PushBack(mv); + } + return input; +} + +template <bool RegressionMode> +typename VectorPrediction<RegressionMode>::ListSampleType::Pointer +VectorPrediction<RegressionMode> +::NormalizeListSample(ListSampleType::Pointer input) +{ + const int nbFeatures = GetSelectedItems("feat").size(); + + // Statistics for shift/scale + MeasurementType meanMeasurementVector; + MeasurementType stddevMeasurementVector; + if (HasValue("instat") && IsParameterEnabled("instat")) + { + typename StatisticsReader::Pointer statisticsReader = StatisticsReader::New(); + std::string XMLfile = GetParameterString("instat"); + statisticsReader->SetFileName(XMLfile); + meanMeasurementVector = statisticsReader->GetStatisticVectorByName("mean"); + stddevMeasurementVector = statisticsReader->GetStatisticVectorByName("stddev"); + } + else + { + meanMeasurementVector.SetSize(nbFeatures); + meanMeasurementVector.Fill(0.); + stddevMeasurementVector.SetSize(nbFeatures); + stddevMeasurementVector.Fill(1.); + } + + typename ShiftScaleFilterType::Pointer trainingShiftScaleFilter = ShiftScaleFilterType::New(); + trainingShiftScaleFilter->SetInput(input); + trainingShiftScaleFilter->SetShifts(meanMeasurementVector); + trainingShiftScaleFilter->SetScales(stddevMeasurementVector); + trainingShiftScaleFilter->Update(); + otbAppLogINFO("mean used: " << meanMeasurementVector); + otbAppLogINFO("standard deviation used: " << stddevMeasurementVector); + + otbAppLogINFO("Loading model"); + + return trainingShiftScaleFilter->GetOutput(); +} + + +template <bool RegressionMode> +otb::ogr::DataSource::Pointer +VectorPrediction<RegressionMode> +::CreateOutputDataSource(otb::ogr::DataSource::Pointer source, otb::ogr::Layer & layer, bool updateMode) +{ + ogr::DataSource::Pointer output; + ogr::DataSource::Pointer buffer = ogr::DataSource::New(); + if (updateMode) + { + // Update mode + otbAppLogINFO("Update input vector data."); + // fill temporary buffer for the transfer + otb::ogr::Layer inputLayer = layer; + layer = buffer->CopyLayer(inputLayer, std::string("Buffer")); + // close input data source + source->Clear(); + // Re-open input data source in update mode + output = otb::ogr::DataSource::New(GetParameterString("in"), otb::ogr::DataSource::Modes::Update_LayerUpdate); + } + else + { + // Create new OGRDataSource + output = ogr::DataSource::New(GetParameterString("out"), ogr::DataSource::Modes::Overwrite); + otb::ogr::Layer newLayer = output->CreateLayer(GetParameterString("out"), const_cast<OGRSpatialReference*>(layer.GetSpatialRef()), layer.GetGeomType()); + // Copy existing fields + OGRFeatureDefn& inLayerDefn = layer.GetLayerDefn(); + for (int k = 0; k < inLayerDefn.GetFieldCount(); k++) + { + OGRFieldDefn fieldDefn(inLayerDefn.GetFieldDefn(k)); + newLayer.CreateField(fieldDefn); + } + } + + return output; +} + + +template <bool RegressionMode> +void +VectorPrediction<RegressionMode> +::AddPredictionField(otb::ogr::Layer & outLayer, otb::ogr::Layer const& layer, bool computeConfidenceMap) +{ + OGRFeatureDefn& layerDefn = layer.GetLayerDefn(); + + const OGRFieldType labelType = RegressionMode ? OFTReal : OFTInteger; + + int idx = layerDefn.GetFieldIndex(GetParameterString("cfield").c_str()); + if (idx >= 0) + { + if (layerDefn.GetFieldDefn(idx)->GetType() != labelType) + itkExceptionMacro("Field name " << GetParameterString("cfield") << " already exists with a different type!"); + } + else + { + OGRFieldDefn predictedField(GetParameterString("cfield").c_str(), labelType); + ogr::FieldDefn predictedFieldDef(predictedField); + outLayer.CreateField(predictedFieldDef); + } + + // Add confidence field in the output layer + if (computeConfidenceMap) + { + idx = layerDefn.GetFieldIndex(confFieldName.c_str()); + if (idx >= 0) + { + if (layerDefn.GetFieldDefn(idx)->GetType() != OFTReal) + itkExceptionMacro("Field name " << confFieldName << " already exists with a different type!"); + } + else + { + OGRFieldDefn confidenceField(confFieldName.c_str(), OFTReal); + confidenceField.SetWidth(confidenceField.GetWidth()); + confidenceField.SetPrecision(confidenceField.GetPrecision()); + ogr::FieldDefn confFieldDefn(confidenceField); + outLayer.CreateField(confFieldDefn); + } + } +} + +template <bool RegressionMode> +void +VectorPrediction<RegressionMode> +::FillOutputLayer(otb::ogr::Layer & outLayer, otb::ogr::Layer const& layer, typename LabelListSampleType::Pointer target, + typename ConfidenceListSampleType::Pointer quality, bool updateMode, bool computeConfidenceMap) +{ + unsigned int count = 0; + std::string classfieldname = GetParameterString("cfield"); + for (auto const& feature : layer) + { + ogr::Feature dstFeature(outLayer.GetLayerDefn()); + dstFeature.SetFrom(feature, TRUE); + dstFeature.SetFID(feature.GetFID()); + auto field = dstFeature[classfieldname]; + switch (field.GetType()) + { + case OFTInteger64: + case OFTInteger: + field.template SetValue<int>(target->GetMeasurementVector(count)[0]); + break; + case OFTReal: + field.template SetValue<double>(target->GetMeasurementVector(count)[0]); + break; + case OFTString: + field.template SetValue<std::string>(std::to_string(target->GetMeasurementVector(count)[0])); + break; + default: + itkExceptionMacro(<< "incorrect field type: " << field.GetType() << "."); + } + if (computeConfidenceMap) + dstFeature[confFieldName].template SetValue<double>(quality->GetMeasurementVector(count)[0]); + if (updateMode) + { + outLayer.SetFeature(dstFeature); + } + else + { + outLayer.CreateFeature(dstFeature); + } + count++; + } +} + +template <bool RegressionMode> +void VectorPrediction<RegressionMode>::DoExecute() +{ + m_Model = MachineLearningModelFactoryType::CreateMachineLearningModel(GetParameterString("model"), MachineLearningModelFactoryType::ReadMode); + + if (m_Model.IsNull()) + { + otbAppLogFATAL(<< "Error when loading model " << GetParameterString("model") << " : unsupported model type"); + } + + m_Model->SetRegressionMode(RegressionMode); + + m_Model->Load(GetParameterString("model")); + otbAppLogINFO("Model loaded"); + + auto shapefileName = GetParameterString("in"); + + auto source = otb::ogr::DataSource::New(shapefileName, otb::ogr::DataSource::Modes::Read); + auto layer = source->GetLayer(0); + + auto input = ReadInputListSample(layer); + + ListSampleType::Pointer listSample = NormalizeListSample(input); + + typename LabelListSampleType::Pointer target; + + // The quality listSample containing confidence values is defined here, but is only used when + // computeConfidenceMap evaluates to true. This listSample is also used in FillOutputLayer(...) + const bool computeConfidenceMap = shouldComputeConfidenceMap(); + typename ConfidenceListSampleType::Pointer quality; + + if (computeConfidenceMap) + { + quality = ConfidenceListSampleType::New(); + target = m_Model->PredictBatch(listSample, quality); + } + else + { + target = m_Model->PredictBatch(listSample); + } + + const bool updateMode = !(IsParameterEnabled("out") && HasValue("out")); + + auto output = CreateOutputDataSource(source, layer, updateMode); + otb::ogr::Layer outLayer = output->GetLayer(0); + + OGRErr errStart = outLayer.ogr().StartTransaction(); + if (errStart != OGRERR_NONE) + { + itkExceptionMacro(<< "Unable to start transaction for OGR layer " << outLayer.ogr().GetName() << "."); + } + + AddPredictionField(outLayer, layer, computeConfidenceMap); + FillOutputLayer(outLayer, layer, target, quality, updateMode, computeConfidenceMap); + + if (outLayer.ogr().TestCapability("Transactions")) + { + const OGRErr errCommitX = outLayer.ogr().CommitTransaction(); + if (errCommitX != OGRERR_NONE) + { + itkExceptionMacro(<< "Unable to commit transaction for OGR layer " << outLayer.ogr().GetName() << "."); + } + } + + output->SyncToDisk(); +} + +} // end namespace wrapper +} // end namespace otb + +#endif diff --git a/Modules/Applications/AppClassification/test/CMakeLists.txt b/Modules/Applications/AppClassification/test/CMakeLists.txt index 607867c1936a594cbdbe1ed3ff8fdb382efb529e..b47c420c21388528cccb295d466a9304b810c781 100644 --- a/Modules/Applications/AppClassification/test/CMakeLists.txt +++ b/Modules/Applications/AppClassification/test/CMakeLists.txt @@ -716,11 +716,25 @@ if(OTB_USE_OPENCV) -out ${TEMP}/apTvClSVMLabeledVector.shp -feat meanB0 meanB1 meanB2 meanB3 varB0 varB1 varB2 varB3 -cfield class - VALID --compare-ogr 0.0 + VALID --compare-ogr ${NOTOL} ${OTBAPP_BASELINE_FILES}/apTvClSVMLabeledVector.shp ${TEMP}/apTvClSVMLabeledVector.shp) endif() +#----------- VectorRegression TESTS ---------------- +if(OTB_USE_OPENCV) + otb_test_application(NAME apTvClDTVectorRegression + APP VectorRegression + OPTIONS -in ${INPUTDATA}/Classification/apTvClSampleExtractionOut.sqlite + -model ${INPUTDATA}/Classification/apTvClDTVectorRegression.dt + -out ${TEMP}/apTvClDTVectorRegression.sqlite + -feat value_0 value_1 value_2 value_3 + -cfield predicted + VALID --compare-ogr ${NOTOL} + ${OTBAPP_BASELINE_FILES}/apTvClDTVectorRegression.sqlite + ${TEMP}/apTvClDTVectorRegression.sqlite) +endif() + #----------- ComputeImagesStatistics TESTS ---------------- otb_test_application(NAME apTvClComputeImagesStatisticsQB1 APP ComputeImagesStatistics diff --git a/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx b/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx index 2629ce715998a58b38902703e53d5e85d6889b46..d3c4a29b45aeff39e3a1fb364146a494f961bc8b 100644 --- a/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx +++ b/Modules/Applications/AppDimensionalityReduction/app/otbVectorDimensionalityReduction.cxx @@ -32,13 +32,6 @@ namespace otb { namespace Wrapper { - -/** Utility function to negate std::isalnum */ -bool IsNotAlphaNum(char c) -{ -return !std::isalnum(c); -} - /** * \class VectorDimensionalityReduction * @@ -180,7 +173,7 @@ private: { std::string item = layerDefn.GetFieldDefn(iField)->GetNameRef(); std::string key(item); - std::string::iterator end = std::remove_if( key.begin(), key.end(), IsNotAlphaNum ); + std::string::iterator end = std::remove_if( key.begin(), key.end(), [](char c){return !std::isalnum(c);}); std::transform( key.begin(), end, key.begin(), tolower ); std::string tmpKey = "feat." + key.substr( 0, static_cast<unsigned long>( end - key.begin() ) ); AddChoice(tmpKey,item); diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h index 6d857dfde441ad207bd449f3c0e88ac9a7b24a59..ab2ef3c0d3657d07c8b7bb9777bbbe77c7107399 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h @@ -152,72 +152,72 @@ public: /* Get the internal application parameter specified * if the follow flag is on, the function returns the target of proxy parameters * WARNING: this method may disappear from the API */ - Parameter* GetParameterByKey(std::string parameter, bool follow=true); + Parameter* GetParameterByKey(std::string const& parameter, bool follow=true); /* Get the internal application parameter specified * * WARNING: this method may disappear from the API */ - const Parameter* GetParameterByKey(std::string parameter, bool follow=true) const; + const Parameter* GetParameterByKey(std::string const& parameter, bool follow=true) const; /* Returns the description of a parameter */ - std::string GetParameterName(std::string paramKey); + std::string GetParameterName(std::string const& paramKey); /* Returns the description of a parameter */ - std::string GetParameterDescription(std::string paramKey); + std::string GetParameterDescription(std::string const& paramKey); /* Set the description of a parameter */ - void SetParameterDescription(std::string paramKey, std::string dec); + void SetParameterDescription(std::string const& paramKey, std::string dec); /* Enable the use of an optional parameter. Returns the previous state */ - void EnableParameter(std::string paramKey); + void EnableParameter(std::string const& paramKey); /* Disable the use of an optional parameter. Returns the previous state */ - void DisableParameter(std::string paramKey); + void DisableParameter(std::string const& paramKey); /* Return the enable state of an optional parameter */ - bool IsParameterEnabled(std::string paramKey, bool recurseParents = false) const; + bool IsParameterEnabled(std::string const& paramKey, bool recurseParents = false) const; /* Return true if the specified parameter is mandatory */ - bool IsMandatory(std::string paramKey) const; + bool IsMandatory(std::string const& paramKey) const; /* Return true if the specified parameter was set automatically in * the application */ - bool HasAutomaticValue(std::string paramKey) const; + bool HasAutomaticValue(std::string const& paramKey) const; /* Returns true if the parameter has an associated value provided externally * (not automatically computed by the application) */ - bool HasUserValue(std::string paramKey) const; + bool HasUserValue(std::string const& paramKey) const; /* If a user value was provided, clear it and update the other parameters */ - void ClearValue(std::string paramKey); + void ClearValue(std::string const& paramKey); /* Returns true if the parameter has an associated value. * This value can be an automatically computed value or default value, * or a value set externally by user */ - bool HasValue(std::string paramKey) const; + bool HasValue(std::string const& paramKey) const; /** Set HasUserValue flag of parameter with key paramKey * Note that when this function is called from DoInit, DoUpdateParameters * or DoExecute, it will always set this flag to false, because this is * the core behavior of the application. */ - void SetParameterUserValue(std::string paramKey, bool value); + void SetParameterUserValue(std::string const& paramKey, bool value); /* Return the user level of access to a parameter */ - UserLevel GetParameterUserLevel(std::string paramKey) const; + UserLevel GetParameterUserLevel(std::string const& paramKey) const; /** Get the role of the parameter */ - Role GetParameterRole(std::string paramKey) const; + Role GetParameterRole(std::string const& paramKey) const; /* Get the parameter type from its name */ - ParameterType GetParameterType(std::string paramKey) const; + ParameterType GetParameterType(std::string const& paramKey) const; /* Returns the description of a parameter */ - std::vector<std::string> GetChoiceKeys(std::string paramKey); + std::vector<std::string> GetChoiceKeys(std::string const& paramKey); /* Returns the description of a parameter */ - std::vector<std::string> GetChoiceNames(std::string paramKey); + std::vector<std::string> GetChoiceNames(std::string const& paramKey); /* Set an integer value * @@ -228,14 +228,14 @@ public: * \li ParameterType_Radius * \li ParameterType_Choice */ - void SetParameterInt(std::string parameter, int value, bool hasUserValueFlag = true); + void SetParameterInt(std::string const& parameter, int value, bool hasUserValueFlag = true); /* Set a floating value * * Can be called for types : * \li ParameterType_Float */ - void SetParameterFloat(std::string parameter, float value, bool hasUserValueFlag = true); + void SetParameterFloat(std::string const& parameter, float value, bool hasUserValueFlag = true); /* Set a string value * @@ -246,7 +246,7 @@ public: * \li ParameterType_StringList * \li ParameterType_ListView */ - void SetParameterString(std::string parameter, std::string value, bool hasUserValueFlag = true); + void SetParameterString(std::string const& parameter, std::string value, bool hasUserValueFlag = true); /* Set a string value * @@ -266,7 +266,7 @@ public: * \li ParameterType_OutputImageParameter * \li ParameterType_OutputVectorDataParameter */ - void SetParameterStringList(std::string parameter, std::vector<std::string> values, bool hasUserValueFlag = true); + void SetParameterStringList(std::string const& parameter, std::vector<std::string> values, bool hasUserValueFlag = true); /** Checks if the application is ready to be executed. It checks that there * is no missing parameter @@ -294,7 +294,7 @@ public: * \li ParameterType_Radius * \li ParameterType_Choice */ - void SetDefaultParameterInt(std::string parameter, int value); + void SetDefaultParameterInt(std::string const& parameter, int value); /* Get the default integer value of a parameter * @@ -304,7 +304,7 @@ public: * \li ParameterType_Radius * \li ParameterType_Choice */ - int GetDefaultParameterInt(std::string parameter); + int GetDefaultParameterInt(std::string const& parameter); /* Set a default floating value, must be used in the * DoInit when setting a value by default @@ -313,28 +313,28 @@ public: * Can be called for types : * \li ParameterType_Float */ - void SetDefaultParameterFloat(std::string parameter, float value); + void SetDefaultParameterFloat(std::string const& parameter, float value); /* Get the default floating value of a parameter * * Can be called for types : * \li ParameterType_Float */ - float GetDefaultParameterFloat(std::string parameter); + float GetDefaultParameterFloat(std::string const& parameter); /** Set a default pixel type for an output image parameter * * \param[in] parameter Name of the output image parameter * \param[in] type Default pixel type */ - void SetDefaultOutputPixelType(std::string parameter, ImagePixelType type); + void SetDefaultOutputPixelType(std::string const& parameter, ImagePixelType type); /** Set a default complex pixel type for an output complex image parameter * * \param[in] parameter Name of the output complex image parameter * \param[in] type Default complex pixel type */ - void SetDefaultOutputComplexPixelType(std::string parameter, ComplexImagePixelType type); + void SetDefaultOutputComplexPixelType(std::string const& parameter, ComplexImagePixelType type); /* Set a minimum int value, must used in the * DoInit when setting a value by default @@ -343,7 +343,7 @@ public: * Can be called for types : * \li ParameterType_Int */ - void SetMinimumParameterIntValue(std::string parameter, int value); + void SetMinimumParameterIntValue(std::string const& parameter, int value); /* Set a maximum int value, must used in the * DoInit when setting a value by default @@ -352,7 +352,7 @@ public: * Can be called for types : * \li ParameterType_Int */ - void SetMaximumParameterIntValue(std::string parameter, int value); + void SetMaximumParameterIntValue(std::string const& parameter, int value); /* Set a minimum int value, must used in the * DoInit when setting a value by default @@ -361,7 +361,7 @@ public: * Can be called for types : * \li ParameterType_Float */ - void SetMinimumParameterFloatValue(std::string parameter, float value); + void SetMinimumParameterFloatValue(std::string const& parameter, float value); /* Set a maximum int value, must used in the * DoInit when setting a value by default @@ -370,7 +370,7 @@ public: * Can be called for types : * \li ParameterType_Float */ - void SetMaximumParameterFloatValue(std::string parameter, float value); + void SetMaximumParameterFloatValue(std::string const& parameter, float value); /** @@ -380,7 +380,7 @@ public: * Can be called for types: * \li ParameterType_ListView */ - void SetListViewSingleSelectionMode(std::string parameter, bool status); + void SetListViewSingleSelectionMode(std::string const& parameter, bool status); /** * True if the parameter is a list view and is in single selection mode @@ -395,21 +395,21 @@ public: * Can be called for types : * \li ParameterType_OutputImage */ - void SetParameterOutputImage(std::string parameter, FloatVectorImageType* value); + void SetParameterOutputImage(std::string const& parameter, FloatVectorImageType* value); /* Set the pixel type in which the image will be saved * * Can be called for types : * \li ParameterType_OutputImage */ - void SetParameterOutputImagePixelType(std::string parameter, ImagePixelType pixelType); + void SetParameterOutputImagePixelType(std::string const& parameter, ImagePixelType pixelType); /* Set an output vector data value * * Can be called for types : * \li ParameterType_OutputVectorData */ - void SetParameterOutputVectorData(std::string parameter, VectorDataType* value); + void SetParameterOutputVectorData(std::string const& parameter, VectorDataType* value); /* Get an integer parameter value * @@ -420,14 +420,14 @@ public: * \li ParameterType_Radius * \li ParameterType_Choice */ - int GetParameterInt(std::string parameter); + int GetParameterInt(std::string const& parameter) const; /* Get a floating parameter value * * Can be called for types : * \li ParameterType_Float */ - float GetParameterFloat(std::string parameter); + float GetParameterFloat(std::string const& parameter) const; /* Get a string parameter value * @@ -441,7 +441,7 @@ public: * \li ParameterType_OutputImage * \li ParameterType_OutputVectorData */ - std::string GetParameterString(std::string parameter); + std::string GetParameterString(std::string const& parameter) const; /* Get a string list parameter value * @@ -470,7 +470,7 @@ public: * \throw itk::Exception if parameter is not found or not an * InputImageParameter */ - void SetParameterInputImage(std::string parameter, ImageBaseType * inputImage); + void SetParameterInputImage(std::string const& parameter, ImageBaseType * inputImage); /** * Get the output image parameter as an ImageBase * instead @@ -481,7 +481,7 @@ public: * \throw itk::Exception if parameter is not found or not an * OutputImageParameter */ - ImageBaseType * GetParameterOutputImage(std::string parameter); + ImageBaseType * GetParameterOutputImage(std::string const& parameter); /** * Add an image to an InputImageList parameter as an ImageBase @@ -492,7 +492,7 @@ public: * \throw itk::Exception if parameter is not found or not an * InputImageList parameter */ - void AddImageToParameterInputImageList(std::string parameter, ImageBaseType * img); + void AddImageToParameterInputImageList(std::string const& parameter, ImageBaseType * img); /** * Set the nth image of an InputImageList parameter as an ImageBase pointer @@ -504,7 +504,7 @@ public: * \throw itk::Exception if parameter is not found or not an * InputImageList parameter or if id is out of bounds */ - void SetNthParameterInputImageList(std::string parameter, const unsigned int &id, ImageBaseType * img); + void SetNthParameterInputImageList(std::string const& parameter, const unsigned int &id, ImageBaseType * img); /** * Add a value to a parameter list as a string @@ -517,7 +517,7 @@ public: * \throw itk::Exception if parameter is not found or not an * InputImageList parameter */ - void AddParameterStringList(std::string parameter, const std::string & str); + void AddParameterStringList(std::string const& parameter, const std::string & str); /** * Set the nth value of a parameter list as a string. @@ -531,7 +531,7 @@ public: * \throw itk::Exception if parameter is not found or not an * InputImageList parameter or if id is out of bounds */ - void SetNthParameterStringList(std::string parameter, const unsigned int &id, const std::string& str); + void SetNthParameterStringList(std::string const& parameter, const unsigned int &id, const std::string& str); /** @@ -541,7 +541,7 @@ public: * \throw itk::Exception if parameter is not found or not an * InputImageList parameter */ - void ClearParameterInputImageList(std::string parameter); + void ClearParameterInputImageList(std::string const& parameter); /** * Get the number of images in an InputImageList parameter. @@ -550,7 +550,7 @@ public: * \throw itk::Exception if parameter is not found or not an * InputImageList parameter */ - unsigned int GetNumberOfElementsInParameterInputImageList(std::string parameter); + unsigned int GetNumberOfElementsInParameterInputImageList(std::string const& parameter); /* Get an image value @@ -558,35 +558,35 @@ public: * Can be called for types : * \li ParameterType_InputImage */ - FloatVectorImageType* GetParameterImage(std::string parameter); - - UInt8ImageType * GetParameterUInt8Image(std::string); - UInt16ImageType * GetParameterUInt16Image(std::string); - Int16ImageType * GetParameterInt16Image(std::string); - UInt32ImageType * GetParameterUInt32Image(std::string); - Int32ImageType * GetParameterInt32Image(std::string); - FloatImageType * GetParameterFloatImage(std::string); - DoubleImageType * GetParameterDoubleImage(std::string); - UInt8VectorImageType * GetParameterUInt8VectorImage(std::string); - UInt16VectorImageType * GetParameterUInt16VectorImage(std::string); - Int16VectorImageType * GetParameterInt16VectorImage(std::string); - UInt32VectorImageType * GetParameterUInt32VectorImage(std::string); - Int32VectorImageType * GetParameterInt32VectorImage(std::string); - FloatVectorImageType * GetParameterFloatVectorImage(std::string); - DoubleVectorImageType * GetParameterDoubleVectorImage(std::string); - UInt8RGBImageType * GetParameterUInt8RGBImage(std::string); - UInt8RGBAImageType * GetParameterUInt8RGBAImage(std::string); + FloatVectorImageType* GetParameterImage(std::string const& parameter); + + UInt8ImageType * GetParameterUInt8Image(std::string const&); + UInt16ImageType * GetParameterUInt16Image(std::string const&); + Int16ImageType * GetParameterInt16Image(std::string const&); + UInt32ImageType * GetParameterUInt32Image(std::string const&); + Int32ImageType * GetParameterInt32Image(std::string const&); + FloatImageType * GetParameterFloatImage(std::string const&); + DoubleImageType * GetParameterDoubleImage(std::string const&); + UInt8VectorImageType * GetParameterUInt8VectorImage(std::string const&); + UInt16VectorImageType * GetParameterUInt16VectorImage(std::string const&); + Int16VectorImageType * GetParameterInt16VectorImage(std::string const&); + UInt32VectorImageType * GetParameterUInt32VectorImage(std::string const&); + Int32VectorImageType * GetParameterInt32VectorImage(std::string const&); + FloatVectorImageType * GetParameterFloatVectorImage(std::string const&); + DoubleVectorImageType * GetParameterDoubleVectorImage(std::string const&); + UInt8RGBImageType * GetParameterUInt8RGBImage(std::string const&); + UInt8RGBAImageType * GetParameterUInt8RGBAImage(std::string const&); // Complex image - ComplexInt16ImageType * GetParameterComplexInt16Image(std::string); - ComplexInt32ImageType * GetParameterComplexInt32Image(std::string); - ComplexFloatImageType * GetParameterComplexFloatImage(std::string); - ComplexDoubleImageType * GetParameterComplexDoubleImage(std::string); + ComplexInt16ImageType * GetParameterComplexInt16Image(std::string const&); + ComplexInt32ImageType * GetParameterComplexInt32Image(std::string const&); + ComplexFloatImageType * GetParameterComplexFloatImage(std::string const&); + ComplexDoubleImageType * GetParameterComplexDoubleImage(std::string const&); - ComplexInt16VectorImageType * GetParameterComplexInt16VectorImage(std::string); - ComplexInt32VectorImageType * GetParameterComplexInt32VectorImage(std::string); - ComplexFloatVectorImageType * GetParameterComplexFloatVectorImage(std::string); - ComplexDoubleVectorImageType * GetParameterComplexDoubleVectorImage(std::string); + ComplexInt16VectorImageType * GetParameterComplexInt16VectorImage(std::string const&); + ComplexInt32VectorImageType * GetParameterComplexInt32VectorImage(std::string const&); + ComplexFloatVectorImageType * GetParameterComplexFloatVectorImage(std::string const&); + ComplexDoubleVectorImageType * GetParameterComplexDoubleVectorImage(std::string const&); /* Get an image list value @@ -594,7 +594,7 @@ public: * Can be called for types : * \li ParameterType_InputImageList */ - FloatVectorImageListType* GetParameterImageList(std::string parameter); + FloatVectorImageListType* GetParameterImageList(std::string const& parameter); /* GetParameterVectorData * @@ -602,7 +602,7 @@ public: * \li ParameterType_InputVectorData */ - VectorDataType* GetParameterVectorData(std::string parameter); + VectorDataType* GetParameterVectorData(std::string const& parameter); /* GetParameteVetorDataList * @@ -610,7 +610,7 @@ public: * \li ParameterType_InputVectorDatalist */ - VectorDataListType* GetParameterVectorDataList(std::string parameter); + VectorDataListType* GetParameterVectorDataList(std::string const& parameter); /* Get the parameter as a std::string * @@ -628,7 +628,7 @@ public: * \li ParameterType_OutputImage * \li ParameterType_OutputVectorData */ - std::string GetParameterAsString(std::string paramKey); + std::string GetParameterAsString(std::string const& paramKey); /* Get the list of all parameters */ @@ -639,7 +639,7 @@ public: * Can be called for types : * \li ParameterType_OutputImage */ - ImagePixelType GetParameterOutputImagePixelType(std::string parameter); + ImagePixelType GetParameterOutputImagePixelType(std::string const& parameter); void SetParameterList(ParameterGroup::Pointer paramGroup) { @@ -797,43 +797,43 @@ protected: void AddProcess(itk::ProcessObject* object, std::string description); /** Add a new choice value to an existing choice parameter */ - void AddChoice(std::string paramKey, std::string paramName); + void AddChoice(std::string const& paramKey, std::string const& paramName); /** Add a new parameter to the parameter group * the parent key of paramKey can be the path to a parameter group * or the path to a choice value */ - void AddParameter(ParameterType type, std::string paramKey, std::string paramName); + void AddParameter(ParameterType type, std::string const& paramKey, std::string const& paramName); /** Add a parameterRAM method with no parameter*/ - void AddRAMParameter(std::string paramKey="ram"); + void AddRAMParameter(std::string const& paramKey="ram"); /** Add a parameterRAM method with parameter*/ - void AddRAMParameter(std::string paramKey, std::string paramName, unsigned int defaultValue); + void AddRAMParameter(std::string const& paramKey, std::string const& paramName, unsigned int defaultValue); /** Add a parameterRAND method with no parameter*/ - void AddRANDParameter(std::string paramKey="rand"); + void AddRANDParameter(std::string const& paramKey="rand"); /** Add a parameterRAND method with parameter * by default seed initialization is based on time value*/ - void AddRANDParameter(std::string paramKey, std::string paramName, unsigned int defaultValue); + void AddRANDParameter(std::string const& paramKey, std::string const& paramName, unsigned int defaultValue); /** Remove the items added to the ListWidget */ - void ClearChoices(std::string key); + void ClearChoices(std::string const& key); /** Get Items selected in the ListView Parameter*/ - std::vector<int> GetSelectedItems(std::string paramKey); + std::vector<int> GetSelectedItems(std::string const& paramKey); /** Declare a parameter as mandatory */ - void MandatoryOn(std::string paramKey); + void MandatoryOn(std::string const& paramKey); /** Declare a parameter as NOT mandatory (default state) */ - void MandatoryOff(std::string paramKey); + void MandatoryOff(std::string const& paramKey); /* Set the user level of access to a parameter */ - void SetParameterUserLevel(std::string paramKey, UserLevel level); + void SetParameterUserLevel(std::string const& paramKey, UserLevel level); /* Set the parameter role (input/output) */ - void SetParameterRole(std::string paramKey, Role role); + void SetParameterRole(std::string const& paramKey, Role role); /* Get an image value * @@ -841,13 +841,13 @@ protected: * \li ParameterType_InputImage */ template <class TImageType> - TImageType* GetParameterImage(std::string parameter); + TImageType* GetParameterImage(std::string const& parameter); /** Declare a parameter as having an automatic value */ - void AutomaticValueOn(std::string paramKey); + void AutomaticValueOn(std::string const& paramKey); /** Declare a parameter as NOT having an automatic value */ - void AutomaticValueOff(std::string paramKey); + void AutomaticValueOff(std::string const& paramKey); /* Set an output image value * @@ -855,7 +855,7 @@ protected: * \li ParameterType_OutputImage */ template <class TImageType> - void SetParameterOutputImage(std::string parameter, TImageType* value); + void SetParameterOutputImage(std::string const& parameter, TImageType* value); private: /* Implement this method to add parameters */ @@ -937,77 +937,77 @@ namespace otb namespace Wrapper { -extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8VectorImageType* Application::GetParameterImage<UInt8VectorImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE Int16VectorImageType* Application::GetParameterImage<Int16VectorImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt16VectorImageType* Application::GetParameterImage<UInt16VectorImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE Int32VectorImageType* Application::GetParameterImage<Int32VectorImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt32VectorImageType* Application::GetParameterImage<UInt32VectorImageType>(std::string); +extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8VectorImageType* Application::GetParameterImage<UInt8VectorImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE Int16VectorImageType* Application::GetParameterImage<Int16VectorImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt16VectorImageType* Application::GetParameterImage<UInt16VectorImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE Int32VectorImageType* Application::GetParameterImage<Int32VectorImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt32VectorImageType* Application::GetParameterImage<UInt32VectorImageType>(std::string const&); -extern template OTBApplicationEngine_EXPORT_TEMPLATE FloatVectorImageType* Application::GetParameterImage<FloatVectorImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE DoubleVectorImageType* Application::GetParameterImage<DoubleVectorImageType>(std::string); +extern template OTBApplicationEngine_EXPORT_TEMPLATE FloatVectorImageType* Application::GetParameterImage<FloatVectorImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE DoubleVectorImageType* Application::GetParameterImage<DoubleVectorImageType>(std::string const&); -extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt16VectorImageType* Application::GetParameterImage<ComplexInt16VectorImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt32VectorImageType* Application::GetParameterImage<ComplexInt32VectorImageType>(std::string); +extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt16VectorImageType* Application::GetParameterImage<ComplexInt16VectorImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt32VectorImageType* Application::GetParameterImage<ComplexInt32VectorImageType>(std::string const&); -extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexFloatVectorImageType* Application::GetParameterImage<ComplexFloatVectorImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexDoubleVectorImageType* Application::GetParameterImage<ComplexDoubleVectorImageType>(std::string); +extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexFloatVectorImageType* Application::GetParameterImage<ComplexFloatVectorImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexDoubleVectorImageType* Application::GetParameterImage<ComplexDoubleVectorImageType>(std::string const&); -extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8RGBImageType* Application::GetParameterImage<UInt8RGBImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8RGBAImageType* Application::GetParameterImage<UInt8RGBAImageType>(std::string); +extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8RGBImageType* Application::GetParameterImage<UInt8RGBImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8RGBAImageType* Application::GetParameterImage<UInt8RGBAImageType>(std::string const&); -extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8ImageType* Application::GetParameterImage<UInt8ImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE Int16ImageType* Application::GetParameterImage<Int16ImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt16ImageType* Application::GetParameterImage<UInt16ImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE Int32ImageType* Application::GetParameterImage<Int32ImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt32ImageType* Application::GetParameterImage<UInt32ImageType>(std::string); +extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt8ImageType* Application::GetParameterImage<UInt8ImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE Int16ImageType* Application::GetParameterImage<Int16ImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt16ImageType* Application::GetParameterImage<UInt16ImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE Int32ImageType* Application::GetParameterImage<Int32ImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE UInt32ImageType* Application::GetParameterImage<UInt32ImageType>(std::string const&); -extern template OTBApplicationEngine_EXPORT_TEMPLATE FloatImageType* Application::GetParameterImage<FloatImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE DoubleImageType* Application::GetParameterImage<DoubleImageType>(std::string); +extern template OTBApplicationEngine_EXPORT_TEMPLATE FloatImageType* Application::GetParameterImage<FloatImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE DoubleImageType* Application::GetParameterImage<DoubleImageType>(std::string const&); -extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt16ImageType* Application::GetParameterImage<ComplexInt16ImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt32ImageType* Application::GetParameterImage<ComplexInt32ImageType>(std::string); +extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt16ImageType* Application::GetParameterImage<ComplexInt16ImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexInt32ImageType* Application::GetParameterImage<ComplexInt32ImageType>(std::string const&); -extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexFloatImageType* Application::GetParameterImage<ComplexFloatImageType>(std::string); -extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexDoubleImageType* Application::GetParameterImage<ComplexDoubleImageType>(std::string); +extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexFloatImageType* Application::GetParameterImage<ComplexFloatImageType>(std::string const&); +extern template OTBApplicationEngine_EXPORT_TEMPLATE ComplexDoubleImageType* Application::GetParameterImage<ComplexDoubleImageType>(std::string const&); // -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8VectorImageType>(std::string, UInt8VectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int16VectorImageType>(std::string, Int16VectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt16VectorImageType>(std::string, UInt16VectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int32VectorImageType>(std::string, Int32VectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt32VectorImageType>(std::string, UInt32VectorImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8VectorImageType>(std::string const&, UInt8VectorImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int16VectorImageType>(std::string const&, Int16VectorImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt16VectorImageType>(std::string const&, UInt16VectorImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int32VectorImageType>(std::string const&, Int32VectorImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt32VectorImageType>(std::string const&, UInt32VectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<FloatVectorImageType>(std::string, FloatVectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<DoubleVectorImageType>(std::string, DoubleVectorImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<FloatVectorImageType>(std::string const&, FloatVectorImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<DoubleVectorImageType>(std::string const&, DoubleVectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt16VectorImageType>(std::string, +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt16VectorImageType>(std::string const&, ComplexInt16VectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt32VectorImageType>(std::string, +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt32VectorImageType>(std::string const&, ComplexInt32VectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexFloatVectorImageType>(std::string, +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexFloatVectorImageType>(std::string const&, ComplexFloatVectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexDoubleVectorImageType>(std::string, +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexDoubleVectorImageType>(std::string const&, ComplexDoubleVectorImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8RGBImageType>(std::string, UInt8RGBImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8RGBAImageType>(std::string, UInt8RGBAImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8RGBImageType>(std::string const&, UInt8RGBImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8RGBAImageType>(std::string const&, UInt8RGBAImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8ImageType>(std::string, UInt8ImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int16ImageType>(std::string, Int16ImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt16ImageType>(std::string, UInt16ImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int32ImageType>(std::string, Int32ImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt32ImageType>(std::string, UInt32ImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt8ImageType>(std::string const&, UInt8ImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int16ImageType>(std::string const&, Int16ImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt16ImageType>(std::string const&, UInt16ImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<Int32ImageType>(std::string const&, Int32ImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<UInt32ImageType>(std::string const&, UInt32ImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<FloatImageType>(std::string, FloatImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<DoubleImageType>(std::string, DoubleImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<FloatImageType>(std::string const&, FloatImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<DoubleImageType>(std::string const&, DoubleImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt16ImageType>(std::string, ComplexInt16ImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt32ImageType>(std::string, ComplexInt32ImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt16ImageType>(std::string const&, ComplexInt16ImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt32ImageType>(std::string const&, ComplexInt32ImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexFloatImageType>(std::string, ComplexFloatImageType*); -extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexDoubleImageType>(std::string, ComplexDoubleImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexFloatImageType>(std::string const&, ComplexFloatImageType*); +extern template OTBApplicationEngine_EXPORT_TEMPLATE void Application::SetParameterOutputImage<ComplexDoubleImageType>(std::string const&, ComplexDoubleImageType*); } // namespace Wrapper } // namespace otb diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.hxx b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.hxx index 33330cd2418fa7c81e506806d6a43b3d9d583f23..104b4a99a5e682295aa3c17373ce2ac2f1d53404 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.hxx +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.hxx @@ -36,7 +36,7 @@ namespace Wrapper template <class TImageType> TImageType* Application -::GetParameterImage(std::string parameter) +::GetParameterImage(std::string const& parameter) { typename TImageType::Pointer ret; @@ -57,7 +57,7 @@ Application template <class TImageType> void Application -::SetParameterOutputImage(std::string parameter, TImageType* value) +::SetParameterOutputImage(std::string const& parameter, TImageType* value) { Parameter* param = GetParameterByKey(parameter); diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx index 9cdfa1e1d841dd1a4c2f8693b342bc3dd6c72c63..95f4f794430447c6697da6b9245973c7f515d1e8 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx @@ -75,77 +75,77 @@ namespace Wrapper { -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt8VectorImageType* Application::GetParameterImage<UInt8VectorImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE Int16VectorImageType* Application::GetParameterImage<Int16VectorImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt16VectorImageType* Application::GetParameterImage<UInt16VectorImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE Int32VectorImageType* Application::GetParameterImage<Int32VectorImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt32VectorImageType* Application::GetParameterImage<UInt32VectorImageType>(std::string); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt8VectorImageType* Application::GetParameterImage<UInt8VectorImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE Int16VectorImageType* Application::GetParameterImage<Int16VectorImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt16VectorImageType* Application::GetParameterImage<UInt16VectorImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE Int32VectorImageType* Application::GetParameterImage<Int32VectorImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt32VectorImageType* Application::GetParameterImage<UInt32VectorImageType>(std::string const&); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE FloatVectorImageType* Application::GetParameterImage<FloatVectorImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE DoubleVectorImageType* Application::GetParameterImage<DoubleVectorImageType>(std::string); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE FloatVectorImageType* Application::GetParameterImage<FloatVectorImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE DoubleVectorImageType* Application::GetParameterImage<DoubleVectorImageType>(std::string const&); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexInt16VectorImageType* Application::GetParameterImage<ComplexInt16VectorImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexInt32VectorImageType* Application::GetParameterImage<ComplexInt32VectorImageType>(std::string); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexInt16VectorImageType* Application::GetParameterImage<ComplexInt16VectorImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexInt32VectorImageType* Application::GetParameterImage<ComplexInt32VectorImageType>(std::string const&); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexFloatVectorImageType* Application::GetParameterImage<ComplexFloatVectorImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexDoubleVectorImageType* Application::GetParameterImage<ComplexDoubleVectorImageType>(std::string); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexFloatVectorImageType* Application::GetParameterImage<ComplexFloatVectorImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexDoubleVectorImageType* Application::GetParameterImage<ComplexDoubleVectorImageType>(std::string const&); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt8RGBImageType* Application::GetParameterImage<UInt8RGBImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt8RGBAImageType* Application::GetParameterImage<UInt8RGBAImageType>(std::string); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt8RGBImageType* Application::GetParameterImage<UInt8RGBImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt8RGBAImageType* Application::GetParameterImage<UInt8RGBAImageType>(std::string const&); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt8ImageType* Application::GetParameterImage<UInt8ImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE Int16ImageType* Application::GetParameterImage<Int16ImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt16ImageType* Application::GetParameterImage<UInt16ImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE Int32ImageType* Application::GetParameterImage<Int32ImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt32ImageType* Application::GetParameterImage<UInt32ImageType>(std::string); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt8ImageType* Application::GetParameterImage<UInt8ImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE Int16ImageType* Application::GetParameterImage<Int16ImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt16ImageType* Application::GetParameterImage<UInt16ImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE Int32ImageType* Application::GetParameterImage<Int32ImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE UInt32ImageType* Application::GetParameterImage<UInt32ImageType>(std::string const&); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE FloatImageType* Application::GetParameterImage<FloatImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE DoubleImageType* Application::GetParameterImage<DoubleImageType>(std::string); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE FloatImageType* Application::GetParameterImage<FloatImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE DoubleImageType* Application::GetParameterImage<DoubleImageType>(std::string const&); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexInt16ImageType* Application::GetParameterImage<ComplexInt16ImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexInt32ImageType* Application::GetParameterImage<ComplexInt32ImageType>(std::string); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexInt16ImageType* Application::GetParameterImage<ComplexInt16ImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexInt32ImageType* Application::GetParameterImage<ComplexInt32ImageType>(std::string const&); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexFloatImageType* Application::GetParameterImage<ComplexFloatImageType>(std::string); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexDoubleImageType* Application::GetParameterImage<ComplexDoubleImageType>(std::string); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexFloatImageType* Application::GetParameterImage<ComplexFloatImageType>(std::string const&); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE ComplexDoubleImageType* Application::GetParameterImage<ComplexDoubleImageType>(std::string const&); // -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt8VectorImageType>(std::string, UInt8VectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<Int16VectorImageType>(std::string, Int16VectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt16VectorImageType>(std::string, UInt16VectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<Int32VectorImageType>(std::string, Int32VectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt32VectorImageType>(std::string, UInt32VectorImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt8VectorImageType>(std::string const&, UInt8VectorImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<Int16VectorImageType>(std::string const&, Int16VectorImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt16VectorImageType>(std::string const&, UInt16VectorImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<Int32VectorImageType>(std::string const&, Int32VectorImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt32VectorImageType>(std::string const&, UInt32VectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<FloatVectorImageType>(std::string, FloatVectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<DoubleVectorImageType>(std::string, DoubleVectorImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<FloatVectorImageType>(std::string const&, FloatVectorImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<DoubleVectorImageType>(std::string const&, DoubleVectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt16VectorImageType>(std::string, +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt16VectorImageType>(std::string const&, ComplexInt16VectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt32VectorImageType>(std::string, +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt32VectorImageType>(std::string const&, ComplexInt32VectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexFloatVectorImageType>(std::string, +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexFloatVectorImageType>(std::string const&, ComplexFloatVectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexDoubleVectorImageType>(std::string, +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexDoubleVectorImageType>(std::string const&, ComplexDoubleVectorImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt8RGBImageType>(std::string, UInt8RGBImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt8RGBAImageType>(std::string, UInt8RGBAImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt8RGBImageType>(std::string const&, UInt8RGBImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt8RGBAImageType>(std::string const&, UInt8RGBAImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt8ImageType>(std::string, UInt8ImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<Int16ImageType>(std::string, Int16ImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt16ImageType>(std::string, UInt16ImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<Int32ImageType>(std::string, Int32ImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt32ImageType>(std::string, UInt32ImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt8ImageType>(std::string const&, UInt8ImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<Int16ImageType>(std::string const&, Int16ImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt16ImageType>(std::string const&, UInt16ImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<Int32ImageType>(std::string const&, Int32ImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<UInt32ImageType>(std::string const&, UInt32ImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<FloatImageType>(std::string, FloatImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<DoubleImageType>(std::string, DoubleImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<FloatImageType>(std::string const&, FloatImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<DoubleImageType>(std::string const&, DoubleImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt16ImageType>(std::string, ComplexInt16ImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt32ImageType>(std::string, ComplexInt32ImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt16ImageType>(std::string const&, ComplexInt16ImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexInt32ImageType>(std::string const&, ComplexInt32ImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexFloatImageType>(std::string, ComplexFloatImageType*); -template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexDoubleImageType>(std::string, ComplexDoubleImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexFloatImageType>(std::string const&, ComplexFloatImageType*); +template OTBApplicationEngine_EXPORT_EXPLICIT_TEMPLATE void Application::SetParameterOutputImage<ComplexDoubleImageType>(std::string const&, ComplexDoubleImageType*); void Application::SetName( const std::string & name ) @@ -383,36 +383,36 @@ ParameterGroup* Application::GetParameterList() return m_ParameterList; } -Parameter* Application::GetParameterByKey(std::string name, bool follow) +Parameter* Application::GetParameterByKey(std::string const& name, bool follow) { return GetParameterList()->GetParameterByKey(name, follow); } -void Application::SetParameterInt(std::string key, int value, bool hasUserValueFlag) +void Application::SetParameterInt(std::string const& key, int value, bool hasUserValueFlag) { GetParameterByKey(key)->FromInt(value); this->SetParameterUserValue(key, hasUserValueFlag); } -void Application::SetParameterFloat(std::string key, float value, bool hasUserValueFlag) +void Application::SetParameterFloat(std::string const& key, float value, bool hasUserValueFlag) { GetParameterByKey(key)->FromFloat(value); this->SetParameterUserValue(key, hasUserValueFlag); } -void Application::SetParameterString(std::string parameter, std::string value, bool hasUserValueFlag) +void Application::SetParameterString(std::string const& parameter, std::string value, bool hasUserValueFlag) { GetParameterByKey(parameter)->FromString(value); this->SetParameterUserValue(parameter, hasUserValueFlag); } -void Application::SetParameterStringList(std::string key, std::vector<std::string> values, bool hasUserValueFlag) +void Application::SetParameterStringList(std::string const& key, std::vector<std::string> values, bool hasUserValueFlag) { GetParameterByKey(key)->FromStringList(values); this->SetParameterUserValue(key, hasUserValueFlag); } -void Application::SetParameterUserValue(std::string paramKey, bool value) +void Application::SetParameterUserValue(std::string const& paramKey, bool value) { /** UserValue is set/unset parameter must be active. Can't set the m_Active flg in Parameter::SetUserValue() instead of @@ -429,7 +429,7 @@ void Application::SetParameterUserValue(std::string paramKey, bool value) } } -const Parameter* Application::GetParameterByKey(std::string name, bool follow) const +const Parameter* Application::GetParameterByKey(std::string const& name, bool follow) const { // GetParameterList is non const... Application* _this = const_cast<Application*>(this); @@ -942,36 +942,36 @@ Application::Stop() } /* Enable the use of an optional parameter. Returns the previous state */ -void Application::EnableParameter(std::string paramKey) +void Application::EnableParameter(std::string const& paramKey) { Parameter* param = GetParameterByKey(paramKey); param->SetActive(true); } /* Disable the use of an optional parameter. Returns the previous state */ -void Application::DisableParameter(std::string paramKey) +void Application::DisableParameter(std::string const& paramKey) { GetParameterByKey(paramKey)->SetActive(false); } /* Return the enable state of an optional parameter */ -bool Application::IsParameterEnabled(std::string paramKey, bool recurseParents) const +bool Application::IsParameterEnabled(std::string const& paramKey, bool recurseParents) const { return GetParameterByKey(paramKey)->GetActive(recurseParents); } /* Return true if the specified parameter is mandatory */ -bool Application::IsMandatory(std::string paramKey) const +bool Application::IsMandatory(std::string const& paramKey) const { return GetParameterByKey(paramKey)->GetMandatory(); } -void Application::MandatoryOn(std::string paramKey) +void Application::MandatoryOn(std::string const& paramKey) { GetParameterByKey(paramKey)->SetMandatory(true); } -void Application::MandatoryOff(std::string paramKey) +void Application::MandatoryOff(std::string const& paramKey) { GetParameterByKey(paramKey)->SetMandatory(false); } @@ -979,30 +979,30 @@ void Application::MandatoryOff(std::string paramKey) /* Return true if the specified parameter was set automatically in the * application */ -bool Application::HasAutomaticValue(std::string paramKey) const +bool Application::HasAutomaticValue(std::string const& paramKey) const { return GetParameterByKey(paramKey)->GetAutomaticValue(); } -void Application::AutomaticValueOn(std::string paramKey) +void Application::AutomaticValueOn(std::string const& paramKey) { GetParameterByKey(paramKey)->SetAutomaticValue(true); } -void Application::AutomaticValueOff(std::string paramKey) +void Application::AutomaticValueOff(std::string const& paramKey) { GetParameterByKey(paramKey)->SetAutomaticValue(false); } /* Returns true if the parameter has an associated value provided externally * (not automatically computed by the application) */ -bool Application::HasUserValue(std::string paramKey) const +bool Application::HasUserValue(std::string const& paramKey) const { return GetParameterByKey(paramKey)->HasUserValue(); } /* If a user value was provided clear it and update the other parameters */ -void Application::ClearValue(std::string paramKey) +void Application::ClearValue(std::string const& paramKey) { GetParameterByKey(paramKey)->ClearValue(); } @@ -1010,37 +1010,37 @@ void Application::ClearValue(std::string paramKey) /* Returns true if the parameter has an associated value. * This value can be an automatically computed value or default value, * or a value set externally by user */ -bool Application::HasValue(std::string paramKey) const +bool Application::HasValue(std::string const& paramKey) const { return GetParameterByKey(paramKey)->HasValue(); } /* Return the user level of access to a parameter */ -UserLevel Application::GetParameterUserLevel(std::string paramKey) const +UserLevel Application::GetParameterUserLevel(std::string const& paramKey) const { return GetParameterByKey(paramKey)->GetUserLevel(); } /* Return the role (input/output) of a parameter */ -Role Application::GetParameterRole(std::string paramKey) const +Role Application::GetParameterRole(std::string const& paramKey) const { return GetParameterByKey(paramKey)->GetRole(); } /* Return the role (input/output) of a parameter */ -void Application::SetParameterRole(std::string paramKey, Role role) +void Application::SetParameterRole(std::string const& paramKey, Role role) { GetParameterByKey(paramKey)->SetRole(role); } /* Get the parameter type from its name */ -ParameterType Application::GetParameterType(std::string key) const +ParameterType Application::GetParameterType(std::string const& key) const { return GetParameterByKey(key)->GetType(); } -std::vector<std::string> Application::GetChoiceKeys(std::string name) +std::vector<std::string> Application::GetChoiceKeys(std::string const& name) { Parameter* param = GetParameterByKey(name); if (dynamic_cast<ChoiceParameter*>(param)) @@ -1056,7 +1056,7 @@ std::vector<std::string> Application::GetChoiceKeys(std::string name) itkExceptionMacro(<< name << " is not a choice parameter"); } -std::vector<std::string> Application::GetChoiceNames(std::string name) +std::vector<std::string> Application::GetChoiceNames(std::string const& name) { Parameter* param = GetParameterByKey(name); if (dynamic_cast<ChoiceParameter*>(param)) @@ -1073,7 +1073,7 @@ std::vector<std::string> Application::GetChoiceNames(std::string name) } -void Application::SetDefaultParameterInt(std::string parameter, int value) +void Application::SetDefaultParameterInt(std::string const& parameter, int value) { Parameter* param = GetParameterByKey(parameter); bool hasUserValue = param->HasUserValue(); @@ -1104,7 +1104,7 @@ void Application::SetDefaultParameterInt(std::string parameter, int value) } } -int Application::GetDefaultParameterInt(std::string parameter) +int Application::GetDefaultParameterInt(std::string const& parameter) { Parameter* param = GetParameterByKey(parameter); int ret = 0 ; @@ -1135,7 +1135,7 @@ int Application::GetDefaultParameterInt(std::string parameter) return ret; } -void Application::SetDefaultParameterFloat(std::string key, float value) +void Application::SetDefaultParameterFloat(std::string const& key, float value) { auto param = downcast_check<FloatParameter>(GetParameterByKey(key)); param->SetDefaultValue(value); @@ -1146,44 +1146,44 @@ void Application::SetDefaultParameterFloat(std::string key, float value) } } -float Application::GetDefaultParameterFloat(std::string key) +float Application::GetDefaultParameterFloat(std::string const& key) { auto param = downcast_check<FloatParameter>(GetParameterByKey(key)); return param->GetDefaultValue(); } -void Application::SetDefaultOutputPixelType(std::string key, ImagePixelType type) +void Application::SetDefaultOutputPixelType(std::string const& key, ImagePixelType type) { auto param = downcast_check<OutputImageParameter>(GetParameterByKey(key)); param->SetDefaultPixelType(type); param->SetPixelType(type); } -void Application::SetMinimumParameterIntValue(std::string key, int value) +void Application::SetMinimumParameterIntValue(std::string const& key, int value) { auto param = downcast_check<IntParameter>(GetParameterByKey(key)); param->SetMinimumValue(value); } -void Application::SetMaximumParameterIntValue(std::string key, int value) +void Application::SetMaximumParameterIntValue(std::string const& key, int value) { auto param = downcast_check<IntParameter>(GetParameterByKey(key)); param->SetMaximumValue(value); } -void Application::SetMinimumParameterFloatValue(std::string key, float value) +void Application::SetMinimumParameterFloatValue(std::string const& key, float value) { auto param = downcast_check<FloatParameter>(GetParameterByKey(key)); param->SetMinimumValue(value); } -void Application::SetMaximumParameterFloatValue(std::string key, float value) +void Application::SetMaximumParameterFloatValue(std::string const& key, float value) { auto param = downcast_check<FloatParameter>(GetParameterByKey(key)); param->SetMaximumValue(value); } -void Application::SetListViewSingleSelectionMode(std::string key, bool status) +void Application::SetListViewSingleSelectionMode(std::string const& key, bool status) { auto param = downcast_check<ListViewParameter>(GetParameterByKey(key)); param->SetSingleSelection(status); @@ -1195,56 +1195,56 @@ bool Application::GetListViewSingleSelectionMode(const std::string& key) return param->GetSingleSelection(); } -void Application::SetParameterOutputImage(std::string key, FloatVectorImageType* value) +void Application::SetParameterOutputImage(std::string const& key, FloatVectorImageType* value) { auto param = downcast_check<OutputImageParameter>(GetParameterByKey(key)); param->SetValue(value); } -void Application::SetParameterOutputImagePixelType(std::string key, ImagePixelType pixelType) +void Application::SetParameterOutputImagePixelType(std::string const& key, ImagePixelType pixelType) { auto param = downcast_check<OutputImageParameter>(GetParameterByKey(key)); param->SetPixelType(pixelType); } -void Application::SetParameterOutputVectorData(std::string key, VectorDataType* value) +void Application::SetParameterOutputVectorData(std::string const& key, VectorDataType* value) { auto param = downcast_check<OutputVectorDataParameter>(GetParameterByKey(key)); param->SetValue(value); } -std::string Application::GetParameterName(std::string parameter) +std::string Application::GetParameterName(std::string const& parameter) { // get the actual parameter, even if it is a proxy Parameter* param = GetParameterByKey(parameter,false); return param->GetName(); } -std::string Application::GetParameterDescription(std::string parameter) +std::string Application::GetParameterDescription(std::string const& parameter) { // get the actual parameter, even if it is a proxy Parameter* param = GetParameterByKey(parameter,false); return param->GetDescription(); } -void Application::SetParameterDescription(std::string parameter, std::string desc) +void Application::SetParameterDescription(std::string const& parameter, std::string desc) { // get the actual parameter, even if it is a proxy Parameter* param = GetParameterByKey(parameter,false); param->SetDescription(desc); } -int Application::GetParameterInt(std::string key) +int Application::GetParameterInt(std::string const& key) const { return GetParameterByKey(key)->ToInt(); } -float Application::GetParameterFloat(std::string key) +float Application::GetParameterFloat(std::string const& key) const { return GetParameterByKey(key)->ToFloat(); } -std::string Application::GetParameterString(std::string key) +std::string Application::GetParameterString(std::string const& key) const { return GetParameterByKey(key)->ToString(); } @@ -1254,113 +1254,113 @@ std::vector<std::string> Application::GetParameterStringList(const std::string& return GetParameterByKey(key)->ToStringList(); } -void Application::SetParameterInputImage(std::string key, ImageBaseType* inputImage) +void Application::SetParameterInputImage(std::string const& key, ImageBaseType* inputImage) { auto param = downcast_check<InputImageParameter>(GetParameterByKey(key)); param->SetImage(inputImage); } -ImageBaseType* Application::GetParameterOutputImage(std::string key) +ImageBaseType* Application::GetParameterOutputImage(std::string const& key) { auto param = downcast_check<OutputImageParameter>(GetParameterByKey(key)); return param->GetValue(); } -void Application::AddImageToParameterInputImageList(std::string key, ImageBaseType* img) +void Application::AddImageToParameterInputImageList(std::string const& key, ImageBaseType* img) { auto param = downcast_check<InputImageListParameter>(GetParameterByKey(key)); param->AddImage(img); } -void Application::SetNthParameterInputImageList(std::string key, const unsigned int& id, ImageBaseType* img) +void Application::SetNthParameterInputImageList(std::string const& key, const unsigned int& id, ImageBaseType* img) { auto param = downcast_check<InputImageListParameter>(GetParameterByKey(key)); param->SetNthImage(id, img); } -void Application::AddParameterStringList(std::string key, const std::string& str) +void Application::AddParameterStringList(std::string const& key, const std::string& str) { auto param = downcast_check<InputImageListParameter>(GetParameterByKey(key)); param->AddFromFileName(str); } -void Application::SetNthParameterStringList(std::string key, const unsigned int& id, const std::string& str) +void Application::SetNthParameterStringList(std::string const& key, const unsigned int& id, const std::string& str) { auto param = downcast_check<InputImageListParameter>(GetParameterByKey(key)); param->SetNthFileName(id, str); } -void Application::ClearParameterInputImageList(std::string key) +void Application::ClearParameterInputImageList(std::string const& key) { auto param = downcast_check<InputImageListParameter>(GetParameterByKey(key)); param->ClearValue(); } -unsigned int Application::GetNumberOfElementsInParameterInputImageList(std::string key) +unsigned int Application::GetNumberOfElementsInParameterInputImageList(std::string const& key) { auto param = downcast_check<InputImageListParameter>(GetParameterByKey(key)); return param->Size(); } -FloatVectorImageType* Application::GetParameterImage(std::string parameter) +FloatVectorImageType* Application::GetParameterImage(std::string const& parameter) { return this->GetParameterImage<FloatVectorImageType>(parameter); } -FloatVectorImageListType* Application::GetParameterImageList(std::string key) +FloatVectorImageListType* Application::GetParameterImageList(std::string const& key) { auto param = downcast_check<InputImageListParameter>(GetParameterByKey(key)); return param->GetImageList(); } -VectorDataType* Application::GetParameterVectorData(std::string key) +VectorDataType* Application::GetParameterVectorData(std::string const& key) { auto param = downcast_check<InputVectorDataParameter>(GetParameterByKey(key)); return param->GetVectorData(); } -VectorDataListType* Application::GetParameterVectorDataList(std::string key) +VectorDataListType* Application::GetParameterVectorDataList(std::string const& key) { auto param = downcast_check<InputVectorDataListParameter>(GetParameterByKey(key)); return param->GetVectorDataList(); } -std::string Application::GetParameterAsString(std::string key) +std::string Application::GetParameterAsString(std::string const& key) { return GetParameterString(key); } -ImagePixelType Application::GetParameterOutputImagePixelType(std::string key) +ImagePixelType Application::GetParameterOutputImagePixelType(std::string const& key) { auto param = downcast_check<OutputImageParameter>(GetParameterByKey(key)); return param->GetPixelType(); } void -Application::AddChoice(std::string paramKey, std::string paramName) +Application::AddChoice(std::string const& paramKey, std::string const& paramName) { GetParameterList()->AddChoice(paramKey, paramName); } void -Application::ClearChoices(std::string paramKey) +Application::ClearChoices(std::string const& paramKey) { GetParameterList()->ClearChoices(paramKey); } std::vector<int> -Application::GetSelectedItems(std::string param) +Application::GetSelectedItems(std::string const& param) { return GetParameterList()->GetSelectedItems(param); } void -Application::AddParameter(ParameterType type, std::string paramKey, std::string paramName) +Application::AddParameter(ParameterType type, std::string const& paramKey, std::string const& paramName) { GetParameterList()->AddParameter(type, paramKey, paramName); } -void Application::AddRAMParameter(std::string paramKey, std::string paramName, unsigned int defaultValue) +void Application::AddRAMParameter(std::string const& paramKey, std::string const& paramName, unsigned int defaultValue) { GetParameterList()->AddParameter(ParameterType_RAM, paramKey, paramName); SetDefaultParameterInt(paramKey, defaultValue); @@ -1368,7 +1368,7 @@ void Application::AddRAMParameter(std::string paramKey, std::string paramName, u } // paramKey default value = ram -void Application::AddRAMParameter(std::string paramKey) +void Application::AddRAMParameter(std::string const& paramKey) { // Get the RAM Parameter from the configuration manager AddRAMParameter(paramKey, "Available RAM (MB)", otb::ConfigurationManager::GetMaxRAMHint()); @@ -1376,7 +1376,7 @@ void Application::AddRAMParameter(std::string paramKey) SetParameterDescription(paramKey, "Available memory for processing (in MB)."); } -void Application::AddRANDParameter(std::string paramKey, std::string paramName, unsigned int defaultValue) +void Application::AddRANDParameter(std::string const& paramKey, std::string const& paramName, unsigned int defaultValue) { GetParameterList()->AddParameter(ParameterType_Int, paramKey, paramName); SetDefaultParameterInt(paramKey, defaultValue); @@ -1384,7 +1384,7 @@ void Application::AddRANDParameter(std::string paramKey, std::string paramName, } // paramKey default value = rand -void Application::AddRANDParameter(std::string paramKey) +void Application::AddRANDParameter(std::string const& paramKey) { // Get the RAND Parameter from the configuration file @@ -1711,7 +1711,7 @@ Application::GetImageBasePixelType(const std::string & key, unsigned int idx) } #define otbGetParameterImageMacro( Image ) \ - Image##Type * Application::GetParameter##Image(std::string parameter) \ + Image##Type * Application::GetParameter##Image(std::string const& parameter) \ { \ Parameter* param = GetParameterByKey(parameter); \ InputImageParameter* paramDown = dynamic_cast<InputImageParameter*>(param); \