Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
like_ero_set.hh
1 // Copyright (C) 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_ELEMENTARY_LIKE_ERO_SET_HH
27 # define MLN_MORPHO_ELEMENTARY_LIKE_ERO_SET_HH
28 
32 
33 # include <mln/morpho/includes.hh>
34 
35 
36 namespace mln
37 {
38 
39  namespace morpho
40  {
41 
42  namespace elementary
43  {
44 
45  template <typename I, typename N>
46  mln_concrete(I)
47  like_ero_set(bool val[5],
48  const Image<I>& input, const Neighborhood<N>& nbh);
49 
50 
51 # ifndef MLN_INCLUDE_ONLY
52 
53  namespace impl
54  {
55 
56  namespace generic
57  {
58 
59  template <typename I, typename N>
60  mln_concrete(I)
61  like_ero_set(bool val[5],
62  const Image<I>& input_, const Neighborhood<N>& nbh_)
63  {
64  trace::entering("morpho::elementary::impl::generic::like_ero_set");
65 
66  bool
67  ext_value = val[0],
68  do_duplicate = val[1],
69  on_input_p = val[2],
70  on_input_n = val[3],
71  output_p = val[4];
72 
73  const I& input = exact(input_);
74  const N& nbh = exact(nbh_);
75 
76  extension::adjust_fill(input, nbh, ext_value);
77 
78  mln_concrete(I) output;
79  if (do_duplicate)
80  output = duplicate(input);
81  else
82  {
83  initialize(output, input);
84  data::fill(output, false);
85  }
86 
87  mln_piter(I) p(input.domain());
88  mln_niter(N) n(nbh, p);
89  for_all(p)
90  if (input(p) == on_input_p)
91  for_all(n)
92  if (input.has(n) && input(n) == on_input_n)
93  output(p) = output_p;
94 
95  trace::exiting("morpho::elementary::impl::generic::like_ero_set");
96  return output;
97  }
98 
99  } // end of namespace mln::morpho::elementary::impl::generic
100 
101 
102  template <typename I, typename N>
103  mln_concrete(I)
104  like_ero_set_fastest(bool val[5],
105  const Image<I>& input_, const Neighborhood<N>& nbh_)
106  {
107  trace::entering("morpho::elementary::impl::like_ero_set_fastest");
108 
109  bool
110  ext_value = val[0],
111  do_duplicate = val[1],
112  on_input_p = val[2],
113  on_input_n = val[3],
114  output_p = val[4];
115 
116  const I& input = exact(input_);
117  const N& nbh = exact(nbh_);
118 
119  extension::adjust_fill(input, nbh, ext_value);
120 
121  mln_concrete(I) output;
122  if (do_duplicate)
123  output = duplicate(input);
124  else
125  {
126  initialize(output, input);
127  data::fill(output, false);
128  }
129 
130  mln_pixter(const I) p_in(input);
131  mln_pixter(I) p_out(output);
132  mln_nixter(const I, N) n(p_in, nbh);
133  for_all_2(p_in, p_out)
134  if (p_in.val() == on_input_p)
135  for_all(n)
136  if (n.val() == on_input_n)
137  p_out.val() = output_p;
138 
139  trace::exiting("morpho::elementary::impl::like_ero_set_fastest");
140  return output;
141  }
142 
143  } // end of namespace mln::morpho::elementary::impl
144 
145 
146  namespace internal
147  {
148 
149  template <typename I, typename N>
150  mln_concrete(I)
151  like_ero_set_dispatch(metal::false_,
152  bool val[5],
153  const I& input, const N& nbh)
154  {
155  return impl::generic::like_ero_set(val, input, nbh);
156  }
157 
158  template <typename I, typename N>
159  mln_concrete(I)
160  like_ero_set_dispatch(metal::true_,
161  bool val[5],
162  const I& input, const N& nbh)
163  {
164  return impl::like_ero_set_fastest(val, input, nbh);
165  }
166 
167  template <typename I, typename N>
168  mln_concrete(I)
169  like_ero_set_dispatch(bool val[5],
170  const I& input, const N& nbh)
171  {
172  typedef mlc_equal(mln_trait_image_speed(I),
173  trait::image::speed::fastest) I_fastest;
174  typedef mln_window(N) W;
175  typedef mln_is_simple_window(W) N_simple;
176 
177  return like_ero_set_dispatch(mlc_and(I_fastest, N_simple)(),
178  val, input, nbh);
179  }
180 
181  } // end of namespace mln::morpho::elementary::internal
182 
183 
184  // Facade.
185 
186  template <typename I, typename N>
187  mln_concrete(I)
188  like_ero_set(bool val[5],
189  const Image<I>& input, const Neighborhood<N>& nbh)
190  {
191  return internal::like_ero_set_dispatch(val, exact(input), exact(nbh));
192  }
193 
194 # endif // ! MLN_INCLUDE_ONLY
195 
196  } // end of namespace mln::morpho::elementary
197 
198  } // end of namespace mln::morpho
199 
200 } // end of namespace mln
201 
202 
203 #endif // ! MLN_MORPHO_ELEMENTARY_LIKE_ERO_SET_HH