• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

paste_without_localization.hh

00001 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
00002 // (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_DATA_PASTE_WITHOUT_LOCALIZATION_HH
00028 # define MLN_DATA_PASTE_WITHOUT_LOCALIZATION_HH
00029 
00034 
00035 # include <mln/core/concept/image.hh>
00036 # include <mln/core/box_runstart_piter.hh>
00037 
00038 # include <mln/border/get.hh>
00039 
00040 namespace mln
00041 {
00042 
00043   namespace data
00044   {
00045 
00052     //
00053     template <typename I, typename J>
00054     void paste_without_localization(const Image<I>& input, Image<J>& output);
00055 
00056 
00057 
00058 # ifndef MLN_INCLUDE_ONLY
00059 
00060 
00061     // Tests
00062 
00063     namespace internal
00064     {
00065 
00066 
00067         template <typename I, typename J>
00068         inline
00069         void paste_without_localization_tests(const Image<I>& input,
00070                                               Image<J>& output)
00071         {
00072           mlc_converts_to(mln_value(I), mln_value(J))::check();
00073 
00074           (void) input;
00075           (void) output;
00076         }
00077 
00078     } // end of namespace mln::data::internal
00079 
00080 
00081 
00082     // Implementations
00083 
00084 
00085     namespace impl
00086     {
00087 
00088       namespace generic
00089       {
00090 
00091         template <typename I, typename J>
00092         inline
00093         void paste_without_localization(const Image<I>& input_,
00094                                         Image<J>& output_)
00095         {
00096           trace::entering("data::impl::generic::paste_without_localization");
00097 
00098           internal::paste_without_localization_tests(input_, output_);
00099 
00100           const I& input = exact(input_);
00101           J& output = exact(output_);
00102 
00103           mln_fwd_piter(I) pi(input.domain());
00104           pi.start();
00105           mln_fwd_piter(J) po(output.domain());
00106           po.start();
00107           while (pi.is_valid() && po.is_valid())
00108           {
00109             output(po) = input(pi);
00110             pi.next();
00111             po.next();
00112           }
00113 
00114           trace::exiting("data::impl::generic::paste_without_localization");
00115         }
00116 
00117 
00118       } // end of namespace mln::data::impl::generic
00119 
00120 
00121 
00140       template <typename I, typename J>
00141       inline
00142       void paste_without_localization_fastest(const Image<I>& input_,
00143                                               Image<J>& output_)
00144       {
00145         trace::entering("data::impl::paste_without_localization_fastest");
00146 
00147         internal::paste_without_localization_tests(input_, output_);
00148 
00149         const I& input = exact(input_);
00150         J& output = exact(output_);
00151 
00152         typedef mln_value(I) V;
00153         memcpy(output.buffer(), input.buffer(), input.nelements() * sizeof(V));
00154 
00155         trace::exiting("data::impl::paste_without_localization_fastest");
00156       }
00157 
00158 
00159 
00177       template <typename I, typename J>
00178       inline
00179       void paste_without_localization_lines(const Image<I>& input_,
00180                                             Image<J>& output_)
00181       {
00182         trace::entering("data::impl::paste_without_localization_fastest");
00183 
00184         internal::paste_without_localization_tests(input_, output_);
00185 
00186         const I& input = exact(input_);
00187         J& output = exact(output_);
00188 
00189         box_runstart_piter<mln_site(I)> pi(input.domain());
00190         box_runstart_piter<mln_site(J)> po(output.domain());
00191 
00192         typedef mln_value(I) V;
00193 
00194         for_all_2(pi, po)
00195           memcpy(&output(po), &input(pi), input.ncols() * sizeof(V));
00196 
00197         trace::exiting("data::impl::paste_without_localization_fastest");
00198       }
00199 
00200 
00201 
00218       template <typename I, typename J>
00219       inline
00220       void paste_without_localization_fast(const Image<I>& input_,
00221                                            Image<J>& output_)
00222       {
00223         trace::entering("data::impl::paste_without_localization_fast");
00224 
00225         internal::paste_without_localization_tests(input_, output_);
00226 
00227         const I& input = exact(input_);
00228         J& output = exact(output_);
00229 
00230         mln_pixter(const I) pi(input);
00231         mln_pixter(J) po(output);
00232 
00233         for_all_2(pi, po)
00234           po.val() = pi.val();
00235 
00236         trace::exiting("data::impl::paste_without_localization_fast");
00237       }
00238 
00239 
00240 
00241     } // end of namespace mln::data::impl
00242 
00243 
00244 
00245     // Dispatch
00246 
00247     namespace internal
00248     {
00249 
00250       template <typename I, typename J>
00251       inline
00252       void paste_without_localization_dispatch(
00253         mln::trait::image::value_access::direct,
00254         mln::trait::image::value_access::direct,
00255         mln::trait::image::ext_domain::some,
00256         mln::trait::image::ext_domain::some,
00257         const I& input,
00258         J& output)
00259       {
00260         if (sizeof(mln_value(I)) == sizeof(mln_value(J)))
00261         {
00262           if (border::get(input) == border::get(output)
00263               && input.domain() == output.domain())
00264             impl::paste_without_localization_fastest(input, output);
00265           else
00266             impl::paste_without_localization_lines(input, output);
00267         }
00268         else
00269           impl::paste_without_localization_fast(input, output);
00270 
00271       }
00272 
00273 
00274       template <typename I, typename J>
00275       inline
00276       void paste_without_localization_dispatch(
00277         mln::trait::image::value_access::any,
00278         mln::trait::image::value_access::any,
00279         mln::trait::image::ext_domain::any,
00280         mln::trait::image::ext_domain::any,
00281         const I& input,
00282         J& output)
00283       {
00284         impl::generic::paste_without_localization(input, output);
00285       }
00286 
00287 
00288       template <typename I, typename J>
00289       inline
00290       void paste_without_localization_dispatch(
00291         mln::trait::image::value_storage::any,
00292         mln::trait::image::value_storage::any,
00293         const Image<I>& input,
00294         Image<J>& output)
00295       {
00296         impl::generic::paste_without_localization(input, output);
00297       }
00298 
00299 
00300       template <typename I, typename J>
00301       inline
00302       void paste_without_localization_dispatch(
00303         mln::trait::image::value_storage::one_block,
00304         mln::trait::image::value_storage::one_block,
00305         const Image<I>& input_,
00306         Image<J>& output_)
00307       {
00308         const I& input  = exact(input_);
00309         J&       output = exact(output_);
00310 
00311 
00313         if (mlc_is(mln_trait_image_value_alignment(I),
00314                    trait::image::value_alignment::with_grid)::value &&
00315             mlc_is(mln_trait_image_value_alignment(J),
00316                    trait::image::value_alignment::with_grid)::value)
00317           {
00318             paste_without_localization_dispatch(
00319               mln_trait_image_value_access(I)(),
00320               mln_trait_image_value_access(J)(),
00321               mln_trait_image_ext_domain(I)(),
00322               mln_trait_image_ext_domain(J)(),
00323               input, output);
00324           }
00325         else
00326           impl::generic::paste_without_localization(input, output);
00327       }
00328 
00329 
00330       template <typename I, typename J>
00331       inline
00332       void paste_without_localization_dispatch(const Image<I>& input,
00333                                                Image<J>& output)
00334       {
00335         paste_without_localization_dispatch(mln_trait_image_value_storage(I)(),
00336                                             mln_trait_image_value_storage(J)(),
00337                                             input, output);
00338       }
00339 
00340     } // end of namespace mln::data::internal
00341 
00342 
00343 
00344 
00345     // Facade
00346 
00347     template <typename I, typename J>
00348     inline
00349     void paste_without_localization(const Image<I>& input, Image<J>& output)
00350     {
00351       trace::entering("data::paste_without_localization");
00352 
00353       internal::paste_without_localization_tests(input, output);
00354 
00355       internal::paste_without_localization_dispatch(input, output);
00356 
00357       trace::exiting("data::paste_without_localization");
00358     }
00359 
00360 # endif // ! MLN_INCLUDE_ONLY
00361 
00362   } // end of namespace mln::data
00363 
00364 } // end of namespace mln
00365 
00366 
00367 
00368 #endif // ! MLN_DATA_PASTE_WITHOUT_LOCALIZATION_HH

Generated on Fri Sep 16 2011 16:33:49 for Milena (Olena) by  doxygen 1.7.1