Changeset 86 for foam/trunk/vision/src/Matrix.h
 Timestamp:
 06/02/2009 11:15:10 AM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

foam/trunk/vision/src/Matrix.h
r85 r86 17 17 #include <assert.h> 18 18 #include <iostream> 19 #include "Vector.h" 19 20 20 21 #ifndef FOAM_MATRIX 21 22 #define FOAM_MATRIX 22 23 23 template<class T> 24 template<class T> 24 25 class Matrix 25 26 { 26 27 public: 28 Matrix(); 27 29 Matrix(unsigned int r, unsigned int c); 28 30 ~Matrix(); 29 31 Matrix(const Matrix &other); 30 32 Matrix(unsigned int r, unsigned int c, float *data); 33 31 34 // Row proxy classes to allow matrix[r][c] notation 32 35 class Row … … 87 90 T *GetRawData() { return m_Data; } 88 91 const T *GetRawDataConst() const { return m_Data; } 92 Vector<T> GetRowVector(unsigned int r) const; 93 Vector<T> GetColVector(unsigned int c) const; 89 94 90 95 void Print() const; 91 96 void SetAll(T s); 97 void Zero() { SetAll(0); } 98 bool IsInf(); 92 99 Matrix Transposed(); 93 100 … … 120 127 121 128 template<class T> 129 Matrix<T>::Matrix() : 130 m_Rows(0), 131 m_Cols(0), 132 m_Data(NULL) 133 { 134 } 135 136 template<class T> 137 Matrix<T>::Matrix(unsigned int r, unsigned int c, float *data) : 138 m_Rows(r), 139 m_Cols(c), 140 m_Data(data) 141 { 142 } 143 144 template<class T> 122 145 Matrix<T>::~Matrix() 123 146 { … … 173 196 } 174 197 } 198 } 199 200 template<class T> 201 bool Matrix<T>::IsInf() 202 { 203 for (unsigned int i=0; i<m_Rows; i++) 204 { 205 for (unsigned int j=0; j<m_Cols; j++) 206 { 207 if (isinf((*this)[i][j])) return true; 208 if (isnan((*this)[i][j])) return true; 209 } 210 } 211 return false; 175 212 } 176 213 … … 266 303 } 267 304 305 template<class T> 306 Vector<T> Matrix<T>::GetRowVector(unsigned int r) const 307 { 308 assert(r<m_Rows); 309 Vector<T> ret(m_Cols); 310 for (unsigned int j=0; j<m_Cols; j++) 311 { 312 ret[j]=(*this)[r][j]; 313 } 314 return ret; 315 } 316 317 template<class T> 318 Vector<T> Matrix<T>::GetColVector(unsigned int c) const 319 { 320 assert(c<m_Cols); 321 Vector<T> ret(m_Rows); 322 for (unsigned int i=0; i<m_Rows; i++) 323 { 324 ret[i]=(*this)[i][c]; 325 } 326 return ret; 327 } 268 328 269 329 template<class T>
Note: See TracChangeset
for help on using the changeset viewer.