marching_tets.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2018 Francis Williams <[email protected]>
  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_MARCHING_TETS_H
  9. #define IGL_MARCHING_TETS_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <Eigen/Sparse>
  13. namespace igl {
  14. /// Performs the marching tetrahedra algorithm on a tet mesh defined by TV and
  15. /// TT with scalar values defined at each vertex in TV. The output is a
  16. /// triangle mesh approximating the isosurface coresponding to the value
  17. /// isovalue.
  18. ///
  19. /// @param[in] TV #tet_vertices x 3 array -- The vertices of the tetrahedral mesh
  20. /// @param[in] TT #tets x 4 array -- The indexes of each tet in the tetrahedral mesh
  21. /// @param[in] S #tet_vertices x 1 array -- The values defined on each tet vertex
  22. /// @param[in] isovalue scalar -- The isovalue of the level set we want to compute
  23. /// @param[out] SV #SV x 3 array -- The vertices of the output level surface mesh
  24. /// @param[out] SF #SF x 3 array -- The face indexes of the output level surface mesh
  25. /// @param[out] J #SF list of indices into TT revealing which tet each face comes from
  26. /// @param[out] BC #SV x #TV list of barycentric coordinates so that SV = BC*TV
  27. template <typename DerivedTV,
  28. typename DerivedTT,
  29. typename DerivedS,
  30. typename DerivedSV,
  31. typename DerivedSF,
  32. typename DerivedJ,
  33. typename BCType>
  34. IGL_INLINE void marching_tets(
  35. const Eigen::MatrixBase<DerivedTV>& TV,
  36. const Eigen::MatrixBase<DerivedTT>& TT,
  37. const Eigen::MatrixBase<DerivedS>& S,
  38. const typename DerivedS::Scalar isovalue,
  39. Eigen::PlainObjectBase<DerivedSV>& SV,
  40. Eigen::PlainObjectBase<DerivedSF>& SF,
  41. Eigen::PlainObjectBase<DerivedJ>& J,
  42. Eigen::SparseMatrix<BCType>& BC);
  43. /// \overload
  44. /// \brief assumes isovalue = 0
  45. template <typename DerivedTV,
  46. typename DerivedTT,
  47. typename DerivedS,
  48. typename DerivedSV,
  49. typename DerivedSF,
  50. typename DerivedJ,
  51. typename BCType>
  52. IGL_INLINE void marching_tets(
  53. const Eigen::MatrixBase<DerivedTV>& TV,
  54. const Eigen::MatrixBase<DerivedTT>& TT,
  55. const Eigen::MatrixBase<DerivedS>& S,
  56. Eigen::PlainObjectBase<DerivedSV>& SV,
  57. Eigen::PlainObjectBase<DerivedSF>& SF,
  58. Eigen::PlainObjectBase<DerivedJ>& J,
  59. Eigen::SparseMatrix<BCType>& BC) {
  60. return igl::marching_tets(TV, TT, S, 0.0, SV, SF, J, BC);
  61. }
  62. /// \overload
  63. template <typename DerivedTV,
  64. typename DerivedTT,
  65. typename DerivedS,
  66. typename DerivedSV,
  67. typename DerivedSF,
  68. typename DerivedJ>
  69. IGL_INLINE void marching_tets(
  70. const Eigen::MatrixBase<DerivedTV>& TV,
  71. const Eigen::MatrixBase<DerivedTT>& TT,
  72. const Eigen::MatrixBase<DerivedS>& S,
  73. const typename DerivedS::Scalar isovalue,
  74. Eigen::PlainObjectBase<DerivedSV>& SV,
  75. Eigen::PlainObjectBase<DerivedSF>& SF,
  76. Eigen::PlainObjectBase<DerivedJ>& J) {
  77. Eigen::SparseMatrix<typename DerivedSV::Scalar> _BC;
  78. return igl::marching_tets(TV, TT, S, isovalue, SV, SF, J, _BC);
  79. }
  80. /// \overload
  81. template <typename DerivedTV,
  82. typename DerivedTT,
  83. typename DerivedS,
  84. typename DerivedSV,
  85. typename DerivedSF,
  86. typename BCType>
  87. IGL_INLINE void marching_tets(
  88. const Eigen::MatrixBase<DerivedTV>& TV,
  89. const Eigen::MatrixBase<DerivedTT>& TT,
  90. const Eigen::MatrixBase<DerivedS>& S,
  91. const typename DerivedS::Scalar isovalue,
  92. Eigen::PlainObjectBase<DerivedSV>& SV,
  93. Eigen::PlainObjectBase<DerivedSF>& SF,
  94. Eigen::SparseMatrix<BCType>& BC) {
  95. Eigen::VectorXi _J;
  96. return igl::marching_tets(TV, TT, S, isovalue, SV, SF, _J, BC);
  97. }
  98. /// \overload
  99. template <typename DerivedTV,
  100. typename DerivedTT,
  101. typename DerivedS,
  102. typename DerivedSV,
  103. typename DerivedSF>
  104. IGL_INLINE void marching_tets(
  105. const Eigen::MatrixBase<DerivedTV>& TV,
  106. const Eigen::MatrixBase<DerivedTT>& TT,
  107. const Eigen::MatrixBase<DerivedS>& S,
  108. const typename DerivedS::Scalar isovalue,
  109. Eigen::PlainObjectBase<DerivedSV>& SV,
  110. Eigen::PlainObjectBase<DerivedSF>& SF) {
  111. Eigen::VectorXi _J;
  112. Eigen::SparseMatrix<typename DerivedSV::Scalar> _BC;
  113. return igl::marching_tets(TV, TT, S, isovalue, SV, SF, _J, _BC);
  114. }
  115. }
  116. #ifndef IGL_STATIC_LIBRARY
  117. # include "marching_tets.cpp"
  118. #endif
  119. #endif // IGL_MARCHING_TETS_H