trim_with_solid.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 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_COPYLEFT_CGAL_TRIM_WITH_SOLID_H
  9. #define IGL_COPYLEFT_CGAL_TRIM_WITH_SOLID_H
  10. #include "../../igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. namespace copyleft
  15. {
  16. namespace cgal
  17. {
  18. enum TrimWithSolidMethod
  19. {
  20. /// Resolve intersections only between A and B and then check whether
  21. /// every face in A is inside/outside of B. (Included for debugging).
  22. CHECK_EACH_FACE = 1,
  23. /// Resolve intersections only between A and B, then separate into
  24. /// patches of connected faces --- where connected means sharing an edge
  25. /// and _not_ the same original face in A --- then label each patch as
  26. /// inside or outside. This should always be strictly equivalent in
  27. /// output and strictly fewer FLOPS than CHECK_EACH_FACE. There will be
  28. /// many tiny patches along the intersection of A and B.
  29. CHECK_EACH_PATCH = 2,
  30. /// Merge A and B into the same mesh and resolve all self-itnersections.
  31. /// Then "undo" remeshing on faces of A not involved in intersections
  32. /// with B (i.e., self-intersections in A). Then seperate into patches
  33. /// based on connected faces --- where connected means sharing a
  34. /// _manifold edge_ --- then label each aptch as inside or outside.
  35. /// Results in fewer patches than CHECK_EACH_PATCH but finding, meshing and
  36. /// mesh-undoing self-intersections in A can be costly. This
  37. /// could result in different output from CHECK_EACH_PATCH because of
  38. /// shared remeshing with (i.e., faces in A that both intersect B and
  39. /// other faces in A). If A has no self-intersections then I claim the
  40. /// outputs should be the same.
  41. RESOLVE_BOTH_AND_RESTORE_THEN_CHECK_EACH_PATCH = 3,
  42. };
  43. /// Given an arbitrary mesh (VA,FA) and the boundary mesh
  44. /// (VB,FB) of a solid (as defined in [Zhou et al. 2016]), Resolve intersections
  45. /// between A and B subdividing faces of A so that intersections with B exists
  46. /// only along edges and vertices (and coplanar faces). Then determine whether
  47. /// each of these faces is inside or outside of B. This can be used to extract
  48. /// the part of A inside or outside of B.
  49. ///
  50. /// @param[in] VA #VA by 3 list of mesh vertex positions of A
  51. /// @param[in] FA #FA by 3 list of mesh triangle indices into VA
  52. /// @param[in] VB #VB by 3 list of mesh vertex positions of B
  53. /// @param[in] FB #FB by 3 list of mesh triangle indices into VB
  54. /// @param[out] V #V by 3 list of mesh vertex positions of output
  55. /// @param[out] F #F by 3 list of mesh triangle indices into V
  56. /// @param[out] D #F list of bools whether face is inside B
  57. /// @param[out] J #F list of indices into FA revealing birth parent
  58. ///
  59. template <
  60. typename DerivedVA,
  61. typename DerivedFA,
  62. typename DerivedVB,
  63. typename DerivedFB,
  64. typename DerivedV,
  65. typename DerivedF,
  66. typename DerivedD,
  67. typename DerivedJ>
  68. IGL_INLINE void trim_with_solid(
  69. const Eigen::MatrixBase<DerivedVA> & VA,
  70. const Eigen::MatrixBase<DerivedFA> & FA,
  71. const Eigen::MatrixBase<DerivedVB> & VB,
  72. const Eigen::MatrixBase<DerivedFB> & FB,
  73. Eigen::PlainObjectBase<DerivedV> & Vd,
  74. Eigen::PlainObjectBase<DerivedF> & F,
  75. Eigen::PlainObjectBase<DerivedD> & D,
  76. Eigen::PlainObjectBase<DerivedJ> & J);
  77. /// \overload
  78. ///
  79. /// @param[in] method which method for extracting and determining the
  80. /// trim contents.
  81. template <
  82. typename DerivedVA,
  83. typename DerivedFA,
  84. typename DerivedVB,
  85. typename DerivedFB,
  86. typename DerivedV,
  87. typename DerivedF,
  88. typename DerivedD,
  89. typename DerivedJ>
  90. IGL_INLINE void trim_with_solid(
  91. const Eigen::MatrixBase<DerivedVA> & VA,
  92. const Eigen::MatrixBase<DerivedFA> & FA,
  93. const Eigen::MatrixBase<DerivedVB> & VB,
  94. const Eigen::MatrixBase<DerivedFB> & FB,
  95. const TrimWithSolidMethod method,
  96. Eigen::PlainObjectBase<DerivedV> & Vd,
  97. Eigen::PlainObjectBase<DerivedF> & F,
  98. Eigen::PlainObjectBase<DerivedD> & D,
  99. Eigen::PlainObjectBase<DerivedJ> & J);
  100. }
  101. }
  102. }
  103. #ifndef IGL_STATIC_LIBRARY
  104. # include "trim_with_solid.cpp"
  105. #endif
  106. #endif