/**************************************************************************** * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * * Copyright(C) 2004-2016 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * * All rights reserved. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * for more details. * * * ****************************************************************************/ #ifndef VCG_USE_EIGEN #include "deprecated_matrix.h" #else #ifndef MATRIX_VCGLIB #define MATRIX_VCGLIB #include "eigen.h" #include namespace vcg{ namespace ndim{ template class Matrix; } } namespace Eigen{ template struct ei_traits > : ei_traits > {}; template struct ei_to_vcgtype { typedef vcg::ndim::Matrix type; }; } namespace vcg{ namespace ndim{ /** \addtogroup math */ /* @{ */ /*! * \deprecated use Matrix or Matrix or any typedef * This class represent a generic mn matrix. The class is templated over the scalar type field. * @param Scalar (Templete Parameter) Specifies the ScalarType field. */ template class Matrix : public Eigen::Matrix<_Scalar,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> // FIXME col or row major ? { typedef Eigen::Matrix<_Scalar,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> _Base; public: _EIGEN_GENERIC_PUBLIC_INTERFACE(Matrix,_Base); typedef _Scalar ScalarType; VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Matrix) /*! * Default constructor * All the elements are initialized to zero. * \param m the number of matrix rows * \param n the number of matrix columns */ Matrix(int m, int n) : Base(m,n) { memset(Base::data(), 0, m*n*sizeof(Scalar)); } /*! * Constructor * The matrix elements are initialized with the values of the elements in \i values. * \param m the number of matrix rows * \param n the number of matrix columns * \param values the values of the matrix elements */ Matrix(int m, int n, Scalar *values) : Base(m,n) { *this = Eigen::Map >(values, m , n); } /*! * Empty constructor * Just create the object */ Matrix() : Base() {} /*! * Copy constructor * The matrix elements are initialized with the value of the corresponding element in \i m * \param m the matrix to be copied */ Matrix(const Matrix &m) : Base(m) {} template Matrix(const Eigen::MatrixBase &m) : Base(m) {} /*! * Default destructor */ ~Matrix() {} /*! * \deprecated use *this.row(i) * Subscript operator: * \param i the index of the row * \return a reference to the i-th matrix row */ inline typename Base::RowXpr operator[](const unsigned int i) { return Base::row(i); } /*! * \deprecated use *this.row(i) * Const subscript operator * \param i the index of the row * \return a reference to the i-th matrix row */ inline const typename Base::RowXpr operator[](const unsigned int i) const { return Base::row(i); } /*! * Matrix multiplication: calculates the cross product. * \param reference to the matrix to multiply by * \return the matrix product */ // FIXME what the hell is that ! /*template void DotProduct(Point &m,Point &result) { unsigned int i, j, p, r; for (i=0, p=0, r=0; i=2); assert(n>=2); Base::resize(m,n); memset(Base::data(), 0, m*n*sizeof(Scalar)); }; }; typedef vcg::ndim::Matrix MatrixMNd; typedef vcg::ndim::Matrix MatrixMNf; /*! @} */ template void Invert(MatrixType & m) { m = m.inverse(); } } } // end of namespace #endif #endif