Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
deghosting/algtinyvector.h
Go to the documentation of this file.00001 00021 #include <vigra/tinyvector.hxx> 00022 #include <vigra/numerictraits.hxx> 00023 00024 namespace vigra { 00025 00028 template <class T, int SIZE> 00029 class AlgTinyVector 00030 { 00031 public: 00032 AlgTinyVector(const AlgTinyVector<T,SIZE> & t) { 00033 for (unsigned int i = 0; i < SIZE; ++i) { 00034 content[i] = t[i]; 00035 } 00036 } 00037 00038 AlgTinyVector(T t) { 00039 for (unsigned int i = 0; i < SIZE; ++i) { 00040 content[i] = t; 00041 } 00042 } 00043 00044 AlgTinyVector() { 00045 AlgTinyVector(0); 00046 } 00047 00048 const T operator[](int i) const { 00049 return content[i]; 00050 } 00051 00052 T& operator[](int i) { 00053 return content[i]; 00054 } 00055 00056 const T operator*(const AlgTinyVector<T,SIZE> & t) const { 00057 T retVal = 0; 00058 for (unsigned int i = 0; i < SIZE; ++i) { 00059 retVal += t[i] * content[i]; 00060 } 00061 return retVal; 00062 } 00063 00064 const AlgTinyVector operator*(const int t) const { 00065 AlgTinyVector<T,SIZE> retVal; 00066 for (unsigned int i = 0; i < SIZE; ++i) { 00067 retVal[i] = t * content[i]; 00068 } 00069 return retVal; 00070 } 00071 00072 const AlgTinyVector operator/(const int t) const { 00073 AlgTinyVector<T,SIZE> retVal; 00074 for (unsigned int i = 0; i < SIZE; ++i) { 00075 retVal[i] = content[i] / t; 00076 } 00077 return retVal; 00078 } 00079 00080 const AlgTinyVector operator-(const AlgTinyVector<T,SIZE> & t) const { 00081 AlgTinyVector<T,SIZE> retVal; 00082 for (unsigned int i = 0; i < SIZE; ++i) { 00083 retVal[i] = t[i] - content[i]; 00084 } 00085 return retVal; 00086 } 00087 00088 const AlgTinyVector operator+(const AlgTinyVector<T,SIZE> & t) const { 00089 AlgTinyVector<T,SIZE> retVal; 00090 for (unsigned int i = 0; i < SIZE; ++i) { 00091 retVal[i] = t[i] + content[i]; 00092 } 00093 return retVal; 00094 } 00095 00096 AlgTinyVector & operator=(const AlgTinyVector<T,SIZE> & t) { 00097 if (this == &t) 00098 return *this; 00099 for (unsigned int i = 0; i < SIZE; ++i) { 00100 content[i] = t[i]; 00101 } 00102 return *this; 00103 } 00104 00105 AlgTinyVector & operator=(const TinyVector<T,SIZE> & t) { 00106 for (unsigned int i = 0; i < SIZE; ++i) { 00107 content[i] = t[i]; 00108 } 00109 return *this; 00110 } 00111 00112 private: 00113 T content[SIZE]; 00114 }; 00115 00116 template <class T, int SIZE> 00117 struct NumericTraits<AlgTinyVector<T, SIZE> > 00118 { 00119 typedef AlgTinyVector<T, SIZE> Type; 00120 typedef AlgTinyVector<typename NumericTraits<T>::Promote, SIZE> Promote; 00121 typedef AlgTinyVector<typename NumericTraits<T>::RealPromote, SIZE> RealPromote; 00122 typedef AlgTinyVector<typename NumericTraits<T>::ComplexPromote, SIZE> ComplexPromote; 00123 typedef T ValueType; 00124 00125 typedef typename NumericTraits<T>::isIntegral isIntegral; 00126 typedef VigraFalseType isScalar; 00127 typedef typename NumericTraits<T>::isSigned isSigned; 00128 typedef VigraFalseType isOrdered; 00129 typedef VigraFalseType isComplex; 00130 00131 static AlgTinyVector<T, SIZE> zero() { 00132 return AlgTinyVector<T, SIZE>(NumericTraits<T>::zero()); 00133 } 00134 static AlgTinyVector<T, SIZE> one() { 00135 return AlgTinyVector<T, SIZE>(NumericTraits<T>::one()); 00136 } 00137 static AlgTinyVector<T, SIZE> nonZero() { 00138 return AlgTinyVector<T, SIZE>(NumericTraits<T>::nonZero()); 00139 } 00140 00141 static Promote toPromote(const AlgTinyVector<T,SIZE> & v) 00142 { 00143 return Promote(v); 00144 } 00145 00146 static RealPromote toRealPromote(const AlgTinyVector<T,SIZE> & v) 00147 { 00148 return RealPromote(v); 00149 } 00150 00151 /*static AlgTinyVector<T, SIZE> 00152 fromPromote(AlgTinyVector<typename NumericTraits<T>::Promote> const & v) 00153 { 00154 AlgTinyVector<T, SIZE> res; 00155 return res; 00156 } 00157 00158 static TinyVector<T, SIZE> 00159 fromRealPromote(AlgTinyVector<typename NumericTraits<T>::RealPromote> const & v) 00160 { 00161 TinyVector<T, SIZE> res(detail::dontInit()); 00162 typedef typename detail::LoopType<SIZE>::type ltype; 00163 ltype::fromRealPromote(res.begin(), v.begin()); 00164 return res; 00165 }*/ 00166 }; 00167 00168 }
1.3.9.1