polar_svd.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "polar_svd.h"
  2. #include <Eigen/SVD>
  3. // Adapted from Olga's CGAL mentee's ARAP code
  4. template <
  5. typename DerivedA,
  6. typename DerivedR,
  7. typename DerivedT>
  8. IGL_INLINE void igl::polar_svd(
  9. const Eigen::PlainObjectBase<DerivedA> & A,
  10. Eigen::PlainObjectBase<DerivedR> & R,
  11. Eigen::PlainObjectBase<DerivedT> & T)
  12. {
  13. Eigen::PlainObjectBase<DerivedA> U;
  14. Eigen::PlainObjectBase<DerivedA> V;
  15. Eigen::Matrix<typename DerivedA::Scalar,DerivedA::RowsAtCompileTime,1> S;
  16. return igl::polar_svd(A,R,T,U,S,V);
  17. }
  18. template <
  19. typename DerivedA,
  20. typename DerivedR,
  21. typename DerivedT,
  22. typename DerivedU,
  23. typename DerivedS,
  24. typename DerivedV>
  25. IGL_INLINE void igl::polar_svd(
  26. const Eigen::PlainObjectBase<DerivedA> & A,
  27. Eigen::PlainObjectBase<DerivedR> & R,
  28. Eigen::PlainObjectBase<DerivedT> & T,
  29. Eigen::PlainObjectBase<DerivedU> & U,
  30. Eigen::PlainObjectBase<DerivedS> & S,
  31. Eigen::PlainObjectBase<DerivedV> & V)
  32. {
  33. Eigen::JacobiSVD<DerivedA> svd;
  34. svd.compute(A, Eigen::ComputeFullU | Eigen::ComputeFullV );
  35. U = svd.matrixU();
  36. V = svd.matrixV();
  37. S = svd.singularValues();
  38. R = U*V.transpose();
  39. T = V*S.asDiagonal()*V.adjoint();
  40. }
  41. #ifndef IGL_HEADER_ONLY
  42. // Explicit template instanciation
  43. template void igl::polar_svd<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  44. template void igl::polar_svd<Eigen::Matrix<double, 2, 2, 0, 2, 2>, Eigen::Matrix<double, 2, 2, 0, 2, 2>, Eigen::Matrix<double, 2, 2, 0, 2, 2> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 2, 2, 0, 2, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 2, 2, 0, 2, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, 2, 2, 0, 2, 2> >&);
  45. template void igl::polar_svd<Eigen::Matrix<double, 3, 3, 0, 3, 3>, Eigen::Matrix<double, 3, 3, 0, 3, 3>, Eigen::Matrix<double, 3, 3, 0, 3, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 3, 0, 3, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 3, 0, 3, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 3, 0, 3, 3> >&);
  46. #endif