27 #ifndef SCRIBO_CORE_INTERNAL_LINK_FUNCTOR_BASE_HH
28 # define SCRIBO_CORE_INTERNAL_LINK_FUNCTOR_BASE_HH
37 # include <mln/core/concept/image.hh>
39 # include <mln/math/abs.hh>
41 # include <mln/util/array.hh>
42 # include <mln/util/couple.hh>
44 # include <mln/labeling/compute.hh>
45 # include <mln/accu/center.hh>
47 # include <scribo/core/tag/anchor.hh>
48 # include <scribo/core/component_set.hh>
49 # include <scribo/core/object_links.hh>
50 # include <scribo/core/concept/link_functor.hh>
51 # include <scribo/primitive/link/internal/compute_anchor.hh>
53 # define scribo_support(T) typename T::support
54 # define scribo_support_(T) T::support
69 template <
typename L,
typename E>
76 typedef mln_site(L) P;
85 unsigned link(
unsigned object)
const;
89 void initialize_link(
unsigned current_object);
90 couple_t finalize_link(
unsigned current_object);
93 bool verify_link_criterion(
unsigned current_object,
94 const P& start_point,
const P&
p,
95 anchor::Type anchor)
const;
97 bool is_potential_link(
unsigned current_object,
98 const P& start_point,
const P& p)
const;
100 bool valid_link(
unsigned current_object,
101 const P& start_point,
const P& p,
102 anchor::Type anchor);
110 void validate_link(
unsigned current_object,
111 const P& start_point,
113 anchor::Type anchor);
117 void validate_link(
unsigned current_object,
118 const P& start_point,
const P& p);
120 void invalidate_link(
unsigned current_object,
121 const P& start_point,
const P& p,
122 anchor::Type anchor);
126 void invalidate_link(
unsigned current_object,
127 const P& start_point,
const P& p);
130 void compute_next_site(P& p);
133 mln_site(L) start_point(
unsigned current_object, anchor::Type anchor);
137 mln_site(L) start_point(
unsigned current_object);
140 void start_processing_object(
unsigned current_object);
148 void initialize_link_(
unsigned current_object);
149 couple_t finalize_link_(
unsigned current_object);
151 bool is_potential_link_(
unsigned current_object,
152 const P& start_point,
const P& p)
const;
154 bool verify_link_criterion_(
unsigned current_object,
155 const P& start_point,
const P& p,
156 anchor::Type anchor)
const;
158 bool valid_link_(
unsigned current_object,
159 const P& start_point,
const P& p,
160 anchor::Type anchor);
162 void validate_link_(
unsigned current_object,
163 const P& start_point,
const P& p,
164 anchor::Type anchor);
166 void invalidate_link_(
unsigned current_object,
167 const P& start_point,
const P& p,
168 anchor::Type anchor);
170 void compute_next_site_(P& p);
172 void start_processing_object_(
unsigned current_object);
174 mln_site(L) start_point_(
unsigned current_object,
175 anchor::Type anchor);
182 const L& labeled_image_;
187 # ifndef MLN_INCLUDE_ONLY
190 template <
typename L,
typename E>
194 : links_(components),
195 components_(components),
202 template <
typename L,
typename E>
205 link_functor_base<L,E>::links()
const
210 template <
typename L,
typename E>
213 link_functor_base<L,E>::link(
unsigned object)
const
215 return links_(
object);
218 template <
typename L,
typename E>
229 template <
typename L,
typename E>
232 link_functor_base<L,E>::is_potential_link(
unsigned current_object,
233 const P& start_point,
237 mln_value(L) v = this->labeled_image_(p);
245 if (this->components_.has_separators() && this->components_.
separators()(p))
248 return v != literal::zero
249 && v != current_object
250 && this->links_(v) != current_object
251 && this->components_(v).tag() != component::Ignored;
255 template <typename L, typename E>
258 link_functor_base<L,E>::initialize_link(
unsigned current_object)
260 exact(
this)->initialize_link_(current_object);
263 template <
typename L,
typename E>
266 link_functor_base<L,E>::finalize_link(
unsigned current_object)
268 return exact(
this)->finalize_link_(current_object);
273 template <
typename L,
typename E>
276 link_functor_base<L,E>::verify_link_criterion(
unsigned current_object,
277 const P& start_point,
279 anchor::Type anchor)
const
283 ! this->components_.separators()(p)
285 &&
exact(
this)->verify_link_criterion_(current_object,
286 start_point, p, anchor);
289 template <
typename L,
typename E>
292 link_functor_base<L,E>::valid_link(
unsigned current_object,
293 const P& start_point,
297 return this->labeled_image_.domain().has(p)
298 &&
exact(
this)->valid_link_(current_object, start_point, p, anchor);
302 template <
typename L,
typename E>
305 link_functor_base<L,E>::validate_link(
unsigned current_object,
306 const P& start_point,
310 exact(
this)->validate_link_(current_object, start_point, p, anchor);
315 template <
typename L,
typename E>
318 link_functor_base<L,E>::validate_link(
unsigned current_object,
319 const P& start_point,
322 validate_link(current_object, start_point, p, anchor::MassCenter);
326 template <
typename L,
typename E>
329 link_functor_base<L,E>::invalidate_link(
unsigned current_object,
330 const P& start_point,
334 exact(
this)->invalidate_link_(current_object, start_point, p, anchor);
338 template <
typename L,
typename E>
341 link_functor_base<L,E>::invalidate_link(
unsigned current_object,
342 const P& start_point,
345 invalidate_link(current_object, start_point, p, anchor::MassCenter);
352 template <
typename L,
typename E>
355 link_functor_base<L,E>::compute_next_site(P& p)
358 exact(
this)->compute_next_site_(p);
362 template <
typename L,
typename E>
365 link_functor_base<L,E>::start_point(
unsigned current_object,
368 return exact(
this)->start_point_(current_object, anchor);
372 template <
typename L,
typename E>
375 link_functor_base<L,E>::start_point(
unsigned current_object)
377 return start_point(current_object, anchor::MassCenter);
381 template <
typename L,
typename E>
384 link_functor_base<L,E>::start_processing_object(
385 unsigned current_object)
387 (void) current_object;
389 exact(
this)->start_processing_object_(current_object);
393 template <
typename L,
typename E>
396 link_functor_base<L,E>::labeled_image()
const
398 return labeled_image_;
405 template <
typename L,
typename E>
408 link_functor_base<L,E>::initialize_link_(
unsigned current_object)
410 (void) current_object;
415 template <
typename L,
typename E>
418 link_functor_base<L,E>::finalize_link_(
unsigned current_object)
420 (void) current_object;
426 template <
typename L,
typename E>
429 link_functor_base<L,E>::is_potential_link_(
unsigned current_object,
430 const P& start_point,
433 (void) current_object;
440 template <
typename L,
typename E>
443 link_functor_base<L,E>::verify_link_criterion_(
unsigned current_object,
444 const P& start_point,
446 anchor::Type anchor)
const
448 (void) current_object;
457 template <
typename L,
typename E>
460 link_functor_base<L,E>::valid_link_(
unsigned current_object,
461 const P& start_point,
465 return is_potential_link(current_object, start_point, p)
466 && verify_link_criterion(current_object, start_point, p, anchor);
470 template <
typename L,
typename E>
473 link_functor_base<L,E>::validate_link_(
unsigned current_object,
474 const P& start_point,
480 this->links_.update(current_object, this->labeled_image_(p));
484 template <
typename L,
typename E>
487 link_functor_base<L,E>::invalidate_link_(
unsigned current_object,
488 const P& start_point,
492 (void) current_object;
500 template <
typename L,
typename E>
503 link_functor_base<L,E>::start_point_(
unsigned current_object,
507 return internal::compute_anchor(this->components_,
508 current_object, anchor);
511 template <
typename L,
typename E>
514 link_functor_base<L,E>::start_processing_object_(
521 # endif // ! MLN_INCLUDE_ONLY
533 #endif // ! SCRIBO_CORE_INTERNAL_LINK_FUNCTOR_BASE_HH