marching_cubes.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 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_MARCHINGCUBES_H
  9. #define IGL_MARCHINGCUBES_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. // marching_cubes( values, points, x_res, y_res, z_res, vertices, faces )
  15. //
  16. // performs marching cubes reconstruction on the grid defined by values, and
  17. // points, and generates vertices and faces
  18. //
  19. // Input:
  20. // xres, yres, zres resolutions of the grid in x,y,z dimensions
  21. // values #number_of_grid_points x 1 array -- the scalar values of an
  22. // implicit function defined on the grid points (<0 in the inside of the
  23. // surface, 0 on the border, >0 outside)
  24. // points #number_of_grid_points x 3 array -- 3-D positions of the grid
  25. // points, ordered in x,y,z order:
  26. // points[index] = the point at (x,y,z) where :
  27. // x = (index % (xres -1),
  28. // y = (index / (xres-1)) %(yres-1),
  29. // z = index / (xres -1) / (yres -1) ).
  30. // where x,y,z index x, y, z dimensions
  31. // i.e. index = x + y*xres + z*xres*yres
  32. // Output:
  33. // vertices #V by 3 list of mesh vertex positions
  34. // faces #F by 3 list of mesh triangle indices
  35. //
  36. template <typename DerivedV, typename DerivedF>
  37. IGL_INLINE void marching_cubes(
  38. const Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 1> &values,
  39. const Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 3> &points,
  40. const unsigned x_res,
  41. const unsigned y_res,
  42. const unsigned z_res,
  43. Eigen::PlainObjectBase<DerivedV> &vertices,
  44. Eigen::PlainObjectBase<DerivedF> &faces);
  45. }
  46. #ifndef IGL_STATIC_LIBRARY
  47. # include "marching_cubes.cpp"
  48. #endif
  49. #endif