internal_angles.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include "get_seconds.h"
  11. template <typename DerivedV, typename DerivedF, typename DerivedK>
  12. IGL_INLINE void igl::internal_angles(
  13. const Eigen::PlainObjectBase<DerivedV>& V,
  14. const Eigen::PlainObjectBase<DerivedF>& F,
  15. Eigen::PlainObjectBase<DerivedK> & K)
  16. {
  17. using namespace Eigen;
  18. using namespace std;
  19. // Edge lengths
  20. Matrix<
  21. typename DerivedV::Scalar,
  22. DerivedF::RowsAtCompileTime,
  23. DerivedF::ColsAtCompileTime> L;
  24. edge_lengths(V,F,L);
  25. assert(F.cols() == 3 && "F should contain triangles");
  26. internal_angles(L,K);
  27. }
  28. template <typename DerivedL, typename DerivedK>
  29. IGL_INLINE void igl::internal_angles(
  30. const Eigen::PlainObjectBase<DerivedL>& L,
  31. Eigen::PlainObjectBase<DerivedK> & K)
  32. {
  33. assert(L.cols() == 3 && "Edge-lengths should come from triangles");
  34. const size_t m = L.rows();
  35. K.resize(m,3);
  36. //for(int d = 0;d<3;d++)
  37. //{
  38. // const auto & s1 = L.col(d).array();
  39. // const auto & s2 = L.col((d+1)%3).array();
  40. // const auto & s3 = L.col((d+2)%3).array();
  41. // K.col(d) = ((s3.square() + s2.square() - s1.square())/(2.*s3*s2)).acos();
  42. //}
  43. // Minimum number of iterms per openmp thread
  44. #ifndef IGL_OMP_MIN_VALUE
  45. # define IGL_OMP_MIN_VALUE 1000
  46. #endif
  47. #pragma omp parallel for if (m>IGL_OMP_MIN_VALUE)
  48. for(size_t f = 0;f<m;f++)
  49. {
  50. for(size_t d = 0;d<3;d++)
  51. {
  52. const auto & s1 = L(f,d);
  53. const auto & s2 = L(f,(d+1)%3);
  54. const auto & s3 = L(f,(d+2)%3);
  55. K(f,d) = acos((s3*s3 + s2*s2 - s1*s1)/(2.*s3*s2));
  56. }
  57. }
  58. }
  59. #ifdef IGL_STATIC_LIBRARY
  60. // Explicit template specialization
  61. 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> >&);
  62. 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> >&);
  63. 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> >&);
  64. #endif