From e587581275a333a3691ad5d3324917194aba34d1 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Wed, 29 Oct 2008 11:17:11 +0000 Subject: [PATCH] add transposeInPlace and duplicate V(int) --- apps/ptx2ply/ptx2ply.cpp | 2 +- vcg/complex/trimesh/update/curvature.h | 2 +- vcg/math/deprecated_matrix.h | 3 +-- vcg/math/deprecated_matrix33.h | 3 +-- vcg/math/deprecated_matrix44.h | 3 +-- vcg/math/eigen_matrix_addons.h | 5 ++++- vcg/math/eigen_matrixbase_addons.h | 7 ++++++- vcg/space/line2.h | 4 ++-- vcg/space/point.h | 2 +- wrap/gl/deprecated_math.h | 8 ++++---- wrap/gui/view.h | 11 ++++------- wrap/io_trimesh/import_ptx.h | 2 +- 12 files changed, 27 insertions(+), 25 deletions(-) diff --git a/apps/ptx2ply/ptx2ply.cpp b/apps/ptx2ply/ptx2ply.cpp index 9bffdc9b..2af14372 100644 --- a/apps/ptx2ply/ptx2ply.cpp +++ b/apps/ptx2ply/ptx2ply.cpp @@ -464,7 +464,7 @@ int readmesh(FILE* fp) } } - currtrasf = currtrasf.transpose().eval(); + currtrasf.transposeInPlace(); // apply tranformation if(hascolor && savecolor) diff --git a/vcg/complex/trimesh/update/curvature.h b/vcg/complex/trimesh/update/curvature.h index 471c884c..011eb8db 100644 --- a/vcg/complex/trimesh/update/curvature.h +++ b/vcg/complex/trimesh/update/curvature.h @@ -641,7 +641,7 @@ public: int n_rot; Jacobi(m33,lambda, vect,n_rot); - vect = vect.transpose().eval(); + vect.transposeInPlace(); ScalarType normal = std::numeric_limits::min(); int normI = 0; for(int i = 0; i < 3; ++i) diff --git a/vcg/math/deprecated_matrix.h b/vcg/math/deprecated_matrix.h index b799fba5..3273170b 100644 --- a/vcg/math/deprecated_matrix.h +++ b/vcg/math/deprecated_matrix.h @@ -728,9 +728,8 @@ namespace vcg{ res.Transpose(); return res; } + void transposeInPlace() { Transpose(); } // for the transistion to eigen - const Matrix& eval() { return *this; } - /*! * Print all matrix elements diff --git a/vcg/math/deprecated_matrix33.h b/vcg/math/deprecated_matrix33.h index 77e6576f..c67663e5 100644 --- a/vcg/math/deprecated_matrix33.h +++ b/vcg/math/deprecated_matrix33.h @@ -403,8 +403,7 @@ public: res.Transpose(); return res; } - // for the transistion to eigen - const Matrix33& eval() { return *this; } + void transposeInPlace() { this->Transpose(); } /// Funzione per costruire una matrice diagonale dati i tre elem. Matrix33 & SetDiagonal(S *v) diff --git a/vcg/math/deprecated_matrix44.h b/vcg/math/deprecated_matrix44.h index 2fc6b10d..28edbfc0 100644 --- a/vcg/math/deprecated_matrix44.h +++ b/vcg/math/deprecated_matrix44.h @@ -289,8 +289,7 @@ public: Transpose(res); return res; } - // for the transistion to eigen - const Matrix44& eval() { return *this; } + void transposeInPlace() { Transpose(*this); } void print() { unsigned int i, j, p; diff --git a/vcg/math/eigen_matrix_addons.h b/vcg/math/eigen_matrix_addons.h index 7d38e860..c04e5215 100644 --- a/vcg/math/eigen_matrix_addons.h +++ b/vcg/math/eigen_matrix_addons.h @@ -27,7 +27,7 @@ enum {Dimension = SizeAtCompileTime}; typedef typename ei_to_vcgtype::type EquivVcgType; typedef vcg::VoidType ParamType; typedef Matrix PointType; -using Base::V; +// using Base::V; // automatic conversion to similar vcg types // the otherway round is implicit because they inherits this Matrix tyoe @@ -78,6 +78,9 @@ inline Scalar& W() { return data()[SizeAtCompileTime-1]; } /** note, W always returns the last entry */ inline const Scalar& W() const { return data()[SizeAtCompileTime-1]; } +EIGEN_DEPRECATED inline Scalar V(int i) const { return (*this)[i]; }; +EIGEN_DEPRECATED inline Scalar& V(int i) { return (*this)[i]; }; + /** \deprecated use .data() */ EIGEN_DEPRECATED Scalar* V() { return data(); } /** \deprecated use .data() */ diff --git a/vcg/math/eigen_matrixbase_addons.h b/vcg/math/eigen_matrixbase_addons.h index b2e4dbe5..68e47e13 100644 --- a/vcg/math/eigen_matrixbase_addons.h +++ b/vcg/math/eigen_matrixbase_addons.h @@ -186,15 +186,20 @@ EIGEN_DEPRECATED void Dump() printf("\n"); } +// norm2 will be renamed squaredNorm() in Eigen +inline Scalar squaredNorm() const { return norm2(); }; + /** \deprecated use norm() */ EIGEN_DEPRECATED inline Scalar Norm() const { return norm(); }; /** \deprecated use squaredNorm() */ -EIGEN_DEPRECATED inline Scalar SquaredNorm() const { return norm2(); }; +EIGEN_DEPRECATED inline Scalar SquaredNorm() const { return squaredNorm(); }; /** \deprecated use normalize() or normalized() */ EIGEN_DEPRECATED inline Derived& Normalize() { normalize(); return derived(); }; /** \deprecated use normalized() */ EIGEN_DEPRECATED inline const EvalType Normalize() const { return normalized(); }; +inline void transposeInPlace() { derived() = derived().transpose().eval(); } + /** \deprecated use .cross(p) */ EIGEN_DEPRECATED inline EvalType operator ^ (const Derived& p ) const { return this->cross(p); } diff --git a/vcg/space/line2.h b/vcg/space/line2.h index c756ef63..e64364a1 100644 --- a/vcg/space/line2.h +++ b/vcg/space/line2.h @@ -105,8 +105,8 @@ public: { return _ori!=p._ori || _dir!=p._dir; } /// Projects a point on the line inline ScalarType Projection( const PointType &p ) const - { if (NORM) return ScalarType((p-_ori)*_dir); - else return ScalarType((p-_ori)*_dir/_dir.SquaredNorm()); + { if (NORM) return ScalarType((p-_ori).dot(_dir)); + else return ScalarType((p-_ori).dot(_dir)/_dir.SquaredNorm()); } /// returns wheter this type is normalized or not static bool IsNormalized() {return NORM;}; diff --git a/vcg/space/point.h b/vcg/space/point.h index b62d2045..0d63595e 100644 --- a/vcg/space/point.h +++ b/vcg/space/point.h @@ -32,7 +32,7 @@ #include #include -namespace vcg{ +namespace vcg { template class Point2; template class Point3; template class Point4; diff --git a/wrap/gl/deprecated_math.h b/wrap/gl/deprecated_math.h index b90998ab..1312d7a6 100644 --- a/wrap/gl/deprecated_math.h +++ b/wrap/gl/deprecated_math.h @@ -74,22 +74,22 @@ inline void glMultMatrixE(const Matrix44f &matrix) { //glMultMatrixf((const GLfloat *)(matrix[0])); if(glMultTransposeMatrixf) glMultTransposeMatrixf((const GLfloat *)(matrix.V())); else { - glMultMatrixf((const GLfloat *)(matrix.transpose().eval().V())); + glMultMatrixf((const GLfloat *)(matrix.transpose().V())); } } inline void glMultMatrix(const Matrix44f &matrix) { - glMultMatrixf((const GLfloat *)(matrix.transpose().eval().V())); + glMultMatrixf((const GLfloat *)(matrix.transpose().V())); } inline void glMultMatrixE(const Matrix44d &matrix) { if(glMultTransposeMatrixd) glMultTransposeMatrixd((const GLdouble *)(matrix.V())); else { - glMultMatrixd((const GLdouble *)(matrix.transpose().eval().V())); + glMultMatrixd((const GLdouble *)(matrix.transpose().V())); } } inline void glMultMatrix(const Matrix44d &matrix) { - glMultMatrixd((const GLdouble *)(matrix.transpose().eval().V())); + glMultMatrixd((const GLdouble *)(matrix.transpose().V())); } inline void glMultMatrixDirect(const Matrix44f &matrix) { diff --git a/wrap/gui/view.h b/wrap/gui/view.h index 75794387..ceb3e6c9 100644 --- a/wrap/gui/view.h +++ b/wrap/gui/view.h @@ -84,6 +84,7 @@ y is upward! #include #include #include +#include #ifdef WIN32 #include @@ -148,13 +149,9 @@ template void View::GetView() { // Use standard routines, and transpose manually. // some 10^-20 seconds slower, but a lot safer - - glGetDoublev(GL_PROJECTION_MATRIX, m); - proj.Import(Matrix44d(m)); - proj = proj.transpose().eval(); - glGetDoublev(GL_MODELVIEW_MATRIX, m); - model.Import(Matrix44d(m)); - model = model.transpose().eval(); + + glGetv(GL_PROJECTION_MATRIX,proj); + glGetv(GL_MODELVIEW_MATRIX,model); glGetIntegerv(GL_VIEWPORT, (GLint*)viewport); diff --git a/wrap/io_trimesh/import_ptx.h b/wrap/io_trimesh/import_ptx.h index 1baeee2e..3a5ab0ad 100644 --- a/wrap/io_trimesh/import_ptx.h +++ b/wrap/io_trimesh/import_ptx.h @@ -230,7 +230,7 @@ namespace io { else return false; // PTX transformation matrix is transposed - currtrasf = currtrasf.transpose().eval(); + currtrasf.transposeInPlace(); // allocating vertex space int vn = rownum*colnum;