diff --git a/vcg/math/lin_algebra.h b/vcg/math/lin_algebra.h index 6c7703d1..db2f4728 100644 --- a/vcg/math/lin_algebra.h +++ b/vcg/math/lin_algebra.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.11 2006/05/25 09:35:55 cignoni +added missing internal prototype to Sort function + Revision 1.10 2006/05/17 09:26:35 cignoni Added initial disclaimer @@ -41,11 +44,11 @@ namespace vcg /*! * */ - template< typename TYPE > - static void JacobiRotate(Matrix44 &A, TYPE s, TYPE tau, int i,int j,int k,int l) + template< typename MATRIX_TYPE > + static void JacobiRotate(MATRIX_TYPE &A, typename MATRIX_TYPE::ScalarType s, typename MATRIX_TYPE::ScalarType tau, int i,int j,int k,int l) { - TYPE g=A[i][j]; - TYPE h=A[k][l]; + MATRIX_TYPE::ScalarType g=A[i][j]; + MATRIX_TYPE::ScalarType h=A[k][l]; A[i][j]=g-s*(h+g*tau); A[k][l]=h+s*(g-h*tau); }; @@ -57,17 +60,20 @@ namespace vcg * \param v is a matrix whose columns contain, the normalized eigenvectors * \param nrot returns the number of Jacobi rotations that were required. */ - template - static void Jacobi(Matrix44 &w, Point4 &d, Matrix44 &v, int &nrot) + template + static void Jacobi(MATRIX_TYPE &w, POINT_TYPE &d, MATRIX_TYPE &v, int &nrot) { + assert(w.RowsNumber()==w.ColumnsNumber()); + int dimension = w.RowsNumber(); + int j,iq,ip,i; //assert(w.IsSymmetric()); - TYPE tresh, theta, tau, t, sm, s, h, g, c; - Point4 b, z; + MATRIX_TYPE::ScalarType tresh, theta, tau, t, sm, s, h, g, c; + POINT_TYPE b, z; v.SetIdentity(); - for (ip=0;ip<4;++ip) //Initialize b and d to the diagonal of a. + for (ip=0;ip(w,s,tau,j,ip,j,iq) ; + JacobiRotate(w,s,tau,j,ip,j,iq) ; } for (j=ip+1;j<=iq-1;j++) { //Case of rotations p < j < q. - JacobiRotate(w,s,tau,ip,j,j,iq); + JacobiRotate(w,s,tau,ip,j,j,iq); } - for (j=iq+1;j<4;j++) { //Case of rotations q< j <= n. - JacobiRotate(w,s,tau,ip,j,iq,j); + for (j=iq+1;j(w,s,tau,ip,j,iq,j); } - for (j=0;j<4;j++) { - JacobiRotate(v,s,tau,j,ip,j,iq); + for (j=0;j(v,s,tau,j,ip,j,iq); } ++nrot; } } } - for (ip=0;ip<4;ip++) + for (ip=0;ip + void SortEigenvaluesAndEigenvectors(POINT_TYPE &eigenvalues, MATRIX_TYPE &eigenvectors) + { + assert(eigenvectors.ColumnsNumber()==eigenvectors.RowsNumber()); + int dimension = eigenvectors.ColumnsNumber(); + int i, j, k; + float p; + for (i=0; i= p) + p = eigenvalues[ k=j ]; + + if (k != i) + { + eigenvalues[k] = eigenvalues[i]; // i.e. + eigenvalues[i] = p; // swaps the value of the elements i-th and k-th + + for (j=0; j