QVMatrix Class Reference
[Math extensions]

Implementation of numerical matrices. More...

#include <qvmath/qvmatrix.h>

List of all members.

Public Member Functions

 QVMatrix ()
 Default constructor.
 QVMatrix (const QVMatrix &matrix)
 Copy constructor.
 QVMatrix (const int rows, const int cols)
 Dimensional constructor.
 QVMatrix (const QVQuaternion &quaternion)
 Rotation matrix constructor.
 QVMatrix (const QVVector &vector, const bool rowVector=true)
 Vector to matrix constructor.
 QVMatrix (const QList< QVVector > &vectorList)
 Constructor from a list of QVVectors.
 QVMatrix (const QList< QVector< double > > &vectorList)
 Constructor from a list of QVectors.
 QVMatrix (const gsl_matrix *matrix)
 Copy constructor for gsl_matrix.
 QVMatrix (const QList< QPointF > &pointList)
 Constructor from a list of QPointF.
 o () const
 Convert to a list of QVVectors operator.
 o () const
 Convert to a list of QVectors operator.
 operator gsl_matrix * () const
 Convert to a gsl_matrix * operator.
QVMatrixoperator= (const QVMatrix &matrix)
 Copy operator.
bool operator== (const QVMatrix &matrix) const
 Matrix-matrix equality operator.
bool operator!= (const QVMatrix &matrix) const
 Matrix-matrix unequality operator.
QVMatrix operator * (const QVMatrix &matrix) const
 Matrix-matrix product operator.
QVMatrix operator/ (const QVMatrix &matrix) const
 Matrix-matrix division.
QVMatrix operator+ (const QVMatrix &matrix) const
 Matrix-matrix addition operator.
QVMatrix operator- (const QVMatrix &matrix) const
 Matrix-matrix substraction operator.
QVMatrix operator- () const
 Matrix negation.
QVMatrix operator * (const double value) const
 Matrix-scalar product.
QVMatrix operator/ (const double value) const
 Matrix-scalar division operator.
QVVector operator * (QVVector &vector) const
 Matrix-vector product.
double & operator() (const int row, const int col)
 Cell access operator.
const double operator() (const int row, const int col) const
 Overloaded version of cell access operator.
const int getDataSize () const
 Gets the size of the data array.
const double * getReadData () const
 Gets a read-only reference to the data buffer of the matrix.
double * getWriteData ()
 Gets a reference of the data buffer of the matrix for read and write accesses.
QVMatrix transpose () const
 Change the order of the indexes in the matrix.
void set (const double value)
 Sets the value of the elements of the matrix.
bool equals (const QVMatrix &matrix) const
 Matrix-matrix equality operator.
QVMatrix dotProduct (const QVMatrix &matrix) const
 Matrix-matrix product.
QVMatrix matrixDivide (const QVMatrix &matrix) const
 Matrix-matrix division.
QVMatrix inverse () const
double det () const
QVVector meanCol () const
QVMatrix addition (const QVMatrix &matrix) const
 Matrix-matrix addition.
QVMatrix substract (const QVMatrix &matrix) const
 Matrix-matrix substraction.
QVMatrix scalarDivide (const double value) const
 Matrix-scalar division.
QVMatrix scalarProduct (const double value) const
 Matrix-scalar product.
double norm2 () const
 Gets the norm2 for matrix.
QVMatrix rowHomogeneousNormalize () const
 Homogeneous normalization for rows of the matrix.
const int getCols () const
 Get width of the matrix.
const int getRows () const
 Get height of the matrix.
const QVVector getRow (const int row) const
 Gets a row of the matrix.
void setRow (const int row, QVVector vector)
 Sets a row of the matrix.
void setRow (const int row, QVector< double > vector)
 Sets a row of the matrix.
const QVVector getCol (const int col) const
 Gets a column of the matrix.
void setCol (const int col, QVVector vector)
 Sets a column of the matrix.
const QVMatrix getSubmatrix (const int firstRow, const int lastRow, const int firstCol, const int lastCol) const
 Gets a submatrix from a matrix.

Static Public Member Functions

static QVMatrix identity (const int size)
 Creates an identity matrix.
static QVMatrix random (const int rows, const int cols)
 Creates a random matrix.
static QVMatrix diagonal (const QVVector &diagonalVector)
 Creates a diagonal matrix.
static QVMatrix rotationMatrix (const double angle)
 Create a planar rotation matrix.
static QVMatrix traslationMatrix (const double x, const double y)
 Create a 3D traslation matrix.
static QVMatrix scaleMatrix (const double zoom)
 Create a 3D translation matrix.
static QVMatrix rotationMatrix3dXAxis (const double angle)
 Create a rotation matrix for 3D-X axis.
static QVMatrix rotationMatrix3dYAxis (const double angle)
 Create a rotation matrix for 3D-Y axis.
static QVMatrix rotationMatrix3dZAxis (const double angle)
 Create a rotation matrix for 3D-Z axis.
static QVMatrix traslationMatrix3d (const double x, const double y, const double z)
 Create a 3D translation matrix.


Detailed Description

Implementation of numerical matrices.

Definition at line 40 of file qvmatrix.h.


Constructor & Destructor Documentation

QVMatrix::QVMatrix (  ) 

Default constructor.

By default, it constructs a 1x1 matrix.

Definition at line 32 of file qvmatrix.cpp.

Referenced by operator *().

QVMatrix::QVMatrix ( const QVMatrix matrix  ) 

Copy constructor.

Creates a matrix object copying the content from a given one.

Parameters:
matrix matrix to be copied.

Definition at line 36 of file qvmatrix.cpp.

QVMatrix::QVMatrix ( const int  rows,
const int  cols 
)

Dimensional constructor.

Creates a new matrix of the specified dimensions.

Parameters:
rows number of rows for the new matrix.
cols number of rows for the new matrix.

Definition at line 40 of file qvmatrix.cpp.

QVMatrix::QVMatrix ( const QVQuaternion quaternion  ) 

Rotation matrix constructor.

Creates a rotation matrix equivalent to a quaternion.

Parameters:
quaternion quaternion equivalent to the rotation.

Definition at line 44 of file qvmatrix.cpp.

QVMatrix::QVMatrix ( const QVVector vector,
const bool  rowVector = true 
)

Vector to matrix constructor.

Creates a row or column matrix from a vector.

Parameters:
vector vector to convert to matrix type.
rowVector if true, creates a row matrix from the vector, else creates a column matrix from it.

Definition at line 61 of file qvmatrix.cpp.

QVMatrix::QVMatrix ( const QList< QVVector > &  vectorList  ) 

Constructor from a list of QVVectors.

Creates a new matrix from a list of row QVVectors.

Parameters:
vectorList list of row vectors.

Definition at line 69 of file qvmatrix.cpp.

QVMatrix::QVMatrix ( const QList< QVector< double > > &  vectorList  ) 

Constructor from a list of QVectors.

Creates a new matrix from a list of row QVectors.

Parameters:
vectorList list of row vectors.

Definition at line 78 of file qvmatrix.cpp.

QVMatrix::QVMatrix ( const gsl_matrix *  matrix  ) 

Copy constructor for gsl_matrix.

Parameters:
matrix matrix to be copied

Definition at line 87 of file qvmatrix.cpp.

QVMatrix::QVMatrix ( const QList< QPointF > &  pointList  ) 

Constructor from a list of QPointF.

Creates a new matrix from a list of points

Parameters:
pointList list of points.

Definition at line 94 of file qvmatrix.cpp.


Member Function Documentation

QVMatrix & QVMatrix::operator= ( const QVMatrix matrix  ) 

Copy operator.

Parameters:
matrix matrix to be copied.

Definition at line 100 of file qvmatrix.cpp.

bool QVMatrix::operator== ( const QVMatrix matrix  )  const [inline]

Matrix-matrix equality operator.

Parameters:
matrix term for the compare operation.
Returns:
true if the given matrix has same dimensions and equal content of the data buffer, else false.
See also:
equals

Definition at line 152 of file qvmatrix.h.

bool QVMatrix::operator!= ( const QVMatrix matrix  )  const [inline]

Matrix-matrix unequality operator.

Parameters:
matrix term for the compare operation.
Returns:
false if the given matrix has same dimensions and equal content of the data buffer, else true.
See also:
equals

Definition at line 159 of file qvmatrix.h.

QVMatrix QVMatrix::operator * ( const QVMatrix matrix  )  const [inline]

Matrix-matrix product operator.

Parameters:
matrix factor for the product operation.
See also:
matrixProduct

Definition at line 165 of file qvmatrix.h.

Referenced by operator-().

QVMatrix QVMatrix::operator/ ( const QVMatrix matrix  )  const [inline]

Matrix-matrix division.

The following expression:

X = A / B

is equivalent to this one

X = A * pseudoInverse(B)

With the difference that the pseudoinverse matrix for B is not directly computed. Instead, the matrix equation:

X * B = A

is solved for the X term. This leads to more stable and efficient results than using the pseudo inverse.

this operator gets X from:

X = A / B -> X * B = A -> B' * X' = A'

using a linear system resolution based on a LU decomposition over A.

Parameters:
matrix factor for the operation.
See also:
matrixDivide(const QVMatrix &) const

Definition at line 192 of file qvmatrix.h.

QVMatrix QVMatrix::operator+ ( const QVMatrix matrix  )  const [inline]

Matrix-matrix addition operator.

Parameters:
matrix term for the operation.
See also:
addition

Definition at line 198 of file qvmatrix.h.

QVMatrix QVMatrix::operator- ( const QVMatrix matrix  )  const [inline]

Matrix-matrix substraction operator.

Parameters:
matrix subtrahend for the operation.
See also:
substract

Definition at line 204 of file qvmatrix.h.

QVMatrix QVMatrix::operator- (  )  const [inline]

Matrix negation.

Obtains a matrix negating all the elements of the original.

See also:
substract

Definition at line 211 of file qvmatrix.h.

QVMatrix QVMatrix::operator * ( const double  value  )  const [inline]

Matrix-scalar product.

Parameters:
value factor for the operation.
See also:
scalarProduct

Definition at line 219 of file qvmatrix.h.

QVMatrix QVMatrix::operator/ ( const double  value  )  const [inline]

Matrix-scalar division operator.

Parameters:
value divider for the operation.
See also:
scalarDivide

Definition at line 225 of file qvmatrix.h.

QVVector QVMatrix::operator * ( QVVector vector  )  const

Matrix-vector product.

Parameters:
vector vector to multiply by.

Definition at line 111 of file qvmatrix.cpp.

double& QVMatrix::operator() ( const int  row,
const int  col 
) [inline]

Cell access operator.

Parameters:
row main index value for data access
col secondary index value for data access

Definition at line 240 of file qvmatrix.h.

Referenced by getSubmatrix(), QVMatrix(), and rowHomogeneousNormalize().

const double QVMatrix::operator() ( const int  row,
const int  col 
) const [inline]

Overloaded version of cell access operator.

Parameters:
row main index value for data access
col secondary index value for data access

Definition at line 247 of file qvmatrix.h.

const int QVMatrix::getDataSize (  )  const [inline]

Gets the size of the data array.

This returns the number of elements in the matrix.

Returns:
the product of the sizes of all the indexes in the matrix.

Definition at line 254 of file qvmatrix.h.

Referenced by addition(), eigenDecomposition(), equals(), norm2(), scalarDivide(), scalarProduct(), set(), and substract().

const double* QVMatrix::getReadData (  )  const [inline]

Gets a read-only reference to the data buffer of the matrix.

Returns:
a constant pointer to the data buffer of the matrix

Definition at line 259 of file qvmatrix.h.

Referenced by addition(), dotProduct(), eigenDecomposition(), equals(), GetDirectIntrinsicCameraMatrixFromHomography(), norm2(), operator<<(), QVVector::QVVector(), solveLinear(), solveOverDetermined(), substract(), and transpose().

double* QVMatrix::getWriteData (  )  [inline]

Gets a reference of the data buffer of the matrix for read and write accesses.

Returns:
a pointer to the data buffer of the matrix

Definition at line 264 of file qvmatrix.h.

Referenced by addition(), CholeskyDecomposition(), dotProduct(), LUDecomposition(), pseudoInverse(), QRDecomposition(), scalarDivide(), scalarProduct(), set(), solveLinear(), solveOverDetermined(), substract(), and transpose().

QVMatrix QVMatrix::transpose (  )  const

Change the order of the indexes in the matrix.

This function reorders the indexes of the matrix.

Todo:
use blas function cblas_axpy for this

Definition at line 184 of file qvmatrix.cpp.

Referenced by ComputeEuclideanHomography(), eigenDecomposition(), getMeanDirection(), matrixDivide(), pseudoInverse(), and solveHomogeneousLinear2().

void QVMatrix::set ( const double  value  ) 

Sets the value of the elements of the matrix.

Parameters:
value value to set elements in the matrix

Todo:
use blas function cblas_axpy for data add

Definition at line 201 of file qvmatrix.cpp.

Referenced by diagonal(), and identity().

bool QVMatrix::equals ( const QVMatrix matrix  )  const

Matrix-matrix equality operator.

Parameters:
matrix term for the compare operation.
Returns:
true if the given matrix has same dimensions and equal content of the data buffer, else false.
See also:
operator==(const QVMatrix &) const

operator!=(const QVMatrix &) const

Definition at line 119 of file qvmatrix.cpp.

Referenced by operator!=(), and operator==().

QVMatrix QVMatrix::dotProduct ( const QVMatrix matrix  )  const

Matrix-matrix product.

Parameters:
matrix factor for the operation.
See also:
operator*(const QVMatrix &) const

Definition at line 136 of file qvmatrix.cpp.

Referenced by operator *().

QVMatrix QVMatrix::matrixDivide ( const QVMatrix matrix  )  const

Matrix-matrix division.

This function solves the X term from the following matrix equation:

X A = B
where A and B are respectively the actual matrix, and the one given by parameter. This is equivalent to using the following expression for X:
X = B A-1
but with a faster method returning a more stable result.

Parameters:
matrix factor for the operation.
See also:
operator/(const QVMatrix &) const

Definition at line 158 of file qvmatrix.cpp.

Referenced by operator/().

QVMatrix QVMatrix::inverse (  )  const

Computes the inverse of the matrix.

Por ahora con la misma pseudoinversa, serĂ­a mejor de otro modo...

Definition at line 173 of file qvmatrix.cpp.

Referenced by BhattacharyyaDistance().

double QVMatrix::det (  )  const

Computes the determinant of the matrix.

Definition at line 179 of file qvmatrix.cpp.

Referenced by BhattacharyyaDistance().

QVVector QVMatrix::meanCol (  )  const

Obtains the mean vector for the column vectors in the matrix

Definition at line 481 of file qvmatrix.cpp.

Referenced by getMeanDirection().

QVMatrix QVMatrix::addition ( const QVMatrix matrix  )  const

Matrix-matrix addition.

Parameters:
matrix operand for the add operation.
See also:
operator+(const QVMatrix &) const

Todo:
use blas function cblas_axpy for data add

Definition at line 212 of file qvmatrix.cpp.

Referenced by operator+().

QVMatrix QVMatrix::substract ( const QVMatrix matrix  )  const

Matrix-matrix substraction.

Parameters:
matrix subtrahend for the operation.
See also:
operator-(const QVMatrix &) const

Todo:
use blas function cblas_axpy for data add

Definition at line 230 of file qvmatrix.cpp.

Referenced by operator-().

QVMatrix QVMatrix::scalarDivide ( const double  value  )  const

Matrix-scalar division.

Parameters:
value scalar value to use in the operation.
See also:
operator/(const double) const

Todo:
use blas function?

Definition at line 264 of file qvmatrix.cpp.

Referenced by operator/().

QVMatrix QVMatrix::scalarProduct ( const double  value  )  const

Matrix-scalar product.

Parameters:
value factor for the operation.
See also:
operator*(const double) const

Todo:
use blas function?

Definition at line 249 of file qvmatrix.cpp.

Referenced by operator *().

double QVMatrix::norm2 (  )  const

Gets the norm2 for matrix.

The resulting value will be the square root of the following sumatory:

$ \|A\|_2 := \sqrt{ \sum |a_{ij}|^2 } $

where $ a_{ij} $ are the elements of the matrix $ A $.

Returns:
norm-2 of the matrix.

Definition at line 279 of file qvmatrix.cpp.

Referenced by solveHomogeneousLinear2().

QVMatrix QVMatrix::rowHomogeneousNormalize (  )  const

Homogeneous normalization for rows of the matrix.

Todo:
explain homogeneous normalization
Returns:
norm-2 of the matrix.

Definition at line 283 of file qvmatrix.cpp.

const int QVMatrix::getCols (  )  const [inline]

Get width of the matrix.

Returns:
number of columns for the matrix.

Definition at line 360 of file qvmatrix.h.

Referenced by CholeskyDecomposition(), determinant(), eigenDecomposition(), Filter(), getCol(), getMeanDirection(), getRow(), getSubmatrix(), LUDecomposition(), matrixDivide(), meanCol(), operator *(), operator<<(), pseudoInverse(), qHash(), QRDecomposition(), QVMatrix(), rowHomogeneousNormalize(), setCol(), setRow(), singularValueDecomposition(), solveHomogeneousLinear(), solveHomogeneousLinear2(), solveLinear(), solveOverDetermined(), and transpose().

const int QVMatrix::getRows (  )  const [inline]

Get height of the matrix.

Returns:
number of rows for the matrix.

Definition at line 365 of file qvmatrix.h.

Referenced by CholeskyDecomposition(), determinant(), eigenDecomposition(), Filter(), getCol(), getRow(), getSubmatrix(), LUDecomposition(), matrixDivide(), o(), QVVector::operator *(), operator<<(), pseudoInverse(), qHash(), QRDecomposition(), QVMatrix(), regressionLine(), rowHomogeneousNormalize(), setCol(), setRow(), singularValueDecomposition(), solveHomogeneousLinear2(), solveLinear(), solveOverDetermined(), and transpose().

const QVVector QVMatrix::getRow ( const int  row  )  const

Gets a row of the matrix.

Parameters:
row row number, a value within [0, r-1], for a matrix with 'r' rows
Returns:
a vector containing the values of the row

Definition at line 294 of file qvmatrix.cpp.

Referenced by o(), and solveHomogeneousLinear2().

void QVMatrix::setRow ( const int  row,
QVVector  vector 
)

Sets a row of the matrix.

Parameters:
row row number, a value within [0, r-1], for a matrix with 'r' rows
vector a vector containing the values for the row

Definition at line 306 of file qvmatrix.cpp.

Referenced by QVMatrix().

void QVMatrix::setRow ( const int  row,
QVector< double >  vector 
)

Sets a row of the matrix.

Parameters:
row row number, a value within [0, r-1], for a matrix with 'r' rows
vector a vector containing the values for the row

Definition at line 316 of file qvmatrix.cpp.

const QVVector QVMatrix::getCol ( const int  col  )  const

Gets a column of the matrix.

Parameters:
col column number, a value within [0, c-1], for a matrix with 'c' columns
Returns:
a vector containing the values of the column

Definition at line 326 of file qvmatrix.cpp.

Referenced by GetExtrinsicCameraMatrixFromHomography(), getMeanDirection(), HomographyTestError(), meanCol(), operator *(), solveHomogeneousLinear(), and solveHomogeneousLinear2().

void QVMatrix::setCol ( const int  col,
QVVector  vector 
)

Sets a column of the matrix.

Parameters:
col column number, a value within [0, c-1], for a matrix with 'c' columns
vector a vector containing the values for the column

Definition at line 338 of file qvmatrix.cpp.

Referenced by GetExtrinsicCameraMatrixFromHomography(), getMeanDirection(), QVMatrix(), and solveHomogeneousLinear2().

const QVMatrix QVMatrix::getSubmatrix ( const int  firstRow,
const int  lastRow,
const int  firstCol,
const int  lastCol 
) const

Gets a submatrix from a matrix.

Parameters:
firstCol first column number for the submatrix
firstRow first row number for the submatrix
lastCol last column number for the submatrix
lastRow last row number for the submatrix
Returns:
a submatrix of size (lastRow - firstRow + 1)x(lastCol - firstCol + 1) containing the corresponding elements from the original matrix.

Definition at line 348 of file qvmatrix.cpp.

QVMatrix QVMatrix::identity ( const int  size  )  [static]

Creates an identity matrix.

Parameters:
size number of cols and rows for the identity matrix

Definition at line 371 of file qvmatrix.cpp.

Referenced by ComputeEuclideanHomography(), GetDirectIntrinsicCameraMatrixFromHomography(), GetIntrinsicCameraMatrixFromHomography(), QVMatrix(), rotationMatrix(), rotationMatrix3dXAxis(), rotationMatrix3dYAxis(), rotationMatrix3dZAxis(), scaleMatrix(), traslationMatrix(), and traslationMatrix3d().

QVMatrix QVMatrix::random ( const int  rows,
const int  cols 
) [static]

Creates a random matrix.

Matrix with elements values from 0 to 1.

Parameters:
rows rows of the matrix
cols cols of the matrix

Definition at line 380 of file qvmatrix.cpp.

QVMatrix QVMatrix::diagonal ( const QVVector diagonalVector  )  [static]

Creates a diagonal matrix.

Matrix with elements values from 0 to 1.

Parameters:
diagonalVector vector containing the diagonal values

Definition at line 389 of file qvmatrix.cpp.

Referenced by singularValueDecomposition().

QVMatrix QVMatrix::rotationMatrix ( const double  angle  )  [static]

Create a planar rotation matrix.

Parameters:
angle angle to rotate around coordinate center

Definition at line 399 of file qvmatrix.cpp.

QVMatrix QVMatrix::traslationMatrix ( const double  x,
const double  y 
) [static]

Create a 3D traslation matrix.

Parameters:
x increment in X axis
y increment in Y axis

Definition at line 410 of file qvmatrix.cpp.

QVMatrix QVMatrix::scaleMatrix ( const double  zoom  )  [static]

Create a 3D translation matrix.

Parameters:
zoom scale

Definition at line 421 of file qvmatrix.cpp.

QVMatrix QVMatrix::rotationMatrix3dXAxis ( const double  angle  )  [static]

Create a rotation matrix for 3D-X axis.

Parameters:
angle angle to rotate around X axis in radians

Definition at line 444 of file qvmatrix.cpp.

QVMatrix QVMatrix::rotationMatrix3dYAxis ( const double  angle  )  [static]

Create a rotation matrix for 3D-Y axis.

Parameters:
angle angle to rotate around Y axis in radians

Definition at line 457 of file qvmatrix.cpp.

QVMatrix QVMatrix::rotationMatrix3dZAxis ( const double  angle  )  [static]

Create a rotation matrix for 3D-Z axis.

Parameters:
angle angle to rotate around Z axis in radians

Definition at line 431 of file qvmatrix.cpp.

QVMatrix QVMatrix::traslationMatrix3d ( const double  x,
const double  y,
const double  z 
) [static]

Create a 3D translation matrix.

Parameters:
x increment in X axis
y increment in Y axis
z increment in Z axis

Definition at line 470 of file qvmatrix.cpp.


The documentation for this class was generated from the following files: