From db1b3a76a15e04ffee79637dfe1f1ddf703c1339 Mon Sep 17 00:00:00 2001 From: Stephane ALBERT <stephane.albert@c-s.fr> Date: Fri, 22 Mar 2019 12:46:45 +0100 Subject: [PATCH] REFAC: 1649: Replace calls to otb::Wrapper::Application::GetParameterImage<>() by ::GetParameterXImage() when type is statically determined. --- .../app/otbPolygonClassStatistics.cxx | 36 +++++++-------- .../app/otbSampleSelection.cxx | 46 +++++++++---------- .../AppImageUtils/app/otbManageNoData.cxx | 13 +++--- .../app/otbLargeScaleMeanShift.cxx | 6 +-- 4 files changed, 50 insertions(+), 51 deletions(-) diff --git a/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx b/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx index 95e3314e11..1d5c7726da 100644 --- a/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx +++ b/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx @@ -54,7 +54,7 @@ public: /** Filters typedef */ typedef otb::OGRDataToClassStatisticsFilter<FloatVectorImageType,UInt8ImageType> FilterType; - + typedef otb::StatisticsXMLFileWriter<FloatVectorImageType::PixelType> StatWriterType; typedef otb::GeometriesSet GeometriesType; @@ -64,7 +64,7 @@ public: private: PolygonClassStatistics() { - + } void DoInit() override @@ -98,17 +98,17 @@ private: AddParameter(ParameterType_InputImage, "mask", "Input validity mask"); SetParameterDescription("mask", "Validity mask (only pixels corresponding to a mask value greater than 0 will be used for statistics)"); MandatoryOff("mask"); - + AddParameter(ParameterType_InputFilename, "vec", "Input vectors"); SetParameterDescription("vec","Input geometries to analyze"); - + AddParameter(ParameterType_OutputFilename, "out", "Output XML statistics file"); SetParameterDescription("out","Output file to store statistics (XML format)"); AddParameter(ParameterType_ListView, "field", "Field Name"); SetParameterDescription("field","Name of the field carrying the class name in the input vectors."); SetListViewSingleSelectionMode("field",true); - + AddParameter(ParameterType_Int, "layer", "Layer Index"); SetParameterDescription("layer", "Layer index to read in the input vector file."); MandatoryOff("layer"); @@ -138,16 +138,16 @@ private: ogr::Feature feature = layer.ogr().GetNextFeature(); ClearChoices("field"); - + for(int iField=0; iField<feature.ogr().GetFieldCount(); iField++) { std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef(); key = item; std::string::iterator end = std::remove_if(key.begin(),key.end(),IsNotAlphaNum); std::transform(key.begin(), end, key.begin(), tolower); - + OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); - + if(fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64) { std::string tmpKey="field."+key.substr(0, end - key.begin()); @@ -159,7 +159,7 @@ private: // Check that the extension of the output parameter is XML (mandatory for // StatisticsXMLFileWriter) // Check it here to trigger the error before polygons analysis - + if ( HasValue("out") ) { // Store filename extension @@ -175,7 +175,7 @@ private: void DoExecute() override { - otb::ogr::DataSource::Pointer vectors = + otb::ogr::DataSource::Pointer vectors = otb::ogr::DataSource::New(this->GetParameterString("vec")); // Retrieve the field name @@ -186,7 +186,7 @@ private: otbAppLogFATAL(<<"No field has been selected for data labelling!"); } - std::vector<std::string> cFieldNames = GetChoiceNames("field"); + std::vector<std::string> cFieldNames = GetChoiceNames("field"); std::string fieldName = cFieldNames[selectedCFieldIdx.front()]; otb::Wrapper::ElevationParametersHandler::SetupDEMHandlerFromElevationParameters(this,"elev"); @@ -203,14 +203,14 @@ private: GeometriesType::Pointer inputGeomSet; ProjectionFilterType::Pointer geometriesProjFilter; GeometriesType::Pointer outputGeomSet; - const OGRSpatialReference imgOGRSref = + const OGRSpatialReference imgOGRSref = OGRSpatialReference( imageProjectionRef.c_str() ); - const OGRSpatialReference vectorOGRSref = + const OGRSpatialReference vectorOGRSref = OGRSpatialReference( vectorProjectionRef.c_str() ); bool doReproj = true; // don't reproject for these cases - if ( vectorProjectionRef.empty() - || ( imgOGRSref.IsSame( &vectorOGRSref ) ) + if ( vectorProjectionRef.empty() + || ( imgOGRSref.IsSame( &vectorOGRSref ) ) || ( imageProjectionRef.empty() && imageKwl.GetSize() == 0) ) doReproj = false; @@ -236,7 +236,7 @@ private: filter->SetInput(this->GetParameterImage("in")); if (IsParameterEnabled("mask") && HasValue("mask")) { - filter->SetMask(this->GetParameterImage<UInt8ImageType>("mask")); + filter->SetMask(this->GetParameterUInt8Image("mask")); } filter->SetOGRData(reprojVector); filter->SetFieldName(fieldName); @@ -245,10 +245,10 @@ private: AddProcess(filter->GetStreamer(),"Analyze polygons..."); filter->Update(); - + FilterType::ClassCountMapType &classCount = filter->GetClassCountOutput()->Get(); FilterType::PolygonSizeMapType &polySize = filter->GetPolygonSizeOutput()->Get(); - + StatWriterType::Pointer statWriter = StatWriterType::New(); statWriter->SetFileName(this->GetParameterString("out")); statWriter->AddInputMap<FilterType::ClassCountMapType>("samplesPerClass",classCount); diff --git a/Modules/Applications/AppClassification/app/otbSampleSelection.cxx b/Modules/Applications/AppClassification/app/otbSampleSelection.cxx index a4f8b1fc33..5537a77f3e 100644 --- a/Modules/Applications/AppClassification/app/otbSampleSelection.cxx +++ b/Modules/Applications/AppClassification/app/otbSampleSelection.cxx @@ -63,7 +63,7 @@ public: UInt8ImageType, otb::RandomSampler> RandomSamplerType; typedef otb::SamplingRateCalculator RateCalculatorType; - + typedef std::map<std::string, unsigned long> ClassCountMapType; typedef RateCalculatorType::MapRateType MapRateType; typedef itk::VariableLengthVector<float> MeasurementType; @@ -96,9 +96,9 @@ private: "parameters 'in' and 'vec' respectively. Only the sampling grid (origin, size, spacing)" "will be read in the input image.\n" "There are several strategies to select samples (parameter strategy) : \n\n" - " - smallest (default) : select the same number of sample in each class" + " - smallest (default) : select the same number of sample in each class" " so that the smallest one is fully sampled.\n" - " - constant : select the same number of samples N in each class" + " - constant : select the same number of samples N in each class" " (with N below or equal to the size of the smallest class).\n" " - byclass : set the required number for each class manually, with an input CSV file" " (first column is class name, second one is the required samples number).\n\n" @@ -109,13 +109,13 @@ private: " - random : select samples randomly distributed\n\n" "Once the strategy and type are selected, the application outputs samples positions" "(parameter out).\n\n" - + "The other parameters to look at are : \n\n" " - layer : index specifying from which layer to pick geometries.\n" " - field : set the field name containing the class.\n" " - mask : an optional raster mask can be used to discard samples.\n" " - outrates : allows outputting a CSV file that summarizes the sampling rates for each class.\n" - + "\nAs with the PolygonClassStatistics application, different types of geometry are supported : " "polygons, lines, points. \nThe behavior of this application is different for each type of geometry : \n\n" " - polygon: select points whose center is inside the polygon\n" @@ -192,7 +192,7 @@ private: SetParameterDescription("strategy.total.v","The number of samples to generate"); SetMinimumParameterIntValue("strategy.total.v",1); SetDefaultParameterInt("strategy.total.v",1000); - + AddChoice("strategy.smallest","Set same number of samples for all classes, with the smallest class fully sampled"); SetParameterDescription("strategy.smallest","Set same number of samples for all classes, with the smallest class fully sampled"); @@ -238,16 +238,16 @@ private: ogr::Feature feature = layer.ogr().GetNextFeature(); ClearChoices("field"); - + for(int iField=0; iField<feature.ogr().GetFieldCount(); iField++) { std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef(); key = item; std::string::iterator end = std::remove_if(key.begin(),key.end(),IsNotAlphaNum); std::transform(key.begin(), end, key.begin(), tolower); - + OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); - + if(fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64) { std::string tmpKey="field."+key.substr(0, end - key.begin()); @@ -266,26 +266,26 @@ private: // Get field name std::vector<int> selectedCFieldIdx = GetSelectedItems("field"); - + if(selectedCFieldIdx.empty()) { otbAppLogFATAL(<<"No field has been selected for data labelling!"); } - - std::vector<std::string> cFieldNames = GetChoiceNames("field"); + + std::vector<std::string> cFieldNames = GetChoiceNames("field"); std::string fieldName = cFieldNames[selectedCFieldIdx.front()]; - + m_ReaderStat->SetFileName(this->GetParameterString("instats")); ClassCountMapType classCount = m_ReaderStat->GetStatisticMapByName<ClassCountMapType>("samplesPerClass"); m_RateCalculator->SetClassCount(classCount); - + switch (this->GetParameterInt("strategy")) { // byclass case 0: { otbAppLogINFO("Sampling strategy : set number of samples for each class"); - ClassCountMapType requiredCount = + ClassCountMapType requiredCount = otb::SamplingRateCalculator::ReadRequiredSamples(this->GetParameterString("strategy.byclass.in")); m_RateCalculator->SetNbOfSamplesByClass(requiredCount); } @@ -330,12 +330,12 @@ private: otbAppLogFATAL("Strategy mode unknown :"<<this->GetParameterString("strategy")); break; } - + if (IsParameterEnabled("outrates") && HasValue("outrates")) { m_RateCalculator->Write(this->GetParameterString("outrates")); } - + MapRateType rates = m_RateCalculator->GetRatesByClass(); std::ostringstream oss; oss << " className requiredSamples totalSamples rate" << std::endl; @@ -376,16 +376,16 @@ private: ProjectionFilterType::Pointer geometriesProjFilter; GeometriesType::Pointer outputGeomSet; bool doReproj = true; - const OGRSpatialReference imgOGRSref = + const OGRSpatialReference imgOGRSref = OGRSpatialReference( imageProjectionRef.c_str() ); - const OGRSpatialReference vectorOGRSref = + const OGRSpatialReference vectorOGRSref = OGRSpatialReference( vectorProjectionRef.c_str() ); // don't reproject for these cases if ( vectorProjectionRef.empty() || ( imgOGRSref.IsSame( &vectorOGRSref ) ) || ( imageProjectionRef.empty() && imageKwl.GetSize() == 0) ) doReproj = false; - + if (doReproj) { inputGeomSet = GeometriesType::New(vectors); @@ -407,7 +407,7 @@ private: // Create output dataset for sample positions otb::ogr::DataSource::Pointer outputSamples = otb::ogr::DataSource::New(this->GetParameterString("out"),otb::ogr::DataSource::Modes::Overwrite); - + switch (this->GetParameterInt("sampler")) { // periodic @@ -426,7 +426,7 @@ private: periodicFilt->SetSamplerParameters(param); if (IsParameterEnabled("mask") && HasValue("mask")) { - periodicFilt->SetMask(this->GetParameterImage<UInt8ImageType>("mask")); + periodicFilt->SetMask(this->GetParameterUInt8Image("mask")); } periodicFilt->GetStreamer()->SetAutomaticTiledStreaming(this->GetParameterInt("ram")); AddProcess(periodicFilt->GetStreamer(),"Selecting positions with periodic sampler..."); @@ -444,7 +444,7 @@ private: randomFilt->SetLayerIndex(this->GetParameterInt("layer")); if (IsParameterEnabled("mask") && HasValue("mask")) { - randomFilt->SetMask(this->GetParameterImage<UInt8ImageType>("mask")); + randomFilt->SetMask(this->GetParameterUInt8Image("mask")); } randomFilt->GetStreamer()->SetAutomaticTiledStreaming(this->GetParameterInt("ram")); AddProcess(randomFilt->GetStreamer(),"Selecting positions with random sampler..."); diff --git a/Modules/Applications/AppImageUtils/app/otbManageNoData.cxx b/Modules/Applications/AppImageUtils/app/otbManageNoData.cxx index 561131caab..97f1193ef3 100644 --- a/Modules/Applications/AppImageUtils/app/otbManageNoData.cxx +++ b/Modules/Applications/AppImageUtils/app/otbManageNoData.cxx @@ -50,7 +50,7 @@ public: /** Filters typedef */ typedef otb::ImageToNoDataMaskFilter<FloatVectorImageType,UInt8ImageType> FilterType; typedef otb::ChangeNoDataValueFilter<FloatVectorImageType,FloatVectorImageType> ChangeNoDataFilterType; - + typedef otb::ImageList<FloatImageType> ImageListType; typedef otb::VectorImageToImageListFilter<FloatVectorImageType,ImageListType> VectorToListFilterType; typedef otb::ImageListToVectorImageFilter<ImageListType,FloatVectorImageType> ListToVectorFilterType; @@ -81,12 +81,12 @@ private: AddParameter(ParameterType_Bool,"usenan", "Consider NaN as no-data"); SetParameterDescription("usenan","If active, the application will consider NaN as no-data values as well"); - + AddParameter(ParameterType_Choice,"mode","No-data handling mode"); SetParameterDescription("mode","Allows choosing between different no-data handling options"); AddChoice("mode.buildmask","Build a no-data Mask"); - + AddParameter(ParameterType_Float,"mode.buildmask.inv","Inside Value"); SetParameterDescription("mode.buildmask.inv","Value given in the output mask to pixels that are not no data pixels"); SetDefaultParameterInt("mode.buildmask.inv",1); @@ -132,7 +132,7 @@ private: void DoExecute() override { FloatVectorImageType::Pointer inputPtr = this->GetParameterImage("in"); - + m_Filter = FilterType::New(); m_Filter->SetInsideValue(this->GetParameterFloat("mode.buildmask.inv")); m_Filter->SetOutsideValue(this->GetParameterFloat("mode.buildmask.outv")); @@ -146,7 +146,7 @@ private: std::vector<double> newNoData(inputPtr->GetNumberOfComponentsPerPixel(),GetParameterFloat("mode.changevalue.newv")); m_ChangeNoDataFilter->SetNewNoDataValues(newNoData); - + if(GetParameterString("mode") == "buildmask") { SetParameterOutputImage("out",m_Filter->GetOutput()); @@ -158,7 +158,7 @@ private: else if (GetParameterString("mode") == "apply") { m_MaskFilters.clear(); - UInt8ImageType::Pointer maskPtr = this->GetParameterImage<UInt8ImageType>("mode.apply.mask"); + UInt8ImageType::Pointer maskPtr = this->GetParameterUInt8Image("mode.apply.mask"); unsigned int nbBands = inputPtr->GetNumberOfComponentsPerPixel(); itk::MetaDataDictionary &dict = inputPtr->GetMetaDataDictionary(); std::vector<bool> flags; @@ -221,4 +221,3 @@ private: } OTB_APPLICATION_EXPORT(otb::Wrapper::ManageNoData) - diff --git a/Modules/Applications/AppSegmentation/app/otbLargeScaleMeanShift.cxx b/Modules/Applications/AppSegmentation/app/otbLargeScaleMeanShift.cxx index 8f09d36adf..d42af406a7 100644 --- a/Modules/Applications/AppSegmentation/app/otbLargeScaleMeanShift.cxx +++ b/Modules/Applications/AppSegmentation/app/otbLargeScaleMeanShift.cxx @@ -33,7 +33,7 @@ namespace Wrapper * * This application gathers the 4 steps of the large-scale MeanShift * segmentation framework. - * + * */ class LargeScaleMeanShift : public CompositeApplication { @@ -192,12 +192,12 @@ private: HasValue("mode.vector.imfield")) { GetInternalApplication("vectorization")->SetParameterInputImage("in", - GetParameterImage<ImageBaseType>("mode.vector.imfield")); + GetParameterImageBase("mode.vector.imfield")); } else { GetInternalApplication("vectorization")->SetParameterInputImage("in", - GetParameterImage<ImageBaseType>("in")); + GetParameterImageBase("in")); } GetInternalApplication("vectorization")->SetParameterString("inseg", tmpFilenames[2]); -- GitLab