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

translation.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_FUN_X2X_TRANSLATION_HH
00027 # define MLN_FUN_X2X_TRANSLATION_HH
00028 
00032 
00033 # include <mln/core/concept/function.hh>
00034 # include <mln/fun/internal/x2x_linear_impl.hh>
00035 # include <mln/algebra/vec.hh>
00036 # include <mln/algebra/h_mat.hh>
00037 # include <mln/fun/i2v/all.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043   namespace fun
00044   {
00045 
00046     namespace x2x
00047     {
00048 
00050       //
00051       template <unsigned n, typename C>
00052       struct translation
00053         :
00054         fun::internal::x2x_linear_impl_< algebra::vec<n,C>, C,
00055                                          translation<n,C> >,
00056         public Function_v2v< translation<n,C> >
00057       {
00059         typedef C data_t;
00060 
00062         typedef translation<n,C> invert;
00064         invert inv() const;
00065 
00067         translation();
00069         translation(const algebra::vec<n,C>& t);
00070 
00072         algebra::vec<n,C> operator()(const algebra::vec<n,C>& v) const;
00073         algebra::vec<n,C> inverse(const algebra::vec<n,C>& v) const;
00074 
00075 
00077         void set_t(const algebra::vec<n,C>& t);
00078 
00080         const algebra::vec<n,C>& t() const;
00081 
00082       protected:
00083         void update();
00084 
00085         algebra::vec<n,C> t_;
00086       };
00087 
00088 
00089 # ifndef MLN_INCLUDE_ONLY
00090 
00091       template <unsigned n, typename C>
00092       inline
00093       translation<n,C>::translation()
00094       {
00095       }
00096 
00097       template <unsigned n, typename C>
00098       inline
00099       translation<n,C>::translation(const algebra::vec<n,C>& t)
00100         :t_(t)
00101       {
00102         this->update();
00103       }
00104 
00105       template <unsigned n, typename C>
00106       inline
00107       algebra::vec<n,C>
00108       translation<n,C>::operator()(const algebra::vec<n,C>& v) const
00109       {
00110         return v + t_;
00111       }
00112 
00113       template <unsigned n, typename C>
00114       inline
00115       algebra::vec<n,C>
00116       translation<n,C>::inverse(const algebra::vec<n,C>& v) const
00117       {
00118         return v - t_;
00119       }
00120 
00121       template <unsigned n, typename C>
00122       inline
00123       translation<n,C>
00124       translation<n,C>::inv() const
00125       {
00126         typename translation::invert res(-t_);
00127 
00128         return res;
00129       }
00130 
00131       template <unsigned n, typename C>
00132       inline
00133       void
00134       translation<n,C>::set_t(const algebra::vec<n,C>& t)
00135       {
00136         this->t_ = t;
00137         this->update();
00138       }
00139 
00140       template <unsigned n, typename C>
00141       inline
00142       const algebra::vec<n,C>&
00143       translation<n,C>::t() const
00144       {
00145         return this->t_;
00146       }
00147 
00148       template <unsigned n, typename C>
00149       inline
00150       void
00151       translation<n,C>::update()
00152       {
00153         this->m_ = algebra::h_mat<n,C>::Id;
00154         for (unsigned i = 0; i < n; ++i)
00155           this->m_(i,n) = this->t_[i];
00156       }
00157 
00158 # endif // ! MLN_INCLUDE_ONLY
00159 
00160 
00161     } // end of namespace mln::fun::x2x
00162 
00163   } // end of namespace mln::fun
00164 
00165 } // end of namespace mln
00166 
00167 
00168 #endif // ! MLN_FUN_X2X_TRANSLATION_HH

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