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