Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef DOUBLEMATRIX_H
00029 #define DOUBLEMATRIX_H
00030
00031 #include "QGpCoreToolsDLLExport.h"
00032 #include "AbstractStream.h"
00033 #include "Matrix.h"
00034 #include "Segment.h"
00035 #include "MatrixIterator.h"
00036
00037 namespace QGpCoreTools {
00038
00039 class QGPCORETOOLS_EXPORT DoubleMatrix: public Matrix<double>
00040 {
00041 public:
00042 DoubleMatrix() : Matrix<double>() {}
00043 DoubleMatrix(int ndim) : Matrix<double>(ndim) {}
00044 DoubleMatrix(int nrow, int ncol) : Matrix<double>(nrow, ncol) {}
00045 DoubleMatrix(const Matrix<double> m) : Matrix<double>(m) {}
00046 DoubleMatrix(const DoubleMatrix& m) : Matrix<double>(m) {}
00047
00048 void rotation(AxisType ax, const Angle& angle);
00049 void random(double min=0.0, double max=1.0);
00050 bool invert();
00051 DoubleMatrix eigenVectors(QVector<double>& eigenValues) const;
00052 };
00053
00054 QGPCORETOOLS_EXPORT AbstractStream& operator<<(AbstractStream& s, const DoubleMatrix& m);
00055
00056 class QGPCORETOOLS_EXPORT Matrix2x2: public DoubleMatrix
00057 {
00058 public:
00059 Matrix2x2() : DoubleMatrix(2, 2) {}
00060 Matrix2x2(const Matrix2x2& o) : DoubleMatrix(static_cast<const DoubleMatrix&>(o)) {}
00061 Matrix2x2(const Matrix<double>& o) : DoubleMatrix(static_cast<const DoubleMatrix&>(o)) {ASSERT(o.columnCount()==2 && o.rowCount()==2);}
00062
00063 inline void rotation(const Angle& angle);
00064 Matrix2x2 operator*(const Matrix2x2& m) const {return DoubleMatrix::operator*(m);}
00065 inline Point2D operator*(const Point2D& p) const;
00066 };
00067
00068 inline void Matrix2x2::rotation(const Angle& angle)
00069 {
00070 DoubleMatrix::rotation(ZAxis, angle);
00071 }
00072
00073 inline Point2D Matrix2x2::operator*(const Point2D& p) const
00074 {
00075 Point2D rp;
00076 const double * values=_d->values();
00077 rp.setX(values[0]*p.x()+values[2]*p.y());
00078 rp.setY(values[1]*p.x()+values[3]*p.y());
00079 return rp;
00080 }
00081
00082 class QGPCORETOOLS_EXPORT Matrix3x3: public DoubleMatrix
00083 {
00084 public:
00085 Matrix3x3() : DoubleMatrix(3, 3) {}
00086 Matrix3x3(const Matrix3x3& o) : DoubleMatrix(static_cast<const DoubleMatrix&>(o)) {}
00087 Matrix3x3(const Matrix<double>& o) : DoubleMatrix(static_cast<const DoubleMatrix&>(o)) {ASSERT(o.columnCount()==3 && o.rowCount()==3);}
00088
00089 inline void rotation(AxisType ax, const Angle& angle);
00090 Matrix3x3 operator*(const Matrix3x3& m) const {return DoubleMatrix::operator*(m);}
00091 inline Point operator*(const Point& p) const;
00092 };
00093
00094 inline void Matrix3x3::rotation(AxisType ax, const Angle& angle)
00095 {
00096 identity();
00097 DoubleMatrix::rotation(ax, angle);
00098 }
00099
00100 inline Point Matrix3x3::operator*(const Point& p) const
00101 {
00102 TRACE;
00103 Point rp;
00104 const double * values=_d->values();
00105 rp.setX(values[0]*p.x()+values[3]*p.y()+values[6]*p.z());
00106 rp.setY(values[1]*p.x()+values[4]*p.y()+values[7]*p.z());
00107 rp.setZ(values[2]*p.x()+values[5]*p.y()+values[8]*p.z());
00108 return rp;
00109 }
00110
00111 class QGPCORETOOLS_EXPORT Matrix4x4: public DoubleMatrix
00112 {
00113 public:
00114 Matrix4x4() : DoubleMatrix(4, 4) {}
00115 Matrix4x4(const Matrix4x4& o) : DoubleMatrix(static_cast<const DoubleMatrix&>(o)) {}
00116 Matrix4x4(const Matrix<double>& o) : DoubleMatrix(static_cast<const DoubleMatrix&>(o)) {ASSERT(o.columnCount()==4 && o.rowCount()==4);}
00117
00118 inline void rotation(AxisType ax, const Angle& angle);
00119 Matrix3x3 rotationOnly() const;
00120 DoubleMatrix operator*(const DoubleMatrix& m) const {return DoubleMatrix::operator*(m);}
00121 inline Point operator*(const Point& p) const;
00122 Segment operator*(const Segment& s) const;
00123 };
00124
00125 inline void Matrix4x4::rotation(AxisType ax, const Angle& angle)
00126 {
00127 identity();
00128 DoubleMatrix::rotation(ax, angle);
00129 }
00130
00131 inline Point Matrix4x4::operator*(const Point& p) const
00132 {
00133 TRACE;
00134 Point rp;
00135 const double * values=_d->values();
00136 rp.setX(values[0]*p.x()+values[4]*p.y()+values[8]*p.z()+values[12]);
00137 rp.setY(values[1]*p.x()+values[5]*p.y()+values[9]*p.z()+values[13]);
00138 rp.setZ(values[2]*p.x()+values[6]*p.y()+values[10]*p.z()+values[14]);
00139 return rp;
00140 }
00141
00142 }
00143
00144 #endif // DOUBLEMATRIX_H