marching_cubes.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Performs marching cubes reconstruction on a grid defined by values, and
  15. /// points, and generates a mesh defined by vertices and faces
  16. ///
  17. /// @param[in] S nx*ny*nz list of values at each grid corner
  18. /// i.e. S(x + y*xres + z*xres*yres) for corner (x,y,z)
  19. /// @param[in] GV nx*ny*nz by 3 array of corresponding grid corner vertex locations
  20. /// @param[in] nx resolutions of the grid in x dimension
  21. /// @param[in] ny resolutions of the grid in y dimension
  22. /// @param[in] nz resolutions of the grid in z dimension
  23. /// @param[in] isovalue the isovalue of the surface to reconstruct
  24. /// @param[out] V #V by 3 list of mesh vertex positions
  25. /// @param[out] F #F by 3 list of mesh triangle indices into rows of V
  26. ///
  27. template <
  28. typename DerivedS,
  29. typename DerivedGV,
  30. typename DerivedV,
  31. typename DerivedF>
  32. IGL_INLINE void marching_cubes(
  33. const Eigen::MatrixBase<DerivedS> & S,
  34. const Eigen::MatrixBase<DerivedGV> & GV,
  35. const unsigned nx,
  36. const unsigned ny,
  37. const unsigned nz,
  38. const typename DerivedS::Scalar isovalue,
  39. Eigen::PlainObjectBase<DerivedV> &V,
  40. Eigen::PlainObjectBase<DerivedF> &F);
  41. /// \overload
  42. ///
  43. /// \brief Sparse voxel version
  44. ///
  45. /// @param[in] S #S list of scalar field values
  46. /// @param[in] GV #S by 3 list of referenced grid vertex positions
  47. /// @param[in] GI #GI by 8 list of grid corner indices into rows of GV
  48. template <
  49. typename DerivedS,
  50. typename DerivedGV,
  51. typename DerivedGI,
  52. typename DerivedV,
  53. typename DerivedF>
  54. IGL_INLINE void marching_cubes(
  55. const Eigen::MatrixBase<DerivedS> & S,
  56. const Eigen::MatrixBase<DerivedGV> & GV,
  57. const Eigen::MatrixBase<DerivedGI> & GI,
  58. const typename DerivedS::Scalar isovalue,
  59. Eigen::PlainObjectBase<DerivedV> &V,
  60. Eigen::PlainObjectBase<DerivedF> &F);
  61. }
  62. #ifndef IGL_STATIC_LIBRARY
  63. # include "marching_cubes.cpp"
  64. #endif
  65. #endif