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_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 algebra::vec<n,C> inverse(const algebra::vec<n,C>& v) const;
00070
00071
00073 void set_t(const algebra::vec<n,C>& t);
00074
00076 const algebra::vec<n,C>& t() const;
00077
00078 protected:
00079 void update();
00080
00081 algebra::vec<n,C> t_;
00082 };
00083
00084
00085 # ifndef MLN_INCLUDE_ONLY
00086
00087 template <unsigned n, typename C>
00088 inline
00089 translation<n,C>::translation()
00090 {
00091 }
00092
00093 template <unsigned n, typename C>
00094 inline
00095 translation<n,C>::translation(const algebra::vec<n,C>& t)
00096 :t_(t)
00097 {
00098 this->update();
00099 }
00100
00101 template <unsigned n, typename C>
00102 inline
00103 algebra::vec<n,C>
00104 translation<n,C>::operator()(const algebra::vec<n,C>& v) const
00105 {
00106 return v + t_;
00107 }
00108
00109 template <unsigned n, typename C>
00110 inline
00111 algebra::vec<n,C>
00112 translation<n,C>::inverse(const algebra::vec<n,C>& v) const
00113 {
00114 return v - t_;
00115 }
00116
00117 template <unsigned n, typename C>
00118 inline
00119 translation<n,C>
00120 translation<n,C>::inv() const
00121 {
00122 typename translation::invert res(-t_);
00123
00124 return res;
00125 }
00126
00127 template <unsigned n, typename C>
00128 inline
00129 void
00130 translation<n,C>::set_t(const algebra::vec<n,C>& t)
00131 {
00132 this->t_ = t;
00133 this->update();
00134 }
00135
00136 template <unsigned n, typename C>
00137 inline
00138 const algebra::vec<n,C>&
00139 translation<n,C>::t() const
00140 {
00141 return this->t_;
00142 }
00143
00144 template <unsigned n, typename C>
00145 inline
00146 void
00147 translation<n,C>::update()
00148 {
00149 this->m_ = algebra::h_mat<n,C>::Id;
00150 for (unsigned i = 0; i < n; ++i)
00151 this->m_(i,n) = this->t_[i];
00152 }
00153
00154 # endif // ! MLN_INCLUDE_ONLY
00155
00156
00157 }
00158
00159 }
00160
00161 }
00162
00163
00164 #endif // ! MLN_FUN_X2X_TRANSLATION_HH