00001
00018 #ifndef _ot_Matrix_h
00019 #define _ot_Matrix_h
00020
00021 #include "otdefs.h"
00022
00023 #define MATRIX_DYNAMIC 1
00024
00029
00036
00037
00038
00039
00040
00041
00045 class otMatrix
00046 {
00047 public:
00048 typedef enum
00049 {
00050 InitMatWithZero,
00051 NoInitMatZero
00052 } InitZero;
00053
00057 otMatrix();
00058
00065 otMatrix(const S16 _i16row, const S16 _i16col, InitZero _init = InitMatWithZero);
00066
00073 otMatrix(const S16 _i16row, const S16 _i16col, F32 * initData);
00074
00081 void create(const S16 _i16row, const S16 _i16col, InitZero _init = InitMatWithZero);
00082
00089 void create(const S16 _i16row, const S16 _i16col, F32 * initData);
00090
00091
00092
00093
00094 class Proxy
00095 {
00096 public:
00097 Proxy(F32 * _array, S16 _maxColumn) : _array(_array)
00098 {
00099 this->_maxColumn = _maxColumn;
00100 }
00101
00102
00103
00104
00105
00106 F32 & operator[](S16 _column)
00107 {
00108 return _array[_column];
00109 }
00110
00111 private:
00112 F32 * _array;
00113 S16 _maxColumn;
00114 };
00115
00116 Proxy operator[](S16 _row)
00117 {
00118 return Proxy(f32data[_row], this->i16col);
00119 }
00120
00121
00122
00127 void close();
00128
00133 bool isValid();
00134
00139 bool isSquare();
00140
00145 S16 getRow();
00146
00151 S16 getCol();
00152
00156 bool operator == (otMatrix _compare);
00157
00161 otMatrix operator + (otMatrix _matAdd);
00162
00166 otMatrix operator - (otMatrix _matSub);
00167
00171 otMatrix operator - (void);
00172
00176 otMatrix operator * (otMatrix _matMul);
00177
00181 otMatrix operator=(otMatrix _mat);
00182
00186 void vSetHomogen(const F32 _val);
00187
00191 void vRoundingElementToZero(const S16 _i, const S16 _j);
00192
00196 otMatrix RoundingMatrixToZero();
00197
00201 void vSetToZero();
00202
00208 void vSetRandom(const S32 _maxRand, const S32 _minRand);
00209
00214 void vSetDiag(const F32 _val);
00215
00219 void vSetIdentity();
00220
00225 void Copy(otMatrix & _outp);
00226
00246 otMatrix InsertVector(otMatrix _Vector, const S16 _posColumn);
00247
00271 otMatrix InsertSubMatrix(otMatrix _subMatrix, const S16 _posRow, const S16 _posColumn);
00272
00297 otMatrix InsertSubMatrix(otMatrix _subMatrix, const S16 _posRow, const S16 _posColumn, const S16 _lenRow, const S16 _lenColumn);
00298
00327 otMatrix InsertSubMatrix(otMatrix _subMatrix, const S16 _posRow, const S16 _posColumn, const S16 _posRowSub, const S16 _posColumnSub, const S16 _lenRow, const S16 _lenColumn);
00328
00333 otMatrix Transpose();
00334
00339 bool bNormVector();
00340
00345 otMatrix Invers();
00346
00353 bool bMatrixIsPositiveDefinite(bool checkPosSemidefinite = false);
00354
00368 otMatrix GetDiagonalEntries(void);
00369
00386 otMatrix CholeskyDec();
00387
00394 otMatrix HouseholderTransformQR(const S16 _rowTransform, const S16 _columnTransform);
00395
00413 bool QRDec(otMatrix & Qt, otMatrix & R);
00414
00427 otMatrix BackSubtitution(otMatrix & A, otMatrix & B);
00428
00438 otMatrix ForwardSubtitution(otMatrix & A, otMatrix & B);
00439
00446 static void garbageClean(U32 start = 0);
00447
00448 static void addGarbage(otMatrix * mat);
00449
00450 static U32 garbageCount();
00451
00452 private:
00453 void init();
00454 #ifdef MATRIX_DYNAMIC
00455 static otMatrix ** _garbage;
00456 static U32 _garbageCount;
00457 F32 ** f32data;
00458 #else
00459 F32 f32data[6][6];
00460 #endif
00461 bool _isValid;
00462 S16 i16row, i16col;
00463 };
00464
00465 otMatrix operator + (const F32 _scalar, otMatrix _mat);
00466 otMatrix operator - (const F32 _scalar, otMatrix _mat);
00467 otMatrix operator * (const F32 _scalar, otMatrix _mat);
00468 otMatrix operator + (otMatrix _mat, const F32 _scalar);
00469 otMatrix operator - (otMatrix _mat, const F32 _scalar);
00470 otMatrix operator * (otMatrix _mat, const F32 _scalar);
00471 otMatrix operator / (otMatrix _mat, const F32 _scalar);
00472
00474
00475 #endif