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