triangle_triangle_intersect.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef IGL_TRIANGLE_TRIANGLE_INTERSECT_H
  2. #define IGL_TRIANGLE_TRIANGLE_INTERSECT_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. namespace igl
  6. {
  7. /// Determine whether two triangles intersect. We consider the `f`th and `g`th
  8. /// triangles in `F` indexing rows of `V` for 3D positions, but the `c`th corner
  9. /// of the `f`th triangle is replaced by `p`. In matlab, this would be
  10. ///
  11. /// ```matlab
  12. /// Tf = V(F(f,:),:);
  13. /// Tf(c,:) = p;
  14. /// ```
  15. ///
  16. /// and
  17. ///
  18. /// ```matlab
  19. /// Tg = V(F(g,:),:);
  20. /// ```
  21. ///
  22. /// Triangles can share an edge, but only if it's the one opposite the replaced
  23. /// corner.
  24. ///
  25. /// @param[in] V #V by 3 list of vertex positions
  26. /// @param[in] F #F by 3 list of triangle indices into rows of V
  27. /// @param[in] E #E by 2 list of unique undirected edge indices into rows of V
  28. /// @param[in] EMAP #F*3 list of indices into F, mapping each directed edge to
  29. /// unique edge in {1,...,E}
  30. /// @param[in] EF #E by 2 list of edge indices into F
  31. /// @param[in] f index into F of first triangle
  32. /// @param[in] c index into F of corner of first triangle to replace with `p`
  33. /// @param[in] p 3D position to replace corner of first triangle
  34. /// @param[in] g index into F of second triangle
  35. /// @returns true if triangles intersect
  36. ///
  37. /// \note This very specialized function should be complemented with the more
  38. /// general functions in igl::tri_tri_intersect (which should be renamed and
  39. /// split into appropriate files). There's a reasonably amount of shared code
  40. /// with igl::copyleft::cgal::remesh_self_intersections too.
  41. ///
  42. /// \see edge_flaps, tri_tri_intersect,
  43. /// predicates::triangle_triangle_intersect
  44. template <
  45. typename DerivedV,
  46. typename DerivedF,
  47. typename DerivedE,
  48. typename DerivedEMAP,
  49. typename DerivedEF,
  50. typename Derivedp>
  51. IGL_INLINE bool triangle_triangle_intersect(
  52. const Eigen::MatrixBase<DerivedV> & V,
  53. const Eigen::MatrixBase<DerivedF> & F,
  54. const Eigen::MatrixBase<DerivedE> & E,
  55. const Eigen::MatrixBase<DerivedEMAP> & EMAP,
  56. const Eigen::MatrixBase<DerivedEF> & EF,
  57. const int f,
  58. const int c,
  59. const Eigen::MatrixBase<Derivedp> & p,
  60. const int g);
  61. /// Assuming that we've computed a list of non-coplanar intersecting triangle
  62. /// pairs between (V1,F1) and (V2,F2), compute the
  63. ///
  64. /// @param[in] V1 #V1 by 3 list of vertex positions
  65. /// @param[in] F1 #F1 by 3 list of triangle indices into rows of V1
  66. /// @param[in] V2 #V2 by 3 list of vertex positions
  67. /// @param[in] F2 #F2 by 3 list of triangle indices into rows of V2
  68. /// @param[in] IF #IF by 2 list of intersecting triangle pairs so that IF(i,:)
  69. /// [f1 f2] means that the f1th triangle in F1 intersects the f2th triangle in
  70. /// F2 and that they're non-coplanar
  71. /// @param[out] EV #EV by 3 list of vertex positions of intersection segments
  72. /// @param[out] EE #EE by 2 list of edge indices into EV
  73. template <
  74. typename DerivedV,
  75. typename DerivedF,
  76. typename DerivedIF,
  77. typename DerivedEV,
  78. typename DerivedEE>
  79. IGL_INLINE void triangle_triangle_intersect(
  80. const Eigen::MatrixBase<DerivedV> & V1,
  81. const Eigen::MatrixBase<DerivedF> & F1,
  82. const Eigen::MatrixBase<DerivedV> & V2,
  83. const Eigen::MatrixBase<DerivedF> & F2,
  84. const Eigen::MatrixBase<DerivedIF> & IF,
  85. Eigen::PlainObjectBase<DerivedEV> & EV,
  86. Eigen::PlainObjectBase<DerivedEE> & EE);
  87. /// \overload
  88. /// \brief Wrapper for triangle_triangle_intersect with self-intersections
  89. template <
  90. typename DerivedV,
  91. typename DerivedF,
  92. typename DerivedIF,
  93. typename DerivedEV,
  94. typename DerivedEE>
  95. IGL_INLINE void triangle_triangle_intersect(
  96. const Eigen::MatrixBase<DerivedV> & V,
  97. const Eigen::MatrixBase<DerivedF> & F,
  98. const Eigen::MatrixBase<DerivedIF> & IF,
  99. Eigen::PlainObjectBase<DerivedEV> & EV,
  100. Eigen::PlainObjectBase<DerivedEE> & EE);
  101. }
  102. #ifndef IGL_STATIC_LIBRARY
  103. # include "triangle_triangle_intersect.cpp"
  104. #endif
  105. #endif