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 trace::entering(
"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;
213 initialize(deja_vu, f);
214 initialize(parent, f);
218 data::fill(deja_vu, false);
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);
254 trace::exiting(
"morpho::tree::impl::generic::compute_parent");
268 template <
typename I,
typename N,
typename S>
270 mln_ch_value(I, mln_psite(I))
271 compute_parent_dispatch(const Image<I>& f,
272 const Neighborhood<N>& nbh,
273 const Site_Set<S>& s)
275 return impl::generic::compute_parent(f, nbh, s);
283 template <
typename I,
typename N,
typename S>
285 mln_ch_value(I, mln_psite(I))
289 trace::entering(
"morpho::tree::compute_parent");
291 internal::compute_parent_tests(f, nbh, s);
293 mln_ch_value(I, mln_psite(I)) output;
294 output = internal::compute_parent_dispatch(f, nbh, s);
296 trace::exiting(
"morpho::tree::compute_parent");
300 # endif // ! MLN_INCLUDE_ONLY
309 #endif // ! MLN_MORPHO_TREE_COMPUTE_PARENT_HH