marching_cubes.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // values #number_of_grid_points x 1 array -- the scalar values of an
  21. // implicit function defined on the grid points (<0 in the inside of the
  22. // surface, 0 on the border, >0 outside)
  23. // points #number_of_grid_points x 3 array -- 3-D positions of the grid
  24. // points, ordered in x,y,z order:
  25. // points[index] = the point at (x,y,z) where :
  26. // x = (index % (xres -1),
  27. // y = (index / (xres-1)) %(yres-1),
  28. // z = index / (xres -1) / (yres -1) ).
  29. // where x,y,z index x, y, z dimensions
  30. // i.e. index = x + y*xres + z*xres*yres
  31. // xres resolutions of the grid in x dimension
  32. // yres resolutions of the grid in y dimension
  33. // zres resolutions of the grid in z dimension
  34. // Output:
  35. // vertices #V by 3 list of mesh vertex positions
  36. // faces #F by 3 list of mesh triangle indices
  37. //
  38. template <typename DerivedV, typename DerivedF>
  39. IGL_INLINE void marching_cubes(
  40. const Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 1> &values,
  41. const Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 3> &points,
  42. const unsigned x_res,
  43. const unsigned y_res,
  44. const unsigned z_res,
  45. Eigen::PlainObjectBase<DerivedV> &vertices,
  46. Eigen::PlainObjectBase<DerivedF> &faces);
  47. }
  48. #ifndef IGL_STATIC_LIBRARY
  49. # include "marching_cubes.cpp"
  50. #endif
  51. #endif