27 #ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SEVERAL_DMAX_HH_
28 # define SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SEVERAL_DMAX_HH_
39 # include <mln/accu/center.hh>
40 # include <mln/labeling/compute.hh>
41 # include <mln/math/abs.hh>
42 # include <mln/util/array.hh>
44 # include <scribo/core/macros.hh>
45 # include <scribo/core/tag/anchor.hh>
46 # include <scribo/core/object_links.hh>
48 # include <scribo/primitive/link/internal/find_link.hh>
49 # include <scribo/primitive/link/internal/link_functor_base.hh>
51 # include <scribo/primitive/link/compute.hh>
69 template <
typename L,
typename E>
73 typedef mln_site(L) P;
81 unsigned neighb_max_distance);
85 bool verify_link_criterion_(
unsigned current_object,
88 anchor::Type anchor)
const;
90 void start_processing_object_(
unsigned current_object);
92 void validate_link_(
unsigned current_object,
const P& start_point,
93 const P& p, anchor::Type anchor);
95 void initialize_link_(
unsigned current_object);
96 couple_t finalize_link_(
unsigned current_object);
98 unsigned nanchors()
const;
105 float neighb_max_distance_;
106 anchor::Direction direction_;
108 using super_::labeled_image_;
112 # ifndef MLN_INCLUDE_ONLY
115 template <
typename L,
typename E>
119 unsigned neighb_max_distance)
123 neighb_max_distance_(neighb_max_distance),
124 direction_(anchor::Horizontal)
131 template <
typename L,
typename E>
134 link_several_dmax_base<L, E>::verify_link_criterion_(
135 unsigned current_object,
136 const P& start_point,
138 anchor::Type anchor)
const
140 (void) current_object;
143 float dist =
math::abs(p[direction_] - start_point[direction_]);
144 return dist <= dmax_;
148 template <
typename L,
typename E>
151 link_several_dmax_base<L, E>::start_processing_object_(
152 unsigned current_object)
155 midcol = (this->components_(current_object).bbox().pmax()[direction_]
156 - this->components_(current_object).bbox().pmin()[direction_]) / 2;
157 dmax_ = midcol + neighb_max_distance_;
161 template <
typename L,
typename E>
164 link_several_dmax_base<L, E>::validate_link_(
unsigned current_object,
165 const P& start_point,
169 (void) current_object;
175 template <
typename L,
typename E>
178 link_several_dmax_base<L, E>::initialize_link_(
unsigned current_object)
180 (void) current_object;
181 this->potential_links_.clear();
185 template <
typename L,
typename E>
188 link_several_dmax_base<L, E>::finalize_link_(
unsigned current_object)
193 min = mln_max(
unsigned),
196 if (this->potential_links_.nelements() > 0)
198 for(
unsigned i = 0; i < this->potential_links_.nelements(); ++i)
200 tmp =
math::abs(this->components_(current_object).
bbox().pmax()[direction_]
201 - this->potential_links_(i).second()[direction_]);
207 mln_assertion(min != mln_max(
unsigned));
217 mln::util::array<
float> overlap;
218 for(
unsigned i = 0; i < this->potential_links_.nelements(); ++i)
219 if (dist[i] < (1.2 * min))
222 other_object = labeled_image_(potential_links_(i).second());
223 nbh_id = other_object;
227 =
math::min(this->components_(current_object).
bbox().pmax().row(),
228 this->components_(other_object).
bbox().pmax().row())
229 -
math::min(this->components_(current_object).
bbox().pmin().row(),
230 this->components_(other_object).
bbox().pmin().row()),
231 dh = this->components_(other_object).bbox().pmax().row()
232 - this->components_(other_object).bbox().pmin().row(),
235 overlap.append(ratio);
236 if (ratio > overlap(id_max_ratio) || nratio == 0)
240 nbh_id = other_object;
242 else if (ratio == overlap(id_max_ratio)
243 && other_object != nbh_id)
251 this->links_.update(current_object,
252 labeled_image_(potential_links_(id_max_ratio).second()));
254 return potential_links_(id_max_ratio);
259 this->links_.clear(current_object);
264 template <
typename L,
typename E>
266 const util::array<anchor::Type>&
267 link_several_dmax_base<L, E>::anchors()
const
272 template <
typename L,
typename E>
275 link_several_dmax_base<L,E>::nanchors()
const
277 return anchors_.nelements();
282 # endif // ! MLN_INCLUDE_ONLY
294 #endif // SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SEVERAL_DMAX_HH_