local_basis.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com>
  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 "local_basis.h"
  9. #include <sstream>
  10. #include <string>
  11. #include <fstream>
  12. #include <vector>
  13. #include <Eigen/Geometry>
  14. template <typename DerivedV, typename DerivedF>
  15. IGL_INLINE void igl::local_basis(
  16. const Eigen::PlainObjectBase<DerivedV>& V,
  17. const Eigen::PlainObjectBase<DerivedF>& F,
  18. Eigen::PlainObjectBase<DerivedV>& B1,
  19. Eigen::PlainObjectBase<DerivedV>& B2,
  20. Eigen::PlainObjectBase<DerivedV>& B3
  21. )
  22. {
  23. using namespace Eigen;
  24. using namespace std;
  25. B1.resize(F.rows(),3);
  26. B2.resize(F.rows(),3);
  27. B3.resize(F.rows(),3);
  28. for (unsigned i=0;i<F.rows();++i)
  29. {
  30. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v1 = (V.row(F(i,1)) - V.row(F(i,0))).normalized();
  31. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> t = V.row(F(i,2)) - V.row(F(i,0));
  32. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v3 = v1.cross(t).normalized();
  33. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v2 = v1.cross(v3).normalized();
  34. B1.row(i) = v1;
  35. B2.row(i) = -v2;
  36. B3.row(i) = v3;
  37. }
  38. }
  39. #ifndef IGL_HEADER_ONLY
  40. // Explicit template specialization
  41. // generated by autoexplicit.sh
  42. #endif