Changeset 96 for foam/trunk/vision/src/Matrix.h
 Timestamp:
 07/29/2009 03:49:34 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

foam/trunk/vision/src/Matrix.h
r90 r96 100 100 bool IsInf(); 101 101 Matrix Transposed() const; 102 Matrix Inverted() const; 102 103 103 104 Matrix &operator=(const Matrix &other); … … 110 111 Matrix &operator=(const Matrix &other); 111 112 Matrix &operator*=(const Matrix &other); 113 bool operator==(const Matrix &other) const; 112 114 113 115 void SortRows(Vector<T> &v); … … 239 241 } 240 242 243 void matrix_inverse(const float *Min, float *Mout, int actualsize); 244 245 template<class T> 246 Matrix<T> Matrix<T>::Inverted() const 247 { 248 assert(m_Rows==m_Cols); // only works for square matrices 249 Matrix<T> ret(m_Rows,m_Cols); 250 matrix_inverse(GetRawDataConst(),ret.GetRawData(),m_Rows); 251 return ret; 252 } 241 253 242 254 template<class T> … … 358 370 } 359 371 372 template<class T> 373 bool Matrix<T>::operator==(const Matrix &other) const 374 { 375 if (m_Rows != other.m_Rows  376 m_Cols != other.m_Cols) 377 { 378 return false; 379 } 380 381 for (unsigned int i=0; i<m_Cols; i++) 382 { 383 for (unsigned int j=0; j<m_Rows; j++) 384 { 385 if (!feq((*this)[i][j],other[i][j])) return false; 386 } 387 } 388 389 return true; 390 } 360 391 361 392 //todo: use memcpy for these 4 functions … … 553 584 Matrix<T> g=a.CropRows(0,1); 554 585 assert(g.GetRows()==1 && g.GetCols()==3 && g[0][0]==1); 555 586 587 // test matrix invert 588 Matrix<T> h(3,3); 589 h.Zero(); 590 h[0][0]=1; 591 h[1][1]=1; 592 h[2][2]=1; 593 Matrix<T> i=h.Inverted(); 594 i==h; 595 596 // some transforms from fluxus 597 Matrix<T> j(4,4); 598 j[0][0]=1.0; 599 j[0][1]=0.0 ; 600 j[0][2]=0.0; 601 j[0][3]=0.0; 602 603 j[1][0]=0.0 ; 604 j[1][1]=0.7071067690849304 ; 605 j[1][2]=0.7071067690849304 ; 606 j[1][3]=0.0 ; 607 608 j[2][0]=0.0 ; 609 j[2][1]=0.7071067690849304 ; 610 j[2][2]=0.7071067690849304 ; 611 j[2][3]=0.0 ; 612 613 j[3][0]=1.0 ; 614 j[3][1]=2.0 ; 615 j[3][2]=3.0 ; 616 j[3][3]=1.0 ; 617 618 Matrix<T> k(4,4); 619 k[0][0]=1.0 ; 620 k[0][1]=0.0 ; 621 k[0][2]=0.0 ; 622 k[0][3]=0.0 ; 623 624 k[1][0]=0.0 ; 625 k[1][1]=0.7071068286895752 ; 626 k[1][2]=0.7071068286895752 ; 627 k[1][3]=0.0 ; 628 629 k[2][0]=0.0 ; 630 k[2][1]=0.7071068286895752 ; 631 k[2][2]=0.7071068286895752 ; 632 k[2][3]=0.0 ; 633 634 k[3][0]=0.9999999403953552 ; 635 k[3][1]=3.535533905029297 ; 636 k[3][2]=0.7071067690849304 ; 637 k[3][3]=0.9999999403953552 ; 638 639 assert(j.Inverted()==k); 556 640 } 557 641
Note: See TracChangeset
for help on using the changeset viewer.