$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
seeds2tiling_roundness.hh
1 // Copyright (C) 2007, 2008, 2009, 2012, 2013 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_GEOM_SEEDS2TILING_ROUNDNESS_HH
28 # define MLN_GEOM_SEEDS2TILING_ROUNDNESS_HH
29 
33 
34 # include <map>
35 
36 # include <mln/core/concept/image.hh>
37 # include <mln/core/image/image2d.hh>
38 # include <mln/core/concept/neighborhood.hh>
39 # include <mln/core/alias/w_window2d_int.hh>
40 # include <mln/core/site_set/p_priority.hh>
41 # include <mln/core/site_set/p_queue_fast.hh>
42 # include <mln/core/routine/duplicate.hh>
43 # include <mln/accu/stat/mean.hh>
44 # include <mln/estim/min_max.hh>
45 # include <mln/algebra/vec.hh>
46 # include <mln/geom/chamfer.hh>
47 
48 
49 namespace mln
50 {
51  namespace geom
52  {
53 
68  template <typename I, typename N>
69  I
70  seeds2tiling_roundness (Image<I>& ima_, const w_window2d_int& w_win,
71  unsigned max, const Neighborhood<N>& nbh_);
72 
73 
74 # ifndef MLN_INCLUDE_ONLY
75 
76  namespace impl
77  {
78 
79  template <typename I, typename N>
80  inline
81  I
82  seeds2tiling_roundness(Image<I>& ima_, const w_window2d_int& w_win,
83  unsigned max, const Neighborhood<N>& nbh_)
84  {
85  mln_trace("geom::impl::seed2tiling_roundness");
86 
87  I& ima = exact(ima_);
88  const N& nbh = exact(nbh_);
89  image2d<unsigned> dist = geom::chamfer(ima, w_win, max);
90 
91  I out = duplicate(ima_);
92  p_priority<unsigned, p_queue_fast<mln_psite(I)> > q;
93 
94  // Init.
95  {
96  mln_piter(I) p(ima.domain());
97 
98  for_all(p)
99  q.push(max - dist(p), p);
100  }
101 
102 
103  // Body: alternative version.
104  {
105  while (! q.is_empty())
106  {
107  mln_psite(I) p = q.pop_front();
108 
109  if (out(p) != literal::zero) // p has already been processed so ignore
110  continue;
111  mln_niter(N) n(nbh, p);
112 
113  for_all(n) if (ima.has(n))
114  if (out(n) != literal::zero)
115  out(p) = out(n);
116  }
117  }
118 
119  return out;
120  }
121 
122  } // end of namespace mln::geom::impl
123 
124 
125  // Facade
126  template <typename I, typename N>
127  inline
128  I
129  seeds2tiling_roundness(Image<I>& ima_, const w_window2d_int& w_win,
130  unsigned max, const Neighborhood<N>& nbh)
131  {
132  mln_trace("geom::seed2tiling_roundness");
133 
134  mln_precondition(exact(ima_).is_valid());
135  I output = impl::seeds2tiling_roundness(ima_, w_win, max, nbh);
136 
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