$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends 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  mln_trace("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  return output;
96  }
97 
98  } // end of namespace mln::morpho::elementary::impl::generic
99 
100 
101  template <typename I, typename N>
102  mln_concrete(I)
103  like_ero_set_fastest(bool val[5],
104  const Image<I>& input_, const Neighborhood<N>& nbh_)
105  {
106  mln_trace("morpho::elementary::impl::like_ero_set_fastest");
107 
108  bool
109  ext_value = val[0],
110  do_duplicate = val[1],
111  on_input_p = val[2],
112  on_input_n = val[3],
113  output_p = val[4];
114 
115  const I& input = exact(input_);
116  const N& nbh = exact(nbh_);
117 
118  extension::adjust_fill(input, nbh, ext_value);
119 
120  mln_concrete(I) output;
121  if (do_duplicate)
122  output = duplicate(input);
123  else
124  {
125  initialize(output, input);
126  data::fill(output, false);
127  }
128 
129  mln_pixter(const I) p_in(input);
130  mln_pixter(I) p_out(output);
131  mln_nixter(const I, N) n(p_in, nbh);
132  for_all_2(p_in, p_out)
133  if (p_in.val() == on_input_p)
134  for_all(n)
135  if (n.val() == on_input_n)
136  p_out.val() = output_p;
137 
138  return output;
139  }
140 
141  } // end of namespace mln::morpho::elementary::impl
142 
143 
144  namespace internal
145  {
146 
147  template <typename I, typename N>
148  mln_concrete(I)
149  like_ero_set_dispatch(metal::false_,
150  bool val[5],
151  const I& input, const N& nbh)
152  {
153  return impl::generic::like_ero_set(val, input, nbh);
154  }
155 
156  template <typename I, typename N>
157  mln_concrete(I)
158  like_ero_set_dispatch(metal::true_,
159  bool val[5],
160  const I& input, const N& nbh)
161  {
162  return impl::like_ero_set_fastest(val, input, nbh);
163  }
164 
165  template <typename I, typename N>
166  mln_concrete(I)
167  like_ero_set_dispatch(bool val[5],
168  const I& input, const N& nbh)
169  {
170  typedef mlc_equal(mln_trait_image_speed(I),
171  trait::image::speed::fastest) I_fastest;
172  typedef mln_window(N) W;
173  typedef mln_is_simple_window(W) N_simple;
174 
175  return like_ero_set_dispatch(mlc_and(I_fastest, N_simple)(),
176  val, input, nbh);
177  }
178 
179  } // end of namespace mln::morpho::elementary::internal
180 
181 
182  // Facade.
183 
184  template <typename I, typename N>
185  mln_concrete(I)
186  like_ero_set(bool val[5],
187  const Image<I>& input, const Neighborhood<N>& nbh)
188  {
189  return internal::like_ero_set_dispatch(val, exact(input), exact(nbh));
190  }
191 
192 # endif // ! MLN_INCLUDE_ONLY
193 
194  } // end of namespace mln::morpho::elementary
195 
196  } // end of namespace mln::morpho
197 
198 } // end of namespace mln
199 
200 
201 #endif // ! MLN_MORPHO_ELEMENTARY_LIKE_ERO_SET_HH