diff --git a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring.cpp b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring.cpp index 07c250117e0..df9f624efe0 100644 --- a/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring.cpp +++ b/Isosurfacing_3/examples/Isosurfacing_3/dual_contouring.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -6,8 +7,12 @@ #include #include -#include +#include +#include +#include +#include +#include #include using Kernel = CGAL::Simple_cartesian; @@ -23,7 +28,9 @@ using Domain = CGAL::Isosurfacing::Dual_contouring_domain_3; using Polygon_range = std::vector >; -// https://www-sop.inria.fr/galaad/surface/ +using Mesh = CGAL::Surface_mesh; + +// "Devil" - https://www-sop.inria.fr/galaad/surface/ auto devil_value = [](const Point& point) { const FT x = point.x(), y = point.y(), z = point.z(); @@ -43,16 +50,19 @@ auto devil_gradient = [](const Point& point) int main(int argc, char** argv) { - const FT isovalue = (argc > 1) ? std::stod(argv[1]) : 0.; + const FT isovalue = (argc > 1) ? std::stod(argv[1]) : 0; + const FT box_c = (argc > 2) ? std::abs(std::stod(argv[2])) : 1.; + const std::size_t grid_n = (argc > 3) ? std::stoi(argv[3]) : 50; // create bounding box and grid - const CGAL::Bbox_3 bbox { -1, -1, -1, 1, 1, 1 }; - Grid grid { bbox, CGAL::make_array(50, 50, 50) }; + const CGAL::Bbox_3 bbox { -box_c, -box_c, -box_c, box_c, box_c, box_c }; + Grid grid { bbox, CGAL::make_array(grid_n, grid_n, grid_n) }; std::cout << "Span: " << grid.span() << std::endl; std::cout << "Cell dimensions: " << grid.spacing()[0] << " " << grid.spacing()[1] << " " << grid.spacing()[2] << std::endl; std::cout << "Cell #: " << grid.xdim() << ", " << grid.ydim() << ", " << grid.zdim() << std::endl; + // fill up values & gradients Values values { devil_value, grid }; Gradients gradients { devil_gradient, grid }; @@ -69,9 +79,19 @@ int main(int argc, char** argv) CGAL::parameters::do_not_triangulate_faces(true) .constrain_to_cell(false)); - std::cout << "Output #vertices: " << points.size() << std::endl; - std::cout << "Output #triangles: " << triangles.size() << std::endl; - CGAL::IO::write_polygon_soup("dual_contouring.off", points, triangles); + std::cout << "Soup #vertices: " << points.size() << std::endl; + std::cout << "Soup #triangles: " << triangles.size() << std::endl; + + if(!CGAL::Polygon_mesh_processing::is_polygon_soup_a_polygon_mesh(triangles)) { + std::cerr << "Warning: the soup is not a 2-manifold surface, non-manifoldness?..." << std::endl; + return EXIT_FAILURE; + } + + std::cout << "Create the mesh..." << std::endl; + Mesh mesh; + CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, triangles, mesh); + + CGAL::IO::write_polygon_mesh("dual_contouring.off", mesh, CGAL::parameters::stream_precision(17)); std::cout << "Done" << std::endl;