27 #ifndef MLN_LABELING_COMPUTE_HH
28 # define MLN_LABELING_COMPUTE_HH
48 # include <mln/core/concept/image.hh>
49 # include <mln/core/concept/accumulator.hh>
50 # include <mln/core/concept/meta_accumulator.hh>
51 # include <mln/util/array.hh>
52 # include <mln/convert/from_to.hh>
53 # include <mln/geom/ncols.hh>
54 # include <mln/value/next.hh>
74 template <
typename A,
typename I,
typename L>
75 util::array<mln_result(A)>
76 compute(
const Accumulator<A>& a,
77 const Image<I>& input,
78 const Image<L>& label,
79 const mln_value(L)& nlabels);
93 template <
typename A,
typename I,
typename L>
94 util::array<mln_meta_accu_result(A, mln_value(I))>
95 compute(
const Meta_Accumulator<A>& a,
96 const Image<I>& input,
97 const Image<L>& label,
98 const mln_value(L)& nlabels);
111 template <
typename A,
typename L>
112 util::array<mln_result(A)>
113 compute(
const Accumulator<A>& a,
114 const Image<L>& label,
115 const mln_value(L)& nlabels);
128 template <
typename A,
typename L>
129 util::array<mln_meta_accu_result(A, mln_psite(L))>
130 compute(
const Meta_Accumulator<A>& a,
131 const Image<L>& label,
132 const mln_value(L)& nlabels);
146 template <
typename A,
typename I,
typename L>
147 util::array<mln_result(A)>
149 const Image<I>& input,
150 const Image<L>& label,
151 const mln_value(L)& nlabels);
155 # ifndef MLN_INCLUDE_ONLY
160 template <
typename A,
typename L>
163 compute_tests(
const Accumulator<A>& a,
164 const Image<L>& label,
165 const mln_value(L)& nlabels)
167 mln_precondition(
exact(label).is_valid());
175 template <
typename A,
typename I,
typename L>
178 compute_tests(
const Accumulator<A>& a,
179 const Image<I>& input,
180 const Image<L>& label,
181 const mln_value(L)& nlabels)
183 mln_precondition(
exact(input).is_valid());
184 mln_precondition(
exact(label).is_valid());
202 template <
typename A,
typename L>
204 util::array<mln_result(A)>
205 compute(
const Accumulator<A>& a_,
206 const Image<L>& label_,
207 const mln_value(L)& nlabels)
209 mln_trace(
"labeling::impl::generic::compute");
210 internal::compute_tests(a_, label_, nlabels);
212 const A& a =
exact(a_);
213 const L& label =
exact(label_);
217 mln_piter(L)
p(label.domain());
219 accus[label(
p)].take(
p);
221 util::array<mln_result(A)> res;
227 template <typename A, typename L>
229 util::array<mln_result(A)>
231 const Image<L>& label_,
232 const mln_value(L)& nlabels)
234 mln_trace(
"labeling::impl::generic::compute");
235 internal::compute_tests(A(), label_, nlabels);
245 const L& label =
exact(label_);
247 mln_piter(L) p(label.domain());
249 accus[label(p)].take(p);
251 util::array<mln_result(A)> res;
257 template <typename A, typename I, typename L>
259 util::array<mln_result(A)>
260 compute(const Accumulator<A>& a_,
261 const Image<I>& input_,
262 const Image<L>& label_,
263 const mln_value(L)& nlabels)
265 mln_trace(
"labeling::impl::generic::compute");
266 internal::compute_tests(a_, input_, label_, nlabels);
268 const A& a =
exact(a_);
269 const I& input =
exact(input_);
270 const L& label =
exact(label_);
274 mln_piter(I) p(input.domain());
276 accus[label(p)].take(input(p));
278 util::array<mln_result(A)> res;
284 template <typename A, typename I, typename L>
286 util::array<mln_result(A)>
288 const Image<I>& input_,
289 const Image<L>& label_,
290 const mln_value(L)& nlabels)
292 mln_trace(
"labeling::impl::generic::compute");
296 const I& input =
exact(input_);
297 const L& label =
exact(label_);
308 mln_piter(I) p(input.domain());
310 accus[label(p)].take(input(p));
312 util::array<mln_result(A)> res;
326 template <typename A, typename I, typename L>
328 util::array<mln_result(A)>
329 compute_fastest(const Accumulator<A>& a_,
330 const Image<I>& input_,
331 const Image<L>& label_,
332 const mln_value(L)& nlabels)
334 mln_trace(
"labeling::impl::compute_fastest");
335 internal::compute_tests(a_, input_, label_, nlabels);
337 const A& a =
exact(a_);
338 const I& input =
exact(input_);
339 const L& label =
exact(label_);
347 typedef mln_site(I) P;
348 typedef const mln_value(I) * iptr_t;
349 typedef const mln_value(L) * lptr_t;
350 box_runstart_piter<P> p(label.domain());
353 iptr_t iptr = & input(p);
354 lptr_t lptr = & label(p);
356 for (
unsigned i = 0; i <
ncols; ++i)
357 accus[*lptr++].
take(*iptr++);
360 util::array<mln_result(A)> res;
370 template <
typename A,
typename I,
typename L>
372 util::array<mln_result(A)>
373 compute_fastest(util::array<A>& accus,
374 const Image<I>& input_,
375 const Image<L>& label_,
376 const mln_value(L)& nlabels)
378 mln_trace(
"labeling::impl::generic::compute_fastest");
384 const I& input =
exact(input_);
385 const L& label =
exact(label_);
398 typedef mln_site(I) P;
399 typedef const mln_value(I) * iptr_t;
400 typedef const mln_value(L) * lptr_t;
401 box_runstart_piter<P> p(label.domain());
404 iptr_t iptr = & input(p);
405 lptr_t lptr = & label(p);
407 for (
unsigned i = 0; i <
ncols; ++i)
408 accus[*lptr++].
take(*iptr++);
411 util::array<mln_result(A)> res;
427 template <
typename A,
typename L>
429 util::array<mln_result(A)>
430 compute_dispatch(
const Accumulator<A>& a,
431 const Image<L>& label,
432 const mln_value(L)& nlabels)
441 template <
typename A,
typename I,
typename L>
443 util::array<mln_result(A)>
445 mln::trait::image::value_access::any,
446 mln::trait::image::value_access::any,
447 mln::trait::image::ext_domain::any,
448 mln::trait::image::ext_domain::any,
449 const Accumulator<A>& a,
450 const Image<I>& input,
451 const Image<L>& label,
452 const mln_value(L)& nlabels)
458 template <
typename A,
typename I,
typename L>
460 util::array<mln_result(A)>
462 mln::trait::image::value_access::direct,
463 mln::trait::image::value_access::direct,
464 mln::trait::image::ext_domain::some,
465 mln::trait::image::ext_domain::some,
466 const Accumulator<A>& a,
467 const Image<I>& input,
468 const Image<L>& label,
469 const mln_value(L)& nlabels)
471 return impl::compute_fastest(a, input, label, nlabels);
475 template <
typename A,
typename I,
typename L>
477 util::array<mln_result(A)>
478 compute_dispatch(mln::trait::image::value_storage::any,
479 mln::trait::image::value_storage::any,
480 const Accumulator<A>& a,
481 const Image<I>& input,
482 const Image<L>& label,
483 const mln_value(L)& nlabels)
489 template <
typename A,
typename I,
typename L>
491 util::array<mln_result(A)>
492 compute_dispatch(mln::trait::image::value_storage::one_block,
493 mln::trait::image::value_storage::one_block,
494 const Accumulator<A>& a,
495 const Image<I>& input_,
496 const Image<L>& label_,
497 const mln_value(L)& nlabels)
499 const I& input =
exact(input_);
500 const L& label =
exact(label_);
503 if (mlc_is(mln_trait_image_value_alignment(I),
504 trait::image::value_alignment::with_grid)::
value &&
505 mlc_is(mln_trait_image_value_alignment(L),
506 trait::image::value_alignment::with_grid)::
value)
508 return compute_dispatch(
509 mln_trait_image_value_access(I)(),
510 mln_trait_image_value_access(L)(),
511 mln_trait_image_ext_domain(I)(),
512 mln_trait_image_ext_domain(L)(),
513 a, input, label, nlabels);
520 template <
typename A,
typename I,
typename L>
522 util::array<mln_result(A)>
523 compute_dispatch(
const Accumulator<A>& a,
524 const Image<I>& input,
525 const Image<L>& label,
526 const mln_value(L)& nlabels)
528 return compute_dispatch(mln_trait_image_value_storage(I)(),
529 mln_trait_image_value_storage(L)(),
530 a, input, label, nlabels);
540 template <
typename A,
typename I,
typename L>
542 util::array<mln_result(A)>
544 mln::trait::image::value_access::any,
545 mln::trait::image::value_access::any,
546 mln::trait::image::ext_domain::any,
547 mln::trait::image::ext_domain::any,
549 const Image<I>& input,
550 const Image<L>& label,
551 const mln_value(L)& nlabels)
557 template <
typename A,
typename I,
typename L>
559 util::array<mln_result(A)>
561 mln::trait::image::value_access::direct,
562 mln::trait::image::value_access::direct,
563 mln::trait::image::ext_domain::some,
564 mln::trait::image::ext_domain::some,
566 const Image<I>& input,
567 const Image<L>& label,
568 const mln_value(L)& nlabels)
570 return impl::compute_fastest(a, input, label, nlabels);
574 template <
typename A,
typename I,
typename L>
576 util::array<mln_result(A)>
577 compute_dispatch(mln::trait::image::value_storage::one_block,
578 mln::trait::image::value_storage::one_block,
580 const Image<I>& input_,
581 const Image<L>& label_,
582 const mln_value(L)& nlabels)
584 const I& input =
exact(input_);
585 const L& label =
exact(label_);
588 if (mlc_is(mln_trait_image_value_alignment(I),
589 trait::image::value_alignment::with_grid)::value &&
590 mlc_is(mln_trait_image_value_alignment(L),
591 trait::image::value_alignment::with_grid)::value)
593 return compute_dispatch(
594 mln_trait_image_value_access(I)(),
595 mln_trait_image_value_access(L)(),
596 mln_trait_image_ext_domain(I)(),
597 mln_trait_image_ext_domain(L)(),
598 a, input, label, nlabels);
605 template <
typename A,
typename I,
typename L>
607 util::array<mln_result(A)>
608 compute_dispatch(util::array<A>& a,
609 const Image<I>& input,
610 const Image<L>& label,
611 const mln_value(L)& nlabels)
613 return compute_dispatch(mln_trait_image_value_storage(I)(),
614 mln_trait_image_value_storage(L)(),
615 a, input, label, nlabels);
622 template <
typename A,
typename L>
624 util::array<mln_result(A)>
625 compute_dispatch(util::array<A>& accus,
626 const Image<L>& label,
627 const mln_value(L)& nlabels)
638 template <
typename A,
typename I,
typename L>
640 util::array<mln_result(A)>
642 const Image<I>& input,
643 const Image<L>& label,
644 const mln_value(L)& nlabels)
646 mln_trace(
"labeling::compute");
650 typedef util::array<mln_result(A)> R;
651 R res = internal::compute_dispatch(a, input, label, nlabels);
656 template <
typename A,
typename I,
typename L>
658 util::array<mln_result(A)>
659 compute(
const Accumulator<A>& a,
660 const Image<I>& input,
661 const Image<L>& label,
662 const mln_value(L)& nlabels)
664 mln_trace(
"labeling::compute");
666 internal::compute_tests(a, input, label, nlabels);
668 typedef util::array<mln_result(A)> R;
669 R res = internal::compute_dispatch(a, input, label, nlabels);
674 template <
typename A,
typename I,
typename L>
676 util::array<mln_meta_accu_result(A, mln_value(I))>
677 compute(
const Meta_Accumulator<A>& a,
678 const Image<I>& input,
679 const Image<L>& label,
680 const mln_value(L)& nlabels)
682 typedef mln_accu_with(A, mln_value(I)) A_;
683 A_ a_ = accu::unmeta(
exact(a), mln_value(I)());
685 return
compute(a_, input, label, nlabels);
689 template <typename A, typename L>
691 util::array<mln_result(A)>
693 const Image<L>& label,
694 const mln_value(L)& nlabels)
696 mln_trace(
"labeling::compute");
698 internal::compute_tests(A(), label, nlabels);
700 typedef util::array<mln_result(A)> R;
701 R res = internal::compute_dispatch(accus, label, nlabels);
703 mln_postcondition(res.nelements() ==
value::next(nlabels));
710 template <
typename A,
typename L>
712 util::array<mln_result(A)>
713 compute(
const Accumulator<A>& a,
714 const Image<L>& label,
715 const mln_value(L)& nlabels)
717 mln_trace(
"labeling::compute");
719 internal::compute_tests(a, label, nlabels);
721 typedef util::array<mln_result(A)> R;
722 R res = internal::compute_dispatch(a, label, nlabels);
724 mln_postcondition(res.nelements() ==
value::next(nlabels));
730 template <
typename A,
typename L>
732 util::array<mln_meta_accu_result(A, mln_psite(L))>
733 compute(
const Meta_Accumulator<A>& a,
734 const Image<L>& label,
735 const mln_value(L)& nlabels)
737 typedef mln_accu_with(A, mln_psite(L)) A_;
738 A_ a_ = accu::unmeta(
exact(a), mln_psite(L)());
740 return
compute(a_, label, nlabels);
744 # endif // ! MLN_INCLUDE_ONLY
751 #endif // ! MLN_LABELING_COMPUTE_HH