Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
paste_without_localization.hh
1 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
2 // (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_DATA_PASTE_WITHOUT_LOCALIZATION_HH
28 # define MLN_DATA_PASTE_WITHOUT_LOCALIZATION_HH
29 
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/core/box_runstart_piter.hh>
37 
38 # include <mln/border/get.hh>
39 
40 namespace mln
41 {
42 
43  namespace data
44  {
45 
52  //
53  template <typename I, typename J>
54  void paste_without_localization(const Image<I>& input, Image<J>& output);
55 
56 
57 
58 # ifndef MLN_INCLUDE_ONLY
59 
60 
61  // Tests
62 
63  namespace internal
64  {
65 
66 
67  template <typename I, typename J>
68  inline
69  void paste_without_localization_tests(const Image<I>& input,
70  Image<J>& output)
71  {
72  mlc_converts_to(mln_value(I), mln_value(J))::check();
73 
74  (void) input;
75  (void) output;
76  }
77 
78  } // end of namespace mln::data::internal
79 
80 
81 
82  // Implementations
83 
84 
85  namespace impl
86  {
87 
88  namespace generic
89  {
90 
91  template <typename I, typename J>
92  inline
93  void paste_without_localization(const Image<I>& input_,
94  Image<J>& output_)
95  {
96  trace::entering("data::impl::generic::paste_without_localization");
97 
98  internal::paste_without_localization_tests(input_, output_);
99 
100  const I& input = exact(input_);
101  J& output = exact(output_);
102 
103  mln_fwd_piter(I) pi(input.domain());
104  pi.start();
105  mln_fwd_piter(J) po(output.domain());
106  po.start();
107  while (pi.is_valid() && po.is_valid())
108  {
109  output(po) = input(pi);
110  pi.next();
111  po.next();
112  }
113 
114  trace::exiting("data::impl::generic::paste_without_localization");
115  }
116 
117 
118  } // end of namespace mln::data::impl::generic
119 
120 
121 
140  template <typename I, typename J>
141  inline
143  Image<J>& output_)
144  {
145  trace::entering("data::impl::paste_without_localization_fastest");
146 
147  internal::paste_without_localization_tests(input_, output_);
148 
149  const I& input = exact(input_);
150  J& output = exact(output_);
151 
152  typedef mln_value(I) V;
153  memcpy(output.buffer(), input.buffer(), input.nelements() * sizeof(V));
154 
155  trace::exiting("data::impl::paste_without_localization_fastest");
156  }
157 
158 
159 
177  template <typename I, typename J>
178  inline
180  Image<J>& output_)
181  {
182  trace::entering("data::impl::paste_without_localization_fastest");
183 
184  internal::paste_without_localization_tests(input_, output_);
185 
186  const I& input = exact(input_);
187  J& output = exact(output_);
188 
189  box_runstart_piter<mln_site(I)> pi(input.domain());
190  box_runstart_piter<mln_site(J)> po(output.domain());
191 
192  typedef mln_value(I) V;
193 
194  for_all_2(pi, po)
195  memcpy(&output(po), &input(pi), input.ncols() * sizeof(V));
196 
197  trace::exiting("data::impl::paste_without_localization_fastest");
198  }
199 
200 
201 
218  template <typename I, typename J>
219  inline
221  Image<J>& output_)
222  {
223  trace::entering("data::impl::paste_without_localization_fast");
224 
225  internal::paste_without_localization_tests(input_, output_);
226 
227  const I& input = exact(input_);
228  J& output = exact(output_);
229 
230  mln_pixter(const I) pi(input);
231  mln_pixter(J) po(output);
232 
233  for_all_2(pi, po)
234  po.val() = pi.val();
235 
236  trace::exiting("data::impl::paste_without_localization_fast");
237  }
238 
239 
240 
241  } // end of namespace mln::data::impl
242 
243 
244 
245  // Dispatch
246 
247  namespace internal
248  {
249 
250  template <typename I, typename J>
251  inline
252  void paste_without_localization_dispatch(
253  mln::trait::image::value_access::direct,
254  mln::trait::image::value_access::direct,
255  mln::trait::image::ext_domain::some,
256  mln::trait::image::ext_domain::some,
257  const I& input,
258  J& output)
259  {
260  if (sizeof(mln_value(I)) == sizeof(mln_value(J)))
261  {
262  if (border::get(input) == border::get(output)
263  && input.domain() == output.domain())
265  else
267  }
268  else
270 
271  }
272 
273 
274  template <typename I, typename J>
275  inline
276  void paste_without_localization_dispatch(
277  mln::trait::image::value_access::any,
278  mln::trait::image::value_access::any,
279  mln::trait::image::ext_domain::any,
280  mln::trait::image::ext_domain::any,
281  const I& input,
282  J& output)
283  {
284  impl::generic::paste_without_localization(input, output);
285  }
286 
287 
288  template <typename I, typename J>
289  inline
290  void paste_without_localization_dispatch(
291  mln::trait::image::value_storage::any,
292  mln::trait::image::value_storage::any,
293  const Image<I>& input,
294  Image<J>& output)
295  {
296  impl::generic::paste_without_localization(input, output);
297  }
298 
299 
300  template <typename I, typename J>
301  inline
302  void paste_without_localization_dispatch(
303  mln::trait::image::value_storage::one_block,
304  mln::trait::image::value_storage::one_block,
305  const Image<I>& input_,
306  Image<J>& output_)
307  {
308  const I& input = exact(input_);
309  J& output = exact(output_);
310 
311 
313  if (mlc_is(mln_trait_image_value_alignment(I),
314  trait::image::value_alignment::with_grid)::value &&
315  mlc_is(mln_trait_image_value_alignment(J),
316  trait::image::value_alignment::with_grid)::value)
317  {
318  paste_without_localization_dispatch(
319  mln_trait_image_value_access(I)(),
320  mln_trait_image_value_access(J)(),
321  mln_trait_image_ext_domain(I)(),
322  mln_trait_image_ext_domain(J)(),
323  input, output);
324  }
325  else
326  impl::generic::paste_without_localization(input, output);
327  }
328 
329 
330  template <typename I, typename J>
331  inline
332  void paste_without_localization_dispatch(const Image<I>& input,
333  Image<J>& output)
334  {
335  paste_without_localization_dispatch(mln_trait_image_value_storage(I)(),
336  mln_trait_image_value_storage(J)(),
337  input, output);
338  }
339 
340  } // end of namespace mln::data::internal
341 
342 
343 
344 
345  // Facade
346 
347  template <typename I, typename J>
348  inline
349  void paste_without_localization(const Image<I>& input, Image<J>& output)
350  {
351  trace::entering("data::paste_without_localization");
352 
353  internal::paste_without_localization_tests(input, output);
354 
355  internal::paste_without_localization_dispatch(input, output);
356 
357  trace::exiting("data::paste_without_localization");
358  }
359 
360 # endif // ! MLN_INCLUDE_ONLY
361 
362  } // end of namespace mln::data
363 
364 } // end of namespace mln
365 
366 
367 
368 #endif // ! MLN_DATA_PASTE_WITHOUT_LOCALIZATION_HH