$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_edges_with_mass_centers.hh
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_MAKE_P_EDGES_WITH_MASS_CENTERS_HH
27 # define MLN_MAKE_P_EDGES_WITH_MASS_CENTERS_HH
28 
36 
37 
38 # include <mln/core/concept/image.hh>
39 # include <mln/core/concept/graph.hh>
40 # include <mln/core/site_set/p_edges.hh>
41 
42 # include <mln/labeling/compute.hh>
43 
44 # include <mln/accu/center.hh>
45 
46 # include <mln/fun/i2v/array.hh>
47 
48 # include <mln/util/site_pair.hh>
49 
50 
51 namespace mln
52 {
53 
54  namespace make
55  {
56 
67  //
68  template <typename W, typename G>
69  inline
70  p_edges<G, fun::i2v::array<util::site_pair<mln_site(W)> > >
71  p_edges_with_mass_centers(const Image<W>& wst_,
72  const Graph<G>& g_);
73 
74 
75 # ifndef MLN_INCLUDE_ONLY
76 
77 
78  template <typename W, typename G>
79  inline
80  p_edges<G, fun::i2v::array<util::site_pair<mln_site(W)> > >
81  p_edges_with_mass_centers(const Image<W>& wst_,
82  const Graph<G>& g_)
83  {
84  mln_trace("make::p_edges_with_mass_centers");
85 
86  const W& wst = exact(wst_);
87  const G& g = exact(g_);
88  mln_precondition(wst.is_valid());
89  mln_precondition(g.is_valid());
90 
91  typedef mln_site(W) P;
92 
93  // nbasins does not include the background label.
94  mln_value(W) nbasins = g.v_nmax() - 1;
95  util::array<mln_vec(P)>
96  mass_centers = labeling::compute(accu::center<P>(), wst, nbasins);
97 
98  typedef fun::i2v::array< util::site_pair<P> > edge_sites_t;
99  edge_sites_t edge_sites(g.e_nmax());
100 
101  mln_edge_iter(G) e(g);
102  for_all(e)
103  edge_sites(e.id()) = util::site_pair<P>(mass_centers[e.v1()],
104  mass_centers[e.v2()]);
105 
106  p_edges<G, edge_sites_t> pe(g, edge_sites);
107 
108  return pe;
109  }
110 
111 # endif // ! MLN_INCLUDE_ONLY
112 
113  } // end of namespace mln::make
114 
115 } // end of namespace mln
116 
117 #endif // ! MLN_MAKE_P_EDGES_WITH_MASS_CENTERS_HH