• 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>, translation<n,C> >,
00055         public Function_v2v< translation<n,C> >
00056       {
00058         typedef translation<n,C> invert;
00060         invert inv() const;
00061 
00063         translation();
00065         translation(const algebra::vec<n,C>& t);
00066 
00068         algebra::vec<n,C> operator()(const algebra::vec<n,C>& v) const;
00069 
00071         void set_t(const algebra::vec<n,C>& t);
00072 
00074         const algebra::vec<n,C>& t() const;
00075 
00076       protected:
00077         void update();
00078 
00079         algebra::vec<n,C> t_;
00080       };
00081 
00082 
00083 # ifndef MLN_INCLUDE_ONLY
00084 
00085       template <unsigned n, typename C>
00086       inline
00087       translation<n,C>::translation()
00088       {
00089       }
00090 
00091       template <unsigned n, typename C>
00092       inline
00093       translation<n,C>::translation(const algebra::vec<n,C>& t)
00094         :t_(t)
00095       {
00096         this->update();
00097       }
00098 
00099       template <unsigned n, typename C>
00100       inline
00101       algebra::vec<n,C>
00102       translation<n,C>::operator()(const algebra::vec<n,C>& v) const
00103       {
00104         return v + t_;
00105       }
00106 
00107       template <unsigned n, typename C>
00108       inline
00109       translation<n,C>
00110       translation<n,C>::inv() const
00111       {
00112         typename translation::invert res(-t_);
00113 
00114         return res;
00115       }
00116 
00117       template <unsigned n, typename C>
00118       inline
00119       void
00120       translation<n,C>::set_t(const algebra::vec<n,C>& t)
00121       {
00122         this->t_ = t;
00123         this->update();
00124       }
00125 
00126       template <unsigned n, typename C>
00127       inline
00128       const algebra::vec<n,C>&
00129       translation<n,C>::t() const
00130       {
00131         return this->t_;
00132       }
00133 
00134       template <unsigned n, typename C>
00135       inline
00136       void
00137       translation<n,C>::update()
00138       {
00139         this->m_ = algebra::h_mat<n,C>::Id;
00140         for (unsigned i = 0; i < n; ++i)
00141           this->m_(i,n) = this->t_[i];
00142       }
00143 
00144 # endif // ! MLN_INCLUDE_ONLY
00145 
00146 
00147     } // end of namespace mln::fun::x2x
00148 
00149   } // end of namespace mln::fun
00150 
00151 } // end of namespace mln
00152 
00153 
00154 #endif // ! MLN_FUN_X2X_TRANSLATION_HH

Generated on Thu Sep 8 2011 18:32:43 for Milena (Olena) by  doxygen 1.7.1