doublearea.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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. #ifndef IGL_DOUBLEAREA_H
  9. #define IGL_DOUBLEAREA_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. namespace igl
  13. {
  14. /// Computes twice the area for each input triangle or quad.
  15. ///
  16. /// @tparam DerivedV derived type of eigen matrix for V (e.g. derived from
  17. /// Eigen::MatrixXd)
  18. /// @tparam DerivedF derived type of eigen matrix for F (e.g. derived from
  19. /// Eigen::MatrixXi)
  20. /// @tparam DeriveddblA derived type of eigen matrix for dblA (e.g. derived from
  21. /// Eigen::MatrixXd)
  22. /// @param[in] V #V by dim list of mesh vertex positions
  23. /// @param[in] F #F by (3|4) list of mesh faces (must be triangles or quads)
  24. /// @param[out] dblA #F list of triangle[quad] double areas (SIGNED only for 2D input)
  25. ///
  26. /// \bug For dim==3 complexity is O(#V + #F). Not just O(#F). This is a big deal
  27. /// if you have 1 million unreferenced vertices and 1 face.
  28. template <typename DerivedV, typename DerivedF, typename DeriveddblA>
  29. IGL_INLINE void doublearea(
  30. const Eigen::MatrixBase<DerivedV> & V,
  31. const Eigen::MatrixBase<DerivedF> & F,
  32. Eigen::PlainObjectBase<DeriveddblA> & dblA);
  33. /// Compute the twice the signed area of a each triangle.
  34. ///
  35. /// @param[in] A #F by dim list of triangle corner positions
  36. /// @param[in] B #F by dim list of triangle corner positions
  37. /// @param[in] C #F by dim list of triangle corner positions
  38. /// @param[out] D #F list of triangle double areas
  39. template <
  40. typename DerivedA,
  41. typename DerivedB,
  42. typename DerivedC,
  43. typename DerivedD>
  44. IGL_INLINE void doublearea(
  45. const Eigen::MatrixBase<DerivedA> & A,
  46. const Eigen::MatrixBase<DerivedB> & B,
  47. const Eigen::MatrixBase<DerivedC> & C,
  48. Eigen::PlainObjectBase<DerivedD> & D);
  49. /// Compute the twice the signed area of a single triangle.
  50. ///
  51. /// @param[in] A triangle corner position
  52. /// @param[in] B triangle corner position
  53. /// @param[in] C triangle corner position
  54. /// @return 2*signed area of triangle
  55. ///
  56. /// \fileinfo
  57. template <
  58. typename DerivedA,
  59. typename DerivedB,
  60. typename DerivedC>
  61. IGL_INLINE typename DerivedA::Scalar doublearea_single(
  62. const Eigen::MatrixBase<DerivedA> & A,
  63. const Eigen::MatrixBase<DerivedB> & B,
  64. const Eigen::MatrixBase<DerivedC> & C);
  65. /// Compute twice the area of each intrinsic triangle in a mesh.
  66. ///
  67. /// @param[in] l #F by dim list of edge lengths using
  68. /// for triangles, columns correspond to edges 23,31,12
  69. /// @param[in] nan_replacement what value should be used for triangles whose given
  70. /// edge lengths do not obey the triangle inequality. These may be very
  71. /// wrong (e.g., [100 1 1]) or may be nearly degenerate triangles whose
  72. /// floating point side length computation leads to breach of the triangle
  73. /// inequality. One may wish to set this parameter to 0 if side lengths l
  74. /// are _known_ to come from a valid embedding (e.g., some mesh (V,F)). In
  75. /// that case, the only circumstance the triangle inequality is broken is
  76. /// when the triangle is nearly degenerate and floating point error
  77. /// dominates: hence replacing with zero is reasonable.
  78. /// @param[out] dblA #F list of triangle double areas
  79. template <typename Derivedl, typename DeriveddblA>
  80. IGL_INLINE void doublearea(
  81. const Eigen::MatrixBase<Derivedl> & l,
  82. const typename Derivedl::Scalar nan_replacement,
  83. Eigen::PlainObjectBase<DeriveddblA> & dblA);
  84. /// \overload
  85. ///
  86. /// \brief default behavior is to assert on NaNs and leave them in place
  87. template <typename Derivedl, typename DeriveddblA>
  88. IGL_INLINE void doublearea(
  89. const Eigen::MatrixBase<Derivedl> & l,
  90. Eigen::PlainObjectBase<DeriveddblA> & dblA);
  91. /// Computes twice the area for each input quadrilateral.
  92. ///
  93. /// @param[in] V #V by dim list of mesh vertex positions
  94. /// @param[in] F #F by 4 list of mesh faces
  95. /// @param[out] dblA #F list of quadrilateral double areas
  96. ///
  97. /// \fileinfo
  98. template <typename DerivedV, typename DerivedF, typename DeriveddblA>
  99. IGL_INLINE void doublearea_quad(
  100. const Eigen::MatrixBase<DerivedV> & V,
  101. const Eigen::MatrixBase<DerivedF> & F,
  102. Eigen::PlainObjectBase<DeriveddblA> & dblA);
  103. }
  104. #ifndef IGL_STATIC_LIBRARY
  105. # include "doublearea.cpp"
  106. #endif
  107. #endif