mesh_boolean.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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::PlainObjectBase<DerivedVA > & VA,
  51. const Eigen::PlainObjectBase<DerivedFA > & FA,
  52. const Eigen::PlainObjectBase<DerivedVB > & VB,
  53. const Eigen::PlainObjectBase<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::PlainObjectBase<DerivedVA > & VA,
  68. const Eigen::PlainObjectBase<DerivedFA > & FA,
  69. const Eigen::PlainObjectBase<DerivedVB > & VB,
  70. const Eigen::PlainObjectBase<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::PlainObjectBase<DerivedVA> & VA,
  104. const Eigen::PlainObjectBase<DerivedFA> & FA,
  105. const Eigen::PlainObjectBase<DerivedVB> & VB,
  106. const Eigen::PlainObjectBase<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. // Given a merged mesh (V,F) and list of sizes of inputs
  147. //
  148. // Inputs:
  149. // V #V by 3 list of merged mesh vertex positions
  150. // F #F by 3 list of merged mesh face indices so that first sizes(0)
  151. // faces come from the first input, and the next sizes(1) faces come
  152. // from the second input, and so on.
  153. // sizes #inputs list of sizes so that sizes(i) is the #faces in the
  154. // ith input
  155. // wind_num_op function handle for filtering winding numbers from
  156. // tuples of integer values to [0,1] outside/inside values
  157. // keep function handle for determining if a patch should be "kept"
  158. // in the output based on the winding number on either side
  159. // Outputs:
  160. // VC #VC by 3 list of vertex positions of boolean result mesh
  161. // FC #FC by 3 list of triangle indices into VC
  162. // J #FC list of birth parent indices
  163. //
  164. template <
  165. typename DerivedVV,
  166. typename DerivedFF,
  167. typename Derivedsizes,
  168. typename DerivedVC,
  169. typename DerivedFC,
  170. typename DerivedJ>
  171. IGL_INLINE bool mesh_boolean(
  172. const Eigen::PlainObjectBase<DerivedVV > & VV,
  173. const Eigen::PlainObjectBase<DerivedFF > & FF,
  174. const Eigen::PlainObjectBase<Derivedsizes> & sizes,
  175. const std::function<int(const Eigen::Matrix<int,1,Eigen::Dynamic>) >& wind_num_op,
  176. const std::function<int(const int, const int)> & keep,
  177. Eigen::PlainObjectBase<DerivedVC > & VC,
  178. Eigen::PlainObjectBase<DerivedFC > & FC,
  179. Eigen::PlainObjectBase<DerivedJ > & J);
  180. // Inputs:
  181. // VA #VA by 3 list of vertex positions of first mesh
  182. // FA #FA by 3 list of triangle indices into VA
  183. // VB #VB by 3 list of vertex positions of second mesh
  184. // FB #FB by 3 list of triangle indices into VB
  185. // type type of boolean operation
  186. // Outputs:
  187. // VC #VC by 3 list of vertex positions of boolean result mesh
  188. // FC #FC by 3 list of triangle indices into VC
  189. // Returns true ff inputs induce a piecewise constant winding number
  190. // field and type is valid
  191. template <
  192. typename DerivedVA,
  193. typename DerivedFA,
  194. typename DerivedVB,
  195. typename DerivedFB,
  196. typename DerivedVC,
  197. typename DerivedFC>
  198. IGL_INLINE bool mesh_boolean(
  199. const Eigen::PlainObjectBase<DerivedVA > & VA,
  200. const Eigen::PlainObjectBase<DerivedFA > & FA,
  201. const Eigen::PlainObjectBase<DerivedVB > & VB,
  202. const Eigen::PlainObjectBase<DerivedFB > & FB,
  203. const MeshBooleanType & type,
  204. Eigen::PlainObjectBase<DerivedVC > & VC,
  205. Eigen::PlainObjectBase<DerivedFC > & FC);
  206. }
  207. }
  208. }
  209. #ifndef IGL_STATIC_LIBRARY
  210. # include "mesh_boolean.cpp"
  211. #endif
  212. #endif