Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
untake.hh
1 // Copyright (C) 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_ACCU_IMAGE_UNTAKE_HH
27 # define MLN_ACCU_IMAGE_UNTAKE_HH
28 
33 
34 # include <mln/core/concept/accumulator.hh>
35 # include <mln/core/concept/image.hh>
36 # include <mln/border/resize_equal.hh>
37 
38 
39 namespace mln
40 {
41 
42  namespace accu
43  {
44 
45  namespace image
46  {
47 
48  template <typename I>
49  void
50  untake(Image<I>& input, const mln_deduce(I, value, argument)& arg);
51 
52  template <typename I, typename J>
53  void
54  untake(Image<I>& input, const Image<J>& arg);
55 
56 
57 # ifndef MLN_INCLUDE_ONLY
58 
59 
60  // Tests.
61 
62  namespace internal
63  {
64 
65  template <typename I, typename J>
66  inline
67  void
68  untake_tests(Image<I>& input_, const Image<J>& arg_)
69  {
70  I& input = exact(input_);
71  const J& arg = exact(arg_);
72 
73  mln_precondition(input.is_valid());
74  mln_precondition(arg.is_valid());
75 
76  mln_precondition(arg.domain() <= input.domain());
77 
78  (void) input;
79  (void) arg;
80  }
81 
82  } // end of namespace mln::accu::image::internal
83 
84 
85 
86  // Implementations.
87 
88  namespace impl
89  {
90 
91  // Generic versions.
92 
93  namespace generic
94  {
95 
96  template <typename I>
97  inline
98  void
99  untake(Image<I>& input_, const mln_deduce(I, value, argument)& arg)
100  {
101  trace::entering("accu::impl::image::generic::untake");
102 
103  mlc_is_a(mln_value(I), Accumulator)::check();
104 
105  I& input = exact(input_);
106  mln_precondition(input.is_valid());
107 
108  mln_piter(I) p(input.domain());
109  for_all(p)
110  input(p).untake(arg);
111 
112  trace::exiting("accu::impl::image::generic::untake");
113  }
114 
115  template <typename I, typename J>
116  inline
117  void
118  untake(Image<I>& input_, const Image<J>& arg_)
119  {
120  trace::entering("accu::impl::image::generic::untake");
121 
122  mlc_is_a(mln_value(I), Accumulator)::check();
123  mlc_converts_to(mln_value(J), mln_deduce(I, value, argument))::check();
124 
125  I& input = exact(input_);
126  const J& arg = exact(arg_);
127 
128  internal::untake_tests(input, arg);
129 
130  mln_piter(J) p(arg.domain());
131  for_all(p)
132  input(p).untake(arg(p));
133 
134  trace::exiting("accu::impl::image::generic::untake");
135  }
136 
137  } // end of namespace mln::accu::image::impl::generic
138 
139 
140  // Fastest versions.
141 
142  template <typename I>
143  inline
144  void
145  untake_fastest(Image<I>& input_, const mln_deduce(I, value, argument)& arg)
146  {
147  trace::entering("accu::impl::image::untake_fastest");
148 
149  mlc_is_a(mln_value(I), Accumulator)::check();
150 
151  I& input = exact(input_);
152  mln_precondition(input.is_valid());
153 
154  mln_pixter(I) px(input);
155  for_all(px)
156  px.val().untake(arg);
157 
158  trace::exiting("accu::impl::image::untake_fastest");
159  }
160 
161  template <typename I, typename J>
162  inline
163  void
164  untake_fastest(Image<I>& input_, const Image<J>& arg_)
165  {
166  trace::entering("accu::impl::image::untake_fastest");
167 
168  mlc_is_a(mln_value(I), Accumulator)::check();
169  mlc_converts_to(mln_value(J), mln_deduce(I, value, argument))::check();
170 
171  I& input = exact(input_);
172  const J& arg = exact(arg_);
173 
174  internal::untake_tests(input, arg);
175  // Extra (stronger) test.
176  mln_precondition(arg.domain() == input.domain());
177 
178  border::resize_equal(input, arg);
179 
180  mln_pixter(I) p_in(input);
181  mln_pixter(const J) p_arg(arg);
182  for_all_2(p_in, p_arg)
183  p_in.val().untake( p_arg.val() );
184 
185  trace::exiting("accu::impl::image::untake_fastest");
186  }
187 
188  } // end of namespace mln::accu::image::impl
189 
190 
191 
192  // Dispatch.
193 
194  namespace internal
195  {
196 
197  // 'arg' as value.
198 
199  template <typename I>
200  inline
201  void
202  untake_dispatch(trait::image::speed::any,
203  Image<I>& input, const mln_deduce(I, value, argument)& arg)
204  {
205  impl::generic::untake(input, arg);
206  }
207 
208  template <typename I>
209  inline
210  void
211  untake_dispatch(trait::image::speed::fastest,
212  Image<I>& input, const mln_deduce(I, value, argument)& arg)
213  {
214  impl::untake_fastest(input, arg);
215  }
216 
217  template <typename I>
218  inline
219  void
220  untake_dispatch(Image<I>& input, const mln_deduce(I, value, argument)& arg)
221  {
222  untake_dispatch(mln_trait_image_speed(I)(),
223  input, arg);
224  }
225 
226  // 'arg' as image.
227 
228  template <typename I, typename J>
229  inline
230  void
231  untake_dispatch(trait::image::speed::any,
232  trait::image::speed::any,
233  Image<I>& input, const Image<J>& arg)
234  {
235  impl::generic::untake(input, arg);
236  }
237 
238  template <typename I, typename J>
239  inline
240  void
241  untake_dispatch(trait::image::speed::fastest,
242  trait::image::speed::fastest,
243  Image<I>& input, const Image<J>& arg)
244  {
245  if (exact(arg).domain() == exact(input).domain())
246  impl::untake_fastest(input, arg);
247  else
248  impl::generic::untake(input, arg);
249  }
250 
251  template <typename I, typename J>
252  inline
253  void
254  untake_dispatch(Image<I>& input, const Image<J>& arg)
255  {
256  untake_dispatch(mln_trait_image_speed(I)(),
257  mln_trait_image_speed(J)(),
258  input, arg);
259  }
260 
261  } // end of namespace mln::accu::image::internal
262 
263 
264  // Facades.
265 
266  template <typename I>
267  inline
268  void
269  untake(Image<I>& input, const mln_deduce(I, value, argument)& arg)
270  {
271  trace::entering("accu::image::untake");
272 
273  typedef mln_value(I) A;
274  mlc_is_a(A, Accumulator)::check();
275  mlc_equal(mln_trait_accumulator_has_untake(A),
276  trait::accumulator::has_untake::yes)::check();
277 
278  mln_precondition(exact(input).is_valid());
279  internal::untake_dispatch(input, arg);
280 
281  trace::exiting("accu::image::untake");
282  }
283 
284  template <typename I, typename J>
285  inline
286  void
287  untake(Image<I>& input, const Image<J>& arg)
288  {
289  trace::entering("accu::image::untake");
290 
291  typedef mln_value(I) A;
292  mlc_is_a(A, Accumulator)::check();
293  mlc_equal(mln_trait_accumulator_has_untake(A),
294  trait::accumulator::has_untake::yes)::check();
295  mlc_converts_to(mln_value(J), mln_deduce(I, value, argument))::check();
296 
297  internal::untake_tests(input, arg);
298  internal::untake_dispatch(input, arg);
299 
300  trace::exiting("accu::image::untake");
301  }
302 
303 # endif // ! MLN_INCLUDE_ONLY
304 
305  } // end of namespace mln::accu::image
306 
307  } // end of namespace mln::accu
308 
309 } // end of namespace mln
310 
311 
312 #endif // ! MLN_ACCU_IMAGE_UNTAKE_HH