$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
geom/chamfer.hh
1 // Copyright (C) 2007, 2008, 2009, 2011, 2012 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_CHAMFER_HH
28 # define MLN_GEOM_CHAMFER_HH
29 
33 
34 # include <mln/canvas/chamfer.hh>
35 
36 
37 namespace mln
38 {
39 
40  namespace geom
41  {
42 
47  template <typename I, typename W>
48  mln_ch_value(I, unsigned)
49  chamfer(const Image<I>& input_, const W& w_win_,
50  unsigned max = mln_max(unsigned));
51 
52 
53 # ifndef MLN_INCLUDE_ONLY
54 
55  namespace impl
56  {
57 
58  // Functors.
59 
60  template <typename I_, typename W_>
61  struct chamfer_t
62  {
63  typedef I_ I;
64  typedef mln_ch_value(I, unsigned) O;
65  typedef W_ W;
66  typedef mln_site(I_) P;
67 
68  // requirements from mln::canvas::chamfer:
69 
70  const I& input;
71  const W& win;
72 
73  O output;
74  bool status;
75  unsigned max;
76 
77  void fill_output()
78  {
79  mln_piter(O) p(output.domain());
80  for_all(p)
81  {
82  if (input(p))
83  output(p) = 0u;
84  else
85  output(p) = max;
86  }
87  }
88 
89  inline
90  void init() { initialize(output, exact(input));
91  fill_output();
92  // Was :
93  // data::fill((output | (input | pw::cst(true)).domain()).rw(), 0);
94  // data::fill((output | (input | pw::cst(false)).domain()).rw(), max);
95  }
96  inline
97  bool handles(const P& p) const { return input(p) == false; }
98 
99  // end of requirements
100 
101  inline
102  chamfer_t(const I_& input, const W_& win, unsigned max)
103  : input (input),
104  win (win),
105  max (max)
106  {}
107  };
108 
109  } // end of namespace mln::geom::impl
110 
111 
112 
113  // Facade.
114 
115  template <typename I, typename W>
116  mln_ch_value(I, unsigned)
117  chamfer(const Image<I>& input_, const W& w_win_,
118  unsigned max)
119  {
120  mln_trace("mln::geom::chamfer");
121  // FIXME: check that input_ is binary.
122 
123  const I& input = exact(input_);
124  const W& w_win = exact(w_win_);
125 
126  typedef impl::chamfer_t<I, W> F;
127 
128  F f(input, w_win, max);
129  canvas::chamfer<F> run(f);
130 
131  return f.output;
132  }
133 
134 #endif // ! MLN_INCLUDE_ONLY
135 
136  } // end of namespace mln::geom
137 
138 } // end of namespace mln
139 
140 #endif // ! MLN_GEOM_CHAMFER_HH