27 #ifndef MLN_ACCU_TRANSFORM_LINE_HH
28 # define MLN_ACCU_TRANSFORM_LINE_HH
43 # include <mln/core/concept/image.hh>
44 # include <mln/core/concept/meta_accumulator.hh>
45 # include <mln/extension/adjust.hh>
55 template <
typename A,
typename I>
56 mln_ch_value(I, mln_result(A))
57 transform_line(const Accumulator<A>& a,
58 const Image<I>& input,
59 unsigned length,
unsigned dir);
61 template <typename A, typename I>
63 transform_line(const Meta_Accumulator<A>& a,
64 const Image<I>& input,
65 unsigned length,
unsigned dir);
69 # ifndef MLN_INCLUDE_ONLY
78 template <
typename A,
typename I>
80 transform_line_tests(
const Accumulator<A>& a_,
const Image<I>& input_)
83 const I& input = exact(input_);
85 mln_precondition(input.is_valid());
87 mln_precondition(
sizeof(a.take(input(*p)), 0) ==
sizeof(
int));
107 template <
typename A,
typename I>
109 mln_ch_value(I, mln_result(A))
110 transform_line(const Accumulator<A>& a_,
111 const Image<I>& input_,
112 unsigned length,
unsigned dir)
114 trace::entering(
"accu::impl::transform_line");
116 const I& input = exact(input_);
119 internal::transform_line_tests(a, input);
123 mln_ch_value(I, mln_result(A)) output;
126 typedef mln_psite(I) P;
128 pmin = input.domain().pmin(),
129 pmax = input.domain().pmax();
131 pmax_dir = pmax[dir],
132 pmin_dir = pmin[dir];
136 def::coord& p_dir = p [dir];
137 def::coord& qt_dir = qt[dir];
138 def::coord& qu_dir = qu[dir];
147 qt_dir = p_dir - length / 2;
151 for (
unsigned i = 0; i < length; ++i)
158 output(p) = a.to_result();
163 while (p_dir < pmax_dir)
175 output(p) = a.to_result();
183 for (
int c = P::dim - 1; c >= 0; --c)
197 trace::exiting(
"accu::impl::transform_line");
204 template <
typename A,
typename I>
206 mln_ch_value(I, mln_result(A))
207 transform_line_fastest(const Accumulator<A>& a_,
208 const Image<I>& input_,
209 unsigned length,
unsigned dir)
211 trace::entering(
"accu::impl::transform_line_fastest");
213 const I& input = exact(input_);
216 internal::transform_line_tests(a, input);
220 mln_ch_value(I, mln_result(A)) output;
223 typedef mln_psite(I) P;
225 pmin = input.domain().pmin(),
226 pmax = input.domain().pmax();
228 pmax_dir = pmax[dir],
229 pmin_dir = pmin[dir];
232 def::coord& p_dir = p[dir];
235 mln_delta(P) dp(literal::zero);
237 int step = input.delta_index(dp);
244 unsigned o_p = input.index_of_point(p);
245 unsigned o_qt = o_p - (length / 2) * step;
246 unsigned o_qu = o_qt;
249 for (
unsigned i = 0; i < length; ++i)
254 a.take(input.element(o_qt));
257 output.element(o_p) = a.to_result();
262 while (p_dir < pmax_dir)
267 a.take(input.element(o_qt));
270 a.untake(input.element(o_qu));
275 output.element(o_p) = a.to_result();
283 for (
int c = P::dim - 1; c >= 0; --c)
297 trace::exiting(
"accu::impl::transform_line_fastest");
441 template <
typename A,
typename I>
443 mln_ch_value(I, mln_result(A))
444 transform_line_dispatch(trait::image::speed::any,
445 trait::accumulator::when_pix::any,
446 const Accumulator<A>& a,
447 const Image<I>& input,
448 unsigned length,
unsigned dir)
450 return impl::generic::transform_line(a,
455 template <
typename A,
typename I>
457 mln_ch_value(I, mln_result(A))
458 transform_line_dispatch(trait::image::speed::fastest,
459 trait::accumulator::when_pix::use_none,
460 const Accumulator<A>& a,
461 const Image<I>& input,
462 unsigned length,
unsigned dir)
464 return impl::transform_line_fastest(a,
469 template <
typename A,
typename I>
471 mln_ch_value(I, mln_result(A))
472 transform_line_dispatch(trait::image::speed::fastest,
473 trait::accumulator::when_pix::use_v,
474 const Accumulator<A>& a,
475 const Image<I>& input,
476 unsigned length,
unsigned dir)
478 return impl::transform_line_fastest(a,
483 template <
typename A,
typename I>
485 mln_ch_value(I, mln_result(A))
486 transform_line_dispatch(const Accumulator<A>& a,
487 const Image<I>& input,
488 unsigned length,
unsigned dir)
490 return transform_line_dispatch(mln_trait_image_speed(I)(),
491 mln_trait_accumulator_when_pix(A)(),
492 a, input, length, dir);
503 template <
typename A,
typename I>
505 mln_ch_value(I, mln_result(A))
506 transform_line(const Accumulator<A>& a,
507 const Image<I>& input,
508 unsigned length,
unsigned dir)
510 trace::entering(
"accu::transform_line");
512 internal::transform_line_tests(a, input);
516 mln_ch_value(I, mln_result(A)) output;
517 output = internal::transform_line_dispatch(a, input, length, dir);
519 trace::exiting("accu::transform_line");
524 template <typename A, typename I>
527 transform_line(const Meta_Accumulator<A>& a,
528 const Image<I>& input,
529 unsigned length,
unsigned dir)
531 trace::entering(
"accu::transform_line");
533 typedef mln_accu_with(A, mln_value(I)) A_;
534 A_ a_ = accu::unmeta(exact(a), mln_value(I)());
536 internal::transform_line_tests(a_, input);
538 mln_ch_value(I, mln_result(A_)) output;
539 output = internal::transform_line_dispatch(a_, input, length, dir);
541 trace::exiting("accu::transform_line");
546 # endif // ! MLN_INCLUDE_ONLY
553 #endif // ! MLN_ACCU_TRANSFORM_LINE_HH