doublearea.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "doublearea.h"
  2. #include "edge_lengths.h"
  3. #include <cassert>
  4. template <typename DerivedV, typename DerivedF, typename DeriveddblA>
  5. IGL_INLINE void igl::doublearea(
  6. const Eigen::PlainObjectBase<DerivedV> & V,
  7. const Eigen::PlainObjectBase<DerivedF> & F,
  8. Eigen::PlainObjectBase<DeriveddblA> & dblA)
  9. {
  10. // Only support triangles
  11. assert(F.cols() == 3);
  12. // Compute edge lengths
  13. Eigen::PlainObjectBase<DerivedV> l;
  14. edge_lengths(V,F,l);
  15. return doublearea(l,dblA);
  16. }
  17. template <typename Derivedl, typename DeriveddblA>
  18. IGL_INLINE void igl::doublearea(
  19. const Eigen::PlainObjectBase<Derivedl> & l,
  20. Eigen::PlainObjectBase<DeriveddblA> & dblA)
  21. {
  22. using namespace Eigen;
  23. // Only support triangles
  24. assert(l.cols() == 3);
  25. // Number of triangles
  26. const int m = l.rows();
  27. // semiperimeters
  28. Matrix<typename Derivedl::Scalar,Dynamic,1> s = l.rowwise().sum()*0.5;
  29. assert(s.rows() == m);
  30. // resize output
  31. dblA.resize(l.rows(),1);
  32. // Heron's formula for area
  33. for(int i = 0;i<m;i++)
  34. {
  35. dblA(i) = 2.0*sqrt(s(i)*(s(i)-l(i,0))*(s(i)-l(i,1))*(s(i)-l(i,2)));
  36. }
  37. }
  38. #ifndef IGL_HEADER_ONLY
  39. // Explicit template specialization
  40. // generated by autoexplicit.sh
  41. template void igl::doublearea<Eigen::Matrix<float, -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<float, -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> >&);
  42. template void igl::doublearea<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> >&);
  43. template void igl::doublearea<Eigen::Matrix<double, -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<double, -1, 1, 0, -1, 1> >&);
  44. template void igl::doublearea<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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<int, -1, 1, 0, -1, 1> >&);
  45. #endif