26 #ifndef MLN_CANVAS_LABELING_GENERIC_HH
27 # define MLN_CANVAS_LABELING_GENERIC_HH
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/neighborhood.hh>
36 # include <mln/core/concept/site_set.hh>
38 # include <mln/data/fill.hh>
58 template <
typename I,
typename N,
typename L,
59 typename S,
typename F>
61 labeling(const Image<I>& input_, const Neighborhood<N>& nbh_,
62 L& nlabels, const Site_Set<S>& s_, F& f);
65 # ifndef MLN_INCLUDE_ONLY
70 find_root(I& parent, const mln_psite(I)& x)
75 return parent(x) = find_root(parent, parent(x));
80 template <
typename I,
typename N,
typename L,
81 typename S,
typename F>
83 labeling(const Image<I>& input_, const Neighborhood<N>& nbh_,
84 L& nlabels, const Site_Set<S>& s_, F& f)
86 trace::entering(
"canvas::labeling::impl::generic::labeling");
90 const I& input = exact(input_);
91 const N& nbh = exact(nbh_);
92 const S& s = exact(s_);
95 typedef mln_psite(I) P;
98 mln_ch_value(I,
bool) deja_vu;
99 mln_ch_value(I, P) parent;
102 mln_ch_value(I, L) output;
121 mln_bkd_piter(S) p(s);
122 mln_niter(N) n(nbh, p);
123 for_all(p) if (f.handles(p))
130 if (input.domain().has(n) && deja_vu(n))
135 P r = find_root(parent, n);
151 mln_fwd_piter(S) p(s);
152 for_all(p) if (f.handles(p))
158 if (nlabels == mln_max(L))
161 trace::warning(
"labeling aborted! Too many labels \
162 for this label type: nlabels > \
167 output(p) = ++nlabels;
171 output(p) = output(parent(p));
176 trace::exiting(
"canvas::labeling::impl::generic::labeling");
180 # endif // ! MLN_INCLUDE_ONLY
193 #endif // ! MLN_CANVAS_LABELING_GENERIC_HH