diff --git a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_implicit_iwp.cpp b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_implicit_iwp.cpp index 7de06de04b3..e0bc0151e8a 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_implicit_iwp.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring_implicit_iwp.cpp @@ -20,26 +20,26 @@ int main(int, char**) auto iwp_value = [alpha](const Point& point) { - const FT x = alpha * (point.x() + 1) * CGAL_PI; - const FT y = alpha * (point.y() + 1) * CGAL_PI; - const FT z = alpha * (point.z() + 1) * CGAL_PI; + const FT x = alpha * (point.x() + FT(1.0)) * CGAL_PI; + const FT y = alpha * (point.y() + FT(1.0)) * CGAL_PI; + const FT z = alpha * (point.z() + FT(1.0)) * CGAL_PI; return cos(x) * cos(y) + cos(y) * cos(z) + cos(z) * cos(x) - cos(x) * cos(y) * cos(z); // isovalue = 0 }; auto iwp_gradient = [alpha](const Point& point) { - const FT x = alpha * (point.x() + 1) * CGAL_PI; - const FT y = alpha * (point.y() + 1) * CGAL_PI; - const FT z = alpha * (point.z() + 1) * CGAL_PI; + const FT x = alpha * (point.x() + FT(1.0)) * CGAL_PI; + const FT y = alpha * (point.y() + FT(1.0)) * CGAL_PI; + const FT z = alpha * (point.z() + FT(1.0)) * CGAL_PI; - const FT gx = CGAL_PI * alpha * sin(x) * (cos(y) * (cos(z) - 1.0) - cos(z)); - const FT gy = CGAL_PI * alpha * sin(y) * (cos(x) * (cos(z) - 1.0) - cos(z)); - const FT gz = CGAL_PI * alpha * sin(z) * (cos(x) * (cos(y) - 1.0) - cos(y)); + const FT gx = CGAL_PI * alpha * sin(x) * (cos(y) * (cos(z) - FT(1.0)) - cos(z)); + const FT gy = CGAL_PI * alpha * sin(y) * (cos(x) * (cos(z) - FT(1.0)) - cos(z)); + const FT gz = CGAL_PI * alpha * sin(z) * (cos(x) * (cos(y) - FT(1.0)) - cos(y)); return Vector(gx, gy, gz); }; - const CGAL::Bbox_3 bbox{-1.0, -1.0, -1.0, 1.0, 1.0, 1.0}; - const FT spacing = 0.5; + const CGAL::Bbox_3 bbox{-1.0, -1.0, -1.0, 1.0, 1.0, 1.0}; + const FT spacing = 0.02; const Vector vec_spacing(spacing, spacing, spacing); // create a domain with given bounding box and grid spacing @@ -49,11 +49,11 @@ int main(int, char**) Point_range points; Polygon_range polygons; - // run marching cubes with an isovalue of 0.0 + // run duak contouring with isovalue set to 0.0 CGAL::Isosurfacing::dual_contouring(domain, 0.0, points, polygons); - // save the result in the OFF format - CGAL::IO::write_OFF("result.off", points, polygons); + // save output to the OFF format + CGAL::IO::write_OFF("output.off", points, polygons); return EXIT_SUCCESS; } diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_Cartesian_grid_sphere.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_Cartesian_grid_sphere.cpp index b4e2ca2cfa5..f0e3f90c732 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_Cartesian_grid_sphere.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_Cartesian_grid_sphere.cpp @@ -1,10 +1,7 @@ - #include - #include #include #include - #include #include @@ -14,20 +11,19 @@ using FT = typename Kernel::FT; using Point = typename Kernel::Point_3; using Grid = CGAL::Isosurfacing::Cartesian_grid_3; - using Point_range = std::vector; using Polygon_range = std::vector >; int main(int, char**) { - // create a Cartesian grid with 100^3 grid points and the bounding box [-1, 1]^3 - const CGAL::Bbox_3 bbox{-1., -1., -1., 1., 1., 1.}; + // 3D bounding box [-1, 1]^3 and Cartesian grid + const CGAL::Bbox_3 bbox{-1., -1., -1., 1., 1., 1.}; Grid grid { 50, 50, 50, bbox }; // compute and store function values at all grid points - for(std::size_t x=0; x #include - using Kernel = CGAL::Simple_cartesian; using FT = typename Kernel::FT; using Point = typename Kernel::Point_3; @@ -14,7 +13,7 @@ using Vector = typename Kernel::Vector_3; using Point_range = std::vector; using Triangle_range = std::vector >; -// Sphere = Euclidean distance function to the origin +// 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()); diff --git a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_multiple_mesh_offsets.cpp b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_multiple_mesh_offsets.cpp index aeb76749520..2e6baeab42b 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_multiple_mesh_offsets.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/marching_cubes_multiple_mesh_offsets.cpp @@ -37,7 +37,7 @@ inline Kernel::FT distance_to_mesh(const Tree& tree, const Point& p) { const Point x = tree.closest_point(p); - return sqrt((p - x).squared_length()); + return std::sqrt((p - x).squared_length()); } int main(int argc, char **argv) @@ -97,11 +97,11 @@ int main(int argc, char **argv) { // containers for the triangle soup output Point_range points; - Polygon_range polygons; + Polygon_range triangles; // execute marching cubes with an isovalue equating offset std::cout << "Marching cubes with offset " << offset << "..."; - CGAL::Isosurfacing::marching_cubes(domain, offset, points, polygons); + CGAL::Isosurfacing::marching_cubes(domain, offset, points, triangles); std::cout << "done" << std::endl; // save the output @@ -109,7 +109,7 @@ int main(int argc, char **argv) filename.append(std::to_string(index)); filename.append(std::string(".off")); std::cout << "Save to file " << filename << "..."; - CGAL::IO::write_polygon_soup(filename, points, polygons); + CGAL::IO::write_polygon_soup(filename, points, triangles); std::cout << "done" << std::endl; } diff --git a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/marching_cubes_functors.h b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/marching_cubes_functors.h index ea5e15da42f..3583c55ed44 100644 --- a/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/marching_cubes_functors.h +++ b/Isosurfacing_3/include/CGAL/Isosurfacing_3/internal/marching_cubes_functors.h @@ -77,7 +77,7 @@ typename GeomTraits::Point_3 vertex_interpolation(const typename GeomTraits::Poi typename GeomTraits::Compute_z_3 z_coord = gt.compute_z_3_object(); typename GeomTraits::Construct_point_3 point = gt.construct_point_3_object(); - FT mu = (FT)0.0; + FT mu = FT(0.0); // don't divide by 0 if(abs(d1 - d0) < 0.000001) // @fixme hardcoded bound @@ -85,12 +85,12 @@ typename GeomTraits::Point_3 vertex_interpolation(const typename GeomTraits::Poi else mu = (isovalue - d0) / (d1 - d0); - CGAL_assertion(mu >= FT(0) || mu <= FT(1)); + CGAL_assertion(mu >= FT(0.0) || mu <= FT(1.0)); // linear interpolation - return point(x_coord(p1) * mu + x_coord(p0) * (1 - mu), - y_coord(p1) * mu + y_coord(p0) * (1 - mu), - z_coord(p1) * mu + z_coord(p0) * (1 - mu)); + return point(x_coord(p1) * mu + x_coord(p0) * (FT(1.0) - mu), + y_coord(p1) * mu + y_coord(p0) * (FT(1.0) - mu), + z_coord(p1) * mu + z_coord(p0) * (FT(1.0) - mu)); } // retrieves the corner vertices and their values of a cell and return the lookup index @@ -174,7 +174,7 @@ void mc_construct_triangles(const int i_case, TriangleList& triangles) { // construct triangles - for(int t=0; t<16; t+=3) + for(int t = 0; t < 16; t += 3) { const int t_index = i_case * 16 + t;