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>, 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 }
00162
00163 }
00164
00165 }
00166
00167
00168 #endif // ! MLN_FUN_X2X_TRANSLATION_HH