Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
algtinyvector.h
Go to the documentation of this file.
1 
21 #include <vigra/tinyvector.hxx>
22 #include <vigra/numerictraits.hxx>
23 
24 namespace vigra {
25 
28 template <class T, int SIZE>
30 {
31  public:
33  for (unsigned int i = 0; i < SIZE; ++i) {
34  content[i] = t[i];
35  }
36  }
37 
38  explicit AlgTinyVector(T t=NumericTraits<T>::zero()) {
39  for (unsigned int i = 0; i < SIZE; ++i) {
40  content[i] = t;
41  }
42  }
43 
44  const T operator[](int i) const {
45  return content[i];
46  }
47 
48  T& operator[](int i) {
49  return content[i];
50  }
51 
52  const T operator*(const AlgTinyVector<T,SIZE> & t) const {
53  T retVal = 0;
54  for (unsigned int i = 0; i < SIZE; ++i) {
55  retVal += t[i] * content[i];
56  }
57  return retVal;
58  }
59 
60  const AlgTinyVector operator*(const int t) const {
61  AlgTinyVector<T,SIZE> retVal;
62  for (unsigned int i = 0; i < SIZE; ++i) {
63  retVal[i] = t * content[i];
64  }
65  return retVal;
66  }
67 
68  const AlgTinyVector operator/(const int t) const {
69  AlgTinyVector<T,SIZE> retVal;
70  for (unsigned int i = 0; i < SIZE; ++i) {
71  retVal[i] = content[i] / t;
72  }
73  return retVal;
74  }
75 
77  AlgTinyVector<T,SIZE> retVal;
78  for (unsigned int i = 0; i < SIZE; ++i) {
79  retVal[i] = t[i] - content[i];
80  }
81  return retVal;
82  }
83 
85  AlgTinyVector<T,SIZE> retVal;
86  for (unsigned int i = 0; i < SIZE; ++i) {
87  retVal[i] = t[i] + content[i];
88  }
89  return retVal;
90  }
91 
93  if (this == &t)
94  return *this;
95  for (unsigned int i = 0; i < SIZE; ++i) {
96  content[i] = t[i];
97  }
98  return *this;
99  }
100 
101  AlgTinyVector & operator=(const TinyVector<T,SIZE> & t) {
102  for (unsigned int i = 0; i < SIZE; ++i) {
103  content[i] = t[i];
104  }
105  return *this;
106  }
107 
108  private:
109  T content[SIZE];
110 };
111 
112 template <class T, int SIZE>
113 struct NumericTraits<AlgTinyVector<T, SIZE> >
114 {
119  typedef T ValueType;
120 
121  typedef typename NumericTraits<T>::isIntegral isIntegral;
122  typedef VigraFalseType isScalar;
123  typedef typename NumericTraits<T>::isSigned isSigned;
124  typedef VigraFalseType isOrdered;
125  typedef VigraFalseType isComplex;
126 
128  return AlgTinyVector<T, SIZE>(NumericTraits<T>::zero());
129  }
131  return AlgTinyVector<T, SIZE>(NumericTraits<T>::one());
132  }
134  return AlgTinyVector<T, SIZE>(NumericTraits<T>::nonZero());
135  }
136 
138  {
139  return Promote(v);
140  }
141 
143  {
144  return RealPromote(v);
145  }
146 
147  /*static AlgTinyVector<T, SIZE>
148  fromPromote(AlgTinyVector<typename NumericTraits<T>::Promote> const & v)
149  {
150  AlgTinyVector<T, SIZE> res;
151  return res;
152  }
153 
154  static TinyVector<T, SIZE>
155  fromRealPromote(AlgTinyVector<typename NumericTraits<T>::RealPromote> const & v)
156  {
157  TinyVector<T, SIZE> res(detail::dontInit());
158  typedef typename detail::LoopType<SIZE>::type ltype;
159  ltype::fromRealPromote(res.begin(), v.begin());
160  return res;
161  }*/
162 };
163 
164 }
const AlgTinyVector operator/(const int t) const
Definition: algtinyvector.h:68
static AlgTinyVector< T, SIZE > zero()
const AlgTinyVector operator*(const int t) const
Definition: algtinyvector.h:60
AlgTinyVector(const AlgTinyVector< T, SIZE > &t)
Definition: algtinyvector.h:32
const T operator[](int i) const
Definition: algtinyvector.h:44
AlgTinyVector< typename NumericTraits< T >::ComplexPromote, SIZE > ComplexPromote
AlgTinyVector< typename NumericTraits< T >::RealPromote, SIZE > RealPromote
const AlgTinyVector operator+(const AlgTinyVector< T, SIZE > &t) const
Definition: algtinyvector.h:84
AlgTinyVector< typename NumericTraits< T >::Promote, SIZE > Promote
AlgTinyVector(T t=NumericTraits< T >::zero())
Definition: algtinyvector.h:38
Fixed size vector with scalar multiplication and element-wise substraction and addition.
Definition: algtinyvector.h:29
const T operator*(const AlgTinyVector< T, SIZE > &t) const
Definition: algtinyvector.h:52
NumericTraits< T >::isIntegral isIntegral
static Promote toPromote(const AlgTinyVector< T, SIZE > &v)
AlgTinyVector & operator=(const AlgTinyVector< T, SIZE > &t)
Definition: algtinyvector.h:92
static RealPromote toRealPromote(const AlgTinyVector< T, SIZE > &v)
AlgTinyVector & operator=(const TinyVector< T, SIZE > &t)
static AlgTinyVector< T, SIZE > nonZero()
const AlgTinyVector operator-(const AlgTinyVector< T, SIZE > &t) const
Definition: algtinyvector.h:76
static AlgTinyVector< T, SIZE > one()