26 #ifndef MLN_MORPHO_ELEMENTARY_LIKE_ERO_FUN_HH
27 # define MLN_MORPHO_ELEMENTARY_LIKE_ERO_FUN_HH
34 # include <mln/morpho/includes.hh>
46 template <
typename A,
typename F,
47 typename I,
typename N>
49 like_ero_fun(const Meta_Accumulator<A>& a, const F& f,
50 const Image<I>& input, const Neighborhood<N>& nbh);
54 # ifndef MLN_INCLUDE_ONLY
61 template <
typename V,
typename A>
62 V operator()(
const V& ,
const A& a)
const
77 template <
typename A,
typename F,
78 typename I,
typename N>
80 like_ero_fun(const Meta_Accumulator<A>& a_, const F& f,
81 const Image<I>& input_, const Neighborhood<N>& nbh_)
83 trace::entering(
"morpho::elementary::impl::generic::like_ero_fun");
85 const I& input = exact(input_);
86 const N& nbh = exact(nbh_);
88 mln_accu_with(A, mln_value(I)) a = accu::unmeta(exact(a_), mln_value(I)());
89 extension::adjust_fill(input, nbh, a);
91 mln_concrete(I) output;
92 initialize(output, input);
94 mln_piter(I) p(input.domain());
95 mln_niter(N) n(nbh, p);
98 a.take_as_init(input(p));
99 for_all(n) if (input.has(n))
101 output(p) = f(input(p), a);
104 trace::exiting("morpho::elementary::impl::generic::like_ero_fun");
111 template <typename A, typename F,
112 typename I, typename N>
114 like_ero_fun_fastest(const Meta_Accumulator<A>& a_, const F& f,
115 const Image<I>& input_, const Neighborhood<N>& nbh_)
117 trace::entering(
"morpho::elementary::impl::like_ero_fun_fastest");
119 const I& input = exact(input_);
120 const N& nbh = exact(nbh_);
122 mln_accu_with(A, mln_value(I)) a = accu::unmeta(exact(a_), mln_value(I)());
123 extension::adjust_fill(input, nbh, a);
125 mln_concrete(I) output;
126 initialize(output, input);
128 mln_pixter(const I) p_in(input);
129 mln_pixter(I) p_out(output);
130 mln_nixter(const I, N) n(p_in, nbh);
131 for_all_2(p_in, p_out)
133 a.take_as_init(p_in.val());
136 p_out.val() = f(p_in.val(), a);
139 trace::exiting("morpho::elementary::impl::like_ero_fun_fastest");
149 template <
typename A,
typename F,
150 typename I,
typename N>
152 like_ero_fun_dispatch(metal::false_,
153 const A& a, const F& f,
154 const I& input, const N& nbh)
156 return impl::generic::like_ero_fun(a, f, input, nbh);
159 template <
typename A,
typename F,
160 typename I,
typename N>
162 like_ero_fun_dispatch(metal::true_,
163 const A& a, const F& f,
164 const I& input, const N& nbh)
166 return impl::like_ero_fun_fastest(a, f, input, nbh);
169 template <
typename A,
typename F,
170 typename I,
typename N>
172 like_ero_fun_dispatch(const A& a, const F& f,
173 const I& input, const N& nbh)
175 typedef mlc_equal(mln_trait_image_speed(I),
176 trait::image::speed::fastest) I_fastest;
177 typedef mln_window(N) W;
178 typedef mln_is_simple_window(W) N_simple;
180 return like_ero_fun_dispatch(mlc_and(I_fastest, N_simple)(),
189 template <typename A, typename F,
190 typename I, typename N>
192 like_ero_fun(const Meta_Accumulator<A>& a, const F& f,
193 const Image<I>& input, const Neighborhood<N>& nbh)
195 return internal::like_ero_fun_dispatch(a, f,
196 exact(input), exact(nbh));
199 # endif // ! MLN_INCLUDE_ONLY
208 #endif // ! MLN_MORPHO_ELEMENTARY_LIKE_ERO_FUN_HH