face_areas.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "face_areas.h"
  9. #include "edge_lengths.h"
  10. #include "doublearea.h"
  11. template <typename DerivedV, typename DerivedT, typename DerivedA>
  12. IGL_INLINE void igl::face_areas(
  13. const Eigen::MatrixBase<DerivedV>& V,
  14. const Eigen::MatrixBase<DerivedT>& T,
  15. Eigen::PlainObjectBase<DerivedA>& A)
  16. {
  17. assert(T.cols() == 4);
  18. DerivedA L;
  19. edge_lengths(V,T,L);
  20. return face_areas(L,A);
  21. }
  22. template <typename DerivedL, typename DerivedA>
  23. IGL_INLINE void igl::face_areas(
  24. const Eigen::MatrixBase<DerivedL>& L,
  25. Eigen::PlainObjectBase<DerivedA>& A)
  26. {
  27. return face_areas(L,0./0.,A);
  28. }
  29. template <typename DerivedL, typename DerivedA>
  30. IGL_INLINE void igl::face_areas(
  31. const Eigen::MatrixBase<DerivedL>& L,
  32. const typename DerivedL::Scalar doublearea_nan_replacement,
  33. Eigen::PlainObjectBase<DerivedA>& A)
  34. {
  35. using namespace Eigen;
  36. assert(L.cols() == 6);
  37. const int m = L.rows();
  38. // (unsigned) face Areas (opposite vertices: 1 2 3 4)
  39. Matrix<typename DerivedA::Scalar,Dynamic,1>
  40. A0(m,1), A1(m,1), A2(m,1), A3(m,1);
  41. Matrix<typename DerivedA::Scalar,Dynamic,3>
  42. L0(m,3), L1(m,3), L2(m,3), L3(m,3);
  43. L0<<L.col(1),L.col(2),L.col(3);
  44. L1<<L.col(0),L.col(2),L.col(4);
  45. L2<<L.col(0),L.col(1),L.col(5);
  46. L3<<L.col(3),L.col(4),L.col(5);
  47. doublearea(L0,A0);
  48. doublearea(L1,A1);
  49. doublearea(L2,A2);
  50. doublearea(L3,A3);
  51. A.resize(m,4);
  52. A.col(0) = 0.5*A0;
  53. A.col(1) = 0.5*A1;
  54. A.col(2) = 0.5*A2;
  55. A.col(3) = 0.5*A3;
  56. }
  57. #ifdef IGL_STATIC_LIBRARY
  58. // Explicit template specialization
  59. // generated by autoexplicit.sh
  60. template void igl::face_areas<Eigen::Matrix<double, -1, 6, 0, -1, 6>, Eigen::Matrix<double, -1, 4, 0, -1, 4> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 6, 0, -1, 6> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 4, 0, -1, 4> >&);
  61. #endif