doublearea.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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::PlainObjectBase<DerivedV> & V,
  34. const Eigen::PlainObjectBase<DerivedF> & F,
  35. Eigen::PlainObjectBase<DeriveddblA> & dblA);
  36. // Stream of triangles
  37. template <
  38. typename DerivedA,
  39. typename DerivedB,
  40. typename DerivedC,
  41. typename DerivedD>
  42. IGL_INLINE void doublearea(
  43. const Eigen::PlainObjectBase<DerivedA> & A,
  44. const Eigen::PlainObjectBase<DerivedB> & B,
  45. const Eigen::PlainObjectBase<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::PlainObjectBase<DerivedA> & A,
  56. const Eigen::PlainObjectBase<DerivedB> & B,
  57. const Eigen::PlainObjectBase<DerivedC> & C);
  58. // Same as above but use instrinsic edge lengths rather than (V,F) mesh
  59. // Templates:
  60. // DerivedV derived type of eigen matrix for V (e.g. derived from
  61. // MatrixXd)
  62. // DerivedF derived type of eigen matrix for F (e.g. derived from
  63. // MatrixXi)
  64. // DeriveddblA derived type of eigen matrix for dblA (e.g. derived from
  65. // MatrixXd)
  66. // Inputs:
  67. // l #F by dim list of edge lengths using
  68. // for triangles, columns correspond to edges 23,31,12
  69. // Outputs:
  70. // dblA #F list of triangle double areas
  71. template <typename Derivedl, typename DeriveddblA>
  72. IGL_INLINE void doublearea(
  73. const Eigen::PlainObjectBase<Derivedl> & l,
  74. Eigen::PlainObjectBase<DeriveddblA> & dblA);
  75. // DOUBLEAREA_QUAD computes twice the area for each input quadrilateral
  76. //
  77. // Inputs:
  78. // V #V by dim list of mesh vertex positions
  79. // F #F by simplex_size list of mesh faces (must be quadrilaterals)
  80. // Outputs:
  81. // dblA #F list of quadrilateral double areas
  82. //
  83. template <typename DerivedV, typename DerivedF, typename DeriveddblA>
  84. IGL_INLINE void doublearea_quad(
  85. const Eigen::PlainObjectBase<DerivedV> & V,
  86. const Eigen::PlainObjectBase<DerivedF> & F,
  87. Eigen::PlainObjectBase<DeriveddblA> & dblA);
  88. }
  89. #ifndef IGL_STATIC_LIBRARY
  90. # include "doublearea.cpp"
  91. #endif
  92. #endif