2017-03-18 01:30:31 +01:00
|
|
|
#ifndef MATRIX_H
|
|
|
|
#define MATRIX_H
|
|
|
|
|
|
|
|
#include <cfloat>
|
2024-02-17 11:54:07 +01:00
|
|
|
#include <QVector>
|
2017-08-14 11:16:48 +02:00
|
|
|
#include <QDebug>
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2024-05-19 16:14:23 +02:00
|
|
|
template <class T>
|
2018-03-08 02:24:10 +01:00
|
|
|
class Matrix
|
|
|
|
{
|
2017-03-18 01:30:31 +01:00
|
|
|
public:
|
2024-02-17 11:54:07 +01:00
|
|
|
Matrix() {_h = 0; _w = 0;}
|
2024-05-19 16:14:23 +02:00
|
|
|
Matrix(int h, int w) : _h(h), _w(w) {_m.resize(_h * _w);}
|
|
|
|
Matrix(int h, int w, const T &val) : _m(h * w, val), _h(h), _w(w) {}
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2024-02-19 22:06:18 +01:00
|
|
|
int h() const {return _h;}
|
|
|
|
int w() const {return _w;}
|
2024-05-19 16:14:23 +02:00
|
|
|
T &at(int n) {return _m[n];}
|
|
|
|
T &at(int i, int j) {return _m[_w * i + j];}
|
|
|
|
T const &at(int i, int j) const {return _m.at(_w * i + j);}
|
2017-03-18 01:30:31 +01:00
|
|
|
|
|
|
|
bool isNull() const {return (_h == 0 || _w == 0);}
|
2024-05-19 16:14:23 +02:00
|
|
|
int size() const {return _m.size();}
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2024-05-19 16:14:23 +02:00
|
|
|
protected:
|
|
|
|
QVector<T> _m;
|
|
|
|
int _h, _w;
|
|
|
|
};
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2024-05-19 16:14:23 +02:00
|
|
|
class MatrixD : public Matrix<double>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MatrixD() : Matrix<double>() {}
|
|
|
|
MatrixD(int h, int w) : Matrix<double>(h, w) {}
|
|
|
|
|
|
|
|
bool eliminate(double epsilon = DBL_EPSILON);
|
|
|
|
MatrixD augemented(const MatrixD &M) const;
|
2017-03-18 01:30:31 +01:00
|
|
|
};
|
|
|
|
|
2018-02-13 23:03:18 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
2024-05-19 16:14:23 +02:00
|
|
|
template <class T>
|
|
|
|
inline QDebug operator<<(QDebug dbg, const Matrix<T> &matrix)
|
|
|
|
{
|
|
|
|
dbg.nospace() << "Matrix(" << "\n";
|
|
|
|
for (int i = 0; i < matrix.h(); i++) {
|
|
|
|
for (int j = 0; j < matrix.w(); j++)
|
|
|
|
dbg << "\t" << matrix.at(i, j);
|
|
|
|
dbg << "\n";
|
|
|
|
}
|
|
|
|
dbg << ")";
|
|
|
|
|
|
|
|
return dbg.space();
|
|
|
|
}
|
2018-02-13 23:03:18 +01:00
|
|
|
#endif // QT_NO_DEBUG
|
2017-08-14 11:16:48 +02:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
#endif // MATRIX_H
|