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

take_as_init.hh

00001 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_ACCU_IMAGE_TAKE_AS_INIT_HH
00027 # define MLN_ACCU_IMAGE_TAKE_AS_INIT_HH
00028 
00032 
00033 # include <mln/core/concept/accumulator.hh>
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/border/resize_equal.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace accu
00042   {
00043 
00044     namespace image
00045     {
00046 
00047       template <typename I>
00048       void
00049       take_as_init(Image<I>& input, const mln_deduce(I, value, argument)& v);
00050 
00051       template <typename I, typename J>
00052       void
00053       take_as_init(Image<I>& input, const Image<J>& values);
00054 
00055 
00056 
00057 # ifndef MLN_INCLUDE_ONLY
00058 
00059       // Tests.
00060 
00061       namespace internal
00062       {
00063 
00064         template <typename I, typename J>
00065         inline
00066         void
00067         take_as_init_tests(Image<I>& input_, const Image<J>& values_)
00068         {
00069           I& input = exact(input_);
00070           const J& values = exact(values_);
00071 
00072           mln_precondition(input.is_valid());
00073           mln_precondition(values.is_valid());
00074 
00075           mln_precondition(values.domain() <= input.domain());
00076 
00077           (void) input;
00078           (void) values;
00079         }
00080 
00081       } // end of namespace mln::accu::image::internal
00082 
00083 
00084       namespace impl
00085       {
00086 
00087         // Generic versions.
00088 
00089         namespace generic
00090         {
00091 
00092           template <typename I>
00093           void
00094           take_as_init(Image<I>& input_, const mln_deduce(I, value, argument)& v)
00095           {
00096             trace::entering("accu::impl::image::generic::take_as_init");
00097 
00098             mlc_is_a(mln_value(I), Accumulator)::check();
00099 
00100             I& input = exact(input_);
00101             mln_precondition(input.is_valid());
00102 
00103             mln_piter(I) p(input.domain());
00104             for_all(p)
00105               input(p).take_as_init(v);
00106 
00107             trace::exiting("accu::impl::image::generic::take_as_init");
00108           }
00109 
00110           template <typename I, typename J>
00111           void
00112           take_as_init(Image<I>& input_, const Image<J>& values_)
00113           {
00114             trace::entering("accu::impl::image::generic::take_as_init");
00115 
00116             typedef mln_value(I) A;
00117             mlc_is_a(A, Accumulator)::check();
00118             mlc_converts_to(mln_value(J), mln_argument(A))::check();
00119 
00120             I& input = exact(input_);
00121             const J& values = exact(values_);
00122 
00123             internal::take_as_init_tests(input, values);
00124 
00125             mln_piter(J) p(values.domain());
00126             for_all(p)
00127               input(p).take_as_init(values(p));
00128 
00129             trace::exiting("accu::impl::image::generic::take_as_init");
00130           }
00131 
00132         } // end of namespace mln::accu::image::impl::generic
00133 
00134 
00135         // Fastest versions.
00136 
00137         template <typename I>
00138         void
00139         take_as_init_fastest(Image<I>& input_, const mln_deduce(I, value, argument)& v)
00140         {
00141           trace::entering("accu::impl::image::take_as_init_fastest");
00142           
00143           mlc_is_a(mln_value(I), Accumulator)::check();
00144 
00145           I& input = exact(input_);
00146           mln_precondition(input.is_valid());
00147           
00148           mln_pixter(I) px(input);
00149           for_all(px)
00150             px.val().take_as_init(v);
00151 
00152           trace::exiting("accu::impl::image::take_as_init_fastest");
00153         }
00154 
00155         template <typename I, typename J>
00156         void
00157         take_as_init_fastest(Image<I>& input_, const Image<J>& values_)
00158         {
00159           trace::entering("accu::impl::image::take_as_init_fastest");
00160 
00161           typedef mln_value(I) A;
00162           mlc_is_a(A, Accumulator)::check();
00163           mlc_converts_to(mln_value(J), mln_argument(A))::check();
00164           
00165           I& input = exact(input_);
00166           const J& values = exact(values_);
00167 
00168           internal::take_as_init_tests(input, values);
00169           // Extra test:
00170           mln_precondition(values.domain() == input.domain());
00171 
00172           border::resize_equal(input, values);
00173           
00174           mln_pixter(I) p_in(input);
00175           mln_pixter(const J) p_v(values);
00176           for_all_2(p_in, p_v)
00177             p_in.val().take_as_init(p_v.val());
00178 
00179           trace::exiting("accu::impl::image::take_as_init_fastest");
00180         }
00181 
00182       } // end of namespace mln::accu::image::impl
00183 
00184 
00185 
00186       // Dispatch.
00187 
00188       namespace internal
00189       {
00190 
00191         // With a single value.
00192 
00193         template <typename I, typename V>
00194         inline
00195         void
00196         take_as_init_dispatch(trait::image::speed::any,
00197                               Image<I>& input, const V& v)
00198         {
00199           impl::generic::take_as_init(input, v);
00200         }
00201 
00202         template <typename I, typename V>
00203         inline
00204         void
00205         take_as_init_dispatch(trait::image::speed::fastest,
00206                               Image<I>& input, const V& v)
00207         {
00208           impl::take_as_init_fastest(input, v);
00209         }
00210 
00211         template <typename I, typename V>
00212         inline
00213         void
00214         take_as_init_dispatch(Image<I>& input, const V& v)
00215         {
00216           take_as_init_dispatch(mln_trait_image_speed(I)(),
00217                                 input, v);
00218         }
00219 
00220         // With an image of values.
00221 
00222         template <typename I, typename J>
00223         inline
00224         void
00225         take_as_init_dispatch(trait::image::speed::any,
00226                               trait::image::speed::any,
00227                               Image<I>& input, const Image<J>& values)
00228         {
00229           impl::generic::take_as_init(input, values);
00230         }
00231 
00232         template <typename I, typename J>
00233         inline
00234         void
00235         take_as_init_dispatch(trait::image::speed::fastest,
00236                               trait::image::speed::fastest,
00237                               Image<I>& input, const Image<J>& values)
00238         {
00239           if (exact(values).domain() == exact(input).domain())
00240             impl::take_as_init_fastest(input, values);
00241           else
00242             impl::generic::take_as_init(input, values);
00243         }
00244 
00245         template <typename I, typename J>
00246         inline
00247         void
00248         take_as_init_dispatch(Image<I>& input,
00249                               const Image<J>& values)
00250         {
00251           take_as_init_dispatch(mln_trait_image_speed(I)(),
00252                                 mln_trait_image_speed(J)(),
00253                                 input, values);
00254         }
00255 
00256       } // end of namespace mln::accu::image::internal
00257 
00258 
00259       // Facades.
00260 
00261       template <typename I>
00262       inline
00263       void
00264       take_as_init(Image<I>& input, const mln_deduce(I, value, argument)& v)
00265       {
00266         trace::entering("accu::image::take_as_init");
00267 
00268         mlc_is_a(mln_value(I), Accumulator)::check();
00269 
00270         mln_precondition(exact(input).is_valid());
00271         internal::take_as_init_dispatch(input, v);
00272 
00273         trace::exiting("accu::image::take_as_init");
00274       }
00275 
00276       template <typename I, typename J>
00277       inline
00278       void
00279       take_as_init(Image<I>& input, const Image<J>& values)
00280       {
00281         trace::entering("accu::image::take_as_init");
00282 
00283         typedef mln_value(I) A;
00284         mlc_is_a(A, Accumulator)::check();
00285         mlc_converts_to(mln_value(J), mln_argument(A))::check();
00286 
00287         internal::take_as_init_tests(input, values);
00288         internal::take_as_init_dispatch(input, values);
00289 
00290         trace::exiting("accu::image::take_as_init");
00291       }
00292 
00293 # endif // ! MLN_INCLUDE_ONLY
00294 
00295     } // end of namespace mln::accu::image
00296 
00297   } // end of namespace mln::accu
00298 
00299 } // end of namespace mln
00300 
00301 
00302 #endif // ! MLN_ACCU_IMAGE_TAKE_AS_INIT_HH

Generated on Tue Oct 4 2011 15:24:41 for Milena (Olena) by  doxygen 1.7.1