1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 06:43:22 +02:00

Use QVector as the data container in Matrix

This commit is contained in:
Martin Tůma 2024-02-17 11:54:07 +01:00
parent 516a944859
commit 88b458e959
3 changed files with 7 additions and 40 deletions

View File

@ -3,33 +3,11 @@
#define abs(x) ((x)<0 ? -(x) : (x))
Matrix::~Matrix()
{
delete[] _m;
}
Matrix::Matrix(size_t h, size_t w)
{
_h = h; _w = w;
if (isNull())
_m = 0;
else
_m = new double[_h * _w];
}
Matrix::Matrix(const Matrix& M)
{
_h = M._h; _w = M._w;
if (isNull())
_m = 0;
else
_m = new double[_h * _w];
for (size_t i = 0; i < _h; i++)
for (size_t j = 0; j < _w; j++)
m(i,j) = M.m(i,j);
_h = h;
_w = w;
_m.resize(_h * _w);
}
bool Matrix::eliminate(double epsilon)
@ -87,12 +65,6 @@ Matrix Matrix::augemented(const Matrix &M) const
return A;
}
void Matrix::zeroize()
{
for (size_t i = 0; i < _h * _w; i++)
_m[i] = 0;
}
#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const Matrix &matrix)
{

View File

@ -3,29 +3,27 @@
#include <cstddef>
#include <cfloat>
#include <QVector>
#include <QDebug>
class Matrix
{
public:
Matrix() {_h = 0; _w = 0; _m = 0;}
Matrix() {_h = 0; _w = 0;}
Matrix(size_t h, size_t w);
Matrix(const Matrix& M);
~Matrix();
size_t h() const {return _h;}
size_t w() const {return _w;}
double &m(size_t i, size_t j) {return _m[_w * i + j];}
double const &m(size_t i, size_t j) const {return _m[_w * i + j];}
double const &m(size_t i, size_t j) const {return _m.at(_w * i + j);}
bool isNull() const {return (_h == 0 || _w == 0);}
void zeroize();
bool eliminate(double epsilon = DBL_EPSILON);
Matrix augemented(const Matrix &M) const;
private:
double *_m;
QVector<double> _m;
size_t _h;
size_t _w;
};

View File

@ -23,7 +23,6 @@ void Transform::simple(const ReferencePoint &p1, const ReferencePoint &p2)
void Transform::affine(const QList<ReferencePoint> &points)
{
Matrix c(3, 2);
c.zeroize();
for (size_t i = 0; i < c.h(); i++) {
for (size_t j = 0; j < c.w(); j++) {
for (int k = 0; k < points.size(); k++) {
@ -40,7 +39,6 @@ void Transform::affine(const QList<ReferencePoint> &points)
}
Matrix Q(3, 3);
Q.zeroize();
for (int qi = 0; qi < points.size(); qi++) {
double v[3];
@ -63,7 +61,6 @@ void Transform::affine(const QList<ReferencePoint> &points)
_img2proj = _proj2img.inverted();
}
Transform::Transform()
: _proj2img(NULL_QTRANSFORM), _img2proj(NULL_QTRANSFORM)
{