Commit 10f1592e authored by Julien Michel's avatar Julien Michel

MRG

parents a5e6a982 f34b7ce3
...@@ -285,21 +285,24 @@ public: ...@@ -285,21 +285,24 @@ public:
/** Run-time type information (and related methods). */ /** Run-time type information (and related methods). */
itkTypeMacro(FunctorImageFilter, ImageToImageFilter); itkTypeMacro(FunctorImageFilter, ImageToImageFilter);
/** Get the functor object.
/** Get the functor object. The functor is returned by reference. *
* (Functors do not have to derive from itk::LightObject, so they do * \return A non-const reference to the Functor in use. Note that
* not necessarily have a reference count. So we cannot return a * this call will call the Modified() function of the filter, which
* SmartPointer.) */ * will trigger a full output computation upon Update(). For
FunctorType& GetFunctor() * inspection only, prefer using GetFunctor()
*/
FunctorType& GetModifiableFunctor()
{ {
this->Modified(); this->Modified();
return m_Functor; return m_Functor;
} }
/** Get the functor object. The functor is returned by reference. /** Get the functor object.
* (Functors do not have to derive from itk::LightObject, so they do *
* not necessarily have a reference count. So we cannot return a * \return A const reference to the Functor in use. For a
* SmartPointer.) */ * modifiable version of the functor, see GetModifiableFunctor().
*/
const FunctorType& GetFunctor() const const FunctorType& GetFunctor() const
{ {
return m_Functor; return m_Functor;
......
...@@ -139,13 +139,13 @@ template <typename T> struct GetProxy<itk::ConstNeighborhoodIterator<T> > ...@@ -139,13 +139,13 @@ template <typename T> struct GetProxy<itk::ConstNeighborhoodIterator<T> >
}; };
// Will be easier to write in c++17 with std::apply and fold expressions // Will be easier to write in c++17 with std::apply and fold expressions
template <class Tuple, class Oper, size_t...Is> auto CallOperatorImpl(Tuple& t, const Oper & oper,std::index_sequence<Is...>) template <class Tuple, class Oper, size_t...Is> auto CallOperatorImpl(Tuple& t, Oper & oper,std::index_sequence<Is...>)
{ {
return oper(GetProxy<typename std::remove_reference<decltype(std::get<Is>(t))>::type>::Get(std::get<Is>(t))...); return oper(GetProxy<typename std::remove_reference<decltype(std::get<Is>(t))>::type>::Get(std::get<Is>(t))...);
} }
// Will be easier to write in c++17 with std::apply and fold expressions // Will be easier to write in c++17 with std::apply and fold expressions
template <class Oper, typename ... Args> auto CallOperator(const Oper& oper, std::tuple<Args...> & t) template <class Oper, typename ... Args> auto CallOperator(Oper& oper, std::tuple<Args...> & t)
{ {
return CallOperatorImpl(t,oper,std::make_index_sequence<sizeof...(Args)>{}); return CallOperatorImpl(t,oper,std::make_index_sequence<sizeof...(Args)>{});
} }
......
...@@ -91,6 +91,21 @@ template <typename T> struct TypesCheck ...@@ -91,6 +91,21 @@ template <typename T> struct TypesCheck
} }
}; };
// Fake test operator non const
template <typename TOut,typename TIn> struct TestOperatorNonConst
{
auto operator()(const TIn&)
{
TOut res(OutputSize());
return res;
}
constexpr size_t OutputSize(...) const
{
return 1;
}
};
template <typename TOut, typename TIn> void TestFilter() template <typename TOut, typename TIn> void TestFilter()
{ {
...@@ -114,7 +129,6 @@ template <typename T> struct TypesCheck ...@@ -114,7 +129,6 @@ template <typename T> struct TypesCheck
using FilterType = typename decltype(filter)::ObjectType; using FilterType = typename decltype(filter)::ObjectType;
static_assert(FilterType::NumberOfInputs == 1,""); static_assert(FilterType::NumberOfInputs == 1,"");
static_assert(std::is_same<typename FilterType::template InputImageType<0>, InputImageType>::value, ""); static_assert(std::is_same<typename FilterType::template InputImageType<0>, InputImageType>::value, "");
filter->SetVariadicInputs(in); filter->SetVariadicInputs(in);
filter->SetInput1(in); filter->SetInput1(in);
filter->template SetVariadicInput<0>(in); // template keyword to filter->template SetVariadicInput<0>(in); // template keyword to
...@@ -131,6 +145,14 @@ template <typename T> struct TypesCheck ...@@ -131,6 +145,14 @@ template <typename T> struct TypesCheck
res = filter1->template GetVariadicNamedInput<tag>(); res = filter1->template GetVariadicNamedInput<tag>();
filter1->Update(); filter1->Update();
// Test with non const operator
auto functorNonConstOperator = TestOperatorNonConst<TOut,TIn>{};
auto filterWithNonConstOperator = NewFunctorFilter(functorNonConstOperator);
filterWithNonConstOperator->SetInput1(in);
filterWithNonConstOperator->Update();
// Test with simple lambda // Test with simple lambda
auto lambda = [] (const TIn &) auto lambda = [] (const TIn &)
{ {
...@@ -140,6 +162,10 @@ template <typename T> struct TypesCheck ...@@ -140,6 +162,10 @@ template <typename T> struct TypesCheck
auto filterWithLambda = NewFunctorFilter(lambda,1, {{0,0}}); auto filterWithLambda = NewFunctorFilter(lambda,1, {{0,0}});
filterWithLambda->SetVariadicInputs(in); filterWithLambda->SetVariadicInputs(in);
filterWithLambda->Update(); filterWithLambda->Update();
// Test with standard filter use
using FullFilterType = otb::FunctorImageFilter<TestOperator<TOut,TIn>>;
auto filter2 = FullFilterType::New();
} }
TypesCheck() TypesCheck()
......
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