local_basis.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 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 "local_basis.h"
  9. #include <sstream>
  10. #include <string>
  11. #include <fstream>
  12. #include <vector>
  13. #include <Eigen/Geometry>
  14. template <
  15. typename DerivedV,
  16. typename DerivedF,
  17. typename DerivedB1,
  18. typename DerivedB2,
  19. typename DerivedB3>
  20. IGL_INLINE void igl::local_basis(
  21. const Eigen::MatrixBase<DerivedV>& V,
  22. const Eigen::MatrixBase<DerivedF>& F,
  23. Eigen::PlainObjectBase<DerivedB1>& B1,
  24. Eigen::PlainObjectBase<DerivedB2>& B2,
  25. Eigen::PlainObjectBase<DerivedB3>& B3)
  26. {
  27. assert(V.cols() == 3);
  28. B1.resize(F.rows(),3);
  29. B2.resize(F.rows(),3);
  30. B3.resize(F.rows(),3);
  31. for (unsigned i=0;i<F.rows();++i)
  32. {
  33. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v1 = (V.row(F(i,1)) - V.row(F(i,0))).normalized();
  34. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> t = V.row(F(i,2)) - V.row(F(i,0));
  35. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v3 = v1.cross(t).normalized();
  36. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v2 = v1.cross(v3).normalized();
  37. B1.row(i) = v1;
  38. B2.row(i) = -v2;
  39. B3.row(i) = v3;
  40. }
  41. }
  42. #ifdef IGL_STATIC_LIBRARY
  43. // Explicit template instantiation
  44. template void igl::local_basis<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>> const&, Eigen::MatrixBase<Eigen::Matrix<int, -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>>&);
  45. #endif