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

revert.hh

00001 // Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
00002 // Laboratory (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_ARITH_REVERT_HH
00028 # define MLN_ARITH_REVERT_HH
00029 
00035 
00036 # include <mln/core/concept/image.hh>
00037 # include <mln/trait/value_.hh>
00038 
00039 // Specializations are in:
00040 # include <mln/arith/revert.spe.hh>
00041 
00042 
00043 // FIXME: Rely instead on mln/fun/v2v/revert.hh.
00044 // FIXME: Revert on int value 0 does not give 0 (since min != - max;
00045 //        idem for float etc.)
00046 
00047 
00048 namespace mln
00049 {
00050 
00051   namespace arith
00052   {
00053 
00055 
00065     template <typename I>
00066     mln_concrete(I) revert(const Image<I>& input);
00067 
00068 
00070 
00079     template <typename I>
00080     void revert_inplace(Image<I>& input);
00081 
00082 
00083 # ifndef MLN_INCLUDE_ONLY
00084 
00085     namespace impl
00086     {
00087 
00088       namespace generic
00089       {
00090 
00091         template <typename I, typename O>
00092         inline
00093         void revert(const Image<I>& input_, Image<O>& output_)
00094         {
00095           trace::entering("arith::impl::generic::revert_");
00096 
00097           const I& input = exact(input_);
00098           O& output = exact(output_);
00099 
00100           mln_precondition(input.is_valid());
00101           mln_precondition(output.is_valid());
00102           mln_precondition(input.domain() == output.domain());
00103 
00104           typedef mln_value(I) V;
00105           mln_piter(I) p(input.domain());
00106           for_all(p)
00107             output(p) = mln_min(V) + (mln_max(V) - input(p));
00108 
00109           trace::exiting("arith::impl::generic::revert_");
00110         }
00111 
00112       } // end of namespace mln::arith::impl::generic
00113 
00114     } // end of namespace mln::arith::impl
00115 
00116 
00117 
00118     // Dispatch.
00119 
00120     namespace internal
00121     {
00122 
00123       template <typename I, typename O>
00124       inline
00125       void
00126       revert_dispatch(trait::image::speed::any, const I& input, O& output)
00127       {
00128         impl::generic::revert(input, output);
00129       }
00130 
00131       template <typename I, typename O>
00132       inline
00133       void
00134       revert_dispatch(trait::image::speed::fastest, const I& input, O& output)
00135       {
00136         impl::revert_fastest(input, output);
00137       }
00138 
00139       template <typename I, typename O>
00140       inline
00141       void
00142       revert_dispatch(const Image<I>& input, Image<O>& output)
00143       {
00144         revert_dispatch(mln_trait_image_speed(I)(),
00145                         exact(input), exact(output));
00146 
00147       }
00148 
00149 
00150     } // end of namespace mln::arith::internal
00151 
00152 
00153 
00154     // Facades.
00155 
00156     template <typename I>
00157     inline
00158     mln_concrete(I) revert(const Image<I>& input)
00159     {
00160       trace::entering("arith::revert");
00161 
00162       mln_precondition(exact(input).is_valid());
00163 
00164       mln_concrete(I) output;
00165       initialize(output, input);
00166       internal::revert_dispatch(exact(input), exact(output));
00167 
00168       trace::exiting("arith::revert");
00169       return output;
00170     }
00171 
00172     template <typename I>
00173     inline
00174     void revert_inplace(Image<I>& input)
00175     {
00176       trace::entering("arith::revert_inplace");
00177 
00178       mln_precondition(exact(input).is_valid());
00179 
00180       internal::revert_dispatch(exact(input), exact(input));
00181 
00182       trace::exiting("arith::revert_inplace");
00183     }
00184 
00185 # endif // ! MLN_INCLUDE_ONLY
00186 
00187   } // end of namespace mln::arith
00188 
00189 } // end of namespace mln
00190 
00191 
00192 #endif // ! MLN_ARITH_REVERT_HH

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