doublearea.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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, 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::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. // Inputs:
  60. // l #F by dim list of edge lengths using
  61. // for triangles, columns correspond to edges 23,31,12
  62. // Outputs:
  63. // dblA #F list of triangle double areas
  64. template <typename Derivedl, typename DeriveddblA>
  65. IGL_INLINE void doublearea(
  66. const Eigen::PlainObjectBase<Derivedl> & l,
  67. Eigen::PlainObjectBase<DeriveddblA> & dblA);
  68. // DOUBLEAREA_QUAD computes twice the area for each input quadrilateral
  69. //
  70. // Inputs:
  71. // V #V by dim list of mesh vertex positions
  72. // F #F by simplex_size list of mesh faces (must be quadrilaterals)
  73. // Outputs:
  74. // dblA #F list of quadrilateral double areas
  75. //
  76. template <typename DerivedV, typename DerivedF, typename DeriveddblA>
  77. IGL_INLINE void doublearea_quad(
  78. const Eigen::PlainObjectBase<DerivedV> & V,
  79. const Eigen::PlainObjectBase<DerivedF> & F,
  80. Eigen::PlainObjectBase<DeriveddblA> & dblA);
  81. }
  82. #ifndef IGL_STATIC_LIBRARY
  83. # include "doublearea.cpp"
  84. #endif
  85. #endif