AURobotServers  4
Public Member Functions | Public Attributes | Protected Attributes | List of all members
UMatrix Class Reference

#include <umatrix.h>

Inheritance diagram for UMatrix:
Inheritance graph

Public Member Functions

void add (UMatrix *A, UMatrix *B)
 
void add (UMatrix *A)
 
void add (const double val)
 
void clear ()
 
unsigned int cols ()
 
void copy (UMatrix *source)
 
CvArr * cvArr ()
 
CvMat * cvMat ()
 
double det (int *error)
 
void eig (UMatrix *W, UMatrix *U, UMatrix *V, int flag=CV_SVD_V_T)
 
int elements ()
 
void error (const int ierr, const char *message)
 
bool expand (const unsigned int iRows, const unsigned int iCols)
 
bool expand (const unsigned int iRows, const unsigned int iCols, const double iVal)
 
double get (const unsigned int at)
 
double get (int row, int col)
 
double * getData ()
 
virtual const char * getDataType ()
 
double * getRow (int row)
 
bool init (const unsigned int rows, const unsigned int cols)
 
bool init (const unsigned int rows, const unsigned int cols, const double i)
 
bool init (const unsigned int iRows, const unsigned int iCols, double *data, unsigned int bufferSizeInDoubles)
 
void inverse (UMatrix *B, int method=CV_SVD)
 
virtual bool isAlsoA (const char *typeString)
 
bool isCol ()
 
bool isRow ()
 
int maxSize ()
 
int mult (UMatrix *A, UMatrix *B)
 
void mult (const double scale)
 
bool normalize ()
 
void print (const char *prestring)
 
unsigned int rows ()
 
int save (char *filename, char delim= ' ')
 
bool save (FILE *f, const char *name)
 
void set (const double value0, const double value1, const double value2=0.0, const double value3=0.0)
 
bool setAt (const unsigned int at, const double value)
 
int setCol (unsigned int col, const double value0, const double value1=0.0, const double value2=0.0, const double value3=0.0)
 
int setDiag (double value0, double value1, double value2=0.0, double value3=0.0)
 
bool setMat (const int rCnt, const int cCnt, double *values)
 
int setMinor (UMatrix *mA, const unsigned int ar, const unsigned int ac)
 
int setRC (const unsigned int row, const unsigned int col, const double value)
 
int setRow (unsigned int row, const double value0, const double value1=0.0, const double value2=0.0, const double value3=0.0)
 
int setRow (unsigned int row, unsigned int valCnt, const double val[])
 
bool setSize (const unsigned int iRows, const unsigned int iCols)
 
unsigned int size ()
 
virtual void snprint (const char *prestring, char *buff, const int buffCnt)
 
virtual void snprintMaple (const char *prestring, char *s, const int length)
 
bool solve (UMatrix *iB, UMatrix *X)
 
double sqSum ()
 
void sub (UMatrix *A, UMatrix *B)
 
void sub (UMatrix *A)
 
double trace ()
 
void transpose (UMatrix *B=NULL)
 
bool valid ()
 
- Public Member Functions inherited from UDataBase
bool isA (const char *typeString)
 
 UDataBase ()
 
virtual ~UDataBase ()
 

Public Attributes

int err
 

Protected Attributes

CvMat mat
 
unsigned int matrixSize
 

Detailed Description

Virtual class for matrix operations. This class do not include any elements. decendent classes must define a data area and point m to this area. All initialisation and constructors must be handled by decendent classes.
The matrix index is (row, col), and are 0-based. i.e. for a matrix of size 4x3 the row number range is 0..3 and the column munber range is 0..2.
This class offers most of the useual matrix operations - the rest is supported by openCV

Member Function Documentation

void UMatrix::add ( UMatrix A,
UMatrix B 
)
void UMatrix::add ( UMatrix A)

Add the matrix A to this matrix

References cols(), error(), getData(), rows(), and size().

void UMatrix::add ( const double  val)

Add val to all elements in this matrix.

References cols(), getRow(), and rows().

void UMatrix::clear ( void  )
unsigned int UMatrix::cols ( )
inline
void UMatrix::copy ( UMatrix source)
CvArr* UMatrix::cvArr ( )
inline

Get handle to opencv array structure. This can be used for all CvArr type arguments.

References mat.

Referenced by UImageAna::findRoad(), UImageAna::findRoadCroma(), UImagePoly::makeSimilarImage2(), UImagePoly::makeSimilarImage3(), and solve().

CvMat* UMatrix::cvMat ( )
inline

Get handle to opencv array structure. This can be used for all CvMat type arguments.

Referenced by UFuncStereo::initializeStereo(), UFuncStereo::processImages(), testMatrixVecBig(), testOpticalFlow(), testOpticalFlowHarris(), and UCamRad::updateLensParams().

double UMatrix::det ( int *  error)

Find determinant if matrix is size 1x1, 2x2, 3x3

Parameters
errset to == 0 if sucessfull or
errset to = -1 if matrix is too big
Returns
determinant

References mat.

Referenced by UMatrix4::density(), UMatrix4::det(), UMatrixBig::det(), and valid().

void UMatrix::eig ( UMatrix W,
UMatrix U,
UMatrix V,
int  flag = CV_SVD_V_T 
)

Calculates singular value decomposition (SVD) of this matrix (MxN with M >= N). So that: source = U * W * V'; The result is placed in W (diagonal if W is (NxN) or as vector if W is (Nx1). Also U and V can be calculated, columns in U (MxN) and rows in V (NxN) (or may be NULL if not needed). The matrix size of W, U and V must be set before call. The flag may be either 0 or sum of:
CV_SVD_MODIFY_A enables modification of matrix src1 during the operation. It speeds up the processing.
CV_SVD_U_T means that the tranposed matrix U is returned. Specifying the flag speeds up the processing.
CV_SVD_V_T means that the tranposed matrix V is returned. Specifying the flag speeds up the processing.
Preferred value is CV_SVD_MODIFY_A + CV_SVD_V_T. but default is just CV_SVD_V_T (a bit slower, but 'this' matrix is left as is).
Eigenvalue note:
If source matrix is symmetric the eigenvalues in W agree with matlab, otherwise it seems just to be some vector (diagonal) that can be used in back-transformation using the found U and V matrices. U and V are equal if source matrix is symmetric.

References cols(), error(), mat, and rows().

Referenced by testEigenvector(), and valid().

int UMatrix::elements ( )
inline

Return maximum number of elements available in array data area (rows * columns). Type is always double.

References matrixSize.

Referenced by UMatrixBig::UMatrixBig().

void UMatrix::error ( const int  ierr = -1,
const char *  message = "" 
)

Set err value and show error message to console.

References err.

Referenced by add(), copy(), eig(), expand(), get(), init(), normalize(), setRC(), sub(), transpose(), UMatrix4::UMatrix4(), and valid().

bool UMatrix::expand ( const unsigned int  iRows,
const unsigned int  iCols 
)
bool UMatrix::expand ( const unsigned int  iRows,
const unsigned int  iCols,
const double  iVal 
)

Expand matrix maintaining old values. Fills the new elements with 0.0 except in the main diagonal, where the provided value will be inserted. The 'err' value in matrix will be set to -1 if there is no more space to increase the matrix.

References cols(), err, expand(), getRow(), and rows().

double UMatrix::get ( const unsigned int  at)
inline
double UMatrix::get ( int  row,
int  col 
)
inline

Get a matrix element.

References cols(), error(), mat, and rows().

double* UMatrix::getData ( )
inline
virtual const char* UMatrix::getDataType ( )
inlinevirtual

Get (end) type of this structure

Reimplemented from UDataBase.

References clear(), and isAlsoA().

Referenced by isAlsoA().

double* UMatrix::getRow ( int  row)
inline

Get forst element in a row, for dynamic access to column elements

References mat.

Referenced by add(), expand(), UImagePoly::makeSimilarImage2(), setMinor(), and setRow().

bool UMatrix::init ( const unsigned int  rows,
const unsigned int  cols 
)

Initializes of a matrix to required size, with all elements left as is, that is: if column number is cahanged all data vontent (with exception of elements if first row) are reshuffeld.

References err, error(), mat, and matrixSize.

Referenced by URotation::asUnitZVector4CtoW(), UResLocater::doLocatorUpdates(), UImAna::findContourPolyCroma(), UImageAna::findContourPolyCroma(), UImagePoly::findContourPolyCroma(), UFuncStereo::initializeStereo(), UCamParEst::initParEst(), UCamParEst::initParEst35(), UCamPar::setMatrices(), UPoseQ::setQ(), setSize(), testLinearAlgebra(), UMatrix4::UMatrix4(), and UMatrixBig::UMatrixBig().

bool UMatrix::init ( const unsigned int  rows,
const unsigned int  cols,
const double  i 
)

Initializes of a matrix to required size, and with elements along the main diagonal set to i. Other elements are set to 0.0.

References err, error(), mat, and matrixSize.

bool UMatrix::init ( const unsigned int  iRows,
const unsigned int  iCols,
double *  data,
unsigned int  bufferSizeInDoubles 
)
inline

Initialize matrix with user provided data buffer

Parameters
iRowsis (initial) matrix number of rows
iColsis (initial) matrix number of columns
datais array of doubles to hold at least the initial matrix,
bufferSizeInDoublesis the size of the double buffer (may have extra space for reorganisation of matrix.

References cols(), err, mat, and matrixSize.

void UMatrix::inverse ( UMatrix B,
int  method = CV_SVD 
)

Transpose this matrix. Inverse. Make this matrix an inversed copy of B. The method ishould be CV_SVD for normal matrix and CV_SYM_SVD for symmetric matrices. These methods do not use temporary dynmically allocated matricec. The method CV_LU use gaussian elimination is also supported

References mat.

Referenced by UResLocater::doLocatorUpdates(), UImageAna::findRoadCroma(), UMatrix4::inversed(), isCol(), UImagePoly::makeSimilarImage2(), and testMatrixInv().

bool UMatrix::isAlsoA ( const char *  typeString)
virtual

Function to test if the class or one of its ancestors is of a specific type

Reimplemented from UDataBase.

References getDataType(), and UDataBase::isAlsoA().

Referenced by getDataType().

bool UMatrix::isCol ( )
inline

is vector a row or a column

References add(), copy(), inverse(), mult(), rows(), setMinor(), solve(), sub(), transpose(), and X.

Referenced by normalize(), and transpose().

bool UMatrix::isRow ( )
inline

is vector a row or a column

References cols().

Referenced by normalize(), and transpose().

int UMatrix::maxSize ( )
inline

Return maximum number of elements available in array data area (rows x columns). Type is always double.

References matrixSize.

Referenced by UCalibrationMarkSet::setBarcodePosRowSet(), and UCalibrationMarkSet::setCameraPosRowSet().

int UMatrix::mult ( UMatrix A,
UMatrix B 
)

Resize this matrix as required, and if the size is increased the new elements are filled i along the main diagonal and other new elements are set to zero. Make this matrix the matrix product og A and B. this = A * B.

References cols(), err, mat, rows(), and setSize().

Referenced by UFuzzyPixel::addCovariance(), UFuzzySplit::classifyOld(), UImAna::findContourPolyCroma(), UImageAna::findContourPolyCroma(), UImagePoly::findContourPolyCroma(), UImAna::getAvgVar(), UImageAna::getAvgVar(), UImagePoly::getAvgVar(), UImagePoly::getAvgVar2(), UFuzzySplit::getCenter(), UFuzzySplit::getCovariance(), isCol(), UMatrix4::operator*(), testEigenvector(), and testMatrixVecBig().

void UMatrix::mult ( const double  scale)

Scale all elements in this matrix with scale. this *= scale

References getData(), and size().

bool UMatrix::normalize ( )

Normalize homogeneous vector, so that last element is 1.

References absd(), err, error(), getData(), isCol(), isRow(), and size().

Referenced by UPosition::getPixelPos(), UCalibrationComponents::PaintChartInImage(), and setSize().

void UMatrix::print ( const char *  prestring)
unsigned int UMatrix::rows ( )
inline
int UMatrix::save ( char *  filename,
char  delim = ' ' 
)

save to file in textfile format for MATLAB etc. with numbers in '-1.988e-12' type format with delimitor between columns as sepcified in DELIM, with default as space.
Returns 0 if successfull, else -1.

References cols(), err, and rows().

Referenced by UCalibrationMarkSet::evaluateChartPosRot(), testMatrixVecBig(), and valid().

bool UMatrix::save ( FILE *  f,
const char *  name 
)

Save matrix in matlab format *.m with this variable name.

References cols(), err, and rows().

void UMatrix::set ( const double  value0,
const double  value1,
const double  value2 = 0.0,
const double  value3 = 0.0 
)
inline
bool UMatrix::setAt ( const unsigned int  at,
const double  value 
)
inline

Set one value in a vector. Position is zero based, i.e. set(0, 1.0) sets first element to 1.0.
returns 0 if within range

References mat, and size().

Referenced by URotation::asUnitZVector3CtoW(), URotation::asUnitZVector4CtoW(), and testMatrixVecBig().

int UMatrix::setCol ( unsigned int  col,
const double  value0,
const double  value1 = 0.0,
const double  value2 = 0.0,
const double  value3 = 0.0 
)

Set up to first 4 elements in a column.

References cols(), err, rows(), and setRC().

Referenced by UResLocater::doLocatorUpdates(), and valid().

int UMatrix::setDiag ( double  value0,
double  value1,
double  value2 = 0.0,
double  value3 = 0.0 
)

Set matrix diagnal to these values. Other elements in matrix are untouched

References cols(), rows(), and setRC().

Referenced by UResLocater::doLocatorUpdates(), and valid().

bool UMatrix::setMat ( const int  rCnt,
const int  cCnt,
double *  values 
)

Set matrix values from an array of double values.

Parameters
rCntis the number of rows in matrix
cCntis number of columns.
valuesis an array of size (rCnt,cCnt) with matrix values. first row first.
Returns
true if space for array values.

References err, getData(), and setSize().

Referenced by UVariable::getM(), UFuncLoca2::updateCovStatus(), UFuncLocalize::updateCovStatus(), UCamRad::updateLensParams(), and valid().

int UMatrix::setMinor ( UMatrix mA,
const unsigned int  ar,
const unsigned int  ac 
)

Make a mionor matrix as copy of 'mA' by removing row 'ar' and column 'ac'. Returns -1 if error in source or calculation.

References cols(), err, getRow(), rows(), and setSize().

Referenced by UMatrix4::det(), UMatrixBig::det(), and isCol().

int UMatrix::setRC ( const unsigned int  row,
const unsigned int  col,
const double  value 
)
inline
int UMatrix::setRow ( unsigned int  row,
const double  value0,
const double  value1 = 0.0,
const double  value2 = 0.0,
const double  value3 = 0.0 
)
int UMatrix::setRow ( unsigned int  row,
unsigned int  valCnt,
const double  val[] 
)

Set matrix row from array of doubles.

Parameters
rowis the row to be set (0 based)
valCntis the number of values to be set (no more than number of columns)
valis the array of values.
Returns
err=0

References cols(), err, getRow(), and mini().

bool UMatrix::setSize ( const unsigned int  iRows,
const unsigned int  iCols 
)
inline
unsigned int UMatrix::size ( )
inline

Get the size of the actual vector. More space may be allocated - see maxSize().

References mat.

Referenced by add(), UCamParEst::adjustParameters(), clear(), UPosition::copy(), mult(), normalize(), UPose::set(), setAt(), and sub().

void UMatrix::snprint ( const char *  prestring,
char *  buff,
const int  buffCnt 
)
virtual

Copy elements to string in human readable format

Reimplemented from UDataBase.

References cols(), err, and rows().

Referenced by UCalibrationMarkSet::geterrorInPixels(), and valid().

void UMatrix::snprintMaple ( const char *  prestring,
char *  s,
const int  length 
)
virtual

Copy elements to string s (Maple format).

References cols(), and rows().

Referenced by valid().

bool UMatrix::solve ( UMatrix iB,
UMatrix X 
)

Solve the set of equation in this matrix with the unknowns in result vector X beeing equal to the iB vector. this * X = iB. Returns true if result in X is valid (matrix not singular).

References cvArr().

Referenced by DoFindPeak(), UCalibrationMarkSet::evaluateChartPosRot(), UCalibrationMarkSet::evaluatePosRot(), UPlane::getPlaneCrossing(), isCol(), UCamParEst::solveLeastSquare(), testMatrixVec(), and testMatrixVecBig().

double UMatrix::sqSum ( )

Get squared sum of all elements. Especially usefull for vectors, there the result is the vector distance squared, or the dot product by itself

References cols(), getData(), rows(), and sqr().

Referenced by valid().

void UMatrix::sub ( UMatrix A,
UMatrix B 
)

Make this matrix the element difference of the matrix A and B. this = A - B.

References cols(), error(), getData(), rows(), setSize(), and size().

Referenced by UImAna::getAvgVar(), UImageAna::getAvgVar(), UImagePoly::getAvgVar(), UImagePoly::getAvgVar2(), isCol(), UMatrix4::operator-(), and testLinearAlgebra().

void UMatrix::sub ( UMatrix A)

Subtract the A matrix from this matrix.

References cols(), error(), getData(), rows(), and size().

double UMatrix::trace ( )
void UMatrix::transpose ( UMatrix B = NULL)
bool UMatrix::valid ( )
inline

Is matrix result valid. same as (err == 0)

References det(), eig(), err, error(), print(), save(), setCol(), setDiag(), setMat(), setRow(), snprint(), snprintMaple(), sqSum(), and trace().

Member Data Documentation

int UMatrix::err
CvMat UMatrix::mat
protected
unsigned int UMatrix::matrixSize
protected

Number of elements in matrix buffer, i.e. may be larger than rows X columns.

Referenced by copy(), elements(), expand(), init(), maxSize(), UMatrix4::UMatrix4(), and UMatrixBig::UMatrixBig().


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