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 #ifndef MLN_FUN_P2P_TRANSLATION_HH
00027 # define MLN_FUN_P2P_TRANSLATION_HH
00028 
00032 
00033 # include <mln/core/concept/function.hh>
00034 # include <mln/core/concept/gdpoint.hh>
00035 
00036 
00037 namespace mln
00038 {
00039 
00040   namespace fun
00041   {
00042 
00043     namespace p2p
00044     {
00045 
00046       template <typename P>
00047       struct translation_t : public Function_v2v< translation_t<P> >
00048       {
00049         typedef P result;
00050 
00051         translation_t(const mln_delta(P)& dp);
00052 
00053         P operator()(const P& p) const;
00054         P inverse(const P& p) const;
00055 
00056       protected:
00057         mln_delta(P) dp_;
00058       };
00059 
00060 
00061       template <typename D>
00062       translation_t<mln_site(D)>
00063       translation(const Gdpoint<D>& dp);
00064 
00065 
00066 
00067 # ifndef MLN_INCLUDE_ONLY
00068 
00069       template <typename P>
00070       inline
00071       translation_t<P>::translation_t(const mln_delta(P)& dp)
00072         : dp_(dp)
00073       {
00074       }
00075 
00076       template <typename P>
00077       inline
00078       P
00079       translation_t<P>::operator()(const P& p) const
00080       {
00081         return p + dp_;
00082       }
00083 
00084       template <typename P>
00085       inline
00086       P
00087       translation_t<P>::inverse(const P& p) const
00088       {
00089         return p - dp_;
00090       }
00091 
00092 
00093       template <typename D>
00094       inline
00095       translation_t<mln_site(D)>
00096       translation(const Gdpoint<D>& dp)
00097       {
00098         translation_t<mln_site(D)> tmp(exact(dp));
00099         return tmp;
00100       }
00101 
00102 
00103 # endif // ! MLN_INCLUDE_ONLY
00104 
00105     } 
00106 
00107   } 
00108 
00109 } 
00110 
00111 
00112 #endif // ! MLN_FUN_P2P_TRANSLATION_HH