mesh_boolean.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <[email protected]>
  4. // Qingnan Zhou <[email protected]>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla Public License
  7. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  8. // obtain one at http://mozilla.org/MPL/2.0/.
  9. //
  10. #ifndef IGL_COPYLEFT_CGAL_MESH_BOOLEAN_H
  11. #define IGL_COPYLEFT_CGAL_MESH_BOOLEAN_H
  12. #include "../../igl_inline.h"
  13. #include "../../MeshBooleanType.h"
  14. #include <Eigen/Core>
  15. #include <functional>
  16. #include <vector>
  17. namespace igl
  18. {
  19. namespace copyleft
  20. {
  21. namespace cgal
  22. {
  23. /// Compute Boolean csg operations on "solid", consistently oriented
  24. /// meshes.
  25. ///
  26. /// @param[in] VA #VA by 3 list of vertex positions of first mesh
  27. /// @param[in] FA #FA by 3 list of triangle indices into VA
  28. /// @param[in] VB #VB by 3 list of vertex positions of second mesh
  29. /// @param[in] FB #FB by 3 list of triangle indices into VB
  30. /// @param[in] type type of boolean operation
  31. /// @param[out] VC #VC by 3 list of vertex positions of boolean result mesh
  32. /// @param[out] FC #FC by 3 list of triangle indices into VC
  33. /// @param[out] J #FC list of indices into [FA;FA.rows()+FB] revealing "birth" facet
  34. /// @return true if inputs induce a piecewise constant winding number
  35. /// field and type is valid
  36. ///
  37. /// \see mesh_boolean_cork, intersect_other, remesh_self_intersections
  38. template <
  39. typename DerivedVA,
  40. typename DerivedFA,
  41. typename DerivedVB,
  42. typename DerivedFB,
  43. typename DerivedVC,
  44. typename DerivedFC,
  45. typename DerivedJ>
  46. IGL_INLINE bool mesh_boolean(
  47. const Eigen::MatrixBase<DerivedVA > & VA,
  48. const Eigen::MatrixBase<DerivedFA > & FA,
  49. const Eigen::MatrixBase<DerivedVB > & VB,
  50. const Eigen::MatrixBase<DerivedFB > & FB,
  51. const MeshBooleanType & type,
  52. Eigen::PlainObjectBase<DerivedVC > & VC,
  53. Eigen::PlainObjectBase<DerivedFC > & FC,
  54. Eigen::PlainObjectBase<DerivedJ > & J);
  55. /// \overload
  56. /// @param[in] type_str string describing type of boolean operation see mesh_boolean_type_to_funcs
  57. template <
  58. typename DerivedVA,
  59. typename DerivedFA,
  60. typename DerivedVB,
  61. typename DerivedFB,
  62. typename DerivedVC,
  63. typename DerivedFC,
  64. typename DerivedJ>
  65. IGL_INLINE bool mesh_boolean(
  66. const Eigen::MatrixBase<DerivedVA > & VA,
  67. const Eigen::MatrixBase<DerivedFA > & FA,
  68. const Eigen::MatrixBase<DerivedVB > & VB,
  69. const Eigen::MatrixBase<DerivedFB > & FB,
  70. const std::string & type_str,
  71. Eigen::PlainObjectBase<DerivedVC > & VC,
  72. Eigen::PlainObjectBase<DerivedFC > & FC,
  73. Eigen::PlainObjectBase<DerivedJ > & J);
  74. /// \overload
  75. ///
  76. /// @param[in] wind_num_op function handle for filtering winding numbers from
  77. /// tuples of integer values to [0,1] outside/inside values
  78. /// @param[in] keep function handle for determining if a patch should be "kept"
  79. /// in the output based on the winding number on either side
  80. template <
  81. typename DerivedVA,
  82. typename DerivedFA,
  83. typename DerivedVB,
  84. typename DerivedFB,
  85. typename DerivedVC,
  86. typename DerivedFC,
  87. typename DerivedJ>
  88. IGL_INLINE bool mesh_boolean(
  89. const Eigen::MatrixBase<DerivedVA> & VA,
  90. const Eigen::MatrixBase<DerivedFA> & FA,
  91. const Eigen::MatrixBase<DerivedVB> & VB,
  92. const Eigen::MatrixBase<DerivedFB> & FB,
  93. const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
  94. const std::function<int(const int, const int)> & keep,
  95. Eigen::PlainObjectBase<DerivedVC > & VC,
  96. Eigen::PlainObjectBase<DerivedFC > & FC,
  97. Eigen::PlainObjectBase<DerivedJ > & J);
  98. /// Variadic mesh Boolean operations
  99. ///
  100. /// @param[in] Vlist k-long list of lists of mesh vertex positions
  101. /// @param[in] Flist k-long list of lists of mesh face indices, so that Flist[i] indexes
  102. /// vertices in Vlist[i]
  103. /// @param[in] wind_num_op function handle for filtering winding numbers from
  104. /// n-tuples of integer values to [0,1] outside/inside values
  105. /// @param[in] keep function handle for determining if a patch should be "kept"
  106. /// in the output based on the winding number on either side
  107. /// @param[out] VC #VC by 3 list of vertex positions of boolean result mesh
  108. /// @param[out] FC #FC by 3 list of triangle indices into VC
  109. /// @param[out] J #FC list of indices into [Flist[0];Flist[1];...;Flist[k]]
  110. /// revealing "birth" facet
  111. /// @return true iff inputs induce a piecewise constant winding number
  112. /// field
  113. template <
  114. typename DerivedV,
  115. typename DerivedF,
  116. typename DerivedVC,
  117. typename DerivedFC,
  118. typename DerivedJ>
  119. IGL_INLINE bool mesh_boolean(
  120. const std::vector<DerivedV > & Vlist,
  121. const std::vector<DerivedF > & Flist,
  122. const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
  123. const std::function<int(const int, const int)> & keep,
  124. Eigen::PlainObjectBase<DerivedVC > & VC,
  125. Eigen::PlainObjectBase<DerivedFC > & FC,
  126. Eigen::PlainObjectBase<DerivedJ > & J);
  127. /// \overload
  128. template <
  129. typename DerivedV,
  130. typename DerivedF,
  131. typename DerivedVC,
  132. typename DerivedFC,
  133. typename DerivedJ>
  134. IGL_INLINE bool mesh_boolean(
  135. const std::vector<DerivedV > & Vlist,
  136. const std::vector<DerivedF > & Flist,
  137. const MeshBooleanType & type,
  138. Eigen::PlainObjectBase<DerivedVC > & VC,
  139. Eigen::PlainObjectBase<DerivedFC > & FC,
  140. Eigen::PlainObjectBase<DerivedJ > & J);
  141. /// \overload
  142. /// \brief Given a merged mesh (V,F) and list of sizes of inputs
  143. ///
  144. /// @param[in] V #V by 3 list of merged mesh vertex positions
  145. /// @param[in] F #F by 3 list of merged mesh face indices so that first sizes(0)
  146. /// faces come from the first input, and the next sizes(1) faces come
  147. /// from the second input, and so on.
  148. /// @param[in] sizes #inputs list of sizes so that sizes(i) is the #faces in the
  149. /// ith input
  150. template <
  151. typename DerivedVV,
  152. typename DerivedFF,
  153. typename Derivedsizes,
  154. typename DerivedVC,
  155. typename DerivedFC,
  156. typename DerivedJ>
  157. IGL_INLINE bool mesh_boolean(
  158. const Eigen::MatrixBase<DerivedVV > & VV,
  159. const Eigen::MatrixBase<DerivedFF > & FF,
  160. const Eigen::MatrixBase<Derivedsizes> & sizes,
  161. const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
  162. const std::function<int(const int, const int)> & keep,
  163. Eigen::PlainObjectBase<DerivedVC > & VC,
  164. Eigen::PlainObjectBase<DerivedFC > & FC,
  165. Eigen::PlainObjectBase<DerivedJ > & J);
  166. /// \overload
  167. template <
  168. typename DerivedVA,
  169. typename DerivedFA,
  170. typename DerivedVB,
  171. typename DerivedFB,
  172. typename DerivedVC,
  173. typename DerivedFC>
  174. IGL_INLINE bool mesh_boolean(
  175. const Eigen::MatrixBase<DerivedVA > & VA,
  176. const Eigen::MatrixBase<DerivedFA > & FA,
  177. const Eigen::MatrixBase<DerivedVB > & VB,
  178. const Eigen::MatrixBase<DerivedFB > & FB,
  179. const MeshBooleanType & type,
  180. Eigen::PlainObjectBase<DerivedVC > & VC,
  181. Eigen::PlainObjectBase<DerivedFC > & FC);
  182. }
  183. }
  184. }
  185. #ifndef IGL_STATIC_LIBRARY
  186. # include "mesh_boolean.cpp"
  187. #endif
  188. #endif