From b66f6eb1dee49038e3947b136625c0e5fe83d459 Mon Sep 17 00:00:00 2001 From: ctraizet <cedric.traizet@c-s.fr> Date: Mon, 18 Mar 2019 11:58:33 +0100 Subject: [PATCH] REFAC: replace DotProductImageFilter by a functorImageFilter and moved from OTBCommon to OTBFunctor --- .../Common/include/otbDotProductImageFilter.h | 158 ------------------ .../include/otbDotProductImageFilter.hxx | 48 ------ .../include/otbDotProductImageFilter.h | 93 +++++++++++ .../test/otbProjectiveProjection.cxx | 2 - .../include/otbVcaImageFilter.hxx | 2 +- .../EndmembersExtraction/otb-module.cmake | 1 + 6 files changed, 95 insertions(+), 209 deletions(-) delete mode 100644 Modules/Core/Common/include/otbDotProductImageFilter.h delete mode 100644 Modules/Core/Common/include/otbDotProductImageFilter.hxx create mode 100644 Modules/Core/Functor/include/otbDotProductImageFilter.h diff --git a/Modules/Core/Common/include/otbDotProductImageFilter.h b/Modules/Core/Common/include/otbDotProductImageFilter.h deleted file mode 100644 index a9aedabd04..0000000000 --- a/Modules/Core/Common/include/otbDotProductImageFilter.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbDotProductImageFilter_h -#define otbDotProductImageFilter_h - -#include "itkMacro.h" -#include "otbUnaryFunctorImageFilter.h" - -namespace otb -{ - -namespace Functor { - -/** \class DotProductFunctor - * - * \brief Computes the dot product against a specific vector - * - * - * \ingroup OTBCommon - */ -template<class TInput, class TOutput> -class DotProductFunctor -{ -public: - typedef TInput InputType; - typedef TOutput OutputType; - - DotProductFunctor() {} - virtual ~DotProductFunctor() {} - - bool operator !=(const DotProductFunctor& itkNotUsed(other)) const - { - return false; - } - - bool operator ==(const DotProductFunctor& other) const - { - return !(*this != other); - } - - const InputType& GetVector() - { - return m_Vector; - } - - void SetVector(const InputType& m) - { - m_Vector = m; - } - - OutputType operator ()(const InputType& in) - { - OutputType result = 0; - for(unsigned int i = 0; i < in.Size(); ++i) - { - result += in[i] * m_Vector[i]; - } - return result; - } - -private: - InputType m_Vector; -}; -} - -/** \class DotProductImageFilter - * - * \brief Applies pixel-wise dot product to a VectorImage - * - * Given a vector, this filter outputs the dot product of each pixel of a multiband image - * with respect to the specified vector - * - * \ingroup Streamed - * \ingroup Threaded - * - * \ingroup OTBCommon - */ -template <class TInputImage, class TOutputImage> -class ITK_EXPORT DotProductImageFilter : - public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage, - Functor::DotProductFunctor<typename TInputImage::PixelType, - typename TOutputImage::PixelType> > -{ -public: - /** Standard class typedefs. */ - typedef DotProductImageFilter Self; - typedef itk::UnaryFunctorImageFilter - <TInputImage, - TOutputImage, - Functor::DotProductFunctor< - typename TInputImage::PixelType, - typename TOutputImage::PixelType> - > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - typedef Functor::DotProductFunctor< - typename TInputImage::PixelType, - typename TOutputImage::PixelType> FunctorType; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(DotProductImageFilter, itk::UnaryFunctorImageFilter); - - /** Pixel types. */ - typedef typename TInputImage::PixelType InputPixelType; - typedef typename TOutputImage::PixelType OutputPixelType; - - const InputPixelType& GetVector() - { - return this->GetFunctor().GetVector(); - } - - void SetVector(const InputPixelType& p) - { - this->GetFunctor().SetVector(p); - this->Modified(); - } - -protected: - DotProductImageFilter(); - - ~DotProductImageFilter() override {} - - void PrintSelf(std::ostream& os, itk::Indent indent) const override; - -private: - DotProductImageFilter(const Self &) = delete; - void operator =(const Self&) = delete; -}; - -} // end namespace otb - -#ifndef OTB_MANUAL_INSTANTIATION -#include "otbDotProductImageFilter.hxx" -#endif - -#endif diff --git a/Modules/Core/Common/include/otbDotProductImageFilter.hxx b/Modules/Core/Common/include/otbDotProductImageFilter.hxx deleted file mode 100644 index e06f7f6755..0000000000 --- a/Modules/Core/Common/include/otbDotProductImageFilter.hxx +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbDotProductImageFilter_hxx -#define otbDotProductImageFilter_hxx - -#include "otbDotProductImageFilter.h" - -namespace otb -{ - -/** - * - */ -template <class TInputImage, class TOutputImage> -DotProductImageFilter<TInputImage, TOutputImage> -::DotProductImageFilter() -{ -} - -template <class TInputImage, class TOutputImage> -void -DotProductImageFilter<TInputImage, TOutputImage> -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - -} // end namespace - -#endif diff --git a/Modules/Core/Functor/include/otbDotProductImageFilter.h b/Modules/Core/Functor/include/otbDotProductImageFilter.h new file mode 100644 index 0000000000..471787a8fd --- /dev/null +++ b/Modules/Core/Functor/include/otbDotProductImageFilter.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef otbDotProductImageFilter_h +#define otbDotProductImageFilter_h + +#include "itkMacro.h" +#include "otbFunctorImageFilter.h" + +namespace otb +{ + +namespace Functor { + +/** \class DotProductFunctor + * + * \brief Computes the dot product against a specific vector + * + * \ingroup OTBCommon + */ +template<class TInput, class TOutput> +class DotProductFunctor +{ +public: + typedef TInput InputType; + typedef TOutput OutputType; + + DotProductFunctor() = default; + virtual ~DotProductFunctor() = default; + + const InputType& GetVector() + { + return m_Vector; + } + + void SetVector(const InputType& m) + { + m_Vector = m; + } + + OutputType operator ()(const InputType& in) + { + assert(in.Size() == m.Size()); + OutputType result = 0; + for(unsigned int i = 0; i < in.Size(); ++i) + { + result += in[i] * m_Vector[i]; + } + return result; + } + +private: + InputType m_Vector; +}; +} // namespace Functor + +/** \typedef DotProductImageFilter + * + * \brief Applies pixel-wise dot product to a VectorImage + * + * Given a vector, this filter outputs the dot product of each pixel of a multiband image + * with respect to the specified vector + * + * \sa otb::Functor::DotProductFunctor + * + * \ingroup Streamed + * \ingroup Threaded + * + * \ingroup OTBFunctor + */ +template <typename TInputImage, typename TOutputImage> +using DotProductImageFilter = FunctorImageFilter< + Functor::DotProductFunctor<typename TInputImage::PixelType, typename TOutputImage::PixelType> >; + +} // namespace otb +#endif diff --git a/Modules/Filtering/Statistics/test/otbProjectiveProjection.cxx b/Modules/Filtering/Statistics/test/otbProjectiveProjection.cxx index bf85532bc4..221253601b 100644 --- a/Modules/Filtering/Statistics/test/otbProjectiveProjection.cxx +++ b/Modules/Filtering/Statistics/test/otbProjectiveProjection.cxx @@ -23,7 +23,6 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -#include "otbDotProductImageFilter.h" #include "otbProjectiveProjectionImageFilter.h" #include "otbMatrixImageFilter.h" #include "otbVectorImageToMatrixImageFilter.h" @@ -38,7 +37,6 @@ typedef otb::Image<PixelType, Dimension> ImageType; typedef otb::VectorImage<PixelType, Dimension> VectorImageType; typedef otb::ImageFileReader<VectorImageType> ReaderType; typedef otb::ProjectiveProjectionImageFilter<VectorImageType, VectorImageType, PrecisionType> ProjectiveProjectionImageFilterType; -typedef otb::DotProductImageFilter<VectorImageType, ImageType> DotProductImageFilterType; typedef otb::MatrixImageFilter<VectorImageType, VectorImageType> MatrixImageFilterType; typedef otb::VectorImageToMatrixImageFilter<VectorImageType> VectorImageToMatrixImageFilterType; typedef otb::ImageFileWriter<VectorImageType> WriterType; diff --git a/Modules/Hyperspectral/EndmembersExtraction/include/otbVcaImageFilter.hxx b/Modules/Hyperspectral/EndmembersExtraction/include/otbVcaImageFilter.hxx index c320b26a96..a1a9f4a9d1 100644 --- a/Modules/Hyperspectral/EndmembersExtraction/include/otbVcaImageFilter.hxx +++ b/Modules/Hyperspectral/EndmembersExtraction/include/otbVcaImageFilter.hxx @@ -266,7 +266,7 @@ void VCAImageFilter<TImage>::GenerateData() dotfY->SetInput(Y); typename VectorImageType::PixelType fV(f.data_block(), f.size()); - dotfY->SetVector(typename VectorImageType::PixelType(fV)); + dotfY->GetModifiableFunctor().SetVector(typename VectorImageType::PixelType(fV)); typename ImageType::Pointer v = dotfY->GetOutput(); // abs(v) diff --git a/Modules/Hyperspectral/EndmembersExtraction/otb-module.cmake b/Modules/Hyperspectral/EndmembersExtraction/otb-module.cmake index efdc1bc173..f61e9db8c7 100644 --- a/Modules/Hyperspectral/EndmembersExtraction/otb-module.cmake +++ b/Modules/Hyperspectral/EndmembersExtraction/otb-module.cmake @@ -31,6 +31,7 @@ otb_module(OTBEndmembersExtraction OTBProjection OTBBoostAdapters OTBCommon + OTBFunctor TEST_DEPENDS OTBTestKernel -- GitLab