$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
influence_zones.hh
1 // Copyright (C) 2008, 2009, 2011 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 
30 
31 // FIXME: Refactor and move into the library.
32 
33 #include <mln/core/routine/duplicate.hh>
34 
35 #include <mln/core/site_set/p_queue_fast.hh>
36 
37 
38 namespace mln
39 {
40 
41  // FIXME: Add Image and Neighborhood concept constraints.
42  template <typename I, typename N>
43  inline
44  mln_concrete(I)
45  influence_zones(const I& input, const N& nbh)
46  {
47  mln_concrete(I) output = duplicate(input);
48 
50 
51  {
52  // Initialization.
53  mln_piter(I) p(input.domain());
54  mln_niter(N) n(nbh, p);
55  for_all(p)
56  if (input(p) != 0)
57  for_all(n) if (input.has(n))
58  if (input(n) == 0)
59  {
60  q.push(p);
61  break;
62  }
63  }
64  {
65  // Body.
66  mln_site(I) p;
67  mln_niter(N) n(nbh, p);
68  while (! q.is_empty())
69  {
70  p = q.pop_front();
71  mln_invariant(output(p) != 0);
72  for_all(n) if (input.has(n))
73  if (output(n) == 0)
74  {
75  output(n) = output(p);
76  q.push(n);
77  }
78  }
79  }
80 
81  return output;
82  }
83 
84 } // end of namespace mln