diff --git a/Modules/Applications/AppClassification/app/otbZonalStatistics.cxx b/Modules/Applications/AppClassification/app/otbZonalStatistics.cxx index c11f380fc74d5ec8d1ce3d2878e03e1d7973a62e..452ddfd3440eff566774144dee68e31337990dea 100644 --- a/Modules/Applications/AppClassification/app/otbZonalStatistics.cxx +++ b/Modules/Applications/AppClassification/app/otbZonalStatistics.cxx @@ -39,7 +39,7 @@ #include "otbLabelImageToVectorDataFilter.h" #include "itkBinaryThresholdImageFilter.h" -#include "otbUnaryFunctorImageFilter.h" +#include "otbFunctorImageFilter.h" namespace otb { @@ -79,6 +79,7 @@ public: typedef itk::BinaryThresholdImageFilter<LabelImageType, LabelImageType> ThresholdFilterType; + template<class TInput, class TOutput> struct EncoderFunctorType { StatsFilterType::LabelPopulationMapType* m_CountMap; @@ -92,14 +93,19 @@ public: static constexpr size_t m_NbStatsPerBand{4}; static constexpr size_t m_NbGlobalStats{1}; - size_t GetOutputSize() + size_t OutputSize(const std::array<size_t,1> & itkNotUsed(nbBands)) const { return m_NbInputComponents*m_NbStatsPerBand+m_NbGlobalStats; } - FloatVectorImageType::PixelType operator()(LabelValueType const &pix) + size_t OutputSize() const { - FloatVectorImageType::PixelType outPix(GetOutputSize()); + return m_NbInputComponents*m_NbStatsPerBand+m_NbGlobalStats; + } + + TOutput operator()(TInput const &pix) + { + TOutput outPix(OutputSize()); outPix.Fill(m_OutBvValue); if(pix != m_InNoData) { @@ -129,9 +135,11 @@ public: else return false; } }; - typedef otb::UnaryFunctorImageFilter<LabelImageType, - FloatVectorImageType, - EncoderFunctorType> EncoderFilterType; + typedef otb::FunctorImageFilter<EncoderFunctorType< + LabelValueType, + FloatVectorImageType::PixelType + >> EncoderFilterType; + /** Standard macro */ itkNewMacro(Self); itkTypeMacro(ZonalStatistics, Application); @@ -406,12 +414,17 @@ public: m_EncoderFilter->SetInput(m_RasterizeFilter->GetOutput()); } - m_EncoderFilter->SetFunctor(EncoderFunctorType{&m_CountMap, &m_MeanMap, &m_StdMap, - &m_MinMap, &m_MaxMap, - m_InputImage->GetNumberOfComponentsPerPixel(), - m_IntNoData, m_OutBvValue }); + m_EncoderFilter->GetModifiableFunctor().m_CountMap = &m_CountMap; + m_EncoderFilter->GetModifiableFunctor().m_MeanMap = &m_MeanMap; + m_EncoderFilter->GetModifiableFunctor().m_StdMap = &m_StdMap; + m_EncoderFilter->GetModifiableFunctor().m_MinMap = &m_MinMap; + m_EncoderFilter->GetModifiableFunctor().m_MaxMap = &m_MaxMap; + m_EncoderFilter->GetModifiableFunctor().m_NbInputComponents = m_InputImage->GetNumberOfComponentsPerPixel(); + m_EncoderFilter->GetModifiableFunctor().m_InNoData = m_IntNoData; + m_EncoderFilter->GetModifiableFunctor().m_OutBvValue = m_OutBvValue; + otbAppLogINFO("Output raster image will have " << - (m_EncoderFilter->GetFunctor()).GetOutputSize() << " bands\n"); + (m_EncoderFilter->GetFunctor()).OutputSize() << " bands\n"); AddProcess(m_EncoderFilter, "Encode output raster image"); SetParameterOutputImage("out.raster.filename", m_EncoderFilter->GetOutput()); } diff --git a/Modules/Applications/AppClassification/otb-module.cmake b/Modules/Applications/AppClassification/otb-module.cmake index 8a9c0c6c0201acb777f7953dd3b6445f6d943d61..a35bd17816e7ba1fe518b9b9c1ff2df467ef36a7 100644 --- a/Modules/Applications/AppClassification/otb-module.cmake +++ b/Modules/Applications/AppClassification/otb-module.cmake @@ -49,6 +49,7 @@ otb_module(OTBAppClassification OTBObjectList OTBCommon OTBSampling + OTBFunctor TEST_DEPENDS OTBTestKernel