face_areas.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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(
  28. L,std::numeric_limits<typename DerivedL::Scalar>::quiet_NaN(),A);
  29. }
  30. template <typename DerivedL, typename DerivedA>
  31. IGL_INLINE void igl::face_areas(
  32. const Eigen::MatrixBase<DerivedL>& L,
  33. const typename DerivedL::Scalar doublearea_nan_replacement,
  34. Eigen::PlainObjectBase<DerivedA>& A)
  35. {
  36. using namespace Eigen;
  37. assert(L.cols() == 6);
  38. const int m = L.rows();
  39. // (unsigned) face Areas (opposite vertices: 1 2 3 4)
  40. Matrix<typename DerivedA::Scalar,Dynamic,1>
  41. A0(m,1), A1(m,1), A2(m,1), A3(m,1);
  42. Matrix<typename DerivedA::Scalar,Dynamic,3>
  43. L0(m,3), L1(m,3), L2(m,3), L3(m,3);
  44. L0<<L.col(1),L.col(2),L.col(3);
  45. L1<<L.col(0),L.col(2),L.col(4);
  46. L2<<L.col(0),L.col(1),L.col(5);
  47. L3<<L.col(3),L.col(4),L.col(5);
  48. doublearea(L0,doublearea_nan_replacement,A0);
  49. doublearea(L1,doublearea_nan_replacement,A1);
  50. doublearea(L2,doublearea_nan_replacement,A2);
  51. doublearea(L3,doublearea_nan_replacement,A3);
  52. A.resize(m,4);
  53. A.col(0) = 0.5*A0;
  54. A.col(1) = 0.5*A1;
  55. A.col(2) = 0.5*A2;
  56. A.col(3) = 0.5*A3;
  57. }
  58. #ifdef IGL_STATIC_LIBRARY
  59. // Explicit template instantiation
  60. // generated by autoexplicit.sh
  61. 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> >&);
  62. #endif