marching_cubes.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2020 Alec Jacobson <[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_CUBES_H
  9. #define IGL_MARCHING_CUBES_H
  10. #include "igl_inline.h"
  11. #include <unordered_map>
  12. #include <Eigen/Core>
  13. namespace igl
  14. {
  15. /// Performs marching cubes reconstruction on a grid defined by values, and
  16. /// points, and generates a mesh defined by vertices and faces
  17. ///
  18. /// @param[in] S nx*ny*nz list of values at each grid corner
  19. /// i.e. S(x + y*xres + z*xres*yres) for corner (x,y,z)
  20. /// @param[in] GV nx*ny*nz by 3 array of corresponding grid corner vertex locations
  21. /// @param[in] nx resolutions of the grid in x dimension
  22. /// @param[in] ny resolutions of the grid in y dimension
  23. /// @param[in] nz resolutions of the grid in z dimension
  24. /// @param[in] isovalue the isovalue of the surface to reconstruct
  25. /// @param[out] V #V by 3 list of mesh vertex positions
  26. /// @param[out] F #F by 3 list of mesh triangle indices into rows of V
  27. ///
  28. template <
  29. typename DerivedS,
  30. typename DerivedGV,
  31. typename DerivedV,
  32. typename DerivedF>
  33. IGL_INLINE void marching_cubes(
  34. const Eigen::MatrixBase<DerivedS> & S,
  35. const Eigen::MatrixBase<DerivedGV> & GV,
  36. const unsigned nx,
  37. const unsigned ny,
  38. const unsigned nz,
  39. const typename DerivedS::Scalar isovalue,
  40. Eigen::PlainObjectBase<DerivedV> &V,
  41. Eigen::PlainObjectBase<DerivedF> &F);
  42. /// \overload
  43. ///
  44. /// \brief Return edge-to-vertex map which can be used to implement
  45. /// batched root finding by caller (see 909_BatchMarchingCubes)
  46. ///
  47. /// @param[out] E2V map from edge key to index into rows of V
  48. template <
  49. typename DerivedS,
  50. typename DerivedGV,
  51. typename DerivedV,
  52. typename DerivedF>
  53. IGL_INLINE void marching_cubes(
  54. const Eigen::MatrixBase<DerivedS> & S,
  55. const Eigen::MatrixBase<DerivedGV> & GV,
  56. const unsigned nx,
  57. const unsigned ny,
  58. const unsigned nz,
  59. const typename DerivedS::Scalar isovalue,
  60. Eigen::PlainObjectBase<DerivedV> &V,
  61. Eigen::PlainObjectBase<DerivedF> &F,
  62. std::unordered_map<std::int64_t,int> &E2V);
  63. /// \overload
  64. ///
  65. /// \brief Sparse voxel version
  66. ///
  67. /// @param[in] S #S list of scalar field values
  68. /// @param[in] GV #S by 3 list of referenced grid vertex positions
  69. /// @param[in] GI #GI by 8 list of grid corner indices into rows of GV (e.g.,
  70. /// as output by igl::sparse_voxel_grid) in y-x-z binary counting order.
  71. template <
  72. typename DerivedS,
  73. typename DerivedGV,
  74. typename DerivedGI,
  75. typename DerivedV,
  76. typename DerivedF>
  77. IGL_INLINE void marching_cubes(
  78. const Eigen::MatrixBase<DerivedS> & S,
  79. const Eigen::MatrixBase<DerivedGV> & GV,
  80. const Eigen::MatrixBase<DerivedGI> & GI,
  81. const typename DerivedS::Scalar isovalue,
  82. Eigen::PlainObjectBase<DerivedV> &V,
  83. Eigen::PlainObjectBase<DerivedF> &F);
  84. }
  85. #ifndef IGL_STATIC_LIBRARY
  86. # include "marching_cubes.cpp"
  87. #endif
  88. #endif