mesh_boolean.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_BOOLEAN_MESH_BOOLEAN_H
  11. #define IGL_COPYLEFT_BOOLEAN_MESH_BOOLEAN_H
  12. #include "../../igl_inline.h"
  13. #include "MeshBooleanType.h"
  14. #include <Eigen/Core>
  15. #include <functional>
  16. namespace igl
  17. {
  18. namespace copyleft
  19. {
  20. namespace boolean
  21. {
  22. // MESH_BOOLEAN Compute boolean csg operations on "solid", consistently
  23. // oriented meshes.
  24. //
  25. // Inputs:
  26. // VA #VA by 3 list of vertex positions of first mesh
  27. // FA #FA by 3 list of triangle indices into VA
  28. // VB #VB by 3 list of vertex positions of second mesh
  29. // FB #FB by 3 list of triangle indices into VB
  30. // wind_num_op function handle for filtering winding numbers from
  31. // tuples of integer values to [0,1] outside/inside values
  32. // keep function handle for determining if a patch should be "kept"
  33. // in the output based on the winding number on either side
  34. // resolve_fun function handle for computing resolve of a
  35. // self-intersections of a mesh and outputting the new mesh.
  36. // Outputs:
  37. // VC #VC by 3 list of vertex positions of boolean result mesh
  38. // FC #FC by 3 list of triangle indices into VC
  39. // J #FC list of indices into [FA;FB] revealing "birth" facet
  40. // Returns true iff inputs induce a piecewise constant winding number
  41. // field
  42. //
  43. // See also: mesh_boolean_cork, intersect_other,
  44. // remesh_self_intersections
  45. template <
  46. typename DerivedVA,
  47. typename DerivedFA,
  48. typename DerivedVB,
  49. typename DerivedFB,
  50. typename WindingNumberOp,
  51. typename KeepFunc,
  52. typename ResolveFunc,
  53. typename DerivedVC,
  54. typename DerivedFC,
  55. typename DerivedJ>
  56. IGL_INLINE bool mesh_boolean(
  57. const Eigen::PlainObjectBase<DerivedVA> & VA,
  58. const Eigen::PlainObjectBase<DerivedFA> & FA,
  59. const Eigen::PlainObjectBase<DerivedVB> & VB,
  60. const Eigen::PlainObjectBase<DerivedFB> & FB,
  61. const WindingNumberOp& wind_num_op,
  62. const KeepFunc& keep,
  63. const ResolveFunc& resolve_fun,
  64. Eigen::PlainObjectBase<DerivedVC > & VC,
  65. Eigen::PlainObjectBase<DerivedFC > & FC,
  66. Eigen::PlainObjectBase<DerivedJ > & J);
  67. // Inputs:
  68. // VA #VA by 3 list of vertex positions of first mesh
  69. // FA #FA by 3 list of triangle indices into VA
  70. // VB #VB by 3 list of vertex positions of second mesh
  71. // FB #FB by 3 list of triangle indices into VB
  72. // type type of boolean operation
  73. // resolve_fun function handle for computing resolve of a
  74. // self-intersections of a mesh and outputting the new mesh.
  75. // Outputs:
  76. // VC #VC by 3 list of vertex positions of boolean result mesh
  77. // FC #FC by 3 list of triangle indices into VC
  78. // J #FC list of indices into [FA;FB] revealing "birth" facet
  79. // Returns true if inputs induce a piecewise constant winding number
  80. // field and type is valid.
  81. //
  82. // See also: mesh_boolean_cork, intersect_other,
  83. // remesh_self_intersections
  84. template <
  85. typename DerivedVA,
  86. typename DerivedFA,
  87. typename DerivedVB,
  88. typename DerivedFB,
  89. typename ResolveFunc,
  90. typename DerivedVC,
  91. typename DerivedFC,
  92. typename DerivedJ>
  93. IGL_INLINE bool mesh_boolean(
  94. const Eigen::PlainObjectBase<DerivedVA > & VA,
  95. const Eigen::PlainObjectBase<DerivedFA > & FA,
  96. const Eigen::PlainObjectBase<DerivedVB > & VB,
  97. const Eigen::PlainObjectBase<DerivedFB > & FB,
  98. const MeshBooleanType & type,
  99. const ResolveFunc& resolve_func,
  100. Eigen::PlainObjectBase<DerivedVC > & VC,
  101. Eigen::PlainObjectBase<DerivedFC > & FC,
  102. Eigen::PlainObjectBase<DerivedJ > & J);
  103. // Inputs:
  104. // VA #VA by 3 list of vertex positions of first mesh
  105. // FA #FA by 3 list of triangle indices into VA
  106. // VB #VB by 3 list of vertex positions of second mesh
  107. // FB #FB by 3 list of triangle indices into VB
  108. // type type of boolean operation
  109. // Outputs:
  110. // VC #VC by 3 list of vertex positions of boolean result mesh
  111. // FC #FC by 3 list of triangle indices into VC
  112. // J #FC list of indices into [FA;FB] revealing "birth" facet
  113. // Returns true if inputs induce a piecewise constant winding number
  114. // field and type is valid
  115. //
  116. // See also: mesh_boolean_cork, intersect_other,
  117. // remesh_self_intersections
  118. template <
  119. typename DerivedVA,
  120. typename DerivedFA,
  121. typename DerivedVB,
  122. typename DerivedFB,
  123. typename DerivedVC,
  124. typename DerivedFC,
  125. typename DerivedJ>
  126. IGL_INLINE bool mesh_boolean(
  127. const Eigen::PlainObjectBase<DerivedVA > & VA,
  128. const Eigen::PlainObjectBase<DerivedFA > & FA,
  129. const Eigen::PlainObjectBase<DerivedVB > & VB,
  130. const Eigen::PlainObjectBase<DerivedFB > & FB,
  131. const MeshBooleanType & type,
  132. Eigen::PlainObjectBase<DerivedVC > & VC,
  133. Eigen::PlainObjectBase<DerivedFC > & FC,
  134. Eigen::PlainObjectBase<DerivedJ > & J);
  135. // Inputs:
  136. // VA #VA by 3 list of vertex positions of first mesh
  137. // FA #FA by 3 list of triangle indices into VA
  138. // VB #VB by 3 list of vertex positions of second mesh
  139. // FB #FB by 3 list of triangle indices into VB
  140. // type type of boolean operation
  141. // Outputs:
  142. // VC #VC by 3 list of vertex positions of boolean result mesh
  143. // FC #FC by 3 list of triangle indices into VC
  144. // Returns true ff inputs induce a piecewise constant winding number
  145. // field and type is valid
  146. template <
  147. typename DerivedVA,
  148. typename DerivedFA,
  149. typename DerivedVB,
  150. typename DerivedFB,
  151. typename DerivedVC,
  152. typename DerivedFC>
  153. IGL_INLINE bool mesh_boolean(
  154. const Eigen::PlainObjectBase<DerivedVA > & VA,
  155. const Eigen::PlainObjectBase<DerivedFA > & FA,
  156. const Eigen::PlainObjectBase<DerivedVB > & VB,
  157. const Eigen::PlainObjectBase<DerivedFB > & FB,
  158. const MeshBooleanType & type,
  159. Eigen::PlainObjectBase<DerivedVC > & VC,
  160. Eigen::PlainObjectBase<DerivedFC > & FC);
  161. }
  162. }
  163. }
  164. #ifndef IGL_STATIC_LIBRARY
  165. # include "mesh_boolean.cpp"
  166. #endif
  167. #endif