// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2013 Alec Jacobson // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #include "polar_svd.h" #include #include #include // Adapted from Olga's CGAL mentee's ARAP code template < typename DerivedA, typename DerivedR, typename DerivedT> IGL_INLINE void igl::polar_svd( const Eigen::MatrixBase & A, const bool includeReflections, Eigen::PlainObjectBase & R, Eigen::PlainObjectBase & T) { typedef Eigen::Matrix MatA; MatA U; MatA V; Eigen::Matrix S; return igl::polar_svd(A,includeReflections,R,T,U,S,V); } template < typename DerivedA, typename DerivedR, typename DerivedT, typename DerivedU, typename DerivedS, typename DerivedV> IGL_INLINE void igl::polar_svd( const Eigen::MatrixBase & A, const bool includeReflections, Eigen::PlainObjectBase & R, Eigen::PlainObjectBase & T, Eigen::PlainObjectBase & U, Eigen::PlainObjectBase & S, Eigen::PlainObjectBase & V) { using namespace std; typedef Eigen::Matrix MatA; Eigen::JacobiSVD svd; svd.compute(A, Eigen::ComputeFullU | Eigen::ComputeFullV ); U = svd.matrixU(); V = svd.matrixV(); S = svd.singularValues(); R = U*V.transpose(); const auto & SVT = S.asDiagonal() * V.adjoint(); // Check for reflection if(!includeReflections && R.determinant() < 0) { // Annoyingly the .eval() is necessary auto W = V.eval(); W.col(V.cols()-1) *= -1.; R = U*W.transpose(); T = W*SVT; }else { T = V*SVT; } } template < typename DerivedA, typename DerivedR, typename DerivedT, typename DerivedU, typename DerivedS, typename DerivedV> IGL_INLINE void igl::polar_svd( const Eigen::MatrixBase & A, Eigen::PlainObjectBase & R, Eigen::PlainObjectBase & T, Eigen::PlainObjectBase & U, Eigen::PlainObjectBase & S, Eigen::PlainObjectBase & V) { return igl::polar_svd(A,false,R,T,U,S,V); } /// \overload template < typename DerivedA, typename DerivedR, typename DerivedT> IGL_INLINE void igl::polar_svd( const Eigen::MatrixBase & A, Eigen::PlainObjectBase & R, Eigen::PlainObjectBase & T) { return igl::polar_svd(A,false,R,T); } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation template void igl::polar_svd >, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix,Eigen::Matrix >(Eigen::MatrixBase > const &,Eigen::PlainObjectBase > &,Eigen::PlainObjectBase > &,Eigen::PlainObjectBase > &,Eigen::PlainObjectBase > &,Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::polar_svd, Eigen::Matrix, Eigen::Matrix >(Eigen::MatrixBase > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif