Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
seeds2tiling_roundness.hh
1 // Copyright (C) 2007, 2008, 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_GEOM_SEEDS2TILING_ROUNDNESS_HH
27 # define MLN_GEOM_SEEDS2TILING_ROUNDNESS_HH
28 
32 
33 # include <map>
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/core/concept/neighborhood.hh>
37 # include <mln/core/alias/w_window2d_int.hh>
38 # include <mln/core/site_set/p_priority.hh>
39 # include <mln/core/site_set/p_queue_fast.hh>
40 # include <mln/core/routine/duplicate.hh>
41 # include <mln/accu/stat/mean.hh>
42 # include <mln/estim/min_max.hh>
43 # include <mln/algebra/vec.hh>
44 # include <mln/geom/chamfer.hh>
45 
46 
47 namespace mln
48 {
49  namespace geom
50  {
51 
65  template <typename I, typename N>
66  I
67  seeds2tiling_roundness (Image<I>& ima_, const w_window2d_int& w_win,
68  unsigned max, const Neighborhood<N>& nbh_);
70 
71 
72 # ifndef MLN_INCLUDE_ONLY
73 
74  namespace impl
75  {
76 
77  template <typename I, typename N>
78  inline
79  I
80  seeds2tiling_roundness(Image<I>& ima_, const w_window2d_int& w_win,
81  unsigned max, const Neighborhood<N>& nbh_)
82  {
83  trace::entering("geom::impl::seed2tiling_roundness");
84 
85  I& ima = exact(ima_);
86  const N& nbh = exact(nbh_);
87  image2d<unsigned> dist = geom::chamfer(ima, w_win, max);
88 
89  I out = duplicate(ima_);
90  p_priority<unsigned, p_queue_fast<mln_psite(I)> > q;
91 
92  // Init.
93  {
94  mln_piter(I) p(ima.domain());
95 
96  for_all(p)
97  q.push(max - dist(p), p);
98  }
99 
100 
101  // Body: alternative version.
102  {
103  while (! q.is_empty())
104  {
105  mln_psite(I) p = q.pop_front();
106 
107  if (out(p) != literal::zero) // p has already been processed so ignore
108  continue;
109  mln_niter(N) n(nbh, p);
110 
111  for_all(n) if (ima.has(n))
112  if (out(n) != literal::zero)
113  out(p) = out(n);
114  }
115  }
116 
117  trace::exiting("geom::impl::seed2tiling_roundness");
118  return out;
119  }
120 
121  } // end of namespace mln::geom::impl
122 
123 
124  // Facade
125  template <typename I, typename N>
126  inline
127  I
128  seeds2tiling_roundness(Image<I>& ima_, const w_window2d_int& w_win,
129  unsigned max, const Neighborhood<N>& nbh)
130  {
131  trace::entering("geom::seed2tiling_roundness");
132 
133  mln_precondition(exact(ima_).is_valid());
134  I output = impl::seeds2tiling_roundness(ima_, w_win, max, nbh);
135 
136  trace::exiting("geom::seed2tiling_roundness");
137  return output;
138  }
139 
140 
141 
142 # endif // ! MLN_INCLUDE_ONLY
143 
144  } // end of namespace mln::geom
145 
146 } // end of namespace mln
147 
148 
149 #endif // ! MLN_GEOM_SEEDS2TILING_ROUNDNESS_HH