doublearea.h 4.1 KB

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