26 #ifndef MLN_MAKE_VORONOI_HH
27 # define MLN_MAKE_VORONOI_HH
36 # include <mln/core/concept/neighborhood.hh>
37 # include <mln/core/site_set/p_vertices.hh>
38 # include <mln/accu/stat/mean.hh>
39 # include <mln/estim/min_max.hh>
40 # include <mln/util/graph.hh>
57 template <
typename I,
typename N>
58 p_vertices<util::graph, fun::i2v::array<mln_site(I)> >
61 const Neighborhood<N>& nbh);
63 # ifndef MLN_INCLUDE_ONLY
65 template <
typename I,
typename N>
67 p_vertices<util::graph, fun::i2v::array<mln_site(I)> >
70 const Neighborhood<N>& nbh)
72 typedef algebra::vec<2,float> X;
73 typedef mln_value(I) V;
74 typedef mln_psite(I) P;
77 I& orig =
exact(orig_);
80 estim::min_max (ima, min, max);
81 unsigned nb = max - min + 1;
82 fun::i2v::array<P> v(nb);
83 std::vector< accu::stat::mean< X > > tab_mean (nb);
84 std::map<std::pair<V, V>,
bool> m;
88 mln_piter(I)
p(orig.domain());
94 X x = mln_psite(I)(
p);
95 tab_mean[orig(p) -
min].take(x);
102 mln_piter(I) p(ima.domain());
103 mln_niter(N) n(nbh, p);
107 for_all (n) if (ima.has(n))
108 if (ima(p) != ima(n))
109 m[std::pair<V, V>(ima(p) - min, ima(n) - min)] = true;
114 for (
unsigned i = 0; i < nb; ++i)
119 v[i] =
point2d ((
unsigned)tab_mean[i].to_result ()[0],
120 (
unsigned)tab_mean[i].to_result ()[1]);
123 typename std::map<std::pair<V, V>,
bool>::const_iterator it = m.begin ();
124 for (; it != m.end (); ++it)
125 gr.add_edge((*it).first.first, (*it).first.second);
127 p_vertices<util::graph, fun::i2v::array<P> > res(gr, v);
131 # endif // ! MLN_INCLUDE_ONLY
138 #endif // ! MLN_MAKE_VORONOI_HH