GestureRecognitionToolkit  Version: 1.0 Revision: 04-03-15
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
GRT::Matrix< T > Class Template Reference

Public Member Functions

 Matrix ()
 
 Matrix (const unsigned int rows, const unsigned int cols)
 
 Matrix (const Matrix &rhs)
 
 Matrix (const std::vector< std::vector< T > > &data)
 
virtual ~Matrix ()
 
Matrixoperator= (const Matrix &rhs)
 
T * operator[] (const unsigned int r)
 
const T * operator[] (const unsigned int r) const
 
std::vector< T > getRowVector (const unsigned int r) const
 
std::vector< T > getColVector (const unsigned int c) const
 
std::vector< T > getConcatenatedVector (const bool concatByRow=true) const
 
virtual bool resize (const unsigned int r, const unsigned int c)
 
virtual bool copy (const Matrix< T > &rhs)
 
bool setAllValues (const T &value)
 
bool setRowVector (const std::vector< T > &row, const unsigned int rowIndex)
 
bool setColVector (const std::vector< T > &column, const unsigned int colIndex)
 
bool push_back (const std::vector< T > &sample)
 
bool reserve (const unsigned int capacity)
 
void clear ()
 
unsigned int getNumRows () const
 
unsigned int getNumCols () const
 
unsigned int getCapacity () const
 
unsigned int getSize () const
 
T ** getDataPointer () const
 

Protected Attributes

unsigned int rows
 The number of rows in the Matrix.
 
unsigned int cols
 The number of columns in the Matrix.
 
unsigned int size
 Stores rows * cols.
 
unsigned int capacity
 The capacity of the Matrix, this will be the number of rows, not the actual memory size.
 
T * dataPtr
 A pointer to the raw data.
 
T ** rowPtr
 A pointer to each row in the data.
 
ErrorLog errorLog
 

Detailed Description

template<class T>
class GRT::Matrix< T >

Definition at line 41 of file Matrix.h.

Constructor & Destructor Documentation

template<class T>
GRT::Matrix< T >::Matrix ( )
inline

Default Constructor

Definition at line 46 of file Matrix.h.

template<class T>
GRT::Matrix< T >::Matrix ( const unsigned int  rows,
const unsigned int  cols 
)
inline

Constructor, sets the size of the matrix to [rows cols]

Parameters
constUINT rows: sets the number of rows in the matrix, must be a value greater than zero
constUINT cols: sets the number of columns in the matrix, must be a value greater than zero

Definition at line 61 of file Matrix.h.

template<class T>
GRT::Matrix< T >::Matrix ( const Matrix< T > &  rhs)
inline

Copy Constructor, copies the values from the rhs Matrix to this Matrix instance

Parameters
constMatrix &rhs: the Matrix from which the values will be copied

Definition at line 72 of file Matrix.h.

template<class T>
GRT::Matrix< T >::Matrix ( const std::vector< std::vector< T > > &  data)
inline

Copy Constructor, copies the values from the input vector to this Matrix instance. The input vector must be a vector< vector< T > > in a [rows cols] format. The number of columns in each row must be consistent. Both the rows and columns must be greater than 0.

Parameters
constvector< vector< T > > &data: the input data which will be copied to this Matrix instance

Definition at line 89 of file Matrix.h.

template<class T>
virtual GRT::Matrix< T >::~Matrix ( )
inlinevirtual

Destructor, cleans up any memory

Definition at line 129 of file Matrix.h.

Member Function Documentation

template<class T>
void GRT::Matrix< T >::clear ( )
inline

Cleans up any dynamic memory and sets the number of rows and columns in the matrix to zero

Definition at line 511 of file Matrix.h.

template<class T>
virtual bool GRT::Matrix< T >::copy ( const Matrix< T > &  rhs)
inlinevirtual

Copies the data from the rhs matrix to this matrix.

Parameters
constMatrix<T> &rhs: the matrix you want to copy into this matrix
Returns
returns true or false, indicating if the copy was successful

Definition at line 308 of file Matrix.h.

template<class T>
unsigned int GRT::Matrix< T >::getCapacity ( ) const
inline

Gets the capacity of the Matrix. This is the number of rows that have been reserved for the Matrix. You can control the capacity using the reserve function

Returns
returns the number of columns in the Matrix

Definition at line 546 of file Matrix.h.

template<class T>
std::vector<T> GRT::Matrix< T >::getColVector ( const unsigned int  c) const
inline

Gets a column vector [rows 1] from the Matrix at the column index c

Parameters
constUINT c: the index of the column, this should be in the range [0 cols-1]
Returns
returns a column vector from the Matrix at the column index c

Definition at line 186 of file Matrix.h.

template<class T>
std::vector<T> GRT::Matrix< T >::getConcatenatedVector ( const bool  concatByRow = true) const
inline

Concatenates the entire matrix into a single vector and returns the vector. The data can either be concatenated by row or by column, by setting the respective concatByRow parameter to true of false. If concatByRow is true then the data in the matrix will be added to the vector row-vector by row-vector, otherwise the data will be added column-vector by column-vector.

Parameters
constbool concatByRow: sets if the matrix data will be added to the vector row-vector by row-vector
Returns
returns a vector containing the entire matrix data

Definition at line 202 of file Matrix.h.

template<class T>
T** GRT::Matrix< T >::getDataPointer ( ) const
inline

Gets a pointer to the

Returns
returns the number of columns in the Matrix

Definition at line 560 of file Matrix.h.

template<class T>
unsigned int GRT::Matrix< T >::getNumCols ( ) const
inline

Gets the number of columns in the Matrix

Returns
returns the number of columns in the Matrix

Definition at line 538 of file Matrix.h.

template<class T>
unsigned int GRT::Matrix< T >::getNumRows ( ) const
inline

Gets the number of rows in the Matrix

Returns
returns the number of rows in the Matrix

Definition at line 531 of file Matrix.h.

template<class T>
std::vector<T> GRT::Matrix< T >::getRowVector ( const unsigned int  r) const
inline

Gets a row vector [1 cols] from the Matrix at the row index r

Parameters
constUINT r: the index of the row, this should be in the range [0 rows-1]
Returns
returns a row vector from the Matrix at the row index r

Definition at line 173 of file Matrix.h.

template<class T>
unsigned int GRT::Matrix< T >::getSize ( ) const
inline

Gets the size of the Matrix. This is rows * size.

Returns
returns the number of columns in the Matrix

Definition at line 553 of file Matrix.h.

template<class T>
Matrix& GRT::Matrix< T >::operator= ( const Matrix< T > &  rhs)
inline

Defines how the data from the rhs Matrix should be copied to this Matrix

Parameters
constMatrix &rhs: another instance of a Matrix
Returns
returns a reference to this instance of the Matrix

Definition at line 139 of file Matrix.h.

template<class T>
T* GRT::Matrix< T >::operator[] ( const unsigned int  r)
inline

Returns a pointer to the data at row r

Parameters
constUINT r: the index of the row you want, should be in the range [0 rows-1]
Returns
a pointer to the data at row r

Definition at line 153 of file Matrix.h.

template<class T>
const T* GRT::Matrix< T >::operator[] ( const unsigned int  r) const
inline

Returns a const pointer to the data at row r

Parameters
constUINT r: the index of the row you want, should be in the range [0 rows-1]
Returns
a const pointer to the data at row r

Definition at line 163 of file Matrix.h.

template<class T>
bool GRT::Matrix< T >::push_back ( const std::vector< T > &  sample)
inline

Adds the input sample to the end of the Matrix, extending the number of rows by 1. The number of columns in the sample must match the number of columns in the Matrix, unless the Matrix size has not been set, in which case the new sample size will define the number of columns in the Matrix.

Parameters
conststd::vector<T> &sample: the new column vector you want to add to the end of the Matrix. Its size should match the number of columns in the Matrix
Returns
returns true or false, indicating if the push was successful

Definition at line 390 of file Matrix.h.

template<class T>
bool GRT::Matrix< T >::reserve ( const unsigned int  capacity)
inline

This function reserves a consistent block of data so new rows can more effecitenly be pushed_back into the Matrix. The capacity variable represents the number of rows you want to reserve, based on the current number of columns.

Parameters
constunsigned int capacity: the new capacity value
Returns
returns true if the data was reserved, false otherwise

Definition at line 469 of file Matrix.h.

template<class T>
virtual bool GRT::Matrix< T >::resize ( const unsigned int  r,
const unsigned int  c 
)
inlinevirtual

Resizes the Matrix to the new size of [r c]. If [r c] matches the previous size then the matrix will not be resized but the function will return true.

Parameters
constUINT r: the number of rows, must be greater than zero
constUINT c: the number of columns, must be greater than zero
Returns
returns true or false, indicating if the resize was successful

Definition at line 234 of file Matrix.h.

template<class T>
bool GRT::Matrix< T >::setAllValues ( const T &  value)
inline

Sets all the values in the Matrix to the input value

Parameters
constT &value: the value you want to set all the Matrix values to
Returns
returns true or false, indicating if the set was successful

Definition at line 335 of file Matrix.h.

template<class T>
bool GRT::Matrix< T >::setColVector ( const std::vector< T > &  column,
const unsigned int  colIndex 
)
inline

Sets all the values in the column at colIndex with the values in the vector called column. The size of the column vector must match the number of rows in this Matrix.

Parameters
conststd::vector<T> &column: the vector of column values you want to add
constunsigned int colIndex: the column index of the column you want to update, must be in the range [0 cols]
Returns
returns true or false, indicating if the set was successful

Definition at line 372 of file Matrix.h.

template<class T>
bool GRT::Matrix< T >::setRowVector ( const std::vector< T > &  row,
const unsigned int  rowIndex 
)
inline

Sets all the values in the row at rowIndex with the values in the vector called row. The size of the row vector must match the number of columns in this Matrix.

Parameters
conststd::vector<T> &row: the vector of row values you want to add
constunsigned int rowIndex: the row index of the row you want to update, must be in the range [0 rows]
Returns
returns true or false, indicating if the set was successful

Definition at line 353 of file Matrix.h.


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