Changeset 97 for foam/trunk/vision/src/Matrix.h
 Timestamp:
 08/03/2009 01:42:48 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

foam/trunk/vision/src/Matrix.h
r96 r97 94 94 void SetRowVector(unsigned int r, const Vector<T> &row); 95 95 void SetColVector(unsigned int c, const Vector<T> &col); 96 96 void NormaliseRows(); 97 void NormaliseCols(); 98 97 99 void Print() const; 98 100 void SetAll(T s); … … 119 121 Matrix CropCols(unsigned int s, unsigned int e); 120 122 121 void Save(FILE *f) ;123 void Save(FILE *f) const; 122 124 void Load(FILE *f); 123 125 … … 230 232 Matrix<T> Matrix<T>::Transposed() const 231 233 { 232 Matrix<T> copy( *this);234 Matrix<T> copy(m_Cols,m_Rows); 233 235 for (unsigned int i=0; i<m_Rows; i++) 234 236 { 235 237 for (unsigned int j=0; j<m_Cols; j++) 236 238 { 237 copy[ i][j]=(*this)[j][i];239 copy[j][i]=(*this)[i][j]; 238 240 } 239 241 } … … 255 257 Matrix<T> Matrix<T>::operator+(const Matrix &other) const 256 258 { 257 assert(m_Rows= other.m_Rows);258 assert(m_Cols= other.m_Cols);259 assert(m_Rows==other.m_Rows); 260 assert(m_Cols==other.m_Cols); 259 261 260 262 Matrix<T> ret(m_Rows,m_Cols); … … 272 274 Matrix<T> Matrix<T>::operator(const Matrix &other) const 273 275 { 274 assert(m_Rows= other.m_Rows);275 assert(m_Cols= other.m_Cols);276 assert(m_Rows==other.m_Rows); 277 assert(m_Cols==other.m_Cols); 276 278 277 279 Matrix<T> ret(m_Rows,m_Cols); … … 530 532 531 533 template<class T> 532 void Matrix<T>::Save(FILE* f) 534 void Matrix<T>::NormaliseRows() 535 { 536 for(unsigned int i=0; i<m_Rows; i++) 537 { 538 SetRowVector(i,GetRowVector(i).Normalised()); 539 } 540 } 541 542 template<class T> 543 void Matrix<T>::NormaliseCols() 544 { 545 for(unsigned int i=0; i<m_Cols; i++) 546 { 547 SetColVector(i,GetColVector(i).Normalised()); 548 } 549 } 550 551 template<class T> 552 void Matrix<T>::Save(FILE* f) const 533 553 { 534 554 int version = 1; … … 638 658 639 659 assert(j.Inverted()==k); 660 661 Matrix<float> l(2,2); 662 l[0][0]=3; 663 l[0][1]=3; 664 l[1][0]=0; 665 l[1][1]=0; 666 667 Matrix<float> n(2,2); 668 n[0][0]=2; 669 n[0][1]=2; 670 n[1][0]=0; 671 n[1][1]=0; 672 673 n*=l; 674 675 Matrix<float> o(4,4); 676 o.Zero(); 677 o[0][0]=1; 678 o[1][1]=1; 679 o[2][2]=1; 680 o[3][3]=1; 681 682 j*=k; 683 assert(j==o); 684 685 { 686 Matrix<float> a(2,3); 687 Matrix<float> b(3,2); 688 689 a[0][0]=1; a[0][1]=2; a[0][2]=3; 690 a[1][0]=4; a[1][1]=5; a[1][2]=6; 691 692 b[0][0]=2; b[0][1]=3; 693 b[1][0]=1; b[1][1]=1; 694 b[2][0]=1; b[2][1]=2; 695 696 Matrix<float> result(2,2); 697 result[0][0]=3; result[0][1]=11; 698 result[1][0]=9; result[1][1]=29; 699 700 assert(a*b==result); 701 } 702 640 703 } 641 704
Note: See TracChangeset
for help on using the changeset viewer.