$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
image/take.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_TAKE_HH
27 # define MLN_ACCU_IMAGE_TAKE_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  take(Image<I>& input, const mln_deduce(I, value, argument)& arg);
51 
52  template <typename I, typename J>
53  void
54  take(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  take_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  take(Image<I>& input_, const mln_deduce(I, value, argument)& arg)
100  {
101  mln_trace("accu::impl::image::generic::take");
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).take(arg);
111 
112  }
113 
114  template <typename I, typename J>
115  inline
116  void
117  take(Image<I>& input_, const Image<J>& arg_)
118  {
119  mln_trace("accu::impl::image::generic::take");
120 
121  mlc_is_a(mln_value(I), Accumulator)::check();
122  mlc_converts_to(mln_value(J), mln_deduce(I, value, argument))::check();
123 
124  I& input = exact(input_);
125  const J& arg = exact(arg_);
126 
127  internal::take_tests(input, arg);
128 
129  mln_piter(J) p(arg.domain());
130  for_all(p)
131  input(p).take(arg(p));
132 
133  }
134 
135  } // end of namespace mln::accu::image::impl::generic
136 
137 
138  // Fastest versions.
139 
140  template <typename I>
141  inline
142  void
143  take_fastest(Image<I>& input_, const mln_deduce(I, value, argument)& arg)
144  {
145  mln_trace("accu::impl::image::take_fastest");
146 
147  mlc_is_a(mln_value(I), Accumulator)::check();
148 
149  I& input = exact(input_);
150  mln_precondition(input.is_valid());
151 
152  mln_pixter(I) px(input);
153  for_all(px)
154  px.val().take(arg);
155 
156  }
157 
158  template <typename I, typename J>
159  inline
160  void
161  take_fastest(Image<I>& input_, const Image<J>& arg_)
162  {
163  mln_trace("accu::impl::image::take_fastest");
164 
165  mlc_is_a(mln_value(I), Accumulator)::check();
166  mlc_converts_to(mln_value(J), mln_deduce(I, value, argument))::check();
167 
168  I& input = exact(input_);
169  const J& arg = exact(arg_);
170 
171  internal::take_tests(input, arg);
172  // Extra (stronger) test.
173  mln_precondition(arg.domain() == input.domain());
174 
175  border::resize_equal(input, arg);
176 
177  mln_pixter(I) p_in(input);
178  mln_pixter(const J) p_arg(arg);
179  for_all_2(p_in, p_arg)
180  p_in.val().take( p_arg.val() );
181 
182  }
183 
184  } // end of namespace mln::accu::image::impl
185 
186 
187 
188  // Dispatch.
189 
190  namespace internal
191  {
192 
193  // 'arg' as value.
194 
195  template <typename I>
196  inline
197  void
198  take_dispatch(trait::image::speed::any,
199  Image<I>& input, const mln_deduce(I, value, argument)& arg)
200  {
201  impl::generic::take(input, arg);
202  }
203 
204  template <typename I>
205  inline
206  void
207  take_dispatch(trait::image::speed::fastest,
208  Image<I>& input, const mln_deduce(I, value, argument)& arg)
209  {
210  impl::take_fastest(input, arg);
211  }
212 
213  template <typename I>
214  inline
215  void
216  take_dispatch(Image<I>& input, const mln_deduce(I, value, argument)& arg)
217  {
218  take_dispatch(mln_trait_image_speed(I)(),
219  input, arg);
220  }
221 
222  // 'arg' as image.
223 
224  template <typename I, typename J>
225  inline
226  void
227  take_dispatch(trait::image::speed::any,
228  trait::image::speed::any,
229  Image<I>& input, const Image<J>& arg)
230  {
231  impl::generic::take(input, arg);
232  }
233 
234  template <typename I, typename J>
235  inline
236  void
237  take_dispatch(trait::image::speed::fastest,
238  trait::image::speed::fastest,
239  Image<I>& input, const Image<J>& arg)
240  {
241  if (exact(arg).domain() == exact(input).domain())
242  impl::take_fastest(input, arg);
243  else
244  impl::generic::take(input, arg);
245  }
246 
247  template <typename I, typename J>
248  inline
249  void
250  take_dispatch(Image<I>& input, const Image<J>& arg)
251  {
252  take_dispatch(mln_trait_image_speed(I)(),
253  mln_trait_image_speed(J)(),
254  input, arg);
255  }
256 
257  } // end of namespace mln::accu::image::internal
258 
259 
260  // Facades.
261 
262  template <typename I>
263  inline
264  void
265  take(Image<I>& input, const mln_deduce(I, value, argument)& arg)
266  {
267  mln_trace("accu::image::take");
268 
269  mlc_is_a(mln_value(I), Accumulator)::check();
270 
271  mln_precondition(exact(input).is_valid());
272  internal::take_dispatch(input, arg);
273 
274  }
275 
276  template <typename I, typename J>
277  inline
278  void
279  take(Image<I>& input, const Image<J>& arg)
280  {
281  mln_trace("accu::image::take");
282 
283  mlc_is_a(mln_value(I), Accumulator)::check();
284  mlc_converts_to(mln_value(J), mln_deduce(I, value, argument))::check();
285 
286  internal::take_tests(input, arg);
287  internal::take_dispatch(input, arg);
288 
289  }
290 
291 # endif // ! MLN_INCLUDE_ONLY
292 
293  } // end of namespace mln::accu::image
294 
295  } // end of namespace mln::accu
296 
297 } // end of namespace mln
298 
299 
300 #endif // ! MLN_ACCU_IMAGE_TAKE_HH