26 #ifndef MLN_MORPHO_TREE_COMPUTE_PARENT_HH
27 # define MLN_MORPHO_TREE_COMPUTE_PARENT_HH
40 # include <mln/core/concept/image.hh>
41 # include <mln/core/concept/neighborhood.hh>
42 # include <mln/data/fill.hh>
127 template <
typename I,
typename N,
typename S>
128 mln_ch_value(I, mln_psite(I))
130 const Site_Set<S>& s);
134 # ifndef MLN_INCLUDE_ONLY
143 template <
typename I,
typename N,
typename S>
145 compute_parent_tests(
const Image<I>& f_,
146 const Neighborhood<N>& nbh_,
147 const Site_Set<S>& s_)
149 const I& f =
exact(f_);
150 const N& nbh =
exact(nbh_);
151 const S& s =
exact(s_);
153 mln_precondition(f.is_valid());
154 mln_precondition(nbh.is_valid());
155 mln_precondition(s == f.domain());
165 template <
typename T>
168 zfind_root(
T& zpar, const mln_psite(
T)& x)
170 mlc_equal(mln_value(
T), mln_psite(
T))::check();
174 return zpar(x) = zfind_root(zpar, zpar(x));
190 template <
typename I,
typename N,
typename S>
192 mln_ch_value(I, mln_psite(I))
194 const Neighborhood<N>& nbh_,
195 const Site_Set<S>& s_)
197 mln_trace(
"morpho::tree::impl::generic::compute_parent");
199 typedef mln_psite(I) P;
201 const I& f =
exact(f_);
202 const N& nbh =
exact(nbh_);
203 const S& s =
exact(s_);
206 internal::compute_parent_tests(f, nbh, s);
209 mln_ch_value(I,
bool) deja_vu;
210 mln_ch_value(I, P) parent;
211 mln_ch_value(I, P) zpar;
221 mln_bkd_piter(S)
p(s);
222 mln_niter(N) n(nbh,
p);
230 if (f.domain().has(n) && deja_vu(n))
233 P r = internal::zfind_root(zpar, n);
245 mln_fwd_piter(S) p(s);
249 if (f(parent(q)) == f(q))
250 parent(p) = parent(q);
267 template <
typename I,
typename N,
typename S>
269 mln_ch_value(I, mln_psite(I))
270 compute_parent_dispatch(const Image<I>& f,
271 const Neighborhood<N>& nbh,
272 const Site_Set<S>& s)
282 template <
typename I,
typename N,
typename S>
284 mln_ch_value(I, mln_psite(I))
286 const Site_Set<S>& s)
288 mln_trace(
"morpho::tree::compute_parent");
290 internal::compute_parent_tests(f, nbh, s);
292 mln_ch_value(I, mln_psite(I)) output;
293 output = internal::compute_parent_dispatch(f, nbh, s);
298 # endif // ! MLN_INCLUDE_ONLY
307 #endif // ! MLN_MORPHO_TREE_COMPUTE_PARENT_HH