Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
seeds2tiling.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_HH
27 # define MLN_GEOM_SEEDS2TILING_HH
28 
32 
33 # include <map>
34 
35 # include <mln/core/concept/neighborhood.hh>
36 # include <mln/core/site_set/p_queue.hh>
37 # include <mln/core/routine/duplicate.hh>
38 # include <mln/accu/stat/mean.hh>
39 # include <mln/estim/min_max.hh>
40 # include <mln/algebra/vec.hh>
41 
42 
43 namespace mln
44 {
45 
46  namespace geom
47  {
48 
58  //
59  template <typename I, typename N>
60  mln_concrete(I) seeds2tiling (const Image<I>& ima_,
61  const Neighborhood<N>& nbh);
62 
63 
64 # ifndef MLN_INCLUDE_ONLY
65 
66  namespace impl
67  {
68 
73  //
74  template <typename I, typename N>
75  inline
76  mln_concrete(I)
77  seeds2tiling (const Image<I>& ima_,
78  const Neighborhood<N>& nbh_)
79  {
80  trace::entering("geom::impl::seed2tiling");
81 
82  mln_precondition(exact(ima_).is_valid());
83  mln_precondition(exact(nbh_).is_valid());
84 
85  const I& ima = exact(ima_);
86  mln_concrete(I) out = duplicate(ima_);
87  const N& nbh = exact(nbh_);
89 
90  // Init.
91  {
92  mln_piter(I) p(ima.domain());
93  mln_niter(N) n(nbh, p);
94 
95  for_all(p) if (ima(p) == 0)
96  for_all(n) if (ima(n) != 0)
97  {
98  q.push(p);
99  break;
100  }
101  }
102 
103  // Body.
104  {
105  while (! q.is_empty())
106  {
107  mln_psite(I) p = q.front();
108  q.pop();
109  if (out(p) != 0) // p has already been processed so ignore
110  continue;
111 
112  mln_niter(N) n(nbh, p);
113  for_all(n) if (ima.has(n))
114  {
115  if (out(n) != 0)
116  out(p) = out(n);
117  else
118  q.push(n); // n may already be in the queue,
119  // yet we then queue again this psite
120  }
121  }
122  }
123 
124  trace::exiting("geom::impl::seed2tiling");
125  return out;
126  }
127 
128  } // end of namespace mln::geom::impl
129 
130 
131 
132  // Facade
133 
134  template <typename I, typename N>
135  inline
136  mln_concrete(I) seeds2tiling(const Image<I>& ima_, const Neighborhood<N>& nbh)
137  {
138  trace::entering("geom::seed2tiling");
139 
140  mln_precondition(exact(ima_).is_valid());
141  mln_precondition(exact(nbh).is_valid());
142 
143  mln_concrete(I) output = impl::seeds2tiling(ima_, nbh);
144 
145  trace::exiting("geom::seed2tiling");
146  return output;
147  }
148 
149 
150 # endif // ! MLN_INCLUDE_ONLY
151 
152  } // end of namespace mln::geom
153 
154 } // end of namespace mln
155 
156 
157 #endif // ! MLN_GEOM_SEEDS2TILING_HH