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))
58 const Image<I>& input,
59 unsigned length,
unsigned dir);
61 template <typename A, typename I>
62 mln_ch_value(I, mln_meta_accu_result(A, mln_value(I)))
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))
111 const Image<I>& input_,
112 unsigned length,
unsigned dir)
114 mln_trace(
"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)
203 template <
typename A,
typename I>
205 mln_ch_value(I, mln_result(A))
206 transform_line_fastest(const Accumulator<A>& a_,
207 const Image<I>& input_,
208 unsigned length,
unsigned dir)
210 mln_trace(
"accu::impl::transform_line_fastest");
212 const I& input =
exact(input_);
215 internal::transform_line_tests(a, input);
219 mln_ch_value(I, mln_result(A)) output;
222 typedef mln_psite(I) P;
224 pmin = input.domain().pmin(),
225 pmax = input.domain().pmax();
227 pmax_dir = pmax[dir],
228 pmin_dir = pmin[dir];
231 def::
coord& p_dir = p[dir];
234 mln_delta(P) dp(literal::zero);
236 int step = input.delta_offset(dp);
243 unsigned o_p = input.offset_of_point(p);
244 unsigned o_qt = o_p - (length / 2) * step;
245 unsigned o_qu = o_qt;
248 for (
unsigned i = 0; i < length; ++i)
253 a.take(input.element(o_qt));
256 output.element(o_p) = a.to_result();
261 while (p_dir < pmax_dir)
266 a.take(input.element(o_qt));
269 a.untake(input.element(o_qu));
274 output.element(o_p) = a.to_result();
282 for (
int c = P::dim - 1; c >= 0; --c)
438 template <
typename A,
typename I>
440 mln_ch_value(I, mln_result(A))
441 transform_line_dispatch(trait::image::speed::any,
442 trait::accumulator::when_pix::any,
443 const Accumulator<A>& a,
444 const Image<I>& input,
445 unsigned length,
unsigned dir)
452 template <
typename A,
typename I>
454 mln_ch_value(I, mln_result(A))
455 transform_line_dispatch(trait::image::speed::fastest,
456 trait::accumulator::when_pix::use_none,
457 const Accumulator<A>& a,
458 const Image<I>& input,
459 unsigned length,
unsigned dir)
461 return impl::transform_line_fastest(a,
466 template <
typename A,
typename I>
468 mln_ch_value(I, mln_result(A))
469 transform_line_dispatch(trait::image::speed::fastest,
470 trait::accumulator::when_pix::use_v,
471 const Accumulator<A>& a,
472 const Image<I>& input,
473 unsigned length,
unsigned dir)
475 return impl::transform_line_fastest(a,
480 template <
typename A,
typename I>
482 mln_ch_value(I, mln_result(A))
483 transform_line_dispatch(const Accumulator<A>& a,
484 const Image<I>& input,
485 unsigned length,
unsigned dir)
487 return transform_line_dispatch(mln_trait_image_speed(I)(),
488 mln_trait_accumulator_when_pix(A)(),
489 a, input, length, dir);
500 template <
typename A,
typename I>
502 mln_ch_value(I, mln_result(A))
504 const Image<I>& input,
505 unsigned length,
unsigned dir)
507 mln_trace(
"accu::transform_line");
509 internal::transform_line_tests(a, input);
513 mln_ch_value(I, mln_result(A)) output;
514 output = internal::transform_line_dispatch(a, input, length, dir);
520 template <typename A, typename I>
522 mln_ch_value(I, mln_meta_accu_result(A, mln_value(I)))
524 const Image<I>& input,
525 unsigned length,
unsigned dir)
527 mln_trace(
"accu::transform_line");
529 typedef mln_accu_with(A, mln_value(I)) A_;
532 internal::transform_line_tests(a_, input);
534 mln_ch_value(I, mln_result(A_)) output;
535 output = internal::transform_line_dispatch(a_, input, length, dir);
541 # endif // ! MLN_INCLUDE_ONLY
548 #endif // ! MLN_ACCU_TRANSFORM_LINE_HH