diff --git a/Modules/Core/Functor/include/otbFunctorImageFilter.h b/Modules/Core/Functor/include/otbFunctorImageFilter.h index 3af0e552c3ac1df83b5ebdce796a521cfbfeae06..2b2be20a409b48faa10abc171fd5cba41df59e08 100644 --- a/Modules/Core/Functor/include/otbFunctorImageFilter.h +++ b/Modules/Core/Functor/include/otbFunctorImageFilter.h @@ -162,13 +162,6 @@ 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; -// }; - - /** * \struct FunctorFilterSuperclassHelper * \brief Struct allowing to derive the superclass prototype for the @@ -208,7 +201,7 @@ template <typename C, typename R, typename... T> struct FunctorFilterSuperclassH }; /** - * brief This helper method builds a fully functional FunctorImageFilter from a functor instance + * \brief This helper method builds a fully functional FunctorImageFilter from a functor instance * * Functor can be any operator() that matches the following: * - Accepts any number of arguments of T, diff --git a/Modules/Core/Functor/include/otbVariadicInputsImageFilter.h b/Modules/Core/Functor/include/otbVariadicInputsImageFilter.h index 5ed4a29e85d2ea44fe23b51131349d61574b552d..9625815f24f3e54a2df56af5ee0560144b7fcc4d 100644 --- a/Modules/Core/Functor/include/otbVariadicInputsImageFilter.h +++ b/Modules/Core/Functor/include/otbVariadicInputsImageFilter.h @@ -24,8 +24,30 @@ namespace otb { -/// TODO: Documentation - +/** + * \brief Base class for image filter with variadic inputs. + * + * This filter act as a base class for all filters that will take + * several input images with different types and produce an output + * image. + * + * Type for each input is taken from the variadic template parameter + * TInputs. + * + * Inputs get be set/get with SetVariadicInput<N>() and + * GetVariadicInput<N>(), when N is the index (first input is 0) of + * the input. This is resolved at compile time: you can not call + * SetVariadicInput<N>() with an argument not matching the Nth input + * type (it will lead to type mismatch compilation error). + * + * Alternatively, you can call SetVariadicInputs() with all the input + * image in the same order as in the template parameters. + * + * Last, there is a macro that generates SetInput1() ... SetInput10() + * (iff the number of varidic input types is large enough) for + * backward compatibility. + * + */ template<class TOuptut, class ... TInputs> class VariadicInputsImageFilter : public itk::ImageSource<TOuptut> { public: @@ -39,11 +61,15 @@ public: template <size_t I> using InputImageType = typename std::tuple_element<I,InputTypesTupleType>::type; static constexpr size_t NumberOfInputs = std::tuple_size<InputTypesTupleType>::value; - + // Good old new macro itkNewMacro(Self); - + + /** + * \param Set the Ith input + */ template <std::size_t I> void SetVariadicInput(const typename std::tuple_element<I,InputTypesTupleType>::type * inputPtr) { + static_assert(std::tuple_size<InputTypesTupleType>::value>I,"Template value I is out of range."); this->SetNthInput(I,const_cast<typename std::tuple_element<I,InputTypesTupleType>::type *>(inputPtr)); } @@ -68,19 +94,29 @@ public: DefineLegacySetInputMacro(10); #undef DefineLegacySetInputMacro - + + /** + * \return the Ith variadic input + */ template <std::size_t I> const typename std::tuple_element<I,InputTypesTupleType>::type * GetVariadicInput() { + static_assert(std::tuple_size<InputTypesTupleType>::value>I,"Template value I is out of range."); using ImageType = typename std::tuple_element<I,InputTypesTupleType>::type; return dynamic_cast<const ImageType *>(this->GetInput(I)); } + /** + * \param inputs A vararg list of inputs + */ void SetVariadicInputs(TInputs*... inputs) { auto inTuple = std::make_tuple(inputs...); SetInputsImpl(inTuple,std::make_index_sequence<sizeof...(inputs)>{}); } + /** + * \return A tuple with all inputs + */ auto GetVariadicInputs() { return GetInputsImpl(std::make_index_sequence<sizeof...(TInputs)>{});