From 7229c77576ed30e73dfb88eda29b44f3535ae7ab Mon Sep 17 00:00:00 2001 From: ganovelli Date: Mon, 12 Dec 2005 11:25:00 +0000 Subject: [PATCH] added diagonal matrix, outer produce and namespace --- vcg/math/matrix.h | 98 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/vcg/math/matrix.h b/vcg/math/matrix.h index 9aa2dd0b..d24333c7 100644 --- a/vcg/math/matrix.h +++ b/vcg/math/matrix.h @@ -20,19 +20,41 @@ * for more details. * * * ****************************************************************************/ +/*************************************************************************** +$Log: not supported by cvs2svn $ +***************************************************************************/ + +#ifndef MATRIX_VCGLIB +#define MATRIX_VCGLIB #include #include #include #include #include +#include +namespace vcg{ + namespace ndim{ -namespace vcg -{ /** \addtogroup math */ /* @{ */ + /*! + * This class represent a diagonal m×m matrix. + */ + + class MatrixDiagBase{public: + virtual const int & Dimension()const =0; + virtual const float operator[](const int & i)const = 0; + }; + template + class MatrixDiag: public PointBase, public MatrixDiagBase{ + public: + const int & Dimension() const {return N;} + MatrixDiag(const PointBase&p):PointBase(p){} + }; + /*! * This class represent a generic m×n matrix. The class is templated over the scalar type field. * @param TYPE (Templete Parameter) Specifies the ScalarType field. @@ -391,13 +413,61 @@ namespace vcg return result; }; + /*! + * Matrix multiplication: calculates the cross product. + * \param reference to the matrix to multiply by + * \return the matrix product + */ + template + void DotProduct(PointBase &m,PointBase &result) + { + unsigned int i, j, p, r; + for (i=0, p=0, r=0; i operator*(const MatrixDiagBase &m) + { + assert(_columns == _rows); + assert(_columns == m.Dimension()); + int i,j; + Matrix result(_rows, _columns); + + for (i=0; i + void OuterProduct(const PointBase a, const PointBase< M,TYPE> b) + { + assert(N == _rows); + assert(M == _columns); + Matrix result(_rows,_columns); + unsigned int i, j; + + for (i=0; i operator*(const vcg::Point3 &p) + vcg::ndim::Point3 operator*(const vcg::ndim::Point3 &p) { assert(_columns==3 && _rows==3); vcg::Point3 result; @@ -583,4 +653,24 @@ namespace vcg }; /*! @} */ -}; // end of namespace \ No newline at end of file + + template + void Invert(MatrixType & m){ + typename MatrixType::ScalarType *diag; + diag = new MatrixType::ScalarType [m.ColumnsNumber()]; + + MatrixType res(m.RowsNumber(),m.ColumnsNumber()); + vcg::SingularValueDecomposition (m,&diag[0],res,50 ); + m.Transpose(); + // prodotto per la diagonale + unsigned int i,j; + for (i=0; i