Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
canvas/chamfer.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_CANVAS_CHAMFER_HH
27 # define MLN_CANVAS_CHAMFER_HH
28 
34 # include <mln/core/internal/image_morpher.hh>
35 # include <mln/win/sym.hh>
36 
37 namespace mln
38 {
39  namespace canvas
40  {
41 
46  template <typename F>
47  struct chamfer
48  {
49  typedef typename F::I I;
50  typedef typename F::W W;
51  typedef mln_psite(I) point;
52 
53  F& f;
54 
55  chamfer(F& f);
56 
57  void run();
58  };
59 
60 # ifndef MLN_INCLUDE_ONLY
61 
62  template<typename F>
63  inline
65  : f(f)
66  {
67  run();
68  }
69 
70  template<typename F>
71  inline
72  void
73  chamfer<F>::run()
74  {
75 
77  {
78  f.init();
79  }
80 
82  {
83  mln_fwd_piter(I) p(f.input.domain());
84  mln_qiter(W) q(f.win, p);
85 
86  for_all(p) if (f.handles (p))
87  for_all(q) if (f.input.domain().has(q))
88  if (f.output(q) != f.max
89  && f.output(q) + q.w() < f.output(p))
90  f.output(p) = f.output(q) + q.w();
91  }
92 
94  {
95  W w_win_b = win::sym(f.win);
96 
97  mln_bkd_piter(I) p(f.input.domain());
98  mln_qiter(W) q(w_win_b, p);
99 
100  for_all(p) if (f.handles (p))
101  for_all(q) if (f.input.domain().has(q))
102  if (f.output(q) != f.max
103  && f.output(q) + q.w() < f.output(p))
104  f.output(p) = f.output(q) + q.w();
105  f.status = true;
106  }
107  }
108 
109 # endif // ! MLN_INCLUDE_ONLY
110 
111  } // end of mln::canvas
112 
113 } // end of mln
114 
115 #endif // ! MLN_CANVAS_CHAMFER_HH