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
00027 #ifndef MLN_ALGEBRA_H_VEC_HH
00028 # define MLN_ALGEBRA_H_VEC_HH
00029
00033
00034 # include <mln/algebra/vec.hh>
00035 # include <mln/literal/one.hh>
00036
00037
00038 namespace mln
00039 {
00040
00041
00042 namespace algebra {
00043 template <unsigned d, typename C> class h_vec;
00044 }
00045
00046
00047 namespace trait
00048 {
00049
00050
00051
00052 template < template <class> class Name,
00053 unsigned d, typename C >
00054 struct set_precise_unary_< Name, algebra::h_vec<d, C> >
00055 {
00056 typedef mln_trait_unary(Name, C) V;
00057 typedef algebra::h_vec<d, V> ret;
00058 };
00059
00060
00061
00062 template < template <class, class> class Name,
00063 unsigned d, typename C,
00064 typename Q >
00065 struct set_precise_binary_< Name,
00066 algebra::h_vec<d, C>, algebra::h_vec<d, Q> >
00067 {
00068 typedef mln_trait_binary(Name, C, Q) V;
00069 typedef algebra::h_vec<d, V> ret;
00070 };
00071
00072 template < template <class, class> class Name,
00073 unsigned d, typename C,
00074 typename S >
00075 struct set_precise_binary_< Name,
00076 algebra::h_vec<d, C>, mln::value::scalar_<S> >
00077 {
00078 typedef mln_trait_binary(Name, C, S) V;
00079 typedef algebra::h_vec<d, V> ret;
00080 };
00081
00082 }
00083
00084
00085
00086 namespace algebra
00087 {
00088
00089
00093 template <unsigned d, typename C>
00094 class h_vec : public vec<d + 1, C>
00095 {
00096 public:
00098 enum { dim = d };
00099
00101 h_vec();
00103 h_vec(const vec<d+1, C>& other);
00104
00105 h_vec& operator=(const vec<d+1, C>& rhs);
00106
00108 vec<d,C> to_vec() const;
00109 };
00110
00111
00112
00113 # ifndef MLN_INCLUDE_ONLY
00114
00115 template <unsigned d, typename C>
00116 inline
00117 h_vec<d,C>::h_vec()
00118 {
00119
00120
00121
00122
00123 this->data_[d] = literal::one;
00124 }
00125
00126 template <unsigned d, typename C>
00127 inline
00128 h_vec<d,C>::h_vec(const vec<d+1, C>& other)
00129 : vec<d+1, C>(other)
00130 {
00131 }
00132
00133 template <unsigned d, typename C>
00134 inline
00135 h_vec<d,C>& h_vec<d,C>::operator=(const vec<d+1, C>& rhs)
00136 {
00137 if (& rhs == this)
00138 return *this;
00139 this->vec<d+1, C>::operator=(rhs);
00140 return *this;
00141 }
00142
00143 template <unsigned d, typename C>
00144 inline
00145 vec<d,C> h_vec<d,C>::to_vec() const
00146 {
00147 const C w = this->data_[d];
00148 mln_assertion(w != 0);
00149
00150 vec<d,C> tmp;
00151 for (unsigned i = 0; i < d; ++i)
00152 tmp[i] = static_cast<C>(this->data_[i] / w);
00153 return tmp;
00154 }
00155
00156
00157
00158 template <unsigned n, typename T>
00159 inline
00160 h_vec<n, T>
00161 vec<n,T>::to_h_vec() const
00162 {
00163 h_vec<n, T> tmp;
00164 for (unsigned i = 0; i < n; ++i)
00165 tmp[i] = this->data_[i];
00166 tmp[n] = literal::one;
00167 return tmp;
00168 }
00169
00170 # endif // ! MLN_INCLUDE_ONLY
00171
00172 }
00173
00174 }
00175
00176
00177 #endif // ! MLN_ALGEBRA_H_VEC_HH