marching_cubes.h 2.1 KB

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