Horus Doc || C++ Reference || Class Overview   Pixels   Images   Detector   Geometry   Registry || Doxygen's quick Index  

HxVector.h

00001 /*
00002  *  Copyright (c) 1998, University of Amsterdam, The Netherlands.
00003  *  All rights reserved.
00004  *
00005  *
00006  *  Author(s):
00007  *  Dennis Koelma (koelma@wins.uva.nl)
00008  *  Edo Poll (poll@wins.uva.nl)
00009  *  Jan-Mark Geusebroek (mark@wins.uva.nl)
00010  */
00011 
00012 #ifndef HxVector_h
00013 #define HxVector_h
00014 
00015 #include "HxIoFwd.h"
00016 #include "HxStd.h"
00017 
00018 
00019 class L_HXBASIS HxMatrix;
00020 
00025 class L_HXBASIS HxVector {
00026 public:
00027 
00029 
00031                         HxVector();
00032 
00034                         HxVector(int n);
00035 
00037                         HxVector(int n, double* data);
00038 
00040                         HxVector(double a0, double a1);
00041 
00043                         HxVector(double a0, double a1, double a2);
00044 
00046                         HxVector(double a0, double a1, double a2, double a3);
00047 
00049                         HxVector(const HxVector& v);
00050 
00052                         HxVector(const HxMatrix& m);
00054 
00055                         ~HxVector();
00056 
00057 
00059 
00061     int                 nElem() const;
00062 
00064     int                 valid() const;
00066 
00068 
00070     HxVector&                   operator=(double a);
00071 
00073     HxVector&                   operator=(const HxVector& v);
00074 
00076     double&                     operator[](int i) const;
00077 
00079     HxVector                    operator-() const;
00080 
00082     friend L_HXBASIS double     operator*(const HxVector& a, const HxVector& b);
00083 
00085     friend HxVector             operator*(const double a, const HxVector& b);
00086 
00088     friend HxVector             operator*(const HxVector& a, const double b);
00089 
00091     friend HxVector             operator/(const HxVector& a, double          b);
00092 
00094     friend HxVector             operator/(double          a, const HxVector& b);
00095 
00097     friend L_HXBASIS HxVector   operator+(const HxVector& a, const HxVector& b);
00098 
00100     friend HxVector             operator+(const HxVector& a, double          b);
00101 
00103     friend HxVector             operator+(double          a, const HxVector& b);
00104 
00106     friend L_HXBASIS HxVector   operator-(const HxVector& a, const HxVector& b);
00107 
00109     friend HxVector             operator-(const HxVector& a, double          b);
00110 
00112     friend HxVector             operator-(double          a, const HxVector& b);
00113 
00115     friend L_HXBASIS int        operator==(const HxVector& a, const HxVector& b);
00116 
00118     friend int                  operator!=(const HxVector& a, const HxVector& b);
00119 
00121 
00123 
00125     HxMatrix            t() const;
00126 
00128     HxMatrix            diag() const;
00129 
00133     HxVector            add(const HxVector& b) const;
00134 
00138     HxVector            add(const double val) const;
00139 
00143     HxVector            sub(const HxVector& b) const;
00144 
00148     HxVector            sub(const double val) const;
00149 
00153     HxVector            mul(const HxVector& b) const;
00154 
00158     HxVector            mul(const HxMatrix& m) const;
00159 
00163     HxVector            mul(const double val) const;
00164 
00168     HxVector            div(const double val) const;
00169 
00171     HxVector            sin() const;
00172 
00174     HxVector            cos() const;
00175 
00177     HxVector            tan() const;
00178 
00180     HxVector            sinh() const;
00181 
00183     HxVector            cosh() const;
00184 
00186     HxVector            tanh() const;
00187 
00189     HxVector            exp() const;
00190 
00192     HxVector            log() const;
00193 
00195     HxVector            sqrt() const;
00196 
00198     HxVector            abs() const;
00199 
00201     HxVector            sgn() const;
00202 
00204     HxVector            map(double (*f)(double)) const;
00206 
00207     STD_OSTREAM&        put(STD_OSTREAM& os) const;
00208 private:
00209     friend class HxMatrix;
00210 
00211     int                 _n;    // number of elements
00212     double*             _data; // data pointer
00213 };
00214 
00215 inline HxVector::HxVector()
00216 {
00217     _n = 0;
00218     _data = 0;
00219 }
00220 
00221 inline HxVector::HxVector(int n)
00222 {
00223     _n = n;
00224     _data = new double[_n];
00225 }
00226 
00227 inline HxVector::HxVector(int n, double* data)
00228 {
00229     _n = n;
00230     _data = data;
00231 }
00232 
00233 inline HxVector::HxVector(double a0, double a1)
00234 {
00235     _n = 2;
00236     _data = new double[_n];
00237     _data[0] = a0;
00238     _data[1] = a1;
00239 }
00240 
00241 inline HxVector::HxVector(double a0, double a1, double a2)
00242 {
00243     _n = 3;
00244     _data = new double[_n];
00245     _data[0] = a0;
00246     _data[1] = a1;
00247     _data[2] = a2;
00248 }
00249 
00250 inline HxVector::HxVector(double a0, double a1, double a2, double a3)
00251 {
00252     _n = 4;
00253     _data = new double[_n];
00254     _data[0] = a0;
00255     _data[1] = a1;
00256     _data[2] = a2;
00257     _data[3] = a3;
00258 }
00259 
00260 inline HxVector::HxVector(const HxVector& v)
00261 {
00262     _n = v.nElem();
00263     _data = new double[_n];
00264 
00265     double* t = v._data;
00266     double* u = _data;
00267     int i = v.nElem();
00268     while (--i >= 0)
00269         *u++ = *t++;
00270 }
00271 
00272 inline HxVector::~HxVector()
00273 { 
00274     delete [] _data; 
00275 }
00276 
00277 inline int
00278 HxVector::nElem() const
00279 { 
00280     return _n; 
00281 }
00282 
00283 inline int
00284 HxVector::valid() const
00285 {
00286     return (_n != 0);
00287 }
00288 
00289 inline HxVector&
00290 HxVector::operator=(double a)
00291 {
00292     int i = nElem();
00293     double *t = _data;
00294     while (--i >= 0)
00295         *t++ = a;
00296     return *this;
00297 }
00298 
00299 inline HxVector&
00300 HxVector::operator=(const HxVector& v)
00301 {
00302     if (this != &v) {
00303         delete [] _data;
00304         _n = v.nElem();
00305         _data = new double [_n];
00306         double *t = _data;
00307         double *u = v._data;
00308         int i = v.nElem();
00309         while (--i >= 0)
00310             *t++ = *u++;
00311     }
00312     return *this;
00313 }
00314 
00315 inline double&
00316 HxVector::operator[](int i) const
00317 { 
00318     return _data[i];
00319 } 
00320 
00321 inline HxVector
00322 HxVector::operator-() const
00323 {
00324     HxVector m(*this);
00325     double* t = m._data;
00326     double* u = _data;
00327     int i = nElem();
00328     while (--i >= 0)
00329         *t++ = -(*u++);
00330     return m;
00331 }
00332 
00333 inline HxVector
00334 operator*(const HxVector& a, double b)
00335 {
00336     HxVector m(a);
00337     double* t = m._data;
00338     double* u = a._data;
00339     int i = a.nElem();
00340     while (--i >= 0)
00341         *t++ = *u++ * b;
00342     return m;
00343 }
00344 
00345 inline HxVector 
00346 operator*(double a, const HxVector &b)
00347 {
00348     HxVector m(b);
00349     double* t = m._data;
00350     double* u = b._data;
00351     int i = b.nElem();
00352     while (--i >= 0)
00353     *t++ = a * *u++;
00354     return m;
00355 }
00356 
00357 inline HxVector 
00358 operator/(const HxVector &a, double b)
00359 {
00360     HxVector m(a);
00361     double* t = m._data;
00362     double* u = a._data;
00363     int i = a.nElem();
00364     while (--i >= 0)
00365         *t++ = *u++ / b;
00366     return m;
00367 }
00368 
00369 inline HxVector 
00370 operator/(double a, const HxVector &b)
00371 {
00372     HxVector m(b);
00373     double* t = m._data;
00374     double* u = b._data;
00375     int i = b.nElem();
00376     while (--i >= 0)
00377         *t++ = a / *u++;
00378     return m;
00379 }
00380 
00381 inline HxVector 
00382 operator+(const HxVector &a, double b)
00383 {
00384     HxVector m(a);
00385     double* t = m._data;
00386     double* u = a._data;
00387     int i = a.nElem();
00388     while (--i >= 0)
00389         *t++ = *u++ + b;
00390     return m;
00391 }
00392 
00393 inline HxVector 
00394 operator+(double a, const HxVector &b)
00395 {
00396     HxVector m(b);
00397     double* t = m._data;
00398     double* u = b._data;
00399     int i = b.nElem();
00400     while (--i >= 0)
00401         *t++ = a + *u++;
00402     return m;
00403 }
00404 
00405 inline HxVector 
00406 operator-(const HxVector &a, double b)
00407 {
00408     HxVector m(a);
00409     double* t = m._data;
00410     double* u = a._data;
00411     int i = a.nElem();
00412     while (--i >= 0)
00413         *t++ = *u++ - b;
00414     return m;
00415 }
00416 
00417 inline HxVector 
00418 operator-(double a, const HxVector &b)
00419 {
00420     HxVector m(b);
00421     double* t = m._data;
00422     double* u = b._data;
00423     int i = b.nElem();
00424     while (--i >= 0)
00425         *t++ = a - *u++;
00426     return m;
00427 }
00428 
00429 inline int 
00430 operator!=(const HxVector &a, const HxVector &b)
00431 {
00432     return !(a == b);
00433 }
00434 
00435 
00436 inline STD_OSTREAM&
00437 operator<<(STD_OSTREAM& os, const HxVector v)
00438 {
00439     return v.put(os);
00440 }
00441 
00442 inline HxVector
00443 HxVector::map(double (*f)(double)) const
00444 {
00445     HxVector m(*this);
00446     double* t = m._data;
00447     double* u = _data;
00448     int i = nElem();
00449     while (--i >= 0)
00450             *t++ = f(*u++);
00451     return m;
00452 }
00453 
00454 L_HXBASIS double       operator*(const HxVector& a, const HxVector& b);
00455 L_HXBASIS HxVector     operator+(const HxVector& a, const HxVector& b);
00456 L_HXBASIS HxVector     operator-(const HxVector& a, const HxVector& b);
00457 L_HXBASIS int          operator==(const HxVector& a, const HxVector& b);
00458 
00459 #endif

Generated on Mon Jan 27 15:48:50 2003 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001