00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH
00027 # define MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH
00028 
00034 
00035 
00036 # include <mln/core/concept/image.hh>
00037 # include <mln/core/concept/graph.hh>
00038 # include <mln/core/site_set/p_vertices.hh>
00039 
00040 # include <mln/labeling/compute.hh>
00041 
00042 # include <mln/accu/center.hh>
00043 
00044 # include <mln/fun/i2v/array.hh>
00045 
00046 
00047 namespace mln
00048 {
00049 
00050   namespace make
00051   {
00052 
00063     
00064     template <typename W, typename G>
00065     inline
00066     p_vertices<G, fun::i2v::array<mln_site(W)> >
00067     p_vertices_with_mass_centers(const Image<W>& wst_,
00068                                  const Graph<G>& g_);
00069 
00070 
00071 # ifndef MLN_INCLUDE_ONLY
00072 
00073 
00074     template <typename W, typename G>
00075     inline
00076     p_vertices<G, fun::i2v::array<mln_site(W)> >
00077     p_vertices_with_mass_centers(const Image<W>& wst_,
00078                                  const Graph<G>& g_)
00079     {
00080       trace::entering("make::p_vertices_with_mass_centers");
00081 
00082       const W& wst = exact(wst_);
00083       const G& g = exact(g_);
00084       mln_precondition(wst.is_valid());
00085       mln_precondition(g.is_valid());
00086 
00087       typedef mln_site(W) P;
00088       typedef fun::i2v::array<P> vertex_sites_t;
00089 
00090       
00091       mln_value(W) nbasins = g.v_nmax() - 1;
00092       vertex_sites_t vertex_sites;
00093       convert::from_to(labeling::compute(accu::center<P>(), wst, nbasins),
00094                        vertex_sites);
00095 
00096       p_vertices<G, vertex_sites_t> pv(g, vertex_sites);
00097 
00098       trace::exiting("make::p_vertices_with_mass_centers");
00099       return pv;
00100     }
00101 
00102 # endif // ! MLN_INCLUDE_ONLY
00103 
00104   } 
00105 
00106 } 
00107 
00108 #endif // ! MLN_MAKE_P_VERTICES_WITH_MASS_CENTERS_HH