tetrahedralize.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_COPYLEFT_TETGEN_TETRAHEDRALIZE_H
  9. #define IGL_COPYLEFT_TETGEN_TETRAHEDRALIZE_H
  10. #include "../../igl_inline.h"
  11. #include <vector>
  12. #include <string>
  13. #include <Eigen/Core>
  14. #ifndef TETLIBRARY
  15. #define TETLIBRARY
  16. #endif
  17. #include "tetgen.h" // Defined REAL
  18. namespace igl
  19. {
  20. namespace copyleft
  21. {
  22. namespace tetgen
  23. {
  24. // Mesh the interior of a surface mesh (V,F) using tetgen
  25. //
  26. // Inputs:
  27. // V #V by 3 vertex position list
  28. // F #F list of polygon face indices into V (0-indexed)
  29. // switches string of tetgen options (See tetgen documentation) e.g.
  30. // "pq1.414a0.01" tries to mesh the interior of a given surface with
  31. // quality and area constraints
  32. // "" will mesh the convex hull constrained to pass through V (ignores F)
  33. // Outputs:
  34. // TV #V by 3 vertex position list
  35. // TT #T by 4 list of tet face indices
  36. // TF #F by 3 list of triangle face indices
  37. // Returns status:
  38. // 0 success
  39. // 1 tetgen threw exception
  40. // 2 tetgen did not crash but could not create any tets (probably there are
  41. // holes, duplicate faces etc.)
  42. // -1 other error
  43. IGL_INLINE int tetrahedralize(
  44. const std::vector<std::vector<REAL > > & V,
  45. const std::vector<std::vector<int> > & F,
  46. const std::string switches,
  47. std::vector<std::vector<REAL > > & TV,
  48. std::vector<std::vector<int > > & TT,
  49. std::vector<std::vector<int> > & TF);
  50. // Wrapper with Eigen types
  51. // Templates:
  52. // DerivedV real-value: i.e. from MatrixXd
  53. // DerivedF integer-value: i.e. from MatrixXi
  54. template <
  55. typename DerivedV,
  56. typename DerivedF,
  57. typename DerivedTV,
  58. typename DerivedTT,
  59. typename DerivedTF>
  60. IGL_INLINE int tetrahedralize(
  61. const Eigen::PlainObjectBase<DerivedV>& V,
  62. const Eigen::PlainObjectBase<DerivedF>& F,
  63. const std::string switches,
  64. Eigen::PlainObjectBase<DerivedTV>& TV,
  65. Eigen::PlainObjectBase<DerivedTT>& TT,
  66. Eigen::PlainObjectBase<DerivedTF>& TF);
  67. // Mesh the interior of a surface mesh (V,F) using tetgen
  68. //
  69. // Inputs:
  70. // V #V by 3 vertex position list
  71. // F #F list of polygon face indices into V (0-indexed)
  72. // M #V list of markers for vertices
  73. // switches string of tetgen options (See tetgen documentation) e.g.
  74. // "pq1.414a0.01" tries to mesh the interior of a given surface with
  75. // quality and area constraints
  76. // "" will mesh the convex hull constrained to pass through V (ignores F)
  77. // Outputs:
  78. // TV #V by 3 vertex position list
  79. // TT #T by 4 list of tet face indices
  80. // TF #F by 3 list of triangle face indices
  81. // TM #V list of markers for vertices
  82. // Returns status:
  83. // 0 success
  84. // 1 tetgen threw exception
  85. // 2 tetgen did not crash but could not create any tets (probably there are
  86. // holes, duplicate faces etc.)
  87. // -1 other error
  88. IGL_INLINE int tetrahedralize(
  89. const std::vector<std::vector<REAL > > & V,
  90. const std::vector<std::vector<int> > & F,
  91. const std::vector<int> & VM,
  92. const std::vector<int> & FM,
  93. const std::string switches,
  94. std::vector<std::vector<REAL > > & TV,
  95. std::vector<std::vector<int > > & TT,
  96. std::vector<std::vector<int> > & TF,
  97. std::vector<int> & TM);
  98. // Wrapper with Eigen types
  99. // Templates:
  100. // DerivedV real-value: i.e. from MatrixXd
  101. // DerivedF integer-value: i.e. from MatrixXi
  102. template <
  103. typename DerivedV,
  104. typename DerivedF,
  105. typename DerivedVM,
  106. typename DerivedFM,
  107. typename DerivedTV,
  108. typename DerivedTT,
  109. typename DerivedTF,
  110. typename DerivedTM>
  111. IGL_INLINE int tetrahedralize(
  112. const Eigen::PlainObjectBase<DerivedV>& V,
  113. const Eigen::PlainObjectBase<DerivedF>& F,
  114. const Eigen::PlainObjectBase<DerivedVM>& VM,
  115. const Eigen::PlainObjectBase<DerivedFM>& FM,
  116. const std::string switches,
  117. Eigen::PlainObjectBase<DerivedTV>& TV,
  118. Eigen::PlainObjectBase<DerivedTT>& TT,
  119. Eigen::PlainObjectBase<DerivedTF>& TF,
  120. Eigen::PlainObjectBase<DerivedTM>& TM);
  121. // Mesh the interior of a surface mesh (V,F) using tetgen
  122. //
  123. // Inputs:
  124. // V #V by 3 vertex position list
  125. // F #F list of polygon face indices into V (0-indexed)
  126. // H #H by 3 list of seed points inside holes
  127. // R #R by 5 list of region attributes
  128. // switches string of tetgen options (See tetgen documentation) e.g.
  129. // "pq1.414a0.01" tries to mesh the interior of a given surface with
  130. // quality and area constraints
  131. // "" will mesh the convex hull constrained to pass through V (ignores F)
  132. // Outputs:
  133. // TV #V by 3 vertex position list
  134. // TT #T by 4 list of tet face indices
  135. // TF #F by 3 list of triangle face indices
  136. // TR #T list of region ID for each tetrahedron
  137. // TN #T by 4 list of indices neighbors for each tetrahedron
  138. // PT #V list of incident tetrahedron for a vertex
  139. // FT #F by 2 list of tetrahedrons sharing a triface
  140. // numRegions Number of regions in output mesh
  141. // Returns status:
  142. // 0 success
  143. // 1 tetgen threw exception
  144. // 2 tetgen did not crash but could not create any tets (probably there are
  145. // holes, duplicate faces etc.)
  146. // -1 other error
  147. IGL_INLINE int tetrahedralize(
  148. const std::vector<std::vector<REAL> > &V,
  149. const std::vector<std::vector<int> > &F,
  150. const std::vector<std::vector<REAL> > &H,
  151. const std::vector<std::vector<REAL> > &R,
  152. const std::string switches,
  153. std::vector<std::vector<REAL > > & TV,
  154. std::vector<std::vector<int > > & TT,
  155. std::vector<std::vector<int > > & TF,
  156. std::vector<std::vector<REAL > > &TR,
  157. std::vector<std::vector<int > > &TN,
  158. std::vector<std::vector<int > > &PT,
  159. std::vector<std::vector<int > > &FT,
  160. size_t & numRegions);
  161. // Wrapper with Eigen types
  162. // Templates:
  163. // DerivedV real-value: i.e. from MatrixXd
  164. // DerivedF integer-value: i.e. from MatrixXi
  165. template <
  166. typename DerivedV,
  167. typename DerivedF,
  168. typename DerivedH,
  169. typename DerivedR,
  170. typename DerivedTV,
  171. typename DerivedTT,
  172. typename DerivedTF,
  173. typename DerivedTR>
  174. IGL_INLINE int tetrahedralize(
  175. const Eigen::PlainObjectBase<DerivedV>& V,
  176. const Eigen::PlainObjectBase<DerivedF>& F,
  177. const Eigen::PlainObjectBase<DerivedH>& H,
  178. const Eigen::PlainObjectBase<DerivedR>& R,
  179. const std::string switches,
  180. Eigen::PlainObjectBase<DerivedTV>& TV,
  181. Eigen::PlainObjectBase<DerivedTT>& TT,
  182. Eigen::PlainObjectBase<DerivedTF>& TF,
  183. Eigen::PlainObjectBase<DerivedTR>& TR,
  184. Eigen::PlainObjectBase<DerivedTT>& TN,
  185. Eigen::PlainObjectBase<DerivedTT>& PT,
  186. Eigen::PlainObjectBase<DerivedTT>& FT,
  187. size_t & numRegions);
  188. }
  189. }
  190. }
  191. #ifndef IGL_STATIC_LIBRARY
  192. # include "tetrahedralize.cpp"
  193. #endif
  194. #endif