From 774f72d25027a875cd2f6b7797e10b4feb2c3145 Mon Sep 17 00:00:00 2001 From: ctraizet <cedric.traizet@c-s.fr> Date: Mon, 18 Mar 2019 14:56:34 +0100 Subject: [PATCH] REFAC: replace ISRAUUnmixingImageFilter by a functorImageFilter --- .../app/otbHyperspectralUnmixing.cxx | 2 +- .../include/otbISRAUnmixingImageFilter.h | 78 ++----------------- .../include/otbISRAUnmixingImageFilter.hxx | 68 +--------------- .../Hyperspectral/Unmixing/otb-module.cmake | 1 + .../test/otbISRAUnmixingImageFilter.cxx | 4 +- 5 files changed, 16 insertions(+), 137 deletions(-) diff --git a/Modules/Applications/AppHyperspectral/app/otbHyperspectralUnmixing.cxx b/Modules/Applications/AppHyperspectral/app/otbHyperspectralUnmixing.cxx index 0444e858d6..3a1f53eff3 100644 --- a/Modules/Applications/AppHyperspectral/app/otbHyperspectralUnmixing.cxx +++ b/Modules/Applications/AppHyperspectral/app/otbHyperspectralUnmixing.cxx @@ -212,7 +212,7 @@ private: ISRAUnmixingFilterType::New(); unmixer->SetInput(inputImage); - unmixer->SetEndmembersMatrix(endMembersMatrix); + unmixer->GetModifiableFunctor().SetEndmembersMatrix(endMembersMatrix); abundanceMap = unmixer->GetOutput(); m_ProcessObjects.push_back(unmixer.GetPointer()); diff --git a/Modules/Hyperspectral/Unmixing/include/otbISRAUnmixingImageFilter.h b/Modules/Hyperspectral/Unmixing/include/otbISRAUnmixingImageFilter.h index 0f237477a5..88b8d02a00 100644 --- a/Modules/Hyperspectral/Unmixing/include/otbISRAUnmixingImageFilter.h +++ b/Modules/Hyperspectral/Unmixing/include/otbISRAUnmixingImageFilter.h @@ -22,7 +22,7 @@ #define otbISRAUnmixingImageFilter_h #include "itkNumericTraits.h" -#include "otbUnaryFunctorImageFilter.h" +#include "otbFunctorImageFilter.h" #include "vnl/algo/vnl_svd.h" #include <boost/shared_ptr.hpp> @@ -52,13 +52,9 @@ public: typedef vnl_matrix<PrecisionType> MatrixType; ISRAUnmixingFunctor(); - virtual ~ISRAUnmixingFunctor(); + virtual ~ISRAUnmixingFunctor() =default; - unsigned int GetOutputSize() const; - - bool operator !=(const ISRAUnmixingFunctor& other) const; - - bool operator ==(const ISRAUnmixingFunctor& other) const; + size_t OutputSize(const std::array<size_t,1> & nbBands) const; void SetEndmembersMatrix(const MatrixType& U); const MatrixType& GetEndmembersMatrix(void) const; @@ -92,7 +88,7 @@ private: }; } -/** \class ISRAUnmixingImageFilter +/** \typedef ISRAUnmixingImageFilter * * \brief Performs fully constrained least squares on each pixel of a VectorImage * @@ -118,68 +114,10 @@ private: * * \ingroup OTBUnmixing */ -template <class TInputImage, class TOutputImage, class TPrecision> -class ITK_EXPORT ISRAUnmixingImageFilter : - public otb::UnaryFunctorImageFilter<TInputImage, TOutputImage, - Functor::ISRAUnmixingFunctor<typename TInputImage::PixelType, - typename TOutputImage::PixelType, TPrecision> > -{ -public: - /** Standard class typedefs. */ - typedef ISRAUnmixingImageFilter Self; - typedef otb::UnaryFunctorImageFilter - <TInputImage, - TOutputImage, - Functor::ISRAUnmixingFunctor< - typename TInputImage::PixelType, - typename TOutputImage::PixelType, - TPrecision> - > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - typedef Functor::ISRAUnmixingFunctor< - typename TInputImage::PixelType, - typename TOutputImage::PixelType, - TPrecision> FunctorType; - typedef typename FunctorType::MatrixType MatrixType; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(ISRAUnmixingImageFilter, otb::UnaryFunctorImageFilter); - - /** Pixel types. */ - typedef typename TInputImage::PixelType InputPixelType; - typedef typename TOutputImage::PixelType OutputPixelType; - - void SetEndmembersMatrix(const MatrixType& m); - const MatrixType& GetEndmembersMatrix() const; - - void SetMaxIteration( unsigned int val ) - { - this->GetFunctor().SetMaxIteration(val); - this->Modified(); - } - - unsigned int GetMaxIteration() const - { - return this->GetFunctor().GetMaxIteration(); - } - -protected: - ISRAUnmixingImageFilter(); - - ~ISRAUnmixingImageFilter() override; - - void PrintSelf(std::ostream& os, itk::Indent indent) const override; - -private: - ISRAUnmixingImageFilter(const Self &) = delete; - void operator =(const Self&) = delete; - -}; +template <typename TInputImage, typename TOutputImage, typename TPrecision> +using ISRAUnmixingImageFilter = FunctorImageFilter< + Functor::ISRAUnmixingFunctor<typename TInputImage::PixelType, + typename TOutputImage::PixelType, TPrecision> >; } // end namespace otb diff --git a/Modules/Hyperspectral/Unmixing/include/otbISRAUnmixingImageFilter.hxx b/Modules/Hyperspectral/Unmixing/include/otbISRAUnmixingImageFilter.hxx index c6c4634d79..de35f75230 100644 --- a/Modules/Hyperspectral/Unmixing/include/otbISRAUnmixingImageFilter.hxx +++ b/Modules/Hyperspectral/Unmixing/include/otbISRAUnmixingImageFilter.hxx @@ -39,35 +39,13 @@ ISRAUnmixingFunctor<TInput, TOutput, TPrecision> } template <class TInput, class TOutput, class TPrecision> +size_t ISRAUnmixingFunctor<TInput, TOutput, TPrecision> -::~ISRAUnmixingFunctor() -{ -} - -template <class TInput, class TOutput, class TPrecision> -unsigned int -ISRAUnmixingFunctor<TInput, TOutput, TPrecision> -::GetOutputSize() const +::OutputSize(const std::array<size_t,1> & itkNotUsed(nbBands)) const { return m_OutputSize; } -template <class TInput, class TOutput, class TPrecision> -bool -ISRAUnmixingFunctor<TInput, TOutput, TPrecision> -::operator != (const Self& itkNotUsed(other)) const -{ - return true; -} - -template <class TInput, class TOutput, class TPrecision> -bool -ISRAUnmixingFunctor<TInput, TOutput, TPrecision> -::operator == (const Self& itkNotUsed(other)) const -{ - return false; -} - template <class TInput, class TOutput, class TPrecision> void ISRAUnmixingFunctor<TInput, TOutput, TPrecision> @@ -145,45 +123,7 @@ ISRAUnmixingFunctor<TInput, TOutput, TPrecision> return out; } -} - -template <class TInputImage, class TOutputImage, class TPrecision> -ISRAUnmixingImageFilter<TInputImage, TOutputImage, TPrecision> -::ISRAUnmixingImageFilter() -{ -} - -template <class TInputImage, class TOutputImage, class TPrecision> -ISRAUnmixingImageFilter<TInputImage, TOutputImage, TPrecision> -::~ISRAUnmixingImageFilter() -{ -} - -template <class TInputImage, class TOutputImage, class TPrecision> -void -ISRAUnmixingImageFilter<TInputImage, TOutputImage, TPrecision> -::SetEndmembersMatrix(const MatrixType& m) -{ - this->GetFunctor().SetEndmembersMatrix(m); - this->Modified(); -} - -template <class TInputImage, class TOutputImage, class TPrecision> -const typename ISRAUnmixingImageFilter<TInputImage, TOutputImage, TPrecision>::MatrixType& -ISRAUnmixingImageFilter<TInputImage, TOutputImage, TPrecision> -::GetEndmembersMatrix() const -{ - return this->GetFunctor().GetEndmembersMatrix(); -} - -template <class TInputImage, class TOutputImage, class TPrecision> -void -ISRAUnmixingImageFilter<TInputImage, TOutputImage, TPrecision> -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - -} // end namespace +} // end namespace functor +} // end namespace otb #endif diff --git a/Modules/Hyperspectral/Unmixing/otb-module.cmake b/Modules/Hyperspectral/Unmixing/otb-module.cmake index a106820650..39505f5fe5 100644 --- a/Modules/Hyperspectral/Unmixing/otb-module.cmake +++ b/Modules/Hyperspectral/Unmixing/otb-module.cmake @@ -34,6 +34,7 @@ otb_module(OTBUnmixing OTBImageBase OTBStatistics OTBWavelet + OTBFunctor TEST_DEPENDS OTBImageIO diff --git a/Modules/Hyperspectral/Unmixing/test/otbISRAUnmixingImageFilter.cxx b/Modules/Hyperspectral/Unmixing/test/otbISRAUnmixingImageFilter.cxx index 25ed81f56a..6ca460e4de 100644 --- a/Modules/Hyperspectral/Unmixing/test/otbISRAUnmixingImageFilter.cxx +++ b/Modules/Hyperspectral/Unmixing/test/otbISRAUnmixingImageFilter.cxx @@ -59,9 +59,9 @@ int otbISRAUnmixingImageFilterTest(int itkNotUsed(argc), char * argv[]) UnmixingImageFilterType::Pointer unmixer = UnmixingImageFilterType::New(); unmixer->SetInput(readerImage->GetOutput()); - unmixer->SetMaxIteration(maxIter); + unmixer->GetModifiableFunctor().SetMaxIteration(maxIter); //unmixer->SetNumberOfThreads(1); - unmixer->SetEndmembersMatrix(endMember2Matrix->GetMatrix()); + unmixer->GetModifiableFunctor().SetEndmembersMatrix(endMember2Matrix->GetMatrix()); WriterType::Pointer writer = WriterType::New(); writer->SetFileName(outputImage); -- GitLab