marching_cubes.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // removeUnreferenced.h
  3. // Preview3D
  4. //
  5. // Created by Olga Diamanti on 05/03/12.
  6. #ifndef IGL_MARCHINGCUBES_H
  7. #define IGL_MARCHINGCUBES_H
  8. #include "igl_inline.h"
  9. #include <Eigen/Core>
  10. namespace igl
  11. {
  12. // marching_cubes( values, points, x_res, y_res, z_res, vertices, faces )
  13. // performs marching cubes reconstruction on the grid defined by values, and points, and generates vertices and faces
  14. //
  15. // Input:
  16. // xres, yres, zres: resolutions of the grid in x,y,z dimensions
  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. // points: #number_of_grid_points x 3 array -- 3-D positions of the grid 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. //
  26. // Output:
  27. // V,F: mesh description (vertices and faces)
  28. template <typename DerivedV, typename DerivedF>
  29. IGL_INLINE void marching_cubes(const Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 1> &values,
  30. const Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 3> &points,
  31. const unsigned x_res,
  32. const unsigned y_res,
  33. const unsigned z_res,
  34. Eigen::PlainObjectBase<DerivedV> &vertices,
  35. Eigen::PlainObjectBase<DerivedF> &faces);
  36. }
  37. #ifdef IGL_HEADER_ONLY
  38. # include "marching_cubes.cpp"
  39. # include "MCTables.cc"
  40. #endif
  41. #endif