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:
// A tuple of bool of the same size as the number of arguments in
// the functor
using InputHasNeighborhood = typename FunctorFilterSuperclassHelper<TFunction>::InputHasNeighborhood;
using InputTypesTupleType = typename Superclass::InputTypesTupleType;
/** Run-time type information (and related methods). */
itkTypeMacro(FunctorImageFilter, ImageToImageFilter);
......@@ -232,16 +233,17 @@ public:
return m_Functor;
}
private:
/// Actual creation of the filter is handled by this free function
friend auto NewFunctorFilter<TFunction>(const TFunction& f, itk::Size<2> radius);
protected:
/// Constructor of functor filter, will copy the functor
FunctorImageFilter(const FunctorType& f, itk::Size<2> radius) : m_Functor(f), m_Radius(radius) {};
FunctorImageFilter(const Self &) = delete;
void operator =(const Self&) = delete;
~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 */
void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
......
......@@ -38,16 +38,16 @@ public:
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) \
template<typename Tuple = InputTypesTupleType, typename std::enable_if<n<=std::tuple_size<Tuple>::value >::type> \
void SetInput ## n(typename std::tuple_element<n-1,Tuple>::type * img) \
template<typename Tuple = InputTypesTupleType, typename Check = typename std::enable_if<n<=std::tuple_size<Tuple>::value >::type> \
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()
......
......@@ -99,7 +99,13 @@ template <typename T> struct TypesCheck
// Build and run filter
auto functor = TestOperator<TOut,TIn>{};
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->SetInput1(in);
filter->template SetVInput<0>(in); // template keyword to avoid C++ parse ambiguity
filter->Update();
}
......@@ -260,6 +266,10 @@ int otbFunctorImageFilter(int itkNotUsed(argc), char * itkNotUsed(argv) [])
auto filter = otb::VariadicInputsImageFilter<VectorImageType,VectorImageType,ImageType>::New();
filter->SetVInput<0>(vimage);
filter->SetVInput<1>(image);
filter->SetInput1(vimage);
filter->SetInput2(image);
filter->SetVInputs(vimage,image);
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