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

transform.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_DATA_TRANSFORM_HH
00027 # define MLN_DATA_TRANSFORM_HH
00028 
00036 
00037 # include <mln/core/concept/image.hh>
00038 # include <mln/core/concept/function.hh>
00039 # include <mln/value/set.hh>
00040 
00041 // Specializations are in:
00042 # include <mln/data/transform.spe.hh>
00043 
00044 
00045 namespace mln
00046 {
00047 
00048   namespace data
00049   {
00050 
00060     template <typename I, typename F>
00061     mln_ch_value(I, mln_result(F))
00062     transform(const Image<I>& input, const Function_v2v<F>& f);
00063 
00064 
00074     template <typename I1, typename I2, typename F>
00075     mln_ch_value(I1, mln_result(F))
00076     transform(const Image<I1>& input1,
00077               const Image<I2>& input2,
00078               const Function_vv2v<F>& f);
00079 
00080 
00081 
00082 # ifndef MLN_INCLUDE_ONLY
00083 
00084     namespace internal
00085     {
00086 
00087       template <typename I, typename F>
00088       void transform_tests(const Image<I>& input,
00089                            const Function_v2v<F>& f)
00090       {
00091         // Dynamic test.
00092         mln_precondition(exact(input).is_valid());
00093 
00094         // Avoid a warning about an undefined variable when NDEBUG
00095         // is not defined.
00096         (void) input;
00097         (void) f;
00098       }
00099 
00100       template <typename I1, typename I2, typename F>
00101       void transform_tests(const Image<I1>& input1, const Image<I2>& input2,
00102                            const Function_vv2v<F>& f)
00103       {
00104         // Dynamic tests.
00105         mln_precondition(exact(input1).is_valid());
00106         mln_precondition(exact(input2).is_valid());
00107         mln_precondition(exact(input2).domain() == exact(input1).domain());
00108 
00109         // Avoid a warning about an undefined variable when NDEBUG
00110         // is not defined.
00111         (void) input1;
00112         (void) input2;
00113         (void) f;
00114       }
00115 
00116     } // end of namespace mln::data::internal
00117 
00118 
00119 
00120     namespace impl
00121     {
00122 
00123 
00124       // Generic implementations.
00125 
00126 
00127       namespace generic
00128       {
00129 
00134         //
00135         template <typename I, typename F>
00136         mln_ch_value(I, mln_result(F))
00137         transform(const Image<I>& input_, const Function_v2v<F>& f_)
00138         {
00139           trace::entering("data::impl::generic::transform");
00140 
00141           const I& input  = exact(input_);
00142           const F& f      = exact(f_);
00143 
00144           data::internal::transform_tests(input, f);
00145 
00146           mln_ch_value(I, mln_result(F)) output;
00147           initialize(output, input);
00148 
00149           mln_piter(I) p(input.domain());
00150           for_all(p)
00151             output(p) = f(input(p));
00152 
00153           trace::exiting("data::impl::generic::transform");
00154           return output;
00155         }
00156 
00157 
00163         //
00164         template <typename I1, typename I2, typename F>
00165         mln_ch_value(I1, mln_result(F))
00166         transform(const Image<I1>& input1_,
00167                   const Image<I2>& input2_,
00168                   const Function_vv2v<F>& f_)
00169         {
00170           trace::entering("data::impl::generic::transform");
00171 
00172           const I1& input1  = exact(input1_);
00173           const I2& input2  = exact(input2_);
00174           const  F& f       = exact(f_);
00175 
00176           data::internal::transform_tests(input1, input2, f);
00177 
00178           mln_ch_value(I1, mln_result(F)) output;
00179           initialize(output, input1);
00180 
00181           mln_piter(I1) p(input1.domain());
00182           for_all(p)
00183             output(p) = f(input1(p), input2(p));
00184 
00185           trace::exiting("data::impl::generic::transform");
00186           return output;
00187         }
00188 
00189       } // end of namespace mln::data::impl::generic
00190 
00191 
00192     } // end of namespace mln::data::impl
00193 
00194 
00195 
00196     // Facades.
00197 
00198 
00199     template <typename I, typename F>
00200     inline
00201     mln_ch_value(I, mln_result(F))
00202     transform(const Image<I>& input, const Function_v2v<F>& f)
00203     {
00204       trace::entering("data::transform");
00205 
00206       internal::transform_tests(input, f);
00207 
00208       mln_ch_value(I, mln_result(F)) output;
00209       output = internal::transform_dispatch(input, f);
00210 
00211       trace::exiting("data::transform");
00212       return output;
00213     }
00214 
00215 
00216     template <typename I1, typename I2, typename F>
00217     inline
00218     mln_ch_value(I1, mln_result(F))
00219     transform(const Image<I1>& input1, const Image<I2>& input2,
00220               const Function_vv2v<F>& f)
00221     {
00222       trace::entering("data::transform");
00223 
00224       internal::transform_tests(input1, input2, f);
00225 
00226       mln_ch_value(I1, mln_result(F)) output;
00227       output = internal::transform_dispatch(input1, input2, f);
00228 
00229       trace::exiting("data::transform");
00230       return output;
00231     }
00232 
00233 
00234 # endif // ! MLN_INCLUDE_ONLY
00235 
00236   } // end of namespace mln::data
00237 
00238 } // end of namespace mln
00239 
00240 
00241 #endif // ! MLN_DATA_TRANSFORM_HH

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