mesh_boolean.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 <CGAL/Exact_predicates_exact_constructions_kernel.h>
  16. #include <functional>
  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. // wind_num_op function handle for filtering winding numbers from
  32. // tuples of integer values to [0,1] outside/inside values
  33. // keep function handle for determining if a patch should be "kept"
  34. // in the output based on the winding number on either side
  35. // resolve_fun function handle for computing resolve of a
  36. // self-intersections of a mesh and outputting the new mesh.
  37. // Outputs:
  38. // VC #VC by 3 list of vertex positions of boolean result mesh
  39. // FC #FC by 3 list of triangle indices into VC
  40. // J #FC list of indices into [FA;FB] revealing "birth" facet
  41. // Returns true iff inputs induce a piecewise constant winding number
  42. // field
  43. //
  44. // See also: mesh_boolean_cork, intersect_other,
  45. // remesh_self_intersections
  46. template <
  47. typename DerivedVA,
  48. typename DerivedFA,
  49. typename DerivedVB,
  50. typename DerivedFB,
  51. typename WindingNumberOp,
  52. typename KeepFunc,
  53. typename ResolveFunc,
  54. typename DerivedVC,
  55. typename DerivedFC,
  56. typename DerivedJ>
  57. IGL_INLINE bool mesh_boolean(
  58. const Eigen::PlainObjectBase<DerivedVA> & VA,
  59. const Eigen::PlainObjectBase<DerivedFA> & FA,
  60. const Eigen::PlainObjectBase<DerivedVB> & VB,
  61. const Eigen::PlainObjectBase<DerivedFB> & FB,
  62. const WindingNumberOp& wind_num_op,
  63. const KeepFunc& keep,
  64. const ResolveFunc& resolve_fun,
  65. Eigen::PlainObjectBase<DerivedVC > & VC,
  66. Eigen::PlainObjectBase<DerivedFC > & FC,
  67. Eigen::PlainObjectBase<DerivedJ > & J);
  68. //// MESH_BOOLEAN Compute boolean csg operations on "solid", consistently
  69. //// oriented meshes.
  70. ////
  71. //// Inputs:
  72. //// Vlist k-long list of lists of mesh vertex positions
  73. //// Flist k-long list of lists of mesh face indices, so that Flist[i] indexes
  74. //// vertices in Vlist[i]
  75. //// wind_num_op function handle for filtering winding numbers from
  76. //// n-tuples of integer values to [0,1] outside/inside values
  77. //// keep function handle for determining if a patch should be "kept"
  78. //// in the output based on the winding number on either side
  79. //// resolve_fun function handle for computing resolve of a
  80. //// self-intersections of a mesh and outputting the new mesh.
  81. //// Outputs:
  82. //// VC #VC by 3 list of vertex positions of boolean result mesh
  83. //// FC #FC by 3 list of triangle indices into VC
  84. //// J #FC list of indices into [Flist[0];Flist[1];...;Flist[k]]
  85. //// revealing "birth" facet
  86. //// Returns true iff inputs induce a piecewise constant winding number
  87. //// field
  88. ////
  89. //// See also: mesh_boolean_cork, intersect_other,
  90. //// remesh_self_intersections
  91. //template <
  92. // typename DerivedV,
  93. // typename DerivedF,
  94. // typename WindingNumberOp,
  95. // typename KeepFunc,
  96. // typename ResolveFunc,
  97. // typename DerivedVC,
  98. // typename DerivedFC,
  99. // typename DerivedJ>
  100. //IGL_INLINE bool mesh_boolean(
  101. // const std::vector<Eigen::PlainObjectBase<DerivedVA> > & Vlist,
  102. // const std::vector<Eigen::PlainObjectBase<DerivedFA> > & Flist,
  103. // const WindingNumberOp& wind_num_op,
  104. // const KeepFunc& keep,
  105. // const ResolveFunc& resolve_fun,
  106. // Eigen::PlainObjectBase<DerivedVC > & VC,
  107. // Eigen::PlainObjectBase<DerivedFC > & FC,
  108. // Eigen::PlainObjectBase<DerivedJ > & J);
  109. // Given a resolved mesh (V,F), containing no self-intersections and a
  110. // list of birth parents.
  111. //
  112. // Inputs:
  113. // V #V by 3 list of resolved mesh vertex positions
  114. // F #F by 3 list of resolve mesh face indices
  115. // CJ #F list of birth parents
  116. // sizes #inputs list of sizes so that sizes(i) is the #faces in the
  117. // ith input
  118. // wind_num_op function handle for filtering winding numbers from
  119. // 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 birth parent indices
  126. //
  127. template <
  128. typename Derivedsizes,
  129. typename WindingNumberOp,
  130. typename KeepFunc,
  131. typename DerivedVC,
  132. typename DerivedFC,
  133. typename DerivedJ>
  134. IGL_INLINE bool mesh_boolean(
  135. const Eigen::Matrix<
  136. CGAL::Epeck::FT,
  137. Eigen::Dynamic,
  138. Eigen::Dynamic,
  139. DerivedVC::IsRowMajor> V,
  140. const Eigen::PlainObjectBase<DerivedFC > & F,
  141. const Eigen::Matrix<
  142. typename DerivedJ::Scalar,
  143. Eigen::Dynamic,
  144. 1> & CJ,
  145. const Eigen::PlainObjectBase<Derivedsizes> & sizes,
  146. const WindingNumberOp& wind_num_op,
  147. const KeepFunc& keep,
  148. Eigen::PlainObjectBase<DerivedVC > & VC,
  149. Eigen::PlainObjectBase<DerivedFC > & FC,
  150. Eigen::PlainObjectBase<DerivedJ > & J);
  151. // Inputs:
  152. // VA #VA by 3 list of vertex positions of first mesh
  153. // FA #FA by 3 list of triangle indices into VA
  154. // VB #VB by 3 list of vertex positions of second mesh
  155. // FB #FB by 3 list of triangle indices into VB
  156. // type type of boolean operation
  157. // resolve_fun function handle for computing resolve of a
  158. // self-intersections of a mesh and outputting the new mesh.
  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 indices into [FA;FB] revealing "birth" facet
  163. // Returns true if inputs induce a piecewise constant winding number
  164. // field and type is valid.
  165. //
  166. // See also: mesh_boolean_cork, intersect_other,
  167. // remesh_self_intersections
  168. template <
  169. typename DerivedVA,
  170. typename DerivedFA,
  171. typename DerivedVB,
  172. typename DerivedFB,
  173. typename ResolveFunc,
  174. typename DerivedVC,
  175. typename DerivedFC,
  176. typename DerivedJ>
  177. IGL_INLINE bool mesh_boolean(
  178. const Eigen::PlainObjectBase<DerivedVA > & VA,
  179. const Eigen::PlainObjectBase<DerivedFA > & FA,
  180. const Eigen::PlainObjectBase<DerivedVB > & VB,
  181. const Eigen::PlainObjectBase<DerivedFB > & FB,
  182. const MeshBooleanType & type,
  183. const ResolveFunc& resolve_func,
  184. Eigen::PlainObjectBase<DerivedVC > & VC,
  185. Eigen::PlainObjectBase<DerivedFC > & FC,
  186. Eigen::PlainObjectBase<DerivedJ > & J);
  187. // Inputs:
  188. // VA #VA by 3 list of vertex positions of first mesh
  189. // FA #FA by 3 list of triangle indices into VA
  190. // VB #VB by 3 list of vertex positions of second mesh
  191. // FB #FB by 3 list of triangle indices into VB
  192. // type type of boolean operation
  193. // Outputs:
  194. // VC #VC by 3 list of vertex positions of boolean result mesh
  195. // FC #FC by 3 list of triangle indices into VC
  196. // J #FC list of indices into [FA;FB] revealing "birth" facet
  197. // Returns true if inputs induce a piecewise constant winding number
  198. // field and type is valid
  199. //
  200. // See also: mesh_boolean_cork, intersect_other,
  201. // remesh_self_intersections
  202. template <
  203. typename DerivedVA,
  204. typename DerivedFA,
  205. typename DerivedVB,
  206. typename DerivedFB,
  207. typename DerivedVC,
  208. typename DerivedFC,
  209. typename DerivedJ>
  210. IGL_INLINE bool mesh_boolean(
  211. const Eigen::PlainObjectBase<DerivedVA > & VA,
  212. const Eigen::PlainObjectBase<DerivedFA > & FA,
  213. const Eigen::PlainObjectBase<DerivedVB > & VB,
  214. const Eigen::PlainObjectBase<DerivedFB > & FB,
  215. const MeshBooleanType & type,
  216. Eigen::PlainObjectBase<DerivedVC > & VC,
  217. Eigen::PlainObjectBase<DerivedFC > & FC,
  218. Eigen::PlainObjectBase<DerivedJ > & J);
  219. // Inputs:
  220. // VA #VA by 3 list of vertex positions of first mesh
  221. // FA #FA by 3 list of triangle indices into VA
  222. // VB #VB by 3 list of vertex positions of second mesh
  223. // FB #FB by 3 list of triangle indices into VB
  224. // type type of boolean operation
  225. // Outputs:
  226. // VC #VC by 3 list of vertex positions of boolean result mesh
  227. // FC #FC by 3 list of triangle indices into VC
  228. // Returns true ff inputs induce a piecewise constant winding number
  229. // field and type is valid
  230. template <
  231. typename DerivedVA,
  232. typename DerivedFA,
  233. typename DerivedVB,
  234. typename DerivedFB,
  235. typename DerivedVC,
  236. typename DerivedFC>
  237. IGL_INLINE bool mesh_boolean(
  238. const Eigen::PlainObjectBase<DerivedVA > & VA,
  239. const Eigen::PlainObjectBase<DerivedFA > & FA,
  240. const Eigen::PlainObjectBase<DerivedVB > & VB,
  241. const Eigen::PlainObjectBase<DerivedFB > & FB,
  242. const MeshBooleanType & type,
  243. Eigen::PlainObjectBase<DerivedVC > & VC,
  244. Eigen::PlainObjectBase<DerivedFC > & FC);
  245. }
  246. }
  247. }
  248. #ifndef IGL_STATIC_LIBRARY
  249. # include "mesh_boolean.cpp"
  250. #endif
  251. #endif