marching_cubes.h 1.6 KB

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