26 #ifndef MLN_LABELING_VALUE_AND_COMPUTE_HH
27 # define MLN_LABELING_VALUE_AND_COMPUTE_HH
33 # include <mln/core/concept/image.hh>
34 # include <mln/core/concept/neighborhood.hh>
35 # include <mln/canvas/labeling/video.hh>
36 # include <mln/data/fill.hh>
55 template <
typename I,
typename N,
typename L,
typename A>
56 util::couple<mln_ch_value(I,L),
57 util::couple<util::array<mln_result(A)>,
60 const Neighborhood<N>& nbh, L& nlabels,
61 const Accumulator<A>& accu);
64 # ifndef MLN_INCLUDE_ONLY
72 template <
typename I,
typename N,
typename L,
typename A>
74 value_and_compute_tests(
const Image<I>& input,
const mln_value(I)& val,
75 const Neighborhood<N>& nbh, L& nlabels,
76 const Accumulator<A>& accu)
78 mln_precondition(exact(input).is_valid());
79 mln_precondition(exact(nbh).is_valid());
97 template <
typename I,
typename L,
typename A>
98 struct value_and_compute_functor
100 typedef mln_psite(I) P;
102 util::array<mln_result(A)> result_;
103 util::array<A> accus_;
106 const mln_value(I)& val;
108 typedef mln_result(A) accu_result;
109 typedef mln_argument(A) accu_argument;
110 typedef util::couple<util::array<accu_result>,
111 util::array<A> > result;
116 typedef mln_domain(I) S;
121 bool handles(
const P& p)
const {
return input(p) == val; }
122 bool equiv(
const P& n,
const P&)
const {
return input(n) == val; }
123 bool labels(
const P&)
const {
return true; }
124 void do_no_union(
const P&,
const P&) {}
125 void init_attr(
const P&) {}
126 void merge_attr(
const P&,
const P&) {}
127 void set_new_label(
const P& p,
const L& l)
130 process__(accu_argument(), p, l);
132 void set_label(
const P& p,
const L& l) { process__(accu_argument(), p, l); };
133 void finalize() { convert::from_to(accus_, result_); }
139 void init_() { accus_.append(A()); }
140 bool handles_(
unsigned p)
const {
return input.element(p) == val; }
141 bool equiv_(
unsigned n,
unsigned)
const {
return input.element(n) == val; }
142 bool labels_(
unsigned)
const {
return true; }
143 void do_no_union_(
unsigned,
unsigned) {}
144 void init_attr_(
unsigned) {}
145 void merge_attr_(
unsigned,
unsigned) {}
146 void set_new_label_(
unsigned p,
const L& l)
149 process__(accu_argument(), p, l);
151 void set_label_(
unsigned p,
const L& l) { process__(accu_argument(), p, l); };
152 void finalize_() { convert::from_to(accus_, result_); }
158 value_and_compute_functor(
const Image<I>& input_,
const mln_value(I)& val)
159 : input(exact(input_)),
167 void process__(
const unsigned&,
unsigned p,
const L& l)
173 void process__(
const mln_psite(I)&,
unsigned p,
const L& l)
175 accus_[l].take(input.point_at_index(p));
180 void process__(
const mln_psite(I)&,
const mln_site(I)& p,
const L& l)
186 void process__(
const mln_value(I)&,
const mln_site(I)&,
const L& l)
191 template <
typename V>
193 void process__(
const V&,
const mln_site(I)&,
const L& l)
195 mlc_abort(V)::check();
208 template <
typename I,
typename N,
typename L,
typename A>
209 util::couple<mln_ch_value(I,L),
210 util::couple<util::array<mln_result(A)>,
216 trace::entering(
"labeling::value_and_compute");
218 internal::value_and_compute_tests(input, val, nbh, nlabels, accu);
220 typedef mln_ch_value(I,L) out_t;
221 typedef impl::value_and_compute_functor<I, L, A> func_t;
222 func_t f(input, val);
223 out_t output = canvas::labeling::video(input, nbh, nlabels, f);
230 trace::exiting(
"labeling::value_and_compute");
234 # endif // ! MLN_INCLUDE_ONLY
241 #endif // ! MLN_LABELING_VALUE_AND_COMPUTE_HH