internal_angles_intrinsic.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "internal_angles_intrinsic.h"
  2. #include "parallel_for.h"
  3. template <typename DerivedL, typename DerivedK>
  4. IGL_INLINE void igl::internal_angles_intrinsic(
  5. const Eigen::MatrixBase<DerivedL>& L_sq,
  6. Eigen::PlainObjectBase<DerivedK> & K)
  7. {
  8. typedef typename DerivedL::Index Index;
  9. assert(L_sq.cols() == 3 && "Edge-lengths should come from triangles");
  10. const Index m = L_sq.rows();
  11. K.resize(m,3);
  12. parallel_for(
  13. m,
  14. [&L_sq,&K](const Index f)
  15. {
  16. for(size_t d = 0;d<3;d++)
  17. {
  18. const auto & s1 = L_sq(f,d);
  19. const auto & s2 = L_sq(f,(d+1)%3);
  20. const auto & s3 = L_sq(f,(d+2)%3);
  21. using Scalar = typename DerivedK::Scalar;
  22. K(f,d) = std::acos((s3 + s2 - s1)/(Scalar(2)*std::sqrt(s3*s2)));
  23. //// See https://github.com/libigl/libigl/issues/1463
  24. //// Kahan's method
  25. //auto c = sqrt(L_sq(f,d));
  26. //auto a = sqrt(L_sq(f,(d+1)%3));
  27. //auto b = sqrt(L_sq(f,(d+2)%3));
  28. //// If necessary, swap a and b so that a ≥ b .
  29. //if(a<b){ std::swap(a,b); }
  30. //// Then perform two more comparisons to decide whether and how to
  31. //// compute an intermediate quantity µ thus:
  32. //using Scalar = typename DerivedK::Scalar;
  33. //Scalar mu;
  34. //if(b>=c && c>=0)
  35. //{
  36. // mu = c-(a-b);
  37. //}else if(c>b && b>=0)
  38. //{
  39. // mu = b-(a-c);
  40. //}else
  41. //{
  42. // // the data are not side–lengths of a real triangle
  43. // K(f,d) = std::numeric_limits<Scalar>::quiet_NaN();
  44. // continue;
  45. //}
  46. //// mu has been computed, attempt to compute angle
  47. //K(f,d) = 2.0*atan(sqrt(((a-b)+c)*mu/((a+(b+c))*((a-c)+b)) ));
  48. }
  49. },
  50. 1000l);
  51. }
  52. #ifdef IGL_STATIC_LIBRARY
  53. // Explicit template instantiation
  54. // generated by autoexplicit.sh
  55. template void igl::internal_angles_intrinsic<Eigen::Matrix<float, -1, 1, 0, -1, 1>, Eigen::Matrix<float, -1, -1, 0, -1, -1>>(Eigen::MatrixBase<Eigen::Matrix<float, -1, 1, 0, -1, 1>> const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&);
  56. // generated by autoexplicit.sh
  57. template void igl::internal_angles_intrinsic<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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&);
  58. // generated by autoexplicit.sh
  59. template void igl::internal_angles_intrinsic<Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1>>(Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>> const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&);
  60. // generated by autoexplicit.sh
  61. template void igl::internal_angles_intrinsic<Eigen::Matrix<float, -1, 3, 0, -1, 3>, Eigen::Matrix<float, -1, 3, 0, -1, 3>>(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 0, -1, 3>> const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 0, -1, 3>>&);
  62. // generated by autoexplicit.sh
  63. template void igl::internal_angles_intrinsic<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 3, 0, -1, 3>>(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3>>&);
  64. // generated by autoexplicit.sh
  65. template void igl::internal_angles_intrinsic<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>>(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3>> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3>>&);
  66. // generated by autoexplicit.sh
  67. template void igl::internal_angles_intrinsic<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1>>(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3>> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&);
  68. // generated by autoexplicit.sh
  69. template void igl::internal_angles_intrinsic<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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  70. template void igl::internal_angles_intrinsic<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::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  71. #endif