diff --git a/Modules/Applications/AppHyperspectral/app/otbHyperspectralUnmixing.cxx b/Modules/Applications/AppHyperspectral/app/otbHyperspectralUnmixing.cxx index 0444e858d6f464a0907d956377035d87dcbb1b41..3a1f53eff353c5e962867dc24547d698015cbd21 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 0f237477a5954d70744403bc9fbf7c95fb45aba6..88b8d02a00c6d2910278afae33e0f912391f0960 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 c6c4634d79a3b16fd8c1aeb0a7ed16fb19271c32..de35f75230a13b1d410f15c729a67a73d24afcff 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 a106820650315d9a8024c7ed9b15c54cec061e7b..39505f5fe536d359b2d2f0cdc7cf925dfc3587ea 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 25ed81f56a08effe5eac3e19d8b04b47858e5974..6ca460e4dead5502982ad4f6c758f1a83fe37476 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);