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