mesh_boolean.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
  4. // Qingnan Zhou <qnzhou@gmail.com>
  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. // MESH_BOOLEAN Compute boolean csg operations on "solid", consistently
  24. // oriented meshes.
  25. //
  26. // Inputs:
  27. // VA #VA by 3 list of vertex positions of first mesh
  28. // FA #FA by 3 list of triangle indices into VA
  29. // VB #VB by 3 list of vertex positions of second mesh
  30. // FB #FB by 3 list of triangle indices into VB
  31. // type type of boolean operation
  32. // Outputs:
  33. // VC #VC by 3 list of vertex positions of boolean result mesh
  34. // FC #FC by 3 list of triangle indices into VC
  35. // J #FC list of indices into [FA;FA.rows()+FB] revealing "birth" facet
  36. // Returns true if inputs induce a piecewise constant winding number
  37. // field and type is valid
  38. //
  39. // See also: mesh_boolean_cork, intersect_other,
  40. // remesh_self_intersections
  41. template <
  42. typename DerivedVA,
  43. typename DerivedFA,
  44. typename DerivedVB,
  45. typename DerivedFB,
  46. typename DerivedVC,
  47. typename DerivedFC,
  48. typename DerivedJ>
  49. IGL_INLINE bool mesh_boolean(
  50. const Eigen::MatrixBase<DerivedVA > & VA,
  51. const Eigen::MatrixBase<DerivedFA > & FA,
  52. const Eigen::MatrixBase<DerivedVB > & VB,
  53. const Eigen::MatrixBase<DerivedFB > & FB,
  54. const MeshBooleanType & type,
  55. Eigen::PlainObjectBase<DerivedVC > & VC,
  56. Eigen::PlainObjectBase<DerivedFC > & FC,
  57. Eigen::PlainObjectBase<DerivedJ > & J);
  58. template <
  59. typename DerivedVA,
  60. typename DerivedFA,
  61. typename DerivedVB,
  62. typename DerivedFB,
  63. typename DerivedVC,
  64. typename DerivedFC,
  65. typename DerivedJ>
  66. IGL_INLINE bool mesh_boolean(
  67. const Eigen::MatrixBase<DerivedVA > & VA,
  68. const Eigen::MatrixBase<DerivedFA > & FA,
  69. const Eigen::MatrixBase<DerivedVB > & VB,
  70. const Eigen::MatrixBase<DerivedFB > & FB,
  71. const std::string & type_str,
  72. Eigen::PlainObjectBase<DerivedVC > & VC,
  73. Eigen::PlainObjectBase<DerivedFC > & FC,
  74. Eigen::PlainObjectBase<DerivedJ > & J);
  75. //
  76. // Inputs:
  77. // VA #VA by 3 list of vertex positions of first mesh
  78. // FA #FA by 3 list of triangle indices into VA
  79. // VB #VB by 3 list of vertex positions of second mesh
  80. // FB #FB by 3 list of triangle indices into VB
  81. // wind_num_op function handle for filtering winding numbers from
  82. // tuples of integer values to [0,1] outside/inside values
  83. // keep function handle for determining if a patch should be "kept"
  84. // in the output based on the winding number on either side
  85. // Outputs:
  86. // VC #VC by 3 list of vertex positions of boolean result mesh
  87. // FC #FC by 3 list of triangle indices into VC
  88. // J #FC list of indices into [FA;FB] revealing "birth" facet
  89. // Returns true iff inputs induce a piecewise constant winding number
  90. // field
  91. //
  92. // See also: mesh_boolean_cork, intersect_other,
  93. // remesh_self_intersections
  94. template <
  95. typename DerivedVA,
  96. typename DerivedFA,
  97. typename DerivedVB,
  98. typename DerivedFB,
  99. typename DerivedVC,
  100. typename DerivedFC,
  101. typename DerivedJ>
  102. IGL_INLINE bool mesh_boolean(
  103. const Eigen::MatrixBase<DerivedVA> & VA,
  104. const Eigen::MatrixBase<DerivedFA> & FA,
  105. const Eigen::MatrixBase<DerivedVB> & VB,
  106. const Eigen::MatrixBase<DerivedFB> & FB,
  107. const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
  108. const std::function<int(const int, const int)> & keep,
  109. Eigen::PlainObjectBase<DerivedVC > & VC,
  110. Eigen::PlainObjectBase<DerivedFC > & FC,
  111. Eigen::PlainObjectBase<DerivedJ > & J);
  112. // MESH_BOOLEAN Variadic boolean operations
  113. //
  114. // Inputs:
  115. // Vlist k-long list of lists of mesh vertex positions
  116. // Flist k-long list of lists of mesh face indices, so that Flist[i] indexes
  117. // vertices in Vlist[i]
  118. // wind_num_op function handle for filtering winding numbers from
  119. // n-tuples of integer values to [0,1] outside/inside values
  120. // keep function handle for determining if a patch should be "kept"
  121. // in the output based on the winding number on either side
  122. // Outputs:
  123. // VC #VC by 3 list of vertex positions of boolean result mesh
  124. // FC #FC by 3 list of triangle indices into VC
  125. // J #FC list of indices into [Flist[0];Flist[1];...;Flist[k]]
  126. // revealing "birth" facet
  127. // Returns true iff inputs induce a piecewise constant winding number
  128. // field
  129. //
  130. // See also: mesh_boolean_cork, intersect_other,
  131. // remesh_self_intersections
  132. template <
  133. typename DerivedV,
  134. typename DerivedF,
  135. typename DerivedVC,
  136. typename DerivedFC,
  137. typename DerivedJ>
  138. IGL_INLINE bool mesh_boolean(
  139. const std::vector<DerivedV > & Vlist,
  140. const std::vector<DerivedF > & Flist,
  141. const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
  142. const std::function<int(const int, const int)> & keep,
  143. Eigen::PlainObjectBase<DerivedVC > & VC,
  144. Eigen::PlainObjectBase<DerivedFC > & FC,
  145. Eigen::PlainObjectBase<DerivedJ > & J);
  146. template <
  147. typename DerivedV,
  148. typename DerivedF,
  149. typename DerivedVC,
  150. typename DerivedFC,
  151. typename DerivedJ>
  152. IGL_INLINE bool mesh_boolean(
  153. const std::vector<DerivedV > & Vlist,
  154. const std::vector<DerivedF > & Flist,
  155. const MeshBooleanType & type,
  156. Eigen::PlainObjectBase<DerivedVC > & VC,
  157. Eigen::PlainObjectBase<DerivedFC > & FC,
  158. Eigen::PlainObjectBase<DerivedJ > & J);
  159. // Given a merged mesh (V,F) and list of sizes of inputs
  160. //
  161. // Inputs:
  162. // V #V by 3 list of merged mesh vertex positions
  163. // F #F by 3 list of merged mesh face indices so that first sizes(0)
  164. // faces come from the first input, and the next sizes(1) faces come
  165. // from the second input, and so on.
  166. // sizes #inputs list of sizes so that sizes(i) is the #faces in the
  167. // ith input
  168. // wind_num_op function handle for filtering winding numbers from
  169. // tuples of integer values to [0,1] outside/inside values
  170. // keep function handle for determining if a patch should be "kept"
  171. // in the output based on the winding number on either side
  172. // Outputs:
  173. // VC #VC by 3 list of vertex positions of boolean result mesh
  174. // FC #FC by 3 list of triangle indices into VC
  175. // J #FC list of birth parent indices
  176. //
  177. template <
  178. typename DerivedVV,
  179. typename DerivedFF,
  180. typename Derivedsizes,
  181. typename DerivedVC,
  182. typename DerivedFC,
  183. typename DerivedJ>
  184. IGL_INLINE bool mesh_boolean(
  185. const Eigen::MatrixBase<DerivedVV > & VV,
  186. const Eigen::MatrixBase<DerivedFF > & FF,
  187. const Eigen::MatrixBase<Derivedsizes> & sizes,
  188. const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
  189. const std::function<int(const int, const int)> & keep,
  190. Eigen::PlainObjectBase<DerivedVC > & VC,
  191. Eigen::PlainObjectBase<DerivedFC > & FC,
  192. Eigen::PlainObjectBase<DerivedJ > & J);
  193. // Inputs:
  194. // VA #VA by 3 list of vertex positions of first mesh
  195. // FA #FA by 3 list of triangle indices into VA
  196. // VB #VB by 3 list of vertex positions of second mesh
  197. // FB #FB by 3 list of triangle indices into VB
  198. // type type of boolean operation
  199. // Outputs:
  200. // VC #VC by 3 list of vertex positions of boolean result mesh
  201. // FC #FC by 3 list of triangle indices into VC
  202. // Returns true ff inputs induce a piecewise constant winding number
  203. // field and type is valid
  204. template <
  205. typename DerivedVA,
  206. typename DerivedFA,
  207. typename DerivedVB,
  208. typename DerivedFB,
  209. typename DerivedVC,
  210. typename DerivedFC>
  211. IGL_INLINE bool mesh_boolean(
  212. const Eigen::MatrixBase<DerivedVA > & VA,
  213. const Eigen::MatrixBase<DerivedFA > & FA,
  214. const Eigen::MatrixBase<DerivedVB > & VB,
  215. const Eigen::MatrixBase<DerivedFB > & FB,
  216. const MeshBooleanType & type,
  217. Eigen::PlainObjectBase<DerivedVC > & VC,
  218. Eigen::PlainObjectBase<DerivedFC > & FC);
  219. }
  220. }
  221. }
  222. #ifndef IGL_STATIC_LIBRARY
  223. # include "mesh_boolean.cpp"
  224. #endif
  225. #endif