27 #ifndef SCRIBO_PRIMITIVE_LINK_WITH_SEVERAL_RIGHT_CLOSEST_LINKS_HH
28 # define SCRIBO_PRIMITIVE_LINK_WITH_SEVERAL_RIGHT_CLOSEST_LINKS_HH
40 # include <mln/core/concept/image.hh>
41 # include <mln/core/concept/neighborhood.hh>
43 # include <mln/math/abs.hh>
45 # include <mln/extension/fill.hh>
47 # include <mln/util/array.hh>
50 # include <scribo/core/macros.hh>
51 # include <scribo/core/object_links.hh>
77 unsigned neighb_max_distance);
86 # ifndef MLN_INCLUDE_ONLY
93 template <
unsigned n,
typename P>
96 find_closest(
const algebra::vec<n,
100 algebra::vec<3, unsigned> dist;
101 for (
unsigned j = 0; j < 3; ++j)
102 dist[j] =
math::abs(res[j].second().col() - c.col());
105 for (
unsigned i = 1; i < n; ++i)
106 if (dist[i] < dist[idx])
116 template <
typename L>
120 unsigned neighb_max_distance)
122 mln_trace(
"scribo::primitive::link::with_several_right_closest_links");
127 link_1(comps), link_2(comps), link_3(comps), final_link(comps);
133 for_all_comps(i, comps)
145 float midcol = (comps(i).bbox().pmax().col()
146 - comps(i).bbox().pmin().col()) / 2;
147 float dmax = midcol + neighb_max_distance;
149 mln_site(L) c = comps(i).
bbox().center();
151 algebra::vec<3, mln::util::couple<
bool, mln_site(L)> > res;
155 a1.row() = comps(i).
bbox().pmin().row()
156 + (c.row() - comps(i).
bbox().pmin().row()) / 4;
157 res[0] = primitive::internal::find_right_link(comps, link_1,
161 res[1] = primitive::internal::find_right_link(comps, link_2,
163 comps(i).mass_center());
167 a2.row() = comps(i).
bbox().pmax().row()
168 - (c.row() - comps(i).
bbox().pmin().row()) / 4;
169 res[2] = primitive::internal::find_right_link(comps, link_3,
174 unsigned closest_idx = internal::find_closest(res, c);
179 if (res[closest_idx].first())
180 final_link[i] = comps(res[closest_idx].second());
189 template <typename L>
198 # endif // ! MLN_INCLUDE_ONLY
206 #endif // ! SCRIBO_PRIMITIVE_LINK_WITH_SEVERAL_RIGHT_CLOSEST_LINKS_HH