marching_cubes.h 1.7 KB

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