$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
paste_without_localization.hh
1 // Copyright (C) 2009, 2010, 2012 EPITA Research and Development
2 // Laboratory (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 
55  template <typename I, typename J>
56  void paste_without_localization(const Image<I>& input, Image<J>& output);
57 
58 
59 
60 # ifndef MLN_INCLUDE_ONLY
61 
62 
63  // Tests
64 
65  namespace internal
66  {
67 
68 
69  template <typename I, typename J>
70  inline
71  void paste_without_localization_tests(const Image<I>& input,
72  Image<J>& output)
73  {
74  mlc_converts_to(mln_value(I), mln_value(J))::check();
75 
76  (void) input;
77  (void) output;
78  }
79 
80  } // end of namespace mln::data::internal
81 
82 
83 
84  // Implementations
85 
86 
87  namespace impl
88  {
89 
90  namespace generic
91  {
92 
93  template <typename I, typename J>
94  inline
95  void paste_without_localization(const Image<I>& input_,
96  Image<J>& output_)
97  {
98  mln_trace("data::impl::generic::paste_without_localization");
99 
100  internal::paste_without_localization_tests(input_, output_);
101 
102  const I& input = exact(input_);
103  J& output = exact(output_);
104 
105  mln_fwd_piter(I) pi(input.domain());
106  pi.start();
107  mln_fwd_piter(J) po(output.domain());
108  po.start();
109  while (pi.is_valid() && po.is_valid())
110  {
111  output(po) = input(pi);
112  pi.next();
113  po.next();
114  }
115 
116  }
117 
118 
119  } // end of namespace mln::data::impl::generic
120 
121 
122 
141  template <typename I, typename J>
142  inline
143  void paste_without_localization_fastest(const Image<I>& input_,
144  Image<J>& output_)
145  {
146  mln_trace("data::impl::paste_without_localization_fastest");
147 
148  internal::paste_without_localization_tests(input_, output_);
149 
150  const I& input = exact(input_);
151  J& output = exact(output_);
152 
153  typedef mln_value(I) V;
154  memcpy(output.buffer(), input.buffer(), input.nelements() * sizeof(V));
155 
156  }
157 
158 
159 
177  template <typename I, typename J>
178  inline
179  void paste_without_localization_lines(const Image<I>& input_,
180  Image<J>& output_)
181  {
182  mln_trace("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  }
198 
199 
200 
217  template <typename I, typename J>
218  inline
219  void paste_without_localization_fast(const Image<I>& input_,
220  Image<J>& output_)
221  {
222  mln_trace("data::impl::paste_without_localization_fast");
223 
224  internal::paste_without_localization_tests(input_, output_);
225 
226  const I& input = exact(input_);
227  J& output = exact(output_);
228 
229  mln_pixter(const I) pi(input);
230  mln_pixter(J) po(output);
231 
232  for_all_2(pi, po)
233  po.val() = pi.val();
234 
235  }
236 
237 
238 
239  } // end of namespace mln::data::impl
240 
241 
242 
243  // Dispatch
244 
245  namespace internal
246  {
247 
248  template <typename I, typename J>
249  inline
250  void paste_without_localization_dispatch(
251  mln::trait::image::value_access::direct,
252  mln::trait::image::value_access::direct,
253  mln::trait::image::ext_domain::some,
254  mln::trait::image::ext_domain::some,
255  const I& input,
256  J& output)
257  {
258  if (sizeof(mln_value(I)) == sizeof(mln_value(J)))
259  {
260  if (border::get(input) == border::get(output)
261  && input.domain() == output.domain())
262  impl::paste_without_localization_fastest(input, output);
263  else
264  impl::paste_without_localization_lines(input, output);
265  }
266  else
267  impl::paste_without_localization_fast(input, output);
268 
269  }
270 
271 
272  template <typename I, typename J>
273  inline
274  void paste_without_localization_dispatch(
275  mln::trait::image::value_access::any,
276  mln::trait::image::value_access::any,
277  mln::trait::image::ext_domain::any,
278  mln::trait::image::ext_domain::any,
279  const I& input,
280  J& output)
281  {
283  }
284 
285 
286  template <typename I, typename J>
287  inline
288  void paste_without_localization_dispatch(
289  mln::trait::image::value_storage::any,
290  mln::trait::image::value_storage::any,
291  const Image<I>& input,
292  Image<J>& output)
293  {
295  }
296 
297 
298  template <typename I, typename J>
299  inline
300  void paste_without_localization_dispatch(
301  mln::trait::image::value_storage::one_block,
302  mln::trait::image::value_storage::one_block,
303  const Image<I>& input_,
304  Image<J>& output_)
305  {
306  const I& input = exact(input_);
307  J& output = exact(output_);
308 
309 
311  if (mlc_is(mln_trait_image_value_alignment(I),
312  trait::image::value_alignment::with_grid)::value &&
313  mlc_is(mln_trait_image_value_alignment(J),
314  trait::image::value_alignment::with_grid)::value)
315  {
316  paste_without_localization_dispatch(
317  mln_trait_image_value_access(I)(),
318  mln_trait_image_value_access(J)(),
319  mln_trait_image_ext_domain(I)(),
320  mln_trait_image_ext_domain(J)(),
321  input, output);
322  }
323  else
325  }
326 
327 
328  template <typename I, typename J>
329  inline
330  void paste_without_localization_dispatch(const Image<I>& input,
331  Image<J>& output)
332  {
333  paste_without_localization_dispatch(mln_trait_image_value_storage(I)(),
334  mln_trait_image_value_storage(J)(),
335  input, output);
336  }
337 
338  } // end of namespace mln::data::internal
339 
340 
341 
342 
343  // Facade
344 
345  template <typename I, typename J>
346  inline
347  void paste_without_localization(const Image<I>& input, Image<J>& output)
348  {
349  mln_trace("data::paste_without_localization");
350 
351  internal::paste_without_localization_tests(input, output);
352 
353  internal::paste_without_localization_dispatch(input, output);
354 
355  }
356 
357 # endif // ! MLN_INCLUDE_ONLY
358 
359  } // end of namespace mln::data
360 
361 } // end of namespace mln
362 
363 
364 
365 #endif // ! MLN_DATA_PASTE_WITHOUT_LOCALIZATION_HH