diff --git a/Examples/OBIA/RadiometricAttributesLabelMapFilterExample.cxx b/Examples/OBIA/RadiometricAttributesLabelMapFilterExample.cxx index 4b17f87c7eb27f38810bb7691bd740a981a0a8fb..1ab6443c048376eafa4f9cbd31dabafba345711c 100644 --- a/Examples/OBIA/RadiometricAttributesLabelMapFilterExample.cxx +++ b/Examples/OBIA/RadiometricAttributesLabelMapFilterExample.cxx @@ -107,7 +107,7 @@ int main(int argc, char* argv[]) typedef otb::BandsStatisticsAttributesLabelMapFilter<LabelMapType, VectorImageType> RadiometricLabelMapFilterType; typedef otb::AttributesMapOpeningLabelMapFilter<LabelMapType> OpeningLabelMapFilterType; typedef itk::LabelMapToBinaryImageFilter<LabelMapType, MaskImageType> LabelMapToBinaryImageFilterType; - typedef itk::UnaryFunctorImageFilter<VectorImageType, ImageType,otb::Functor::NDVI<PixelType,PixelType> > NDVIImageFilterType; + typedef itk::UnaryFunctorImageFilter<VectorImageType, ImageType, otb::Functor::NDVI<PixelType, PixelType>> NDVIImageFilterType; typedef otb::ImageToVectorImageCastFilter<ImageType, VectorImageType> ImageToVectorImageCastFilterType; ReaderType::Pointer reader = ReaderType::New(); @@ -166,8 +166,8 @@ int main(int argc, char* argv[]) // In our case, statistics are computed on the NDVI coefficient on each label object. NDVIImageFilterType::Pointer ndviImageFilter = NDVIImageFilterType::New(); - ndviImageFilter->GetFunctor().SetBandIndex(CommonBandNames::RED,3); - ndviImageFilter->GetFunctor().SetBandIndex(CommonBandNames::NIR,4); + ndviImageFilter->GetFunctor().SetBandIndex(CommonBandNames::RED, 3); + ndviImageFilter->GetFunctor().SetBandIndex(CommonBandNames::NIR, 4); ndviImageFilter->SetInput(vreader->GetOutput()); ImageToVectorImageCastFilterType::Pointer ndviVectorImageFilter = ImageToVectorImageCastFilterType::New(); diff --git a/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx b/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx index 8f0f2d304f9da22018aaca1248d5112069b2f6a0..6845750ac2c420db14567e6aa6dc0c85b720072e 100644 --- a/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx +++ b/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx @@ -26,7 +26,7 @@ Output/pretty_ARVIMultiChannelRAndBAndNIRVegetationIndex.png \ 1 \ 3 \ - 2 + 2 */ @@ -133,9 +133,9 @@ int main(int argc, char* argv[]) writer->SetFileName(argv[2]); // The three used index bands (red, blue and NIR) are declared. - filter->GetFunctor().SetBandIndex(CommonBandNames::RED,::atoi(argv[5])); - filter->GetFunctor().SetBandIndex(CommonBandNames::BLUE,::atoi(argv[6])); - filter->GetFunctor().SetBandIndex(CommonBandNames::NIR,::atoi(argv[7])); + filter->GetFunctor().SetBandIndex(CommonBandNames::RED, ::atoi(argv[5])); + filter->GetFunctor().SetBandIndex(CommonBandNames::BLUE, ::atoi(argv[6])); + filter->GetFunctor().SetBandIndex(CommonBandNames::NIR, ::atoi(argv[7])); // The filter input is linked to the reader output and // the filter output is linked to the writer input. diff --git a/Examples/Radiometry/AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx b/Examples/Radiometry/AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx index 5d740c7ae790dfb9213f51fd5db82eb72ef08605..d42f8cd56e1227d88f1fe1b8bd956538a4bb80aa 100644 --- a/Examples/Radiometry/AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx +++ b/Examples/Radiometry/AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) { std::cerr << "Missing Parameters " << std::endl; std::cerr << "Usage: " << argv[0]; - std::cerr << " inputImage , outputImage , prettyInput , prettyOutput , redChannel , greenChannel , nirChannel ,"<<std::endl; + std::cerr << " inputImage , outputImage , prettyInput , prettyOutput , redChannel , greenChannel , nirChannel ," << std::endl; return 1; } @@ -119,9 +119,9 @@ int main(int argc, char* argv[]) // The three used index bands (red, green and NIR) are declared. - filter->GetFunctor().SetBandIndex(CommonBandNames::RED,::atoi(argv[5])); - filter->GetFunctor().SetBandIndex(CommonBandNames::GREEN,::atoi(argv[6])); - filter->GetFunctor().SetBandIndex(CommonBandNames::NIR,::atoi(argv[7])); + filter->GetFunctor().SetBandIndex(CommonBandNames::RED, ::atoi(argv[5])); + filter->GetFunctor().SetBandIndex(CommonBandNames::GREEN, ::atoi(argv[6])); + filter->GetFunctor().SetBandIndex(CommonBandNames::NIR, ::atoi(argv[7])); // The filter input is linked to the reader output and // the filter output is linked to the writer input. diff --git a/Examples/Simulation/LAIFromNDVIImageTransform.cxx b/Examples/Simulation/LAIFromNDVIImageTransform.cxx index 016be8536aeeb8f0149ca04b6c6c13a4c453ffa6..133e5dd6444ddfd50625cc421e9642dc5558bd98 100644 --- a/Examples/Simulation/LAIFromNDVIImageTransform.cxx +++ b/Examples/Simulation/LAIFromNDVIImageTransform.cxx @@ -64,8 +64,7 @@ int main(int argc, char* argv[]) // Filter type is a generic \doxygen{itk}{UnaryFunctorImageFilter} using Formosat2 specific LAI // \doxygen{otb}{LAIFromNDVIFormosat2Functor}. - typedef otb::Functor::LAIFromNDVIFormosat2Functor<InputImageType::InternalPixelType, OutputImageType::PixelType> - FunctorType; + typedef otb::Functor::LAIFromNDVIFormosat2Functor<InputImageType::InternalPixelType, OutputImageType::PixelType> FunctorType; typedef itk::UnaryFunctorImageFilter<InputImageType, OutputImageType, FunctorType> LAIFRomNDVIImageFilterType; // Instantiating object @@ -96,8 +95,8 @@ int main(int argc, char* argv[]) // unsigned int redChannel = static_cast<unsigned int>(atoi(argv[5])); unsigned int nirChannel = static_cast<unsigned int>(atoi(argv[6])); - filter->GetFunctor().SetBandIndex(CommonBandNames::RED,redChannel); - filter->GetFunctor().SetBandIndex(CommonBandNames::NIR,nirChannel); + filter->GetFunctor().SetBandIndex(CommonBandNames::RED, redChannel); + filter->GetFunctor().SetBandIndex(CommonBandNames::NIR, nirChannel); // The invocation of the \code{Update()} method triggers the // execution of the pipeline. diff --git a/Modules/Applications/AppIndices/app/otbRadiometricIndices.cxx b/Modules/Applications/AppIndices/app/otbRadiometricIndices.cxx index ee70a26325eda212178e79a4bbe2fab6c9d04db0..082106fd43fca3df6e443e7cea0009cfc873cd8e 100644 --- a/Modules/Applications/AppIndices/app/otbRadiometricIndices.cxx +++ b/Modules/Applications/AppIndices/app/otbRadiometricIndices.cxx @@ -47,19 +47,19 @@ public: itkNewMacro(Self); itkTypeMacro(RadiometricIndices, otb::Wrapper::Application); - - using InputType = FloatVectorImageType::InternalPixelType; + + using InputType = FloatVectorImageType::InternalPixelType; using OutputType = FloatImageType::PixelType; - using RadiometricIndexType = otb::Functor::RadiometricIndex<InputType, OutputType>; + using RadiometricIndexType = otb::Functor::RadiometricIndex<InputType, OutputType>; using IndicesStackFunctorType = otb::Functor::IndicesStackFunctor<RadiometricIndexType>; class indiceSpec { public: - indiceSpec(std::string k, std::string i, RadiometricIndexType * ind) - : key(k), item(i), indice(ind) - {} + indiceSpec(std::string k, std::string i, RadiometricIndexType* ind) : key(k), item(i), indice(ind) + { + } std::string key; std::string item; std::unique_ptr<RadiometricIndexType> indice; @@ -94,52 +94,52 @@ private: AddParameter(ParameterType_Int, "channels.blue", "Blue Channel"); SetParameterDescription("channels.blue", "Blue channel index"); SetDefaultParameterInt("channels.blue", 1); - SetMinimumParameterIntValue("channels.blue",1); + SetMinimumParameterIntValue("channels.blue", 1); AddParameter(ParameterType_Int, "channels.green", "Green Channel"); SetParameterDescription("channels.green", "Green channel index"); SetDefaultParameterInt("channels.green", 1); - SetMinimumParameterIntValue("channels.green",1); + SetMinimumParameterIntValue("channels.green", 1); AddParameter(ParameterType_Int, "channels.red", "Red Channel"); SetParameterDescription("channels.red", "Red channel index"); SetDefaultParameterInt("channels.red", 1); - SetMinimumParameterIntValue("channels.red",1); + SetMinimumParameterIntValue("channels.red", 1); AddParameter(ParameterType_Int, "channels.nir", "NIR Channel"); SetParameterDescription("channels.nir", "NIR channel index"); SetDefaultParameterInt("channels.nir", 1); - SetMinimumParameterIntValue("channels.nir",1); + SetMinimumParameterIntValue("channels.nir", 1); AddParameter(ParameterType_Int, "channels.mir", "Mir Channel"); SetParameterDescription("channels.mir", "Mir channel index"); SetDefaultParameterInt("channels.mir", 1); - SetMinimumParameterIntValue("channels.mir",1); + SetMinimumParameterIntValue("channels.mir", 1); AddParameter(ParameterType_ListView, "list", "Available Radiometric Indices"); SetParameterDescription("list", - "List of available radiometric indices with their relevant channels in brackets:\n\n" - "* Vegetation:NDVI - Normalized difference vegetation index (Red, NIR)\n" - "* Vegetation:TNDVI - Transformed normalized difference vegetation index (Red, NIR)\n" - "* Vegetation:RVI - Ratio vegetation index (Red, NIR)\n" - "* Vegetation:SAVI - Soil adjusted vegetation index (Red, NIR)\n" - "* Vegetation:TSAVI - Transformed soil adjusted vegetation index (Red, NIR)\n" - "* Vegetation:MSAVI - Modified soil adjusted vegetation index (Red, NIR)\n" - "* Vegetation:MSAVI2 - Modified soil adjusted vegetation index 2 (Red, NIR)\n" - "* Vegetation:GEMI - Global environment monitoring index (Red, NIR)\n" - "* Vegetation:IPVI - Infrared percentage vegetation index (Red, NIR)\n" - "* Vegetation:LAIFromNDVILog - Leaf Area Index from log NDVI (Red, NIR)\n" - "* Vegetation::LAIFromReflLinear - Leaf Area Index from reflectances with linear combination (Red, NIR)\n" - "* Vegetation::LAIFromNDVIFormo - Leaf Area Index from Formosat 2 TOC (Red, NIR)\n" - "* Water:NDWI - Normalized difference water index (Gao 1996) (NIR, MIR)\n" - "* Water:NDWI2 - Normalized difference water index (Mc Feeters 1996) (Green, NIR)\n" - "* Water:MNDWI - Modified normalized difference water index (Xu 2006) (Green, MIR)\n" - "* Water:NDTI - Normalized difference turbidity index (Lacaux et al.) (Red, Green)\n" - "* Soil:RI - Redness index (Red, Green)\n" - "* Soil:CI - Color index (Red, Green)\n" - "* Soil:BI - Brightness index (Red, Green)\n" - "* Soil:BI2 - Brightness index 2 (NIR, Red, Green)\n" - "* BuiltUp:ISU - Built Surfaces Index (NIR,Red) "); + "List of available radiometric indices with their relevant channels in brackets:\n\n" + "* Vegetation:NDVI - Normalized difference vegetation index (Red, NIR)\n" + "* Vegetation:TNDVI - Transformed normalized difference vegetation index (Red, NIR)\n" + "* Vegetation:RVI - Ratio vegetation index (Red, NIR)\n" + "* Vegetation:SAVI - Soil adjusted vegetation index (Red, NIR)\n" + "* Vegetation:TSAVI - Transformed soil adjusted vegetation index (Red, NIR)\n" + "* Vegetation:MSAVI - Modified soil adjusted vegetation index (Red, NIR)\n" + "* Vegetation:MSAVI2 - Modified soil adjusted vegetation index 2 (Red, NIR)\n" + "* Vegetation:GEMI - Global environment monitoring index (Red, NIR)\n" + "* Vegetation:IPVI - Infrared percentage vegetation index (Red, NIR)\n" + "* Vegetation:LAIFromNDVILog - Leaf Area Index from log NDVI (Red, NIR)\n" + "* Vegetation::LAIFromReflLinear - Leaf Area Index from reflectances with linear combination (Red, NIR)\n" + "* Vegetation::LAIFromNDVIFormo - Leaf Area Index from Formosat 2 TOC (Red, NIR)\n" + "* Water:NDWI - Normalized difference water index (Gao 1996) (NIR, MIR)\n" + "* Water:NDWI2 - Normalized difference water index (Mc Feeters 1996) (Green, NIR)\n" + "* Water:MNDWI - Modified normalized difference water index (Xu 2006) (Green, MIR)\n" + "* Water:NDTI - Normalized difference turbidity index (Lacaux et al.) (Red, Green)\n" + "* Soil:RI - Redness index (Red, Green)\n" + "* Soil:CI - Color index (Red, Green)\n" + "* Soil:BI - Brightness index (Red, Green)\n" + "* Soil:BI2 - Brightness index 2 (NIR, Red, Green)\n" + "* BuiltUp:ISU - Built Surfaces Index (NIR,Red) "); AddRAMParameter(); @@ -152,27 +152,27 @@ private: m_Map.clear(); - m_Map.push_back({"list.ndvi","Vegetation:NDVI",new otb::Functor::NDVI<InputType,OutputType>()}); - m_Map.push_back({"list.tndvi","Vegetation:TNDVI",new otb::Functor::TNDVI<InputType,OutputType>()}); - m_Map.push_back({"list.rdvi","Vegetation:RVI",new otb::Functor::RVI<InputType,OutputType>()}); - m_Map.push_back({"list.savi","Vegetation:SAVI",new otb::Functor::SAVI<InputType,OutputType>()}); - m_Map.push_back({"list.tsavi","Vegetation:TSAVI",new otb::Functor::TSAVI<InputType,OutputType>()}); - m_Map.push_back({"list.msavi","Vegetation:MSAVI",new otb::Functor::MSAVI<InputType,OutputType>()}); - m_Map.push_back({"list.msavi2","Vegetation:MSAVI2",new otb::Functor::MSAVI2<InputType,OutputType>()}); - m_Map.push_back({"list.gemi","Vegetation:GEMI",new otb::Functor::GEMI<InputType,OutputType>()}); - m_Map.push_back({"list.ipvi","Vegetation:IPVI",new otb::Functor::IPVI<InputType,OutputType>()}); - m_Map.push_back({"list.laindvilog","Vegetation:LAIFromNDVILog",new otb::Functor::LAIFromNDVILogarithmic<InputType,OutputType>()}); - m_Map.push_back({"list.lairefl","Vegetation:LAIFromReflLinear",new otb::Functor::LAIFromReflectancesLinear<InputType,OutputType>()}); - m_Map.push_back({"list.laindviformo","Vegetation:LAIFromNDVIFormo",new otb::Functor::LAIFromNDVIFormosat2Functor<InputType,OutputType>()}); - m_Map.push_back({"list.ndwi","Water:NDWI",new otb::Functor::NDWI<InputType,OutputType>()}); - m_Map.push_back({"list.ndwi2","Water:NDWI2",new otb::Functor::NDWI2<InputType,OutputType>()}); - m_Map.push_back({"list.mndwi","Water:MNDWI",new otb::Functor::MNDWI<InputType,OutputType>()}); - m_Map.push_back({"list.ndti","Water:NDTI",new otb::Functor::NDTI<InputType,OutputType>()}); - m_Map.push_back({"list.ri","Soil:RI",new otb::Functor::RI<InputType,OutputType>()}); - m_Map.push_back({"list.ci","Soil:CI",new otb::Functor::CI<InputType,OutputType>()}); - m_Map.push_back({"list.bi","Soil:BI",new otb::Functor::BI<InputType,OutputType>()}); - m_Map.push_back({"list.bi2","Soil:BI2",new otb::Functor::BI2<InputType,OutputType>()}); - m_Map.push_back({"list.isu","BuiltUp:ISU",new otb::Functor::ISU<InputType,OutputType>()}); + m_Map.push_back({"list.ndvi", "Vegetation:NDVI", new otb::Functor::NDVI<InputType, OutputType>()}); + m_Map.push_back({"list.tndvi", "Vegetation:TNDVI", new otb::Functor::TNDVI<InputType, OutputType>()}); + m_Map.push_back({"list.rdvi", "Vegetation:RVI", new otb::Functor::RVI<InputType, OutputType>()}); + m_Map.push_back({"list.savi", "Vegetation:SAVI", new otb::Functor::SAVI<InputType, OutputType>()}); + m_Map.push_back({"list.tsavi", "Vegetation:TSAVI", new otb::Functor::TSAVI<InputType, OutputType>()}); + m_Map.push_back({"list.msavi", "Vegetation:MSAVI", new otb::Functor::MSAVI<InputType, OutputType>()}); + m_Map.push_back({"list.msavi2", "Vegetation:MSAVI2", new otb::Functor::MSAVI2<InputType, OutputType>()}); + m_Map.push_back({"list.gemi", "Vegetation:GEMI", new otb::Functor::GEMI<InputType, OutputType>()}); + m_Map.push_back({"list.ipvi", "Vegetation:IPVI", new otb::Functor::IPVI<InputType, OutputType>()}); + m_Map.push_back({"list.laindvilog", "Vegetation:LAIFromNDVILog", new otb::Functor::LAIFromNDVILogarithmic<InputType, OutputType>()}); + m_Map.push_back({"list.lairefl", "Vegetation:LAIFromReflLinear", new otb::Functor::LAIFromReflectancesLinear<InputType, OutputType>()}); + m_Map.push_back({"list.laindviformo", "Vegetation:LAIFromNDVIFormo", new otb::Functor::LAIFromNDVIFormosat2Functor<InputType, OutputType>()}); + m_Map.push_back({"list.ndwi", "Water:NDWI", new otb::Functor::NDWI<InputType, OutputType>()}); + m_Map.push_back({"list.ndwi2", "Water:NDWI2", new otb::Functor::NDWI2<InputType, OutputType>()}); + m_Map.push_back({"list.mndwi", "Water:MNDWI", new otb::Functor::MNDWI<InputType, OutputType>()}); + m_Map.push_back({"list.ndti", "Water:NDTI", new otb::Functor::NDTI<InputType, OutputType>()}); + m_Map.push_back({"list.ri", "Soil:RI", new otb::Functor::RI<InputType, OutputType>()}); + m_Map.push_back({"list.ci", "Soil:CI", new otb::Functor::CI<InputType, OutputType>()}); + m_Map.push_back({"list.bi", "Soil:BI", new otb::Functor::BI<InputType, OutputType>()}); + m_Map.push_back({"list.bi2", "Soil:BI2", new otb::Functor::BI2<InputType, OutputType>()}); + m_Map.push_back({"list.isu", "BuiltUp:ISU", new otb::Functor::ISU<InputType, OutputType>()}); ClearChoices("list"); @@ -186,12 +186,12 @@ private: std::set<CommonBandNames> GetRequiredBands() { std::set<CommonBandNames> required; - + for (unsigned int idx = 0; idx < GetSelectedItems("list").size(); ++idx) - { - auto requiredForCurrentIndice = m_Map[GetSelectedItems("list")[idx]].indice->GetRequiredBands(); - required.insert(requiredForCurrentIndice.begin(),requiredForCurrentIndice.end()); - } + { + auto requiredForCurrentIndice = m_Map[GetSelectedItems("list")[idx]].indice->GetRequiredBands(); + required.insert(requiredForCurrentIndice.begin(), requiredForCurrentIndice.end()); + } return required; } @@ -209,63 +209,61 @@ private: auto requiredBands = GetRequiredBands(); // Map to store association between bands and indices - std::map<CommonBandNames,size_t> bandIndicesMap; + std::map<CommonBandNames, size_t> bandIndicesMap; // Lambda that will: // - Check if band is required, // - Check band index range, // - Populate the bandIndicesMap - auto bandChecker = [this,requiredBands, nbChan] (std::map<CommonBandNames, size_t> & indicesMap, const CommonBandNames& band, const std::string & key) - { - if(requiredBands.find(band) != requiredBands.end()) + auto bandChecker = [this, requiredBands, nbChan](std::map<CommonBandNames, size_t>& indicesMap, const CommonBandNames& band, const std::string& key) { + if (requiredBands.find(band) != requiredBands.end()) + { + unsigned int idx = this->GetParameterInt(key); + + if (idx > nbChan) { - unsigned int idx = this->GetParameterInt(key); - - if(idx > nbChan) - { - otbAppLogFATAL(<<"Index for band "<<key<<" exceeds the number of channels in image ("<<nbChan<<")"); - } - else - { - indicesMap[band] = idx; - } + otbAppLogFATAL(<< "Index for band " << key << " exceeds the number of channels in image (" << nbChan << ")"); } + else + { + indicesMap[band] = idx; + } + } }; // Call lambda for each possible band - bandChecker(bandIndicesMap,CommonBandNames::BLUE,"channels.blue"); - bandChecker(bandIndicesMap,CommonBandNames::GREEN,"channels.green"); - bandChecker(bandIndicesMap,CommonBandNames::RED,"channels.red"); - bandChecker(bandIndicesMap,CommonBandNames::NIR,"channels.nir"); - bandChecker(bandIndicesMap,CommonBandNames::MIR,"channels.mir"); + bandChecker(bandIndicesMap, CommonBandNames::BLUE, "channels.blue"); + bandChecker(bandIndicesMap, CommonBandNames::GREEN, "channels.green"); + bandChecker(bandIndicesMap, CommonBandNames::RED, "channels.red"); + bandChecker(bandIndicesMap, CommonBandNames::NIR, "channels.nir"); + bandChecker(bandIndicesMap, CommonBandNames::MIR, "channels.mir"); std::vector<RadiometricIndexType*> indices; // Find selected indices - for(unsigned int idx = 0; idx < GetSelectedItems("list").size(); ++idx) - { + for (unsigned int idx = 0; idx < GetSelectedItems("list").size(); ++idx) + { // Retrieve the indice instance indices.push_back(m_Map[GetSelectedItems("list")[idx]].indice.get()); - + // And set bands using the band map indices.back()->SetBandsIndices(bandIndicesMap); } - // Build a composite indices functor to compute all indices at - // once - auto compositeFunctor = IndicesStackFunctorType(indices); + // Build a composite indices functor to compute all indices at + // once + auto compositeFunctor = IndicesStackFunctorType(indices); - // Build and plug functor filter - auto filter = NewFunctorFilter(compositeFunctor); - filter->SetInputs(GetParameterImage("in")); - SetParameterOutputImage("out", filter->GetOutput()); + // Build and plug functor filter + auto filter = NewFunctorFilter(compositeFunctor); + filter->SetInputs(GetParameterImage("in")); + SetParameterOutputImage("out", filter->GetOutput()); - // Call register pipeline to allow streaming and garbage collection - RegisterPipeline(); + // Call register pipeline to allow streaming and garbage collection + RegisterPipeline(); } std::vector<indiceSpec> m_Map; - }; } diff --git a/Modules/Detection/UrbanArea/include/otbUrbanAreaDetectionImageFilter.h b/Modules/Detection/UrbanArea/include/otbUrbanAreaDetectionImageFilter.h index 73c3c13cc2c92819ff923844936e5b6ee1b1664f..c178c9acc56ab65b4118729618177488b95368cd 100644 --- a/Modules/Detection/UrbanArea/include/otbUrbanAreaDetectionImageFilter.h +++ b/Modules/Detection/UrbanArea/include/otbUrbanAreaDetectionImageFilter.h @@ -51,19 +51,25 @@ template<class TInput, class TOutput = double> class RadiometricNonWaterNonVegetationIndexFunctor { public: - typedef Functor::NDVI<double, double> VegetationFunctorType; - typedef Functor::NDWI2<double, double> WaterFunctorType; + typedef Functor::NDVI<double, double> VegetationFunctorType; + typedef Functor::NDWI2<double, double> WaterFunctorType; typedef TOutput ValueType; VegetationFunctorType GetVegetationFunctor(){ return m_VegetationFunctor; } WaterFunctorType GetWaterFunctor(){ return m_WaterFunctor; } - void SetRedIndex(int id){ m_VegetationFunctor.SetBandIndex(CommonBandNames::RED,id); } - void SetGreenIndex(int id){ m_WaterFunctor.SetBandIndex(CommonBandNames::GREEN,id); } + void SetRedIndex(int id) + { + m_VegetationFunctor.SetBandIndex(CommonBandNames::RED, id); + } + void SetGreenIndex(int id) + { + m_WaterFunctor.SetBandIndex(CommonBandNames::GREEN, id); + } void SetNIRIndex(int id) { - m_VegetationFunctor.SetBandIndex(CommonBandNames::NIR,id); - m_WaterFunctor.SetBandIndex(CommonBandNames::NIR,id); + m_VegetationFunctor.SetBandIndex(CommonBandNames::NIR, id); + m_WaterFunctor.SetBandIndex(CommonBandNames::NIR, id); } RadiometricNonWaterNonVegetationIndexFunctor(){} diff --git a/Modules/Radiometry/Indices/include/otbBandName.h b/Modules/Radiometry/Indices/include/otbBandName.h index 01b899b044ecb639be7d1e5d572fb5e501b0f798..118086139976cff411152658b054e26c59e93a44 100644 --- a/Modules/Radiometry/Indices/include/otbBandName.h +++ b/Modules/Radiometry/Indices/include/otbBandName.h @@ -27,11 +27,30 @@ namespace BandName { /** -* Provides a way to identify bands when passing the parameters -* to the radiometric functors.* -*/ -enum class CommonBandNames {BLUE, GREEN, RED, NIR, MIR, MAX}; -enum LandsatTMBandNames {TM1, TM2, TM3, TM4, TM5, TM60, TM61, TM62, TM7}; + * Provides a way to identify bands when passing the parameters + * to the radiometric functors.* + */ +enum class CommonBandNames +{ + BLUE, + GREEN, + RED, + NIR, + MIR, + MAX +}; +enum LandsatTMBandNames +{ + TM1, + TM2, + TM3, + TM4, + TM5, + TM60, + TM61, + TM62, + TM7 +}; // Note for landsat equivalence // http://landsat.gsfc.nasa.gov/news/news-archive/sci_0017.html @@ -57,8 +76,8 @@ enum LandsatTMBandNames {TM1, TM2, TM3, TM4, TM5, TM60, TM61, TM62, TM7}; // 6 10.40-12.50 microm Thermal IR // 7 2.08-2.35 microm Mid-IR -} +} // namespace BandName -} +} // namespace otb #endif diff --git a/Modules/Radiometry/Indices/include/otbBuiltUpIndicesFunctor.h b/Modules/Radiometry/Indices/include/otbBuiltUpIndicesFunctor.h index fe0ac92916a39ab69a083f5cf656fef2619e972d..426548fd5fc40aedf09bed790d64ccb4e2431d08 100644 --- a/Modules/Radiometry/Indices/include/otbBuiltUpIndicesFunctor.h +++ b/Modules/Radiometry/Indices/include/otbBuiltUpIndicesFunctor.h @@ -38,22 +38,24 @@ namespace Functor * \ingroup OTBIndices */ template <class TInput, class TOutput> -class ISU : public RadiometricIndex<TInput,TOutput> +class ISU : public RadiometricIndex<TInput, TOutput> { public: - ISU() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + ISU() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); if (nir == 0) - { + { return static_cast<TOutput>(0.); } - return (static_cast<TOutput>(A - (B * red) / nir)); + return (static_cast<TOutput>(A - (B * red) / nir)); } static constexpr double A = 100.; diff --git a/Modules/Radiometry/Indices/include/otbIndicesStackFunctor.h b/Modules/Radiometry/Indices/include/otbIndicesStackFunctor.h index c131a994e857dec593e8ec7f42b54ec08379ea9f..257f66a84dc7a581a14ad2e1133c2aedf142a7f2 100644 --- a/Modules/Radiometry/Indices/include/otbIndicesStackFunctor.h +++ b/Modules/Radiometry/Indices/include/otbIndicesStackFunctor.h @@ -24,20 +24,22 @@ #include <vector> #include <stdexcept> -namespace otb { +namespace otb +{ -namespace Functor { +namespace Functor +{ /** * \class IndicesStackFunctor * \brief A class to compute a stack of radiometric indices - * + * * This functor can be built from a vector of TIndice*. its operator() * will apply each functor of this vector to the input pixel, and * return a VariableLengthVector containing the list resulting * values. It can be used with otb::FunctorImageFilter * * \sa FunctorImageFilter - * + * * \ingroup OTBIndices */ template <typename TIndice> @@ -56,37 +58,36 @@ public: * the indice stack * \throw std::runtime_error if indices is empty */ - IndicesStackFunctor(const std::vector<IndiceType*> & indices) - : m_Indices(std::move(indices)) + IndicesStackFunctor(const std::vector<IndiceType*>& indices) : m_Indices(std::move(indices)) { - if(indices.empty()) - { + if (indices.empty()) + { throw std::runtime_error("Can not build IndicesStackFunctor from an empty list of indices."); - } + } } - /** + /** * \param input A itk::VariableLengthVector<TInput> holding the * pixel values for each band * \return A VariableLengthVector<TInput::OutputType> holding all * the indices values */ - void operator()(OutputType & out, const PixelType & in) const + void operator()(OutputType& out, const PixelType& in) const { size_t idx = 0; - for(auto indice : m_Indices) - { + for (auto indice : m_Indices) + { out[idx] = (*indice)(in); ++idx; - } + } } /** - * \return the size of the indices list (to be used by FunctorImgeFilter) + * \return the size of the indices list (to be used by FunctorImgeFilter) */ size_t OutputSize(...) const { return m_Indices.size(); - } + } private: /// The list of indices to use diff --git a/Modules/Radiometry/Indices/include/otbNDVIDataNodeFeatureFunction.h b/Modules/Radiometry/Indices/include/otbNDVIDataNodeFeatureFunction.h index 1097860300f54ec0230ffb0472767088d73ea963..9d17e0198a0af4e365c7af5747f8edd91e1bb1ad 100644 --- a/Modules/Radiometry/Indices/include/otbNDVIDataNodeFeatureFunction.h +++ b/Modules/Radiometry/Indices/include/otbNDVIDataNodeFeatureFunction.h @@ -83,8 +83,7 @@ public: typedef PolyLineImageConstIterator<InputImageType, LineType> ImageLineIteratorType; - typedef Functor::NDVI<ScalarRealType, ScalarRealType> - NDVIFunctorType; + typedef Functor::NDVI<ScalarRealType, ScalarRealType> NDVIFunctorType; typedef std::vector<PrecisionType> OutputType; @@ -102,7 +101,7 @@ public: void SetREDChannelIndex(unsigned int id) { - m_NDVIFunctor.SetBandIndex(CommonBandNames::RED,id); + m_NDVIFunctor.SetBandIndex(CommonBandNames::RED, id); } unsigned int GetNIRChannelIndex() const @@ -112,7 +111,7 @@ public: void SetNIRChannelIndex(unsigned int id) { - m_NDVIFunctor.SetBandIndex(CommonBandNames::NIR,id); + m_NDVIFunctor.SetBandIndex(CommonBandNames::NIR, id); } protected: diff --git a/Modules/Radiometry/Indices/include/otbRadiometricIndex.h b/Modules/Radiometry/Indices/include/otbRadiometricIndex.h index 8683f3ecdb0c33d24b8589dadcaf9ef4f6018a8a..f79aefe4ea53e5088b802e0e1fd718f5a2db4278 100644 --- a/Modules/Radiometry/Indices/include/otbRadiometricIndex.h +++ b/Modules/Radiometry/Indices/include/otbRadiometricIndex.h @@ -38,23 +38,23 @@ namespace Functor /** * \class RadiometricIndex * \brief Base class for all radiometric indices - * + * * This class is the base class for all radiometric indices. - * + * * It offers services to: * - Indicate which band are required among the list provided by * TBandNameEnum * - Set indices of each required band * - Compute the indice response to a pixel by subclassing the pure * virtual operator() - * + * * This class is designed for performance on the critical path. For * best performances use the Value() method when implementing * operator() to avoid branches. - * + * * TBandName enum should end with a MAX value that will be used to * derive the number of bands. - * + * * \ingroup OTBIndices */ template <typename TInput, typename TOutput, typename TBandNameEnum = CommonBandNames> @@ -62,8 +62,8 @@ class RadiometricIndex { public: /// Types for input/output - using InputType = TInput; - using PixelType = itk::VariableLengthVector<InputType>; + using InputType = TInput; + using PixelType = itk::VariableLengthVector<InputType>; using OutputType = TOutput; /// Enum Among which bands are used @@ -74,27 +74,25 @@ public: static constexpr double Epsilon = 0.0000001; - /** - * \param requiredBands the set<TBandNameEnum> of required bands + /** + * \param requiredBands the set<TBandNameEnum> of required bands * \throw runtime_error if requiredBands contains TBandNameEnum::MAX */ - RadiometricIndex(const std::set<BandNameType>& requiredBands) - : m_RequiredBands(), - m_BandIndices() + RadiometricIndex(const std::set<BandNameType>& requiredBands) : m_RequiredBands(), m_BandIndices() { - if(requiredBands.find(BandNameType::MAX) != requiredBands.end()) - { + if (requiredBands.find(BandNameType::MAX) != requiredBands.end()) + { throw std::runtime_error("TBandNameEnum::MAX can not be used as a required band"); - } + } // Fill the required bands array m_RequiredBands.fill(false); m_BandIndices.fill(0); - for(auto b : requiredBands) - { - m_RequiredBands[static_cast<size_t>(b)]=true; - } + for (auto b : requiredBands) + { + m_RequiredBands[static_cast<size_t>(b)] = true; + } } /** @@ -104,13 +102,13 @@ public: std::set<BandNameType> GetRequiredBands() const { std::set<BandNameType> resp; - for(size_t i = 0; i < NumberOfBands; ++i) + for (size_t i = 0; i < NumberOfBands; ++i) + { + if (m_RequiredBands[i]) { - if(m_RequiredBands[i]) - { resp.insert(static_cast<BandNameType>(i)); - } } + } return resp; } @@ -122,11 +120,11 @@ public: */ void SetBandIndex(BandNameType band, size_t index) { - if(band == BandNameType::MAX) - { + if (band == BandNameType::MAX) + { throw std::runtime_error("Can not set index for TBandNameEnum::MAX"); - } - m_BandIndices[static_cast<size_t>(band)]=index; + } + m_BandIndices[static_cast<size_t>(band)] = index; } /** @@ -134,12 +132,12 @@ public: * bands indices to set (starts at 1 for first band) * \throw runtime_error if indicesMap contains TBandNameEnum::MAX */ - void SetBandsIndices(const std::map<BandNameType,size_t> & indicesMap) + void SetBandsIndices(const std::map<BandNameType, size_t>& indicesMap) { - for(auto it: indicesMap) - { - SetBandIndex(it.first,it.second); - } + for (auto it : indicesMap) + { + SetBandIndex(it.first, it.second); + } } /** @@ -149,10 +147,10 @@ public: */ size_t GetBandIndex(BandNameType band) const { - if(band == BandNameType::MAX) - { + if (band == BandNameType::MAX) + { throw std::runtime_error("Can not get index for TBandNameEnum::MAX"); - } + } return m_BandIndices[static_cast<size_t>(band)]; } @@ -162,7 +160,7 @@ public: * pixel values for each band * \return The indice value as TOutput (starts at 1 for first band) */ - virtual TOutput operator()(const itk::VariableLengthVector<TInput> & input) const = 0; + virtual TOutput operator()(const itk::VariableLengthVector<TInput>& input) const = 0; protected: /** @@ -181,11 +179,11 @@ protected: assert(band != BandNameType::MAX && "Can not retrieve index for band TBandNameEnum::MAX"); return m_BandIndices[static_cast<size_t>(band)]; } - + /** * Helper method to parse input itk::VariableLengthVector<TInput> * and get the corresponding band value. - * For instance: + * For instance: * \snippet auto red = this->Value(CommonBandNames::RED,input); * * As this function is on the critical performance path, no checks @@ -197,11 +195,11 @@ protected: * pixel values for each band * \return The value of the band as double * - */ - double Value(BandNameType band, const itk::VariableLengthVector<TInput> & input) const + */ + double Value(BandNameType band, const itk::VariableLengthVector<TInput>& input) const { assert(m_RequiredBands[band] && "Retrieving value for a band that is not in the required bands list"); - return static_cast<double>(input[UncheckedBandIndex(band)-1]); + return static_cast<double>(input[UncheckedBandIndex(band) - 1]); } private: @@ -209,15 +207,15 @@ private: RadiometricIndex() = delete; /// An array storing the required status for each band - using RequiredBandsContainer = std::array<bool,NumberOfBands>; + using RequiredBandsContainer = std::array<bool, NumberOfBands>; RequiredBandsContainer m_RequiredBands; /// An array storing the indice for each band - using BandIndicesContainer = std::array<size_t,NumberOfBands>; - BandIndicesContainer m_BandIndices; + using BandIndicesContainer = std::array<size_t, NumberOfBands>; + BandIndicesContainer m_BandIndices; }; -} // End namespace Indices +} // namespace Functor } // End namespace otb #endif diff --git a/Modules/Radiometry/Indices/include/otbSoilIndicesFunctor.h b/Modules/Radiometry/Indices/include/otbSoilIndicesFunctor.h index d3193ce7c2bfda3680d782a11c01e97c6e0c8e03..aaedbc7c0efe62610a54a97817c87e52ff26dd1d 100644 --- a/Modules/Radiometry/Indices/include/otbSoilIndicesFunctor.h +++ b/Modules/Radiometry/Indices/include/otbSoilIndicesFunctor.h @@ -43,22 +43,24 @@ namespace Functor * \ingroup OTBIndices */ template <class TInput, class TOutput> -class RI : public RadiometricIndex<TInput,TOutput> +class RI : public RadiometricIndex<TInput, TOutput> { public: - RI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::GREEN}) {} + RI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::GREEN}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto green = this->Value(CommonBandNames::GREEN,input); - auto red = this->Value(CommonBandNames::RED,input); - - if (std::abs(green) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + auto green = this->Value(CommonBandNames::GREEN, input); + auto red = this->Value(CommonBandNames::RED, input); + + if (std::abs(green) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return static_cast<TOutput>(0.); } - return static_cast<TOutput>(red * red / (green * green * green)); + return static_cast<TOutput>(red * red / (green * green * green)); } }; @@ -77,22 +79,24 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class CI : public RadiometricIndex<TInput,TOutput> +class CI : public RadiometricIndex<TInput, TOutput> { public: - CI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::GREEN}) {} + CI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::GREEN}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto green = this->Value(CommonBandNames::GREEN,input); - auto red = this->Value(CommonBandNames::RED,input); + auto green = this->Value(CommonBandNames::GREEN, input); + auto red = this->Value(CommonBandNames::RED, input); - if (std::abs(green + red) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(green + red) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return static_cast<TOutput>(0.); } - return (static_cast<TOutput>((red - green) / (red + green))); + return (static_cast<TOutput>((red - green) / (red + green))); } }; @@ -107,15 +111,17 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class BI : public RadiometricIndex<TInput,TOutput> +class BI : public RadiometricIndex<TInput, TOutput> { public: - BI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::GREEN}) {} + BI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::GREEN}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto green = this->Value(CommonBandNames::GREEN,input); - auto red = this->Value(CommonBandNames::RED,input); + auto green = this->Value(CommonBandNames::GREEN, input); + auto red = this->Value(CommonBandNames::RED, input); return (static_cast<TOutput>(std::sqrt((red * red + green * green) / 2.))); } @@ -132,17 +138,18 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class BI2 : public RadiometricIndex<TInput,TOutput> +class BI2 : public RadiometricIndex<TInput, TOutput> { public: - - BI2() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::GREEN, CommonBandNames::NIR}) {} - - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + BI2() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::GREEN, CommonBandNames::NIR}) + { + } + + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto green = this->Value(CommonBandNames::GREEN,input); - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto green = this->Value(CommonBandNames::GREEN, input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); return (static_cast<TOutput>(std::sqrt((red * red + green * green + nir * nir) / 3.))); } diff --git a/Modules/Radiometry/Indices/include/otbVegetationIndicesFunctor.h b/Modules/Radiometry/Indices/include/otbVegetationIndicesFunctor.h index f474469e3d34929ab3152b5d9122077335856fbd..63bc7299527ad45a5ab829f6a69d53f6cab3ec94 100644 --- a/Modules/Radiometry/Indices/include/otbVegetationIndicesFunctor.h +++ b/Modules/Radiometry/Indices/include/otbVegetationIndicesFunctor.h @@ -33,36 +33,37 @@ namespace Functor * \brief This functor computes the Normalized Difference Vegetation Index (NDVI) * * [Rouse et al., 1973] - * + * * \ingroup Functor * \ingroup Radiometry * * \ingroup OTBIndices */ template <class TInput, class TOutput> -class NDVI : public RadiometricIndex<TInput,TOutput> +class NDVI : public RadiometricIndex<TInput, TOutput> { public: - NDVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + NDVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); - return static_cast<TOutput>(Compute(red,nir)); - } + return static_cast<TOutput>(Compute(red, nir)); + } // This static compute will be used in indices derived from NDVI - static double Compute(const double & red, const double & nir) + static double Compute(const double& red, const double& nir) { - if (std::abs(nir + red) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(nir + red) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return 0.; } - return (nir - red) / (nir + red); - + return (nir - red) / (nir + red); } }; @@ -77,21 +78,23 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class RVI : public RadiometricIndex<TInput,TOutput> +class RVI : public RadiometricIndex<TInput, TOutput> { public: - RVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + RVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); - if (std::abs(red) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(red) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return static_cast<TOutput>(0.); } - return (static_cast<TOutput>(nir / red)); + return (static_cast<TOutput>(nir / red)); } }; @@ -110,15 +113,17 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class PVI : public RadiometricIndex<TInput,TOutput> +class PVI : public RadiometricIndex<TInput, TOutput> { public: - PVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + PVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); return (static_cast<TOutput>((nir - A * red - B) * C)); } @@ -127,7 +132,6 @@ public: static constexpr double A = 0.90893; static constexpr double B = 7.46216; static constexpr double C = 9.74; - }; /** \class SAVI @@ -141,26 +145,27 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class SAVI : public RadiometricIndex<TInput,TOutput> +class SAVI : public RadiometricIndex<TInput, TOutput> { public: - SAVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + SAVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); - if (std::abs(nir + red + L) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(nir + red + L) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return static_cast<TOutput>(0.); } - return (static_cast<TOutput>(((nir - red) * (1 + L)) / (nir + red + L))); + return (static_cast<TOutput>(((nir - red) * (1 + L)) / (nir + red + L))); } /** L correction */ static constexpr double L = 0.5; - }; /** \class TSAVI @@ -174,23 +179,25 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class TSAVI : public RadiometricIndex<TInput,TOutput> +class TSAVI : public RadiometricIndex<TInput, TOutput> { public: - TSAVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + TSAVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); double denominator = A * nir + red + X * (1. + A * A); - if (std::abs(denominator) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(denominator) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return static_cast<TOutput>(0.); } - return (static_cast<TOutput>((A * (nir - A * red - S)) / denominator)); + return (static_cast<TOutput>((A * (nir - A * red - S)) / denominator)); } /** A and S parameters */ @@ -211,21 +218,23 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class WDVI : public RadiometricIndex<TInput,TOutput> +class WDVI : public RadiometricIndex<TInput, TOutput> { public: /// Constructor - WDVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + WDVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); - return static_cast<TOutput>(Compute(red,nir)); + return static_cast<TOutput>(Compute(red, nir)); } - static double Compute(const double & red, const double & nir) + static double Compute(const double& red, const double& nir) { return (nir - S * red); } @@ -246,29 +255,31 @@ public: */ template <class TInput, class TOutput> -class MSAVI : public RadiometricIndex<TInput,TOutput> +class MSAVI : public RadiometricIndex<TInput, TOutput> { public: - MSAVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + MSAVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); - double ndvi = NDVI<TInput,TOutput>::Compute(red,nir); - double wdvi = WDVI<TInput,TOutput>::Compute(red, nir); + double ndvi = NDVI<TInput, TOutput>::Compute(red, nir); + double wdvi = WDVI<TInput, TOutput>::Compute(red, nir); double L = 1 - 2 * S * ndvi * wdvi; double denominator = nir + red + L; - if (std::abs(denominator) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(denominator) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return static_cast<TOutput>(0.); } - return (static_cast<TOutput>(((nir - red) * (1 + L)) / denominator)); + return (static_cast<TOutput>(((nir - red) * (1 + L)) / denominator)); } private: @@ -287,23 +298,24 @@ private: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class MSAVI2 : public RadiometricIndex<TInput,TOutput> +class MSAVI2 : public RadiometricIndex<TInput, TOutput> { public: + MSAVI2() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - MSAVI2() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} - - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); double sqrt_value = (2 * nir + 1) * (2 * nir + 1) - 8 * (nir - red); if (sqrt_value < 0.) { return static_cast<TOutput>(0.); } - return (static_cast<TOutput>((2 * nir + 1 - std::sqrt(sqrt_value)) / 2.)); + return (static_cast<TOutput>((2 * nir + 1 - std::sqrt(sqrt_value)) / 2.)); } }; @@ -319,36 +331,38 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class GEMI : public RadiometricIndex<TInput,TOutput> +class GEMI : public RadiometricIndex<TInput, TOutput> { public: - GEMI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + GEMI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); double nu; double num_nu; double denom_nu = nir + red + 0.5; - if (std::abs(denom_nu) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(denom_nu) < RadiometricIndex<TInput, TOutput>::Epsilon) + { nu = 0; } else { - num_nu = 2 * (nir * nir - red * red) + 1.5 * nir + 0.5 * red; - nu = num_nu / denom_nu; + num_nu = 2 * (nir * nir - red * red) + 1.5 * nir + 0.5 * red; + nu = num_nu / denom_nu; } - double denom_GEMI = 1 - red; - if (std::abs(denom_GEMI) < RadiometricIndex<TInput,TOutput>::Epsilon) + double denom_GEMI = 1 - red; + if (std::abs(denom_GEMI) < RadiometricIndex<TInput, TOutput>::Epsilon) { return static_cast<TOutput>(0.); } - return (static_cast<TOutput>((nu * (1 - 0.25 * nu) - (red - 0.125)) / denom_GEMI)); + return (static_cast<TOutput>((nu * (1 - 0.25 * nu) - (red - 0.125)) / denom_GEMI)); } }; @@ -366,37 +380,39 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class AVI: public RadiometricIndex<TInput,TOutput> +class AVI : public RadiometricIndex<TInput, TOutput> { public: - AVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::GREEN, CommonBandNames::RED, CommonBandNames::NIR}) {} + AVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::GREEN, CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto green = this->Value(CommonBandNames::GREEN,input); - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto green = this->Value(CommonBandNames::GREEN, input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); constexpr double dfact1 = (LambdaNir - LambdaR) / LambdaR; constexpr double dfact2 = (LambdaR - LambdaG) / LambdaR; double dterm1; double dterm2; - if (std::abs(nir - red) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(nir - red) < RadiometricIndex<TInput, TOutput>::Epsilon) + { dterm1 = 0; } else { - dterm1 = std::atan(dfact1 / (nir - red)); + dterm1 = std::atan(dfact1 / (nir - red)); } - if (std::abs(green - red) < RadiometricIndex<TInput,TOutput>::Epsilon) + if (std::abs(green - red) < RadiometricIndex<TInput, TOutput>::Epsilon) { dterm2 = 0; } else { - dterm2 = std::atan(dfact2 / (green - red)); + dterm2 = std::atan(dfact2 / (green - red)); } return static_cast<TOutput>(dterm1 + dterm2); @@ -426,25 +442,26 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class ARVI : public RadiometricIndex<TInput,TOutput> +class ARVI : public RadiometricIndex<TInput, TOutput> { public: + ARVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::BLUE, CommonBandNames::RED, CommonBandNames::NIR}) + { + } - ARVI(): RadiometricIndex<TInput,TOutput>({CommonBandNames::BLUE, CommonBandNames::RED, CommonBandNames::NIR}) {} - - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto blue = this->Value(CommonBandNames::BLUE,input); - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto blue = this->Value(CommonBandNames::BLUE, input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); - double RHOrb = red - Gamma * (blue - red); + double RHOrb = red - Gamma * (blue - red); double denominator = nir + RHOrb; - if (std::abs(denominator) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(denominator) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return static_cast<TOutput>(0.); } - return (static_cast<TOutput>((nir - RHOrb) / denominator)); + return (static_cast<TOutput>((nir - RHOrb) / denominator)); } /** Gamma parameter */ @@ -464,24 +481,25 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class EVI : public RadiometricIndex<TInput,TOutput> +class EVI : public RadiometricIndex<TInput, TOutput> { public: + EVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::BLUE, CommonBandNames::RED, CommonBandNames::NIR}) + { + } - EVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::BLUE, CommonBandNames::RED, CommonBandNames::NIR}) {} - - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto blue = this->Value(CommonBandNames::BLUE,input); - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto blue = this->Value(CommonBandNames::BLUE, input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); double denominator = nir + C1 * red - C2 * blue + L; - if (std::abs(denominator) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(denominator) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return (static_cast<TOutput>(0.)); } - return (static_cast<TOutput>(G * (nir - red) / denominator)); + return (static_cast<TOutput>(G * (nir - red) / denominator)); } /** Gain factor */ @@ -508,23 +526,25 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class IPVI : public RadiometricIndex<TInput,TOutput> +class IPVI : public RadiometricIndex<TInput, TOutput> { public: - IPVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + IPVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); - if (std::abs(nir + red) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(nir + red) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return static_cast<TOutput>(0.); } else { - return (static_cast<TOutput>(nir / (nir + red))); + return (static_cast<TOutput>(nir / (nir + red))); } } }; @@ -540,25 +560,27 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class TNDVI : public RadiometricIndex<TInput,TOutput> +class TNDVI : public RadiometricIndex<TInput, TOutput> { public: - TNDVI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} + TNDVI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); - double val = NDVI<TInput,TOutput>::Compute(red,nir) + 0.5; + double val = NDVI<TInput, TOutput>::Compute(red, nir) + 0.5; if (val < 0) - { + { return (static_cast<TOutput>(0)); } else { - return (static_cast<TOutput>(std::sqrt(val))); + return (static_cast<TOutput>(std::sqrt(val))); } } }; @@ -580,59 +602,58 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class LAIFromNDVILogarithmic : public RadiometricIndex<TInput,TOutput> +class LAIFromNDVILogarithmic : public RadiometricIndex<TInput, TOutput> { public: - LAIFromNDVILogarithmic() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}), - m_NdviSoil(0.1), - m_NdviInf(0.89), - m_ExtinctionCoefficient(0.71) {} + LAIFromNDVILogarithmic() + : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}), m_NdviSoil(0.1), m_NdviInf(0.89), m_ExtinctionCoefficient(0.71) + { + } - void SetNdviSoil(const double & val) + void SetNdviSoil(const double& val) { m_NdviSoil = val; } - const double & GetNdviSoil() const + const double& GetNdviSoil() const { return m_NdviSoil; } - void SetNdviInf(const double & val) + void SetNdviInf(const double& val) { m_NdviInf = val; } - const double & GetNdviInf() const + const double& GetNdviInf() const { return m_NdviInf; } - void SetExtinctionCoefficient(const double & val) + void SetExtinctionCoefficient(const double& val) { m_ExtinctionCoefficient = val; } - const double & GetExtionctionCoefficient() const + const double& GetExtionctionCoefficient() const { return m_ExtinctionCoefficient; } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); - double val = NDVI<TInput,TOutput>::Compute(red,nir); + double val = NDVI<TInput, TOutput>::Compute(red, nir); if (val < 0) - { + { return (static_cast<TOutput>(0)); } else { - return static_cast<TOutput>( - -(1.0/m_ExtinctionCoefficient)*std::log((val- m_NdviInf)/(m_NdviSoil-m_NdviInf))); + return static_cast<TOutput>(-(1.0 / m_ExtinctionCoefficient) * std::log((val - m_NdviInf) / (m_NdviSoil - m_NdviInf))); } } @@ -660,41 +681,39 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class LAIFromReflectancesLinear : public RadiometricIndex<TInput,TOutput> +class LAIFromReflectancesLinear : public RadiometricIndex<TInput, TOutput> { public: + LAIFromReflectancesLinear() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}), m_RedCoef(-17.91), m_NirCoef(12.26) + { + } - - LAIFromReflectancesLinear() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}), - m_RedCoef(-17.91), - m_NirCoef(12.26) {} - - void SetRedCoef(const double & val) + void SetRedCoef(const double& val) { m_RedCoef = val; } - const double & GetRedCoef() const + const double& GetRedCoef() const { return m_RedCoef; } - void SetNirCoef(const double & val) + void SetNirCoef(const double& val) { m_NirCoef = val; } - const double & GetNirCoef() const + const double& GetNirCoef() const { return m_NirCoef; } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); - return (static_cast<TOutput>(m_RedCoef*red+m_NirCoef*nir)); + return (static_cast<TOutput>(m_RedCoef * red + m_NirCoef * nir)); } double m_RedCoef; @@ -721,28 +740,29 @@ public: */ - template <class TInput, class TOutput> - class LAIFromNDVIFormosat2Functor : public RadiometricIndex<TInput,TOutput> +template <class TInput, class TOutput> +class LAIFromNDVIFormosat2Functor : public RadiometricIndex<TInput, TOutput> +{ +public: + LAIFromNDVIFormosat2Functor() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) { - public: - - LAIFromNDVIFormosat2Functor(): RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::NIR}) {} - - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + } + + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override + { + auto red = this->Value(CommonBandNames::RED, input); + auto nir = this->Value(CommonBandNames::NIR, input); + + if (std::abs(nir + red) < RadiometricIndex<TInput, TOutput>::Epsilon) { - auto red = this->Value(CommonBandNames::RED,input); - auto nir = this->Value(CommonBandNames::NIR,input); - - if (std::abs(nir + red) < RadiometricIndex<TInput,TOutput>::Epsilon) - { - return static_cast<TOutput>(0.); - } - return static_cast<TOutput>(A*(std::exp((nir-red)/(red+nir)*B)-std::exp(C*B))); + return static_cast<TOutput>(0.); } + return static_cast<TOutput>(A * (std::exp((nir - red) / (red + nir) * B) - std::exp(C * B))); + } - static constexpr double A = 0.1519; - static constexpr double B = 3.9443; - static constexpr double C = 0.13; + static constexpr double A = 0.1519; + static constexpr double B = 3.9443; + static constexpr double C = 0.13; }; diff --git a/Modules/Radiometry/Indices/include/otbWaterIndicesFunctor.h b/Modules/Radiometry/Indices/include/otbWaterIndicesFunctor.h index e222efba2a2b46e1e210a7328979d9b4b482e0a0..19acf0fb19bd6681451935869625f2b1267d0665 100644 --- a/Modules/Radiometry/Indices/include/otbWaterIndicesFunctor.h +++ b/Modules/Radiometry/Indices/include/otbWaterIndicesFunctor.h @@ -43,23 +43,24 @@ namespace Functor * \ingroup OTBIndices */ template <class TInput, class TOutput> -class NDWI : public RadiometricIndex<TInput,TOutput> +class NDWI : public RadiometricIndex<TInput, TOutput> { public: + NDWI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::NIR, CommonBandNames::MIR}) + { + } - NDWI(): RadiometricIndex<TInput,TOutput>({CommonBandNames::NIR, CommonBandNames::MIR}) {} - - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto mir = this->Value(CommonBandNames::MIR,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto mir = this->Value(CommonBandNames::MIR, input); + auto nir = this->Value(CommonBandNames::NIR, input); - if (std::abs(nir + mir) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(nir + mir) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return 0.; } - return (nir - mir) / (nir + mir); + return (nir - mir) / (nir + mir); } }; @@ -74,23 +75,24 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class NDWI2 : public RadiometricIndex<TInput,TOutput> +class NDWI2 : public RadiometricIndex<TInput, TOutput> { public: + NDWI2() : RadiometricIndex<TInput, TOutput>({CommonBandNames::NIR, CommonBandNames::GREEN}) + { + } - NDWI2() : RadiometricIndex<TInput,TOutput>({CommonBandNames::NIR, CommonBandNames::GREEN}) {} - - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto green = this->Value(CommonBandNames::GREEN,input); - auto nir = this->Value(CommonBandNames::NIR,input); + auto green = this->Value(CommonBandNames::GREEN, input); + auto nir = this->Value(CommonBandNames::NIR, input); - if (std::abs(nir + green) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(nir + green) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return 0.; } - return (green - nir) / (green + nir); + return (green - nir) / (green + nir); } }; @@ -109,22 +111,24 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class MNDWI : public RadiometricIndex<TInput,TOutput> +class MNDWI : public RadiometricIndex<TInput, TOutput> { public: - MNDWI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::MIR, CommonBandNames::GREEN}) {} + MNDWI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::MIR, CommonBandNames::GREEN}) + { + } - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto green = this->Value(CommonBandNames::GREEN,input); - auto mir = this->Value(CommonBandNames::MIR,input); + auto green = this->Value(CommonBandNames::GREEN, input); + auto mir = this->Value(CommonBandNames::MIR, input); - if (std::abs(mir + green) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(mir + green) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return 0.; } - return (green - mir) / (green + mir); + return (green - mir) / (green + mir); } }; @@ -139,23 +143,24 @@ public: * \ingroup OTBIndices */ template <class TInput, class TOutput> -class NDTI : public RadiometricIndex<TInput,TOutput> +class NDTI : public RadiometricIndex<TInput, TOutput> { public: + NDTI() : RadiometricIndex<TInput, TOutput>({CommonBandNames::RED, CommonBandNames::GREEN}) + { + } - NDTI() : RadiometricIndex<TInput,TOutput>({CommonBandNames::RED, CommonBandNames::GREEN}) {} - - TOutput operator()(const itk::VariableLengthVector<TInput> & input) const override + TOutput operator()(const itk::VariableLengthVector<TInput>& input) const override { - auto green = this->Value(CommonBandNames::GREEN,input); - auto red = this->Value(CommonBandNames::RED,input); + auto green = this->Value(CommonBandNames::GREEN, input); + auto red = this->Value(CommonBandNames::RED, input); - if (std::abs(red + green) < RadiometricIndex<TInput,TOutput>::Epsilon) - { + if (std::abs(red + green) < RadiometricIndex<TInput, TOutput>::Epsilon) + { return 0.; } - return (red -green) / (green + red); + return (red - green) / (green + red); } }; diff --git a/Modules/Radiometry/Indices/include/otbWaterSqrtSpectralAngleImageFilter.h b/Modules/Radiometry/Indices/include/otbWaterSqrtSpectralAngleImageFilter.h index edb380fbb39001fc962c5906a986b34ffa259f19..adbe0dee543242d0156ac2aafb22444f32b52c60 100644 --- a/Modules/Radiometry/Indices/include/otbWaterSqrtSpectralAngleImageFilter.h +++ b/Modules/Radiometry/Indices/include/otbWaterSqrtSpectralAngleImageFilter.h @@ -48,32 +48,38 @@ public: WaterSqrtSpectralAngleFunctor() { - //Set the channels indices - m_BlueIndex = 0; + // Set the channels indices + m_BlueIndex = 0; m_GreenIndex = 1; - m_RedIndex = 2; - m_NIRIndex = 3; + m_RedIndex = 2; + m_NIRIndex = 3; - //Set reference water value + // Set reference water value InputVectorPixelType reference; reference.SetSize(4); - reference[0] = 136.0; reference[1] = 132.0; reference[2] = 47.0; reference[3] = 24.0; + reference[0] = 136.0; + reference[1] = 132.0; + reference[2] = 47.0; + reference[3] = 24.0; this->SetReferenceWaterPixel(reference); } - ~WaterSqrtSpectralAngleFunctor() override {} + ~WaterSqrtSpectralAngleFunctor() override + { + } /** Set Reference Pixel */ void SetReferenceWaterPixel(InputVectorPixelType ref) { if (ref.GetSize() != 4) - { - } + { + } InputVectorPixelType reference; reference.SetSize(4); - reference[m_BlueIndex] = ref[0]; reference[m_GreenIndex] = ref[1]; reference[m_RedIndex] = ref[2]; - reference[m_NIRIndex] = ref[3]; + reference[m_BlueIndex] = ref[0]; + reference[m_GreenIndex] = ref[1]; + reference[m_RedIndex] = ref[2]; + reference[m_NIRIndex] = ref[3]; this->SetReferencePixel(reference); - } /** Getters and setters */ diff --git a/Modules/Radiometry/Indices/test/otbRadiometricIndicesTest.cxx b/Modules/Radiometry/Indices/test/otbRadiometricIndicesTest.cxx index e74713060835612e0e4c9ee503d3e474ee47232b..ef0a6635d44ab98b10b246437f237e549c06e9a5 100644 --- a/Modules/Radiometry/Indices/test/otbRadiometricIndicesTest.cxx +++ b/Modules/Radiometry/Indices/test/otbRadiometricIndicesTest.cxx @@ -26,40 +26,42 @@ #include <iomanip> -template <typename T> itk::VariableLengthVector<T> build_pixel(const std::initializer_list<T> & il) +template <typename T> +itk::VariableLengthVector<T> build_pixel(const std::initializer_list<T>& il) { itk::VariableLengthVector<T> res(il.size()); - size_t idx = 0; + size_t idx = 0; - for(auto v: il) - { - res[idx]=v; + for (auto v : il) + { + res[idx] = v; ++idx; - } + } return res; } -template <class TIndice> bool CheckResult(const std::string & testName, std::map<typename TIndice::BandNameType,size_t> bandMap, - const std::initializer_list<typename TIndice::InputType>& input, const typename TIndice::OutputType & expected) +template <class TIndice> +bool CheckResult(const std::string& testName, std::map<typename TIndice::BandNameType, size_t> bandMap, + const std::initializer_list<typename TIndice::InputType>& input, const typename TIndice::OutputType& expected) { TIndice indice; - + indice.SetBandsIndices(bandMap); - + auto pixel = build_pixel(input); typename TIndice::OutputType v = indice(pixel); - if(std::abs(expected - v) > TIndice::Epsilon) - { - std::cerr<<std::setprecision(10); - std::cerr<<testName <<"\t- failed: expected "<<expected<<", got "<<v<<std::endl; + if (std::abs(expected - v) > TIndice::Epsilon) + { + std::cerr << std::setprecision(10); + std::cerr << testName << "\t- failed: expected " << expected << ", got " << v << std::endl; return false; - } + } else - { + { return true; - } + } } @@ -67,163 +69,168 @@ using namespace otb::Functor; int otbVegetationIndicesTest(int, char**) { - - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}}; + + const std::map<CommonBandNames, size_t> bandMap = { + {CommonBandNames::BLUE, 1}, {CommonBandNames::GREEN, 2}, {CommonBandNames::RED, 3}, {CommonBandNames::NIR, 4}}; // Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result) - bool res = CheckResult< NDVI<int,double> >("ndvi_null ",bandMap,{0,0,0,0},0.); - res = res & CheckResult< NDVI<int,double> >("ndvi_pixel",bandMap,{0,0,1,2},0.3333333); - res = res & CheckResult< RVI<int,double> >("rvi_null",bandMap,{0,0,0,0},0.); - res = res & CheckResult< RVI<int,double> >("rvi_pixel",bandMap,{0,0,2,1},0.5); - res = res & CheckResult< PVI<int,double> >("pvi_pixel",bandMap,{0,0,1,2},-62.0544166); - res = res & CheckResult< SAVI<double,double> >("savi_null",bandMap,{0,0,0,-0.5},0.); - res = res & CheckResult< SAVI<int,double> >("savi_pixel",bandMap,{0,0,1,2},0.42857142857); - res = res & CheckResult< TSAVI<double,double> >("tsavi_null",bandMap,{0,0,-0.1192,0.},0.); - res = res & CheckResult< TSAVI<int,double> >("tsavi_pixel",bandMap,{0,0,1,2},0.1111463957); - res = res & CheckResult< WDVI<int,double> >("wdvi_pixel",bandMap,{0,0,1,2},1.6); - res = res & CheckResult< MSAVI<int,double> >("msavi_pixel",bandMap,{0,0,1,2},0.4402985075); - res = res & CheckResult< MSAVI2<int,double> >("msavi2_pixel",bandMap,{0,0,1,2},0.4384471872); - res = res & CheckResult< GEMI<int,double> >("gemi_pixel",bandMap,{1,4,3,2},2.0625); - res = res & CheckResult< AVI<int,double> >("avi_pixel",bandMap,{0,0,1,2},0.1017245527); - res = res & CheckResult< ARVI<int,double> >("arvi_pixel",bandMap,{0,0,1,2},0.1428571429); - res = res & CheckResult< EVI<int,double> >("evi_pixel",bandMap,{0,0,1,2},0.2777777778); - res = res & CheckResult< IPVI<int,double> >("ipvi_pixel",bandMap,{0,0,1,2},0.6666666667); - res = res & CheckResult< LAIFromNDVILogarithmic<int,double> >("lailog_pixel",bandMap,{0,0,1,2},0.4930511672); - res = res & CheckResult< LAIFromReflectancesLinear<int,double> >("lailog_pixel",bandMap,{0,0,1,2},6.61); - res = res & CheckResult< LAIFromNDVIFormosat2Functor<int,double> >("laifrom_pixel",bandMap,{0,0,1,2},0.3120010659); - - if(res) - { + bool res = CheckResult<NDVI<int, double>>("ndvi_null ", bandMap, {0, 0, 0, 0}, 0.); + res = res & CheckResult<NDVI<int, double>>("ndvi_pixel", bandMap, {0, 0, 1, 2}, 0.3333333); + res = res & CheckResult<RVI<int, double>>("rvi_null", bandMap, {0, 0, 0, 0}, 0.); + res = res & CheckResult<RVI<int, double>>("rvi_pixel", bandMap, {0, 0, 2, 1}, 0.5); + res = res & CheckResult<PVI<int, double>>("pvi_pixel", bandMap, {0, 0, 1, 2}, -62.0544166); + res = res & CheckResult<SAVI<double, double>>("savi_null", bandMap, {0, 0, 0, -0.5}, 0.); + res = res & CheckResult<SAVI<int, double>>("savi_pixel", bandMap, {0, 0, 1, 2}, 0.42857142857); + res = res & CheckResult<TSAVI<double, double>>("tsavi_null", bandMap, {0, 0, -0.1192, 0.}, 0.); + res = res & CheckResult<TSAVI<int, double>>("tsavi_pixel", bandMap, {0, 0, 1, 2}, 0.1111463957); + res = res & CheckResult<WDVI<int, double>>("wdvi_pixel", bandMap, {0, 0, 1, 2}, 1.6); + res = res & CheckResult<MSAVI<int, double>>("msavi_pixel", bandMap, {0, 0, 1, 2}, 0.4402985075); + res = res & CheckResult<MSAVI2<int, double>>("msavi2_pixel", bandMap, {0, 0, 1, 2}, 0.4384471872); + res = res & CheckResult<GEMI<int, double>>("gemi_pixel", bandMap, {1, 4, 3, 2}, 2.0625); + res = res & CheckResult<AVI<int, double>>("avi_pixel", bandMap, {0, 0, 1, 2}, 0.1017245527); + res = res & CheckResult<ARVI<int, double>>("arvi_pixel", bandMap, {0, 0, 1, 2}, 0.1428571429); + res = res & CheckResult<EVI<int, double>>("evi_pixel", bandMap, {0, 0, 1, 2}, 0.2777777778); + res = res & CheckResult<IPVI<int, double>>("ipvi_pixel", bandMap, {0, 0, 1, 2}, 0.6666666667); + res = res & CheckResult<LAIFromNDVILogarithmic<int, double>>("lailog_pixel", bandMap, {0, 0, 1, 2}, 0.4930511672); + res = res & CheckResult<LAIFromReflectancesLinear<int, double>>("lailog_pixel", bandMap, {0, 0, 1, 2}, 6.61); + res = res & CheckResult<LAIFromNDVIFormosat2Functor<int, double>>("laifrom_pixel", bandMap, {0, 0, 1, 2}, 0.3120010659); + + if (res) + { return EXIT_SUCCESS; - } + } else - { + { return EXIT_FAILURE; - } + } } int otbWaterIndicesTest(int, char**) { - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}}; + const std::map<CommonBandNames, size_t> bandMap = { + {CommonBandNames::BLUE, 1}, {CommonBandNames::GREEN, 2}, {CommonBandNames::RED, 3}, {CommonBandNames::NIR, 4}, {CommonBandNames::MIR, 5}}; // Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result) - bool res = CheckResult< NDWI<int,double> >("ndwi_null ",bandMap,{0,0,0,0,0},0.); - res = res & CheckResult< NDWI<int,double> >("ndwi_pixel",bandMap,{1,2,3,4,5},-0.1111111111); - res = res & CheckResult< NDWI2<int,double> >("ndwi2_null",bandMap,{0,0,0,0,0},0.); - res = res & CheckResult< NDWI2<int,double> >("ndwi2_pixel",bandMap,{1,2,3,4,5},-0.3333333333); - res = res & CheckResult< MNDWI<int,double> >("mndwi_null",bandMap,{0,0,0,0,0},0.); - res = res & CheckResult< MNDWI<int,double> >("mndwi_pixel",bandMap,{1,2,3,4,5},-0.4285714286); - res = res & CheckResult< NDTI<int,double> >("ndti_null",bandMap,{0,0,0,0,0},0.); - res = res & CheckResult< NDTI<int,double> >("ndti_pixel",bandMap,{1,2,3,4,5},0.2); - - if(res) - { + bool res = CheckResult<NDWI<int, double>>("ndwi_null ", bandMap, {0, 0, 0, 0, 0}, 0.); + res = res & CheckResult<NDWI<int, double>>("ndwi_pixel", bandMap, {1, 2, 3, 4, 5}, -0.1111111111); + res = res & CheckResult<NDWI2<int, double>>("ndwi2_null", bandMap, {0, 0, 0, 0, 0}, 0.); + res = res & CheckResult<NDWI2<int, double>>("ndwi2_pixel", bandMap, {1, 2, 3, 4, 5}, -0.3333333333); + res = res & CheckResult<MNDWI<int, double>>("mndwi_null", bandMap, {0, 0, 0, 0, 0}, 0.); + res = res & CheckResult<MNDWI<int, double>>("mndwi_pixel", bandMap, {1, 2, 3, 4, 5}, -0.4285714286); + res = res & CheckResult<NDTI<int, double>>("ndti_null", bandMap, {0, 0, 0, 0, 0}, 0.); + res = res & CheckResult<NDTI<int, double>>("ndti_pixel", bandMap, {1, 2, 3, 4, 5}, 0.2); + + if (res) + { return EXIT_SUCCESS; - } + } else - { + { return EXIT_FAILURE; - } + } } int otbSoilIndicesTest(int, char**) { - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}}; + const std::map<CommonBandNames, size_t> bandMap = { + {CommonBandNames::BLUE, 1}, {CommonBandNames::GREEN, 2}, {CommonBandNames::RED, 3}, {CommonBandNames::NIR, 4}, {CommonBandNames::MIR, 5}}; // Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result) - bool res = CheckResult< CI<int,double> >("ci_null ",bandMap,{0,0,0,0,0},0.); - res = res & CheckResult< CI<int,double> >("ci_pixel",bandMap,{1,2,3,4,5},0.2); - res = res & CheckResult< BI<int,double> >("bi_pixel",bandMap,{1,2,3,4,5},2.549509757); - res = res & CheckResult< BI2<int,double> >("bi2_pixel",bandMap,{1,2,3,4,5},3.109126351); + bool res = CheckResult<CI<int, double>>("ci_null ", bandMap, {0, 0, 0, 0, 0}, 0.); + res = res & CheckResult<CI<int, double>>("ci_pixel", bandMap, {1, 2, 3, 4, 5}, 0.2); + res = res & CheckResult<BI<int, double>>("bi_pixel", bandMap, {1, 2, 3, 4, 5}, 2.549509757); + res = res & CheckResult<BI2<int, double>>("bi2_pixel", bandMap, {1, 2, 3, 4, 5}, 3.109126351); - if(res) - { + if (res) + { return EXIT_SUCCESS; - } + } else - { + { return EXIT_FAILURE; - } + } } int otbBuiltUpIndicesTest(int, char**) { - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}}; + const std::map<CommonBandNames, size_t> bandMap = { + {CommonBandNames::BLUE, 1}, {CommonBandNames::GREEN, 2}, {CommonBandNames::RED, 3}, {CommonBandNames::NIR, 4}, {CommonBandNames::MIR, 5}}; // Syntax: CheckResult<Indice Class>("test_name",bandMap,{red_value,nir_value},expected_result) - bool res = CheckResult< ISU<int,double> >("isu_null",bandMap,{0,0,0,0,0},0.); - res = res & CheckResult< ISU<int,double> >("isu_pixel",bandMap,{1,2,3,4,5},81.25); + bool res = CheckResult<ISU<int, double>>("isu_null", bandMap, {0, 0, 0, 0, 0}, 0.); + res = res & CheckResult<ISU<int, double>>("isu_pixel", bandMap, {1, 2, 3, 4, 5}, 81.25); - if(res) - { + if (res) + { return EXIT_SUCCESS; - } + } else - { + { return EXIT_FAILURE; - } + } } -int otbRadiometricIndexTest(int,char**) +int otbRadiometricIndexTest(int, char**) { - auto ndvi = NDVI<double,double>(); - + auto ndvi = NDVI<double, double>(); + auto requiredBands = ndvi.GetRequiredBands(); bool success = true; - if(requiredBands.size() != 2 - || requiredBands.find(CommonBandNames::RED) == requiredBands.end() - || requiredBands.find(CommonBandNames::NIR) == requiredBands.end()) - { - std::cerr<<"Required bands is not {RED,NIR} for NDVI"<<std::endl; + if (requiredBands.size() != 2 || requiredBands.find(CommonBandNames::RED) == requiredBands.end() || + requiredBands.find(CommonBandNames::NIR) == requiredBands.end()) + { + std::cerr << "Required bands is not {RED,NIR} for NDVI" << std::endl; success = false; - } + } - ndvi.SetBandIndex(CommonBandNames::RED,10); - - if(ndvi.GetBandIndex(CommonBandNames::RED) != 10) - { - std::cerr<<"Could not Set/Get band index properly"<<std::endl; + ndvi.SetBandIndex(CommonBandNames::RED, 10); + + if (ndvi.GetBandIndex(CommonBandNames::RED) != 10) + { + std::cerr << "Could not Set/Get band index properly" << std::endl; success = false; - } + } + + const std::map<CommonBandNames, size_t> bandMap = {{CommonBandNames::RED, 100}, {CommonBandNames::NIR, 200}}; - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::RED,100},{CommonBandNames::NIR,200}}; - ndvi.SetBandsIndices(bandMap); - if(ndvi.GetBandIndex(CommonBandNames::RED) != 100 || ndvi.GetBandIndex(CommonBandNames::NIR) != 200) - { - std::cerr<<"Could not set all band indices at once with SetBandIndices"<<std::endl; + if (ndvi.GetBandIndex(CommonBandNames::RED) != 100 || ndvi.GetBandIndex(CommonBandNames::NIR) != 200) + { + std::cerr << "Could not set all band indices at once with SetBandIndices" << std::endl; success = false; - } + } try - { - ndvi.SetBandIndex(CommonBandNames::MAX,1); - std::cerr<<"Calling SetBandIndices with ::MAX should raise a runtime_error exception."<<std::endl; + { + ndvi.SetBandIndex(CommonBandNames::MAX, 1); + std::cerr << "Calling SetBandIndices with ::MAX should raise a runtime_error exception." << std::endl; success = false; - } - catch(const std::runtime_error & e) {} + } + catch (const std::runtime_error& e) + { + } - if(success) - { + if (success) + { return EXIT_SUCCESS; - } + } else - { + { return EXIT_FAILURE; - } + } } int otbIndicesStackFunctorTest(int, char**) { - using IndicesType = RadiometricIndex<double,int,CommonBandNames>; + using IndicesType = RadiometricIndex<double, int, CommonBandNames>; using StackFunctorType = IndicesStackFunctor<IndicesType>; - auto ndvi = NDVI<double,int>(); - auto ndwi = NDWI<double,int>(); + auto ndvi = NDVI<double, int>(); + auto ndwi = NDWI<double, int>(); std::vector<IndicesType*> indices = {&ndvi, &ndwi}; @@ -231,41 +238,42 @@ int otbIndicesStackFunctorTest(int, char**) bool success = true; - if(stack.OutputSize() != 2) - { - std::cerr<<"Size of output pixel for stack functor should be 2"<<std::endl; + if (stack.OutputSize() != 2) + { + std::cerr << "Size of output pixel for stack functor should be 2" << std::endl; success = false; - } + } - const std::map<CommonBandNames,size_t> bandMap = {{CommonBandNames::BLUE,1},{CommonBandNames::GREEN,2},{CommonBandNames::RED,3},{CommonBandNames::NIR,4}, {CommonBandNames::MIR,5}}; + const std::map<CommonBandNames, size_t> bandMap = { + {CommonBandNames::BLUE, 1}, {CommonBandNames::GREEN, 2}, {CommonBandNames::RED, 3}, {CommonBandNames::NIR, 4}, {CommonBandNames::MIR, 5}}; ndvi.SetBandsIndices(bandMap); ndwi.SetBandsIndices(bandMap); StackFunctorType::OutputType out(2); - auto in = build_pixel<double>({1,2,3,4,5}); + auto in = build_pixel<double>({1, 2, 3, 4, 5}); - stack(out,in); + stack(out, in); - if(out[0] != ndvi(in)) - { - std::cerr<<"First output band should correspond to ndvi"<<std::endl; + if (out[0] != ndvi(in)) + { + std::cerr << "First output band should correspond to ndvi" << std::endl; success = false; - } + } - if(out[1] != ndwi(in)) - { - std::cerr<<"Second output band should correspond to ndwi"<<std::endl; + if (out[1] != ndwi(in)) + { + std::cerr << "Second output band should correspond to ndwi" << std::endl; success = false; - } - - if(success) - { + } + + if (success) + { return EXIT_SUCCESS; - } + } else - { + { return EXIT_FAILURE; - } + } } diff --git a/Modules/Radiometry/Simulation/include/otbReduceSpectralResponseClassifierRAndNIR.h b/Modules/Radiometry/Simulation/include/otbReduceSpectralResponseClassifierRAndNIR.h index fa59b243bd4e7fd580d7c9179723cd4b383cfb0f..ea82717f97b18260a1b5e281937b879903607081 100644 --- a/Modules/Radiometry/Simulation/include/otbReduceSpectralResponseClassifierRAndNIR.h +++ b/Modules/Radiometry/Simulation/include/otbReduceSpectralResponseClassifierRAndNIR.h @@ -52,47 +52,46 @@ namespace otb * * \ingroup OTBSimulation */ - template <class TReduceSpectralResponse , class TFunction = Functor::NDVI< typename TReduceSpectralResponse::ValuePrecisionType, - typename TReduceSpectralResponse::ValuePrecisionType > > - class ReduceSpectralResponseClassifierRAndNIR - : public itk::DataObject - { - //friend class - public: - /** Standard class typedefs */ - typedef ReduceSpectralResponseClassifierRAndNIR Self; - typedef itk::DataObject Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Template parameters typedef */ - typedef TReduceSpectralResponse InputReduceSpectralResponseType; - typedef TFunction FunctorType; - typedef typename TReduceSpectralResponse::Pointer InputReduceSpectralResponsePointerType; - typedef typename InputReduceSpectralResponseType::ValuePrecisionType ValuePrecisionType; - - - /** Standard macros */ - itkNewMacro(Self); - itkTypeMacro(ReduceSpectralResponseClassifierRAndNIR, DataObject); - - itkGetConstObjectMacro(InputReduceSpectralResponse, InputReduceSpectralResponseType); - itkSetObjectMacro(InputReduceSpectralResponse, InputReduceSpectralResponseType); - - itkGetConstMacro(RBandNumber, unsigned int); - itkSetMacro(RBandNumber, unsigned int); - - itkGetConstMacro(NIRBandNumber, unsigned int); - itkSetMacro(NIRBandNumber, unsigned int); - - /** Get the functor object. The functor is returned by reference. - * (Functors do not have to derive from itk::LightObject, so they do - * not necessarily have a reference count. So we cannot return a - * SmartPointer.) */ - FunctorType& GetFunctor() - { - return m_Functor; - }; +template <class TReduceSpectralResponse, + class TFunction = Functor::NDVI<typename TReduceSpectralResponse::ValuePrecisionType, typename TReduceSpectralResponse::ValuePrecisionType>> +class ReduceSpectralResponseClassifierRAndNIR : public itk::DataObject +{ + // friend class +public: + /** Standard class typedefs */ + typedef ReduceSpectralResponseClassifierRAndNIR Self; + typedef itk::DataObject Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Template parameters typedef */ + typedef TReduceSpectralResponse InputReduceSpectralResponseType; + typedef TFunction FunctorType; + typedef typename TReduceSpectralResponse::Pointer InputReduceSpectralResponsePointerType; + typedef typename InputReduceSpectralResponseType::ValuePrecisionType ValuePrecisionType; + + + /** Standard macros */ + itkNewMacro(Self); + itkTypeMacro(ReduceSpectralResponseClassifierRAndNIR, DataObject); + + itkGetConstObjectMacro(InputReduceSpectralResponse, InputReduceSpectralResponseType); + itkSetObjectMacro(InputReduceSpectralResponse, InputReduceSpectralResponseType); + + itkGetConstMacro(RBandNumber, unsigned int); + itkSetMacro(RBandNumber, unsigned int); + + itkGetConstMacro(NIRBandNumber, unsigned int); + itkSetMacro(NIRBandNumber, unsigned int); + + /** Get the functor object. The functor is returned by reference. + * (Functors do not have to derive from itk::LightObject, so they do + * not necessarily have a reference count. So we cannot return a + * SmartPointer.) */ + FunctorType& GetFunctor() + { + return m_Functor; + }; /** Set the functor object. This replaces the current Functor with a * copy of the specified Functor. This allows the user to specify a diff --git a/Modules/Radiometry/Simulation/test/otbReduceSpectralResponseClassifierRAndNIR.cxx b/Modules/Radiometry/Simulation/test/otbReduceSpectralResponseClassifierRAndNIR.cxx index aeb5c81bd5217891df5345debe1514dd68899d33..a0e0d61e169419bdc67eabee18589f0353b4f44f 100644 --- a/Modules/Radiometry/Simulation/test/otbReduceSpectralResponseClassifierRAndNIR.cxx +++ b/Modules/Radiometry/Simulation/test/otbReduceSpectralResponseClassifierRAndNIR.cxx @@ -45,7 +45,7 @@ int otbReduceSpectralResponseClassifierRAndNIR(int argc, char * argv[]) typedef otb::ReduceSpectralResponse < ResponseType, SatRSRType> ReduceResponseType; typedef ReduceResponseType::Pointer ReduceResponseTypePointerType; - typedef otb::Functor::NDVI<double, double> TFunctionType; + typedef otb::Functor::NDVI<double, double> TFunctionType; typedef otb::ReduceSpectralResponseClassifierRAndNIR <ReduceResponseType, TFunctionType> ReduceSpectralResponseClassifierRAndNIRType; typedef ReduceSpectralResponseClassifierRAndNIRType::Pointer ReduceSpectralResponseClassifierRAndNIRPointerType;