internal_angles.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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 "internal_angles.h"
  9. #include "edge_lengths.h"
  10. template <typename DerivedV, typename DerivedF, typename DerivedK>
  11. IGL_INLINE void igl::internal_angles(
  12. const Eigen::PlainObjectBase<DerivedV>& V,
  13. const Eigen::PlainObjectBase<DerivedF>& F,
  14. Eigen::PlainObjectBase<DerivedK> & K)
  15. {
  16. using namespace Eigen;
  17. // Edge lengths
  18. Matrix<
  19. typename DerivedV::Scalar,
  20. DerivedF::RowsAtCompileTime,
  21. DerivedF::ColsAtCompileTime> L;
  22. edge_lengths(V,F,L);
  23. assert(F.cols() == 3 && "F should contain triangles");
  24. return internal_angles(L,K);
  25. }
  26. template <typename DerivedL, typename DerivedK>
  27. IGL_INLINE void igl::internal_angles(
  28. const Eigen::PlainObjectBase<DerivedL>& L,
  29. Eigen::PlainObjectBase<DerivedK> & K)
  30. {
  31. assert(L.cols() == 3 && "Edge-lengths should come from triangles");
  32. K.resize(L.rows(),L.cols());
  33. for(int d = 0;d<3;d++)
  34. {
  35. const auto & s1 = L.col(d).array();
  36. const auto & s2 = L.col((d+1)%3).array();
  37. const auto & s3 = L.col((d+2)%3).array();
  38. K.col(d) = ((s3.square() + s2.square() - s1.square())/(2.*s3*s2)).acos();
  39. }
  40. }
  41. #ifdef IGL_STATIC_LIBRARY
  42. // Explicit template specialization
  43. template void igl::internal_angles<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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  44. template void igl::internal_angles<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  45. template void igl::internal_angles<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  46. #endif