From 254818cf7097789a8d0892e0f4724f8208da9f21 Mon Sep 17 00:00:00 2001 From: Pierre Alliez Date: Fri, 5 Jan 2024 14:39:47 +0100 Subject: [PATCH] added example that compares parallel with sequential MC --- .../examples/Isosurfacing_3/CMakeLists.txt | 1 + .../marching_cubes_seq_vs_parallel.cpp | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_seq_vs_parallel.cpp diff --git a/Isosurfacing_3/examples/Isosurfacing_3/CMakeLists.txt b/Isosurfacing_3/examples/Isosurfacing_3/CMakeLists.txt index d32bd8a1962..85206736e94 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/CMakeLists.txt +++ b/Isosurfacing_3/examples/Isosurfacing_3/CMakeLists.txt @@ -7,6 +7,7 @@ project( Isosurfacing_3_Examples ) find_package(CGAL REQUIRED) create_single_source_cgal_program( "marching_cubes_implicit_sphere.cpp" ) +create_single_source_cgal_program( "marching_cubes_seq_vs_parallel.cpp" ) create_single_source_cgal_program( "marching_cubes_Cartesian_grid_sphere.cpp" ) create_single_source_cgal_program( "marching_cubes_signed_mesh_offset.cpp" ) create_single_source_cgal_program( "marching_cubes_multiple_mesh_offsets.cpp" ) diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_seq_vs_parallel.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_seq_vs_parallel.cpp new file mode 100644 index 00000000000..a2150cb808d --- /dev/null +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_seq_vs_parallel.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include + +using Kernel = CGAL::Simple_cartesian; +using FT = typename Kernel::FT; +using Point = typename Kernel::Point_3; +using Vector = typename Kernel::Vector_3; +using Point_range = std::vector; +using Triangle_range = std::vector >; + +// Sphere function = 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**) +{ + // 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.01; + const Vector vec_spacing(spacing, spacing, spacing); + + // create domain with sphere function + auto domain = CGAL::Isosurfacing::create_implicit_Cartesian_grid_domain + (bbox, vec_spacing, sphere_function); + + // points and triangles for the output indexed mesh + Point_range points; + Triangle_range triangles; + + // run marching cubes sequential + std::cout << "marching cubes sequential..."; + const FT isovalue = 0.8; + CGAL::Timer timer; + timer.start(); + CGAL::Isosurfacing::marching_cubes(domain, isovalue, points, triangles); + timer.stop(); + std::cout << "done (" << timer.time() << "s, " << triangles.size() << " triangles)" << std::endl; + CGAL::IO::write_OFF("output-seq.off", points, triangles); + + // clear points and triangles + points.clear(); + triangles.clear(); + + // run marching cubes parallel + std::cout << "marching cubes parallel..."; + timer.start(); + CGAL::Isosurfacing::marching_cubes(domain, isovalue, points, triangles); + timer.stop(); + std::cout << "done (" << timer.time() << "s, " << triangles.size() << " triangles)" << std::endl; + CGAL::IO::write_OFF("output-parallel.off", points, triangles); + + return EXIT_SUCCESS; +}