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         explicit AlgTinyVector(T t=NumericTraits<T>::zero()) {
00039             for (unsigned int i = 0; i < SIZE; ++i) {
00040                 content[i] = t;
00041             }
00042         }
00043         
00044         const T operator[](int i) const {
00045             return content[i];
00046         }
00047         
00048         T& operator[](int i) {
00049             return content[i];
00050         }
00051         
00052         const T operator*(const AlgTinyVector<T,SIZE> & t) const {
00053             T retVal = 0;
00054             for (unsigned int i = 0; i < SIZE; ++i) {
00055                 retVal += t[i] * content[i];
00056             }
00057             return retVal;
00058         }
00059         
00060         const AlgTinyVector operator*(const int t) const {
00061             AlgTinyVector<T,SIZE> retVal;
00062             for (unsigned int i = 0; i < SIZE; ++i) {
00063                 retVal[i] = t * content[i];
00064             }
00065             return retVal;
00066         }
00067         
00068         const AlgTinyVector operator/(const int t) const {
00069             AlgTinyVector<T,SIZE> retVal;
00070             for (unsigned int i = 0; i < SIZE; ++i) {
00071                 retVal[i] = content[i] / t;
00072             }
00073             return retVal;
00074         }
00075         
00076         const AlgTinyVector operator-(const AlgTinyVector<T,SIZE> & t) const {
00077             AlgTinyVector<T,SIZE> retVal;
00078             for (unsigned int i = 0; i < SIZE; ++i) {
00079                 retVal[i] = t[i] - content[i];
00080             }
00081             return retVal;
00082         }
00083         
00084         const AlgTinyVector operator+(const AlgTinyVector<T,SIZE> & t) const {
00085             AlgTinyVector<T,SIZE> retVal;
00086             for (unsigned int i = 0; i < SIZE; ++i) {
00087                 retVal[i] = t[i] + content[i];
00088             }
00089             return retVal;
00090         }        
00091         
00092         AlgTinyVector & operator=(const AlgTinyVector<T,SIZE> & t) {
00093             if (this == &t)
00094                 return *this;
00095             for (unsigned int i = 0; i < SIZE; ++i) {
00096                 content[i] = t[i];
00097             }
00098             return *this;
00099         }
00100         
00101         AlgTinyVector & operator=(const TinyVector<T,SIZE> & t) {
00102             for (unsigned int i = 0; i < SIZE; ++i) {
00103                 content[i] = t[i];
00104             }
00105             return *this;
00106         }
00107         
00108     private:
00109         T content[SIZE];
00110 };
00111 
00112 template <class T, int SIZE>
00113 struct NumericTraits<AlgTinyVector<T, SIZE> >
00114 {
00115     typedef AlgTinyVector<T, SIZE> Type;
00116     typedef AlgTinyVector<typename NumericTraits<T>::Promote, SIZE> Promote;
00117     typedef AlgTinyVector<typename NumericTraits<T>::RealPromote, SIZE> RealPromote;
00118     typedef AlgTinyVector<typename NumericTraits<T>::ComplexPromote, SIZE> ComplexPromote;
00119     typedef T ValueType;
00120 
00121     typedef typename NumericTraits<T>::isIntegral isIntegral;
00122     typedef VigraFalseType isScalar;
00123     typedef typename NumericTraits<T>::isSigned isSigned;
00124     typedef VigraFalseType isOrdered;
00125     typedef VigraFalseType isComplex;
00126 
00127     static AlgTinyVector<T, SIZE> zero() {
00128         return AlgTinyVector<T, SIZE>(NumericTraits<T>::zero());
00129     }
00130     static AlgTinyVector<T, SIZE> one() {
00131         return AlgTinyVector<T, SIZE>(NumericTraits<T>::one());
00132     }
00133     static AlgTinyVector<T, SIZE> nonZero() {
00134         return AlgTinyVector<T, SIZE>(NumericTraits<T>::nonZero());
00135     }
00136 
00137     static Promote toPromote(const AlgTinyVector<T,SIZE> & v)
00138     {
00139         return Promote(v);
00140     }
00141 
00142     static RealPromote toRealPromote(const AlgTinyVector<T,SIZE> & v)
00143     {
00144         return RealPromote(v);
00145     }
00146 
00147     /*static AlgTinyVector<T, SIZE>
00148     fromPromote(AlgTinyVector<typename NumericTraits<T>::Promote> const & v)
00149     {
00150         AlgTinyVector<T, SIZE> res;
00151         return res;
00152     }
00153 
00154     static TinyVector<T, SIZE>
00155     fromRealPromote(AlgTinyVector<typename NumericTraits<T>::RealPromote> const & v)
00156     {
00157         TinyVector<T, SIZE> res(detail::dontInit());
00158         typedef typename detail::LoopType<SIZE>::type ltype;
00159         ltype::fromRealPromote(res.begin(), v.begin());
00160         return res;
00161     }*/
00162 };
00163 
00164 }

Generated on 2 Aug 2015 for Hugintrunk by  doxygen 1.4.7