From db803d3c173c919f55d0d183d33598176eedefc8 Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@cnes.fr> Date: Fri, 16 Nov 2018 09:46:15 +0100 Subject: [PATCH] COMP: Fix static_asserts on pixel type detection --- .../Functor/include/otbFunctorImageFilter.h | 50 ++++++++++++++----- .../Functor/test/otbFunctorImageFilter.cxx | 5 +- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Modules/Core/Functor/include/otbFunctorImageFilter.h b/Modules/Core/Functor/include/otbFunctorImageFilter.h index 7e13f002ce..1a7daba4ec 100644 --- a/Modules/Core/Functor/include/otbFunctorImageFilter.h +++ b/Modules/Core/Functor/include/otbFunctorImageFilter.h @@ -32,7 +32,6 @@ namespace otb { - /** * \struct IsNeighborhood * \brief Struct testing if T is a neighborhood @@ -73,22 +72,42 @@ template <class T> struct IsSuitableType static constexpr bool value = std::is_scalar<T>::value; }; +/// Unwrap complex template <class T> struct IsSuitableType<std::complex<T>> { static constexpr bool value = IsSuitableType<T>::value; }; + +/// Unwrap VariableLengthVector template <class T> struct IsSuitableType<itk::VariableLengthVector<T>> { static constexpr bool value = IsSuitableType<T>::value; }; + +/// Unwrap FixedArray template <class T> struct IsSuitableType<itk::FixedArray<T>> { static constexpr bool value = IsSuitableType<T>::value; }; + +/// Unwrap RGBPixel template <class T> struct IsSuitableType<itk::RGBPixel<T>> { static constexpr bool value = IsSuitableType<T>::value; }; + +/// Unwrap RGBAPixel template <class T> struct IsSuitableType<itk::RGBAPixel<T>> { static constexpr bool value = IsSuitableType<T>::value; }; +/// Discard const qualifier +template <class T> struct IsSuitableType<const T>{ + static constexpr bool value = IsSuitableType<T>::value; +}; + +/// Discard reference +template <class T> struct IsSuitableType<T &>{ + static constexpr bool value = IsSuitableType<T>::value; +}; + + /** * \struct PixelTypeDeduction * \brief Helper struct to derive PixelType from template parameter. @@ -110,13 +129,20 @@ template <class T> struct PixelTypeDeduction<itk::Neighborhood<T>> using PixelType = T; }; -/// Partial specialisation for const itk::Neighborhood<T> & -template <class T> struct PixelTypeDeduction<const itk::Neighborhood<T>&> +/// Discard const qualifier +template <class T> struct PixelTypeDeduction<const T> { - static_assert(IsSuitableType<T>::value,"T can not be used as a template parameter for Image or VectorImage classes."); - using PixelType = T; + using PixelType = typename PixelTypeDeduction<T>::PixelType; }; +/// Discard reference +template <class T> struct PixelTypeDeduction<T &> +{ + using PixelType = typename PixelTypeDeduction<T>::PixelType; +}; + + + /** * \struct ImageTypeDeduction * \brief Helper struct to derive ImageType from template parameter @@ -136,11 +162,11 @@ template <class T> struct ImageTypeDeduction<itk::VariableLengthVector<T>> using ImageType = otb::VectorImage<T>; }; -/// Partial specialisation for const T & -template <class T> struct ImageTypeDeduction<const T &> -{ - using ImageType = typename ImageTypeDeduction<T>::ImageType; -}; +// /// Partial specialisation for const T & +// template <class T> struct ImageTypeDeduction<const T &> +// { +// using ImageType = typename ImageTypeDeduction<T>::ImageType; +// }; /** @@ -165,7 +191,7 @@ template <typename R, typename... T> struct FunctorFilterSuperclassHelper<R(*)(T using InputHasNeighborhood = std::tuple<typename IsNeighborhood<T>::ValueType...>; }; -// Partial specialisation for R(C::*)(T...) const +/// Partial specialisation for R(C::*)(T...) const template <typename C, typename R, typename... T> struct FunctorFilterSuperclassHelper<R(C::*)(T...) const> { using OutputImageType = typename ImageTypeDeduction<R>::ImageType; @@ -173,7 +199,7 @@ template <typename C, typename R, typename... T> struct FunctorFilterSuperclassH using InputHasNeighborhood = std::tuple<typename IsNeighborhood<T>::ValueType...>; }; -// Partial specialisation for R(C::*)(T...) +/// Partial specialisation for R(C::*)(T...) template <typename C, typename R, typename... T> struct FunctorFilterSuperclassHelper<R(C::*)(T...)> { using OutputImageType = typename ImageTypeDeduction<R>::ImageType; diff --git a/Modules/Core/Functor/test/otbFunctorImageFilter.cxx b/Modules/Core/Functor/test/otbFunctorImageFilter.cxx index e1cd5360e2..cf42cb22b5 100644 --- a/Modules/Core/Functor/test/otbFunctorImageFilter.cxx +++ b/Modules/Core/Functor/test/otbFunctorImageFilter.cxx @@ -62,8 +62,6 @@ template <typename T> struct TypesCheck // Test ImageTypeDeduction struct static_assert(std::is_same<typename ImageTypeDeduction<ScalarType>::ImageType,ImageType>::value,""); static_assert(std::is_same<typename ImageTypeDeduction<VectorType>::ImageType,VectorImageType>::value,""); - static_assert(std::is_same<typename ImageTypeDeduction<const ScalarType &>::ImageType,ImageType>::value,""); - static_assert(std::is_same<typename ImageTypeDeduction<const VectorType &>::ImageType,VectorImageType>::value,""); // Fake test operator template <typename TOut,typename TIn> struct TestOperator @@ -120,7 +118,8 @@ template <typename T> struct TypesCheck } }; -auto checksDouble = TypesCheck<double>{}; +auto checksInt = TypesCheck<int>{}; +auto checksDouble = TypesCheck<double>{}; auto checksComplex = TypesCheck<std::complex<double>>{}; // Example functors -- GitLab