diff --git a/Modules/Core/Functor/include/otbFunctorImageFilter.h b/Modules/Core/Functor/include/otbFunctorImageFilter.h index b5fb4a2ff9ed8ab67baff13db10ca676e2dddd1a..35027d7fe3c6314f7c9680fa7dd060c7ccb7908e 100644 --- a/Modules/Core/Functor/include/otbFunctorImageFilter.h +++ b/Modules/Core/Functor/include/otbFunctorImageFilter.h @@ -417,7 +417,44 @@ template <typename Functor, typename TNameMap = void> auto NewFunctorFilter(Func return NewFunctorFilter<FunctorType,TNameMap>(decoratedF,radius); } +/** + * \class DefaultConstructibleFunctorImageFilter + * \brief Adds New() to FunctorImageFilter + * + * FunctorImageFilter is not default constructible (to support lambda + * as template parameter), and thus does not offer the New() static method. + * + * This class provides explicit default construction and New() static + * method when it is required to stick with the ITK/OTB workflow of + * default construction. It can not be used with lamda as TFunction. + * + * \sa FunctorImageFilter + * \ingroup OTBFunctor + */ + +template <class TFunction, class TNameMap = void> +class ITK_EXPORT DefaultConstructibleFunctorImageFilter : public FunctorImageFilter<TFunction, TNameMap> +{ +public: + // Standard typedefs + using Self = DefaultConstructibleFunctorImageFilter; + using FunctorType = TFunction; + using Pointer = itk::SmartPointer<Self>; + using ConstPointer = itk::SmartPointer<const Self>; + // Superclass through the helper struct + using Superclass = FunctorImageFilter<TFunction, TNameMap>; + using OutputImageType = typename Superclass::OutputImageType; + + itkNewMacro(Self); + itkTypeMacro(DefaultConstructibleFunctorImageFilter, FunctorImageFilter); + +protected: + DefaultConstructibleFunctorImageFilter() : Superclass(TFunction{}, {{0, 0}}){}; + DefaultConstructibleFunctorImageFilter(const Self&) = delete; + void operator=(const Self&) = delete; + ~DefaultConstructibleFunctorImageFilter() = default; +}; }// namespace otb #ifndef OTB_MANUAL_INSTANTIATION diff --git a/Modules/Core/Functor/test/otbFunctorImageFilter.cxx b/Modules/Core/Functor/test/otbFunctorImageFilter.cxx index bc3c5f624f848c90a5e4b25950477c0e38cac9e3..3d7e948a50ebb9b3444eb131483702ac61070224 100644 --- a/Modules/Core/Functor/test/otbFunctorImageFilter.cxx +++ b/Modules/Core/Functor/test/otbFunctorImageFilter.cxx @@ -162,6 +162,12 @@ template <typename TOut,typename TIn> struct TestOperatorVoidReturn res = filter1->GetVariadicNamedInput(tag{}); filter1->Update(); + // Test default constructible version + using DefaultConstructibleFilterType = DefaultConstructibleFunctorImageFilter<decltype(functor)>; + auto oldStyleNewFilter = DefaultConstructibleFilterType::New(); + oldStyleNewFilter->SetVariadicInputs(in); + oldStyleNewFilter->Update(); + // Hack to silent -Wunused-but-set-variable std::cout<<res<<std::endl;