00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
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 
00040 # include <mln/arith/revert.spe.hh>
00041 
00042 
00043 
00044 
00045 
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       } 
00113 
00114     } 
00115 
00116 
00117 
00118     
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     } 
00151 
00152 
00153 
00154     
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   } 
00188 
00189 } 
00190 
00191 
00192 #endif // ! MLN_ARITH_REVERT_HH