26 #ifndef SCRIBO_PRIMITIVE_INTERNAL_RD_HH
27 # define SCRIBO_PRIMITIVE_INTERNAL_RD_HH
33 #include <mln/core/image/image2d.hh>
34 #include <mln/core/alias/neighb2d.hh>
35 #include <mln/border/equalize.hh>
36 #include <mln/border/fill.hh>
38 #include <mln/io/pbm/load.hh>
39 #include <mln/io/pbm/save.hh>
40 #include <mln/util/timer.hh>
55 template <
typename I,
typename J>
60 # ifndef MLN_INCLUDE_ONLY
62 template <
typename Par>
65 Rd_find_root_(Par& parent,
unsigned x)
67 if (parent.element(x) == x)
70 return parent.element(x) = Rd_find_root_(parent, parent.element(x));
73 template <
typename I,
typename J,
typename N>
80 const I& f =
exact(f_);
81 const J& g =
exact(g_);
84 typedef mln_psite(I) P;
85 typedef mln_value(I) V;
88 mln_ch_value(I,
bool) deja_vu;
89 mln_ch_value(I,
unsigned) parent;
90 mln_concrete(I) output;
108 mln_fwd_pixter(
const I) pxl_g(g);
111 if (pxl_g.val() ==
false)
114 unsigned p = pxl_g.offset();
117 parent.element(p) = p;
119 output.element(p) = f.element(p);
121 for (
unsigned j = 0; j < n_nbhs; ++j)
123 unsigned n = p + dp[j];
124 if (g.element(n) ==
true)
126 mln_invariant(f.domain().has(f.point_at_offset(n)));
128 unsigned r = Rd_find_root_(parent, n);
132 parent.element(r) = p;
134 output.element(p) = output.element(p) || output.element(r);
143 mln_bkd_pixter(
const I) pxl_g(g);
146 if (pxl_g.val() ==
false)
148 unsigned p = pxl_g.offset();
149 output.element(p) = output.element(parent.element(p));
159 template <
typename I,
typename J>
163 mln_trace(
"scribo::primitive::internal::rd");
165 mln_precondition(
exact(ima).is_valid());
166 mln_precondition(
exact(constraint).is_valid());
179 # endif // ! MLN_INCLUDE_ONLY
190 #endif // ! SCRIBO_PRIMITIVE_INTERNAL_RD_HH