27 #ifndef MLN_CANVAS_LABELING_GENERIC_HH
28 # define MLN_CANVAS_LABELING_GENERIC_HH
35 # include <mln/core/concept/image.hh>
36 # include <mln/core/concept/neighborhood.hh>
37 # include <mln/core/concept/site_set.hh>
39 # include <mln/data/fill.hh>
61 template <
typename I,
typename N,
typename L,
62 typename S,
typename F>
68 # ifndef MLN_INCLUDE_ONLY
73 find_root(I& parent,
const mln_psite(I)& x)
78 return parent(x) = find_root(parent, parent(x));
83 template <
typename I,
typename N,
typename L,
84 typename S,
typename F>
89 mln_trace(
"canvas::labeling::impl::generic::labeling");
93 const I& input =
exact(input_);
94 const N& nbh =
exact(nbh_);
95 const S& s =
exact(s_);
98 typedef mln_psite(I) P;
101 mln_ch_value(I,
bool) deja_vu;
102 mln_ch_value(I, P) parent;
105 mln_ch_value(I, L) output;
123 mln_bkd_piter(S)
p(s);
124 mln_niter(N) n(nbh,
p);
125 for_all(
p)
if (f.handles(
p))
132 if (input.domain().has(n) && deja_vu(n))
137 P r = find_root(parent, n);
153 mln_fwd_piter(S)
p(s);
154 for_all(
p)
if (f.handles(
p))
160 if (nlabels == mln_max(L))
162 mln_trace_warning(
"labeling aborted! Too many labels \
163 for this label type: nlabels > \
168 output(
p) = ++nlabels;
172 output(
p) = output(parent(
p));
179 # endif // ! MLN_INCLUDE_ONLY
192 #endif // ! MLN_CANVAS_LABELING_GENERIC_HH