diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_implicit_sphere.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_implicit_sphere.cpp index 05ad64b0d8b..b814c056603 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_implicit_sphere.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_implicit_sphere.cpp @@ -1,46 +1,43 @@ #include - #include #include - #include - #include - #include using Kernel = CGAL::Simple_cartesian; using FT = typename Kernel::FT; -using Vector = typename Kernel::Vector_3; using Point = typename Kernel::Point_3; - +using Vector = typename Kernel::Vector_3; using Point_range = std::vector; -using Polygon_range = std::vector >; +using Triangle_range = std::vector >; + +// Sphere = Euclidean distance function to the origin +auto sphere_function = [&](const Point& p) -> FT +{ + return std::sqrt(p.x() * p.x() + p.y() * p.y() + p.z() * p.z()); +}; int main(int, char**) { - const CGAL::Bbox_3 bbox { -1.0, -1.0, -1.0, 1.0, 1.0, 1.0 }; + // box domain and spacing vector + const CGAL::Bbox_3 bbox{ -1.0, -1.0, -1.0, 1.0, 1.0, 1.0 }; const FT spacing = 0.04; const Vector vec_spacing(spacing, spacing, spacing); - // Euclidean distance function to the origin - auto sphere_function = [&](const Point& p) -> FT - { - return sqrt(p.x() * p.x() + p.y() * p.y() + p.z() * p.z()); - }; - - // create a domain with given bounding box and grid spacing + // create domain with sphere function auto domain = CGAL::Isosurfacing::create_implicit_Cartesian_grid_domain(bbox, vec_spacing, sphere_function); - // prepare collections for the output indexed mesh + // points and triangles for the output indexed mesh Point_range points; - Polygon_range polygons; + Triangle_range triangles; - // execute marching cubes with an isovalue of 0.8 - CGAL::Isosurfacing::marching_cubes(domain, 0.8, points, polygons); + // execute marching cubes with a given isovalue + const FT isovalue = 0.8; + CGAL::Isosurfacing::marching_cubes(domain, isovalue, points, triangles); // save ouput indexed mesh to a file, in the OFF format - CGAL::IO::write_OFF("result.off", points, polygons); + CGAL::IO::write_OFF("output.off", points, triangles); return EXIT_SUCCESS; }