Commit 17a4c5a4 authored by Victor Poughon's avatar Victor Poughon

ENH: FunctorFilter: fix legacy SetInput and improve tests

parent 2d8c2a48
...@@ -208,6 +208,7 @@ public: ...@@ -208,6 +208,7 @@ public:
// A tuple of bool of the same size as the number of arguments in // A tuple of bool of the same size as the number of arguments in
// the functor // the functor
using InputHasNeighborhood = typename FunctorFilterSuperclassHelper<TFunction>::InputHasNeighborhood; using InputHasNeighborhood = typename FunctorFilterSuperclassHelper<TFunction>::InputHasNeighborhood;
using InputTypesTupleType = typename Superclass::InputTypesTupleType;
/** Run-time type information (and related methods). */ /** Run-time type information (and related methods). */
itkTypeMacro(FunctorImageFilter, ImageToImageFilter); itkTypeMacro(FunctorImageFilter, ImageToImageFilter);
...@@ -232,16 +233,17 @@ public: ...@@ -232,16 +233,17 @@ public:
return m_Functor; return m_Functor;
} }
private: protected:
/// Actual creation of the filter is handled by this free function
friend auto NewFunctorFilter<TFunction>(const TFunction& f, itk::Size<2> radius);
/// Constructor of functor filter, will copy the functor /// Constructor of functor filter, will copy the functor
FunctorImageFilter(const FunctorType& f, itk::Size<2> radius) : m_Functor(f), m_Radius(radius) {}; FunctorImageFilter(const FunctorType& f, itk::Size<2> radius) : m_Functor(f), m_Radius(radius) {};
FunctorImageFilter(const Self &) = delete; FunctorImageFilter(const Self &) = delete;
void operator =(const Self&) = delete; void operator =(const Self&) = delete;
~FunctorImageFilter() = default; ~FunctorImageFilter() = default;
private:
/// Actual creation of the filter is handled by this free function
friend auto NewFunctorFilter<TFunction>(const TFunction& f, itk::Size<2> radius);
/** Overload of ThreadedGenerateData */ /** Overload of ThreadedGenerateData */
void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override; void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
......
...@@ -38,16 +38,16 @@ public: ...@@ -38,16 +38,16 @@ public:
itkNewMacro(Self); itkNewMacro(Self);
template <std::size_t I> void SetVInput(typename std::tuple_element<I,InputTypesTupleType>::type * inputPtr) template <std::size_t I> void SetVInput(const typename std::tuple_element<I,InputTypesTupleType>::type * inputPtr)
{ {
this->SetNthInput(I,inputPtr); this->SetNthInput(I,const_cast<typename std::tuple_element<I,InputTypesTupleType>::type *>(inputPtr));
} }
#define DefineLegacySetInputMacro(n) \ #define DefineLegacySetInputMacro(n) \
template<typename Tuple = InputTypesTupleType, typename std::enable_if<n<=std::tuple_size<Tuple>::value >::type> \ template<typename Tuple = InputTypesTupleType, typename Check = typename std::enable_if<n<=std::tuple_size<Tuple>::value >::type> \
void SetInput ## n(typename std::tuple_element<n-1,Tuple>::type * img) \ void SetInput ## n(const typename std::tuple_element<n-1,Tuple>::type * img) \
{ \ { \
this->SetVInput<n-1>(img); \ this->template SetVInput<n-1>(img); // template keyword to avoid C++ parsing ambiguity \
} }
// The following defines legacy setters SetInput1() // The following defines legacy setters SetInput1()
......
...@@ -99,7 +99,13 @@ template <typename T> struct TypesCheck ...@@ -99,7 +99,13 @@ template <typename T> struct TypesCheck
// Build and run filter // Build and run filter
auto functor = TestOperator<TOut,TIn>{}; auto functor = TestOperator<TOut,TIn>{};
auto filter = NewFunctorFilter(functor); auto filter = NewFunctorFilter(functor);
using FilterType = typename decltype(filter)::ObjectType;
static_assert(std::is_same<typename std::tuple_element<0, typename FilterType::Superclass::InputTypesTupleType>::type, InputImageType>::value, "");
filter->SetVInputs(in); filter->SetVInputs(in);
filter->SetInput1(in);
filter->template SetVInput<0>(in); // template keyword to avoid C++ parse ambiguity
filter->Update(); filter->Update();
} }
...@@ -260,6 +266,10 @@ int otbFunctorImageFilter(int itkNotUsed(argc), char * itkNotUsed(argv) []) ...@@ -260,6 +266,10 @@ int otbFunctorImageFilter(int itkNotUsed(argc), char * itkNotUsed(argv) [])
auto filter = otb::VariadicInputsImageFilter<VectorImageType,VectorImageType,ImageType>::New(); auto filter = otb::VariadicInputsImageFilter<VectorImageType,VectorImageType,ImageType>::New();
filter->SetVInput<0>(vimage); filter->SetVInput<0>(vimage);
filter->SetVInput<1>(image); filter->SetVInput<1>(image);
filter->SetInput1(vimage);
filter->SetInput2(image);
filter->SetVInputs(vimage,image); filter->SetVInputs(vimage,image);
std::cout<<filter->GetVInput<0>()<< filter->GetVInput<1>()<<std::endl; std::cout<<filter->GetVInput<0>()<< filter->GetVInput<1>()<<std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment