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

times.hh

00001 // Copyright (C) 2007, 2008, 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_ARITH_TIMES_HH
00027 # define MLN_ARITH_TIMES_HH
00028 
00034 
00035 # include <mln/arith/includes.hh>
00036 
00037 
00038 // Specializations are in:
00039 # include <mln/arith/times.spe.hh>
00040 
00041 namespace mln
00042 {
00043 
00044 
00045   namespace trait
00046   {
00047 
00048     template <typename L, typename R>
00049     struct set_binary_< op::times, Image, L, Image, R >
00050     {
00051       typedef mln_trait_op_times(mln_value(L), mln_value(R)) value;
00052       typedef mln_ch_value(L, value) ret;
00053     };
00054 
00055     template <typename I, typename S>
00056     struct set_binary_< op::times, Image, I, mln::value::Scalar, S >
00057     {
00058       typedef mln_trait_op_times(mln_value(I), S) value;
00059       typedef mln_ch_value(I, value) ret;
00060     };
00061 
00062   } // end of namespace mln::trait
00063 
00064 
00065 
00066   template <typename L, typename R>
00067   mln_trait_op_times(L,R)
00068   operator*(const Image<L>& lhs, const Image<R>& rhs);
00069 
00070   template <typename L, typename R>
00071   L&
00072   operator*=(Image<L>& lhs, const Image<R>& rhs);
00073 
00074 
00075   template <typename I, typename S>
00076   mln_trait_op_times(I,S)
00077   operator*(const Image<I>& ima, const value::Scalar<S>& s);
00078 
00079   template <typename I, typename S>
00080   I&
00081   operator*=(Image<I>& ima, const value::Scalar<S>& s);
00082 
00083 
00084 
00085   namespace arith
00086   {
00087 
00089 
00096     template <typename L, typename R, typename O>
00097     void times(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output);
00098 
00099 
00101 
00108     template <typename I, typename V, typename O>
00109     void times_cst(const Image<I>& input, const V& val, Image<O>& output);
00110 
00111 
00113 
00123     template <typename L, typename R>
00124     void times_inplace(Image<L>& lhs, const Image<R>& rhs);
00125 
00126 
00127   } // end of namespace mln::arith
00128 
00129 
00130 
00131 
00132 # ifndef MLN_INCLUDE_ONLY
00133 
00134 
00135   template <typename L, typename R>
00136   inline
00137   mln_trait_op_times(L,R)
00138   operator*(const Image<L>& lhs, const Image<R>& rhs)
00139   {
00140     mln_precondition(exact(rhs).domain() == exact(lhs).domain());
00141     mln_trait_op_times(L,R) tmp;
00142     initialize(tmp, lhs);
00143     arith::times(lhs, rhs, tmp);
00144     return tmp;
00145   }
00146 
00147   template <typename L, typename R>
00148   inline
00149   L&
00150   operator*=(Image<L>& lhs, const Image<R>& rhs)
00151   {
00152     mln_precondition(exact(rhs).domain() == exact(lhs).domain());
00153     arith::times_inplace(lhs, rhs);
00154     return exact(lhs);
00155   }
00156 
00157 
00158   template <typename I, typename S>
00159   inline
00160   mln_trait_op_times(I,S)
00161   operator*(const Image<I>& ima, const value::Scalar<S>& s)
00162   {
00163     mln_precondition(exact(ima).is_valid());
00164     mln_trait_op_times(I,S) tmp;
00165     initialize(tmp, ima);
00166     arith::times_cst(ima, exact(s), tmp);
00167     return tmp;
00168   }
00169 
00170   template <typename I, typename S>
00171   inline
00172   I&
00173   operator*=(Image<I>& ima, const value::Scalar<S>& s)
00174   {
00175     mln_precondition(exact(ima).is_valid());
00176     arith::times_cst(ima, exact(s), ima);
00177     return exact(ima);
00178   }
00179 
00180 
00181 
00182   namespace arith
00183   {
00184 
00185     namespace impl
00186     {
00187 
00188       namespace generic
00189       {
00190 
00191         template <typename L, typename R, typename O>
00192         inline
00193         void times_(const L& lhs, const R& rhs, O& output)
00194         {
00195           trace::entering("arith::impl::generic::times_");
00196 
00197           mln_piter(L) p(lhs.domain());
00198           for_all(p)
00199             output(p) = lhs(p) * rhs(p);
00200 
00201           trace::exiting("arith::impl::generic::times_");
00202         }
00203 
00204         template <typename L, typename R>
00205         inline
00206         void times_inplace_(L& lhs, const R& rhs)
00207         {
00208           trace::entering("arith::impl::generic::times_inplace_");
00209 
00210           mln_piter(R) p(rhs.domain());
00211           for_all(p)
00212           lhs(p) *= rhs(p);
00213 
00214           trace::exiting("arith::impl::generic::times_inplace_");
00215         }
00216 
00217       } // end of namespace mln::arith::impl::generic
00218 
00219     } // end of namespace mln::arith::impl
00220 
00221 
00222     // Facades.
00223 
00224     template <typename L, typename R, typename O>
00225     inline
00226     void times(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output)
00227     {
00228       trace::entering("arith::times");
00229 
00230       mln_precondition(exact(rhs).domain() == exact(lhs).domain());
00231       mln_precondition(exact(output).domain() == exact(lhs).domain());
00232       impl::times_(mln_trait_image_speed(L)(), exact(lhs),
00233                   mln_trait_image_speed(R)(), exact(rhs),
00234                   mln_trait_image_speed(O)(), exact(output));
00235 
00236       trace::exiting("arith::times");
00237     }
00238 
00239     template <typename I, typename V, typename O>
00240     inline
00241     void times_cst(const Image<I>& input, const V& val, Image<O>& output)
00242     {
00243       trace::entering("arith::times_cst");
00244 
00245       mln_precondition(exact(output).domain() == exact(input).domain());
00246       times(input, pw::cst(val) | exact(input).domain(), output);
00247       // Calls the previous version.
00248 
00249       trace::exiting("arith::times_cst");
00250     }
00251 
00252     template <typename L, typename R>
00253     inline
00254     void times_inplace(Image<L>& lhs, const Image<R>& rhs)
00255     {
00256       trace::entering("arith::times_inplace");
00257 
00258       mln_precondition(exact(rhs).domain() <= exact(lhs).domain());
00259       impl::times_inplace_(mln_trait_image_speed(L)(), exact(lhs),
00260                            mln_trait_image_speed(R)(), exact(rhs));
00261 
00262       trace::exiting("arith::times_inplace");
00263     }
00264 
00265     template <typename I, typename V>
00266     inline
00267     void times_cst_inplace(Image<I>& input, const V& val)
00268     {
00269       trace::entering("arith::times_cst_inplace");
00270 
00271       mln_precondition(exact(input).is_valid());
00272       times_inplace(input, pw::cst(val) | exact(input).domain());
00273       // Calls the previous version.
00274 
00275       trace::exiting("arith::times_cst_inplace");
00276     }
00277 
00278   } // end of namespace mln::arith
00279 
00280 # endif // ! MLN_INCLUDE_ONLY
00281 
00282 } // end of namespace mln
00283 
00284 
00285 #endif // ! MLN_ARITH_TIMES_HH

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