00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #ifndef QVVECTOR_H
00026 #define QVVECTOR_H
00027
00028 #include <math.h>
00029 #include <iostream>
00030 #include <QVector>
00031 #include <QPointF>
00032 #include <qvdefines.h>
00033
00034 #ifdef GSL_AVAILABLE
00035 #include <gsl/gsl_linalg.h>
00036 #endif
00037
00038 #ifdef _MSC_VER
00039 #ifdef max
00040 #undef max
00041 #endif // max
00042
00043 #ifdef min
00044 #undef min
00045 #endif // min
00046 #endif // _MSC_VER
00047
00048 class QVMatrix;
00049
00058 class QVVector: public QVector<double>
00059 {
00060 public:
00064 QVVector(): QVector<double>() {}
00065
00070 QVVector(const int size, const double defaultValue = 0): QVector<double>(size, defaultValue) {}
00071
00076 QVVector(const int size, const double *defaultValues): QVector<double>(size)
00077 {
00078 for (int i = 0; i < size; i++)
00079 operator[](i) = defaultValues[i];
00080 }
00081
00085 QVVector(const QVVector &vector): QVector<double>(vector) {}
00086
00090 QVVector(const QVector<double> &vector): QVector<double>(vector) {}
00091
00095 QVVector(const QList<double> &list): QVector<double>(list.toVector()) {}
00096
00103 QVVector(const QVMatrix &matrix);
00104
00109 #ifdef GSL_AVAILABLE
00110 QVVector(const gsl_vector *vector): QVector<double>(vector->size)
00111 {
00112 for(int i = 0; i < size(); i++)
00113 replace(i, gsl_vector_get(vector, i));
00114 }
00115 #endif
00116
00120 QVVector(const QPoint &point): QVector<double>(2) { operator[](0) = point.x(); operator[](1) = point.y(); }
00121
00125 QVVector(const QPointF &point): QVector<double>(2) { operator[](0) = point.x(); operator[](1) = point.y(); }
00126
00128
00132 inline double &operator()(const int index)
00133 { return operator[](index); }
00134
00139 inline double operator()(const int index) const
00140 { return operator[](index); }
00141
00146 double operator*(const QVVector &vector) const { return dotProduct(vector); };
00147
00152 QVVector operator^(const QVVector &vector) const { return crossProduct(vector); };
00153
00158 QVVector operator+(const QVVector &vector) const { return add(vector); };
00159
00164 QVVector operator-(const QVVector &vector) const { return substract(vector); };
00165
00171 QVVector operator-() const { return operator*(-1.0); };
00172
00173
00178 QVVector operator+(const double value) const { return scalarAdd(value); };
00179
00184 QVVector operator-(const double value) const { return scalarSubstract(value); };
00185
00190 QVVector operator*(const double value) const { return scalarProduct(value); };
00191
00196 QVVector operator/(const double value) const { return scalarDivision(value); };
00197
00201 QVVector operator*(const QVMatrix &matrix) const;
00202
00207 bool operator==(const QVVector &vector) const { return equals(vector); };
00208
00212 QVVector & operator+=(const QVVector &vector)
00213 {
00214 const int size_ = size();
00215 const double *srcData = vector.constData();
00216 double *dstData = data();
00217
00219 for (int i = 0; i < size_; i++)
00220 dstData[i] += srcData[i];
00221
00222 return *this;
00223 }
00224
00229 operator QPointF() const
00230 {
00231 Q_ASSERT(size() > 1);
00232 Q_ASSERT(size() < 4);
00233 if (size() == 2)
00234 return QPointF(operator[](0), operator[](1));
00235 else
00236 return QPointF(operator[](0)/operator[](2), operator[](1)/operator[](2));
00237 }
00238
00243 #ifdef GSL_AVAILABLE
00244 operator gsl_vector * () const
00245 {
00246 gsl_vector *result = gsl_vector_alloc(size());
00247 const double *data = this->data();
00248 for(uint i = 0; i < result->size; i++)
00249 gsl_vector_set (result, i, data[i]);
00250 return result;
00251 }
00252 #endif
00253
00255
00259 int maxIndex() const;
00260
00264 int minIndex() const;
00265
00269 int maxAbsIndex() const;
00270
00274 int minAbsIndex() const;
00275
00276
00280 void set(const double value);
00281
00287 QVVector subVector(const int firstIndex, const int lastIndex) const;
00288
00293 QVVector scalarDivision(const double value) const;
00294
00299 QVVector scalarAdd(const double value) const;
00300
00305 QVVector scalarSubstract(const double value) const;
00306
00312 QVVector scalarMultiplication(const double value) const;
00313
00318 QVVector scalarProduct(const double value) const;
00319
00323 double norm2() const;
00324
00325
00329 bool containsNaN() const;
00330
00331
00336 QVVector normalize() const;
00337
00338
00341 QVVector abs() const;
00342
00345 double max() const;
00346
00349 double min() const;
00350
00357 double sum() const;
00358
00365 double mean() const;
00366
00371 double median() const;
00372
00379 double variance() const;
00380
00398 double entropy(const double base = 2) const;
00399
00404 double dotProduct(const QVVector &vector) const;
00405
00411 QVVector crossProduct(const QVVector &vector) const;
00412
00417 QVMatrix outerProduct(const QVVector &vector) const;
00418
00423 QVVector add(const QVVector &vector) const;
00424
00429 QVVector substract(const QVVector &vector) const;
00430
00435 bool equals(const QVVector &vector) const;
00436
00438
00449 static const QVVector gaussianVector(const int radius, const double sigma);
00450
00456 static QVVector random(const int elements);
00457
00468 static const QVVector mexicanHatWaveletVector(const int radius, const double sigma);
00469
00473 static const QVVector homogeneousCoordinates(const QPointF &point);
00474
00480 QVVector homogeneousCoordinates() const;
00481
00502 QVMatrix crossProductMatrix() const;
00503
00505 QVMatrix toRowMatrix() const;
00506
00508 QVMatrix toColumnMatrix() const;
00509 };
00510
00516 QVVector operator*(const double value, const QVVector &);
00517
00523 QVVector operator+(const double value, const QVVector &);
00524
00530 QVVector operator-(const double value, const QVVector &);
00531
00534 std::ostream& operator << ( std::ostream &os, const QVVector &vector );
00535
00538 uint qHash(const QVVector &vector);
00539
00540 #endif
00541