face_areas.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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::PlainObjectBase<DerivedV>& V,
  14. const Eigen::PlainObjectBase<DerivedT>& T,
  15. Eigen::PlainObjectBase<DerivedA>& A)
  16. {
  17. assert(T.cols() == 4);
  18. typename Eigen::PlainObjectBase<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::PlainObjectBase<DerivedL>& L,
  25. Eigen::PlainObjectBase<DerivedA>& A)
  26. {
  27. using namespace Eigen;
  28. assert(L.cols() == 6);
  29. const int m = L.rows();
  30. // (unsigned) face Areas (opposite vertices: 1 2 3 4)
  31. Matrix<typename DerivedA::Scalar,Dynamic,1>
  32. A0(m,1), A1(m,1), A2(m,1), A3(m,1);
  33. Matrix<typename DerivedA::Scalar,Dynamic,3>
  34. L0(m,3), L1(m,3), L2(m,3), L3(m,3);
  35. L0<<L.col(1),L.col(2),L.col(3);
  36. L1<<L.col(0),L.col(2),L.col(4);
  37. L2<<L.col(0),L.col(1),L.col(5);
  38. L3<<L.col(3),L.col(4),L.col(5);
  39. doublearea(L0,A0);
  40. doublearea(L1,A1);
  41. doublearea(L2,A2);
  42. doublearea(L3,A3);
  43. A.resize(m,4);
  44. A.col(0) = 0.5*A0;
  45. A.col(1) = 0.5*A1;
  46. A.col(2) = 0.5*A2;
  47. A.col(3) = 0.5*A3;
  48. }
  49. #ifdef IGL_STATIC_LIBRARY
  50. // Explicit template specialization
  51. // generated by autoexplicit.sh
  52. template void igl::face_areas<Eigen::Matrix<double, -1, 6, 0, -1, 6>, Eigen::Matrix<double, -1, 4, 0, -1, 4> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 6, 0, -1, 6> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 4, 0, -1, 4> >&);
  53. #endif