null.cpp 1.3 KB

12345678910111213141516171819202122232425
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "null.h"
  9. #include "EPS.h"
  10. template <typename DerivedA, typename DerivedN>
  11. IGL_INLINE void igl::null(
  12. const Eigen::MatrixBase<DerivedA> & A,
  13. Eigen::PlainObjectBase<DerivedN> & N)
  14. {
  15. typedef typename DerivedA::Scalar Scalar;
  16. Eigen::JacobiSVD<Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic> > svd(A, Eigen::ComputeFullV);
  17. svd.setThreshold(A.cols() * svd.singularValues().maxCoeff() * EPS<Scalar>());
  18. N = svd.matrixV().rightCols(A.cols()-svd.rank());
  19. }
  20. #ifdef IGL_STATIC_LIBRARY
  21. template void igl::null<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  22. template void igl::null<Eigen::Matrix<float, 1, 3, 1, 1, 3>, Eigen::Matrix<float, 3, 2, 0, 3, 2> >(Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 2, 0, 3, 2> >&);
  23. #endif