Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
dilation.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_MORPHO_DILATION_HH
27 # define MLN_MORPHO_DILATION_HH
28 
34 
35 # include <mln/morpho/includes.hh>
36 # include <mln/morpho/general.hh>
37 # include <mln/accu/logic/lor.hh>
38 # include <mln/accu/logic/lor_basic.hh>
39 # include <mln/accu/stat/max.hh>
40 # include <mln/accu/stat/max_h.hh>
41 
42 
43 namespace mln
44 {
45 
46  namespace morpho
47  {
48 
50  template <typename I, typename W>
51  mln_concrete(I)
52  dilation(const Image<I>& input, const Window<W>& win);
53 
54 
55 # ifndef MLN_INCLUDE_ONLY
56 
57 
58  struct dilation_op
59  {
60 
61  template <typename I>
62  mln_morpho_select_accu(I, logic::lor_basic, stat::max)
63  accu(const Image<I>&) const
64  {
65  mln_morpho_select_accu(I, logic::lor_basic, stat::max) tmp;
66  return tmp;
67  }
68 
69  template <typename I>
70  mln_morpho_select_accu(I, logic::lor, stat::max_h)
71  accu_incr(const Image<I>&) const
72  {
73  mln_morpho_select_accu(I, logic::lor, stat::max_h) tmp;
74  return tmp;
75  }
76 
77  template <typename I>
78  mln_value(I) neutral(const Image<I>&) const
79  {
80  return internal::neutral<I>::infimum();
81  }
82 
83  };
84 
85 
86  namespace impl
87  {
88 
89 
90  // On set with centered window (overloads).
91 
92  template <typename I, typename W>
93  mln_concrete(I)
94  general_on_set_centered(const dilation_op&,
95  const Image<I>& input_, const Window<W>& win_)
96  {
97  trace::entering("morpho::impl::general_on_set_centered__dilation");
98 
99  typedef mln_concrete(I) O;
100  const I& input = exact(input_);
101  const W& win = exact(win_);
102 
103  extension::adjust_fill(input, win, false);
104 
105  O output;
106  output = duplicate(input);
107 
108  mln_piter(I) p(input.domain());
109  mln_qiter(W) q(win, p);
110  for_all(p)
111  if (input(p) == false)
112  for_all(q) if (input.has(q))
113  if (input(q) == true)
114  {
115  output(p) = true;
116  break;
117  }
118 
119  trace::exiting("morpho::impl::general_on_set_centered__dilation");
120  return output;
121  }
122 
123 
124  template <typename I, typename W>
125  mln_concrete(I)
126  general_on_set_centered_fastest(const dilation_op&,
127  const Image<I>& input_, const Window<W>& win_)
128  {
129  trace::entering("morpho::impl::general_on_set_centered_fastest__dilation");
130 
131  typedef mln_concrete(I) O;
132  const I& input = exact(input_);
133  const W& win = exact(win_);
134 
135  extension::adjust_fill(input, win, false);
136 
137  O output;
138  output = duplicate(input);
139 
140  mln_pixter(const I) p(input);
141  mln_qixter(const I, W) q(p, win);
142  mln_pixter(O) p_out(output);
143  for_all_2(p, p_out)
144  if (p.val() == false)
145  for_all(q)
146  if (q.val() == true)
147  {
148  p_out.val() = true;
149  break;
150  }
151 
152  trace::exiting("morpho::impl::general_on_set_centered_fastest__dilation");
153  return output;
154  }
155 
156  } // end of namespace morpho::impl
157 
158 
159  template <typename I, typename W>
160  inline
161  mln_concrete(I)
162  dilation(const Image<I>& input, const Window<W>& win)
163  {
164  trace::entering("morpho::dilation");
165  mln_precondition(exact(input).is_valid());
166  mln_precondition(! exact(win).is_empty());
167 
168  mln_concrete(I) output = general(dilation_op(), input, win);
169 
170  if (exact(win).is_centered())
171  mln_postcondition(output >= input);
172 
173  trace::exiting("morpho::dilation");
174  return output;
175  }
176 
177 # endif // ! MLN_INCLUDE_ONLY
178 
179  } // end of namespace mln::morpho
180 
181 } // end of namespace mln
182 
183 
184 #endif // ! MLN_MORPHO_DILATION_HH