From bb611272543fce8c6b21735c383c954421bf130c Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 21 May 2025 15:34:35 +0200 Subject: [PATCH] always use read_polygon_mesh and write_MEDIT --- .../ccdt_3_after_autorefinement.cpp | 33 ++++++++++--------- .../ccdt_3_check_preconditions.cpp | 9 +++-- .../ccdt_3_from_soup_fpmap.cpp | 21 +++++++----- .../ccdt_3_preprocessing.cpp | 27 +++++++-------- ...g_constrained_Delaunay_triangulation_3.cpp | 7 ++-- ...trained_Delaunay_triangulation_3_fpmap.cpp | 6 ++-- ...ned_Delaunay_triangulation_3_from_soup.cpp | 9 +++-- 7 files changed, 65 insertions(+), 47 deletions(-) diff --git a/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_after_autorefinement.cpp b/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_after_autorefinement.cpp index 8fe78adb679..4d926f25bef 100644 --- a/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_after_autorefinement.cpp +++ b/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_after_autorefinement.cpp @@ -1,12 +1,13 @@ #include -#include "CGAL/Polygon_mesh_processing/polygon_soup_self_intersections.h" +#include +#include #include +#include #include #include -#include - #include +#include using K = CGAL::Exact_predicates_inexact_constructions_kernel; using Point = K::Point_3; @@ -20,8 +21,7 @@ int main(int argc, char* argv[]) : CGAL::data_file_path("meshes/spheres_intersecting.off"); CGAL::Surface_mesh mesh; - std::ifstream in(filename); - if(!in || !(in >> mesh)) { + if(!CGAL::IO::read_polygon_mesh(filename, mesh)) { std::cerr << "Error: cannot read file " << filename << std::endl; return EXIT_FAILURE; } @@ -29,6 +29,8 @@ int main(int argc, char* argv[]) std::cout << "Number of facets in " << filename << ": " << mesh.number_of_faces() << "\n"; + CGAL::Conforming_constrained_Delaunay_triangulation_3 ccdt; + if(PMP::does_self_intersect(mesh)) { std::cout << "Mesh self-intersects, performing autorefine...\n"; @@ -46,22 +48,21 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } - auto ccdt = CGAL::make_conforming_constrained_Delaunay_triangulation_3(points, polygons); + ccdt = CGAL::make_conforming_constrained_Delaunay_triangulation_3(points, polygons); - std::cout << "Number of constrained facets in the CDT: " - << ccdt.number_of_constrained_facets() << '\n'; - - CGAL::draw(ccdt); } else { - auto ccdt = CGAL::make_conforming_constrained_Delaunay_triangulation_3(mesh); - - std::cout << "Number of constrained facets in the CDT: " - << ccdt.number_of_constrained_facets() << '\n'; - - CGAL::draw(ccdt); + ccdt = CGAL::make_conforming_constrained_Delaunay_triangulation_3(mesh); } + std::cout << "Number of constrained facets in the CDT: " + << ccdt.number_of_constrained_facets() << '\n'; + + std::ofstream ofs(argc > 2 ? argv[2] : "out.mesh"); + ofs.precision(17); + CGAL::IO::write_MEDIT(ofs, ccdt); + + CGAL::draw(ccdt); return EXIT_SUCCESS; } diff --git a/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_check_preconditions.cpp b/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_check_preconditions.cpp index b3acadde9e0..5d1daff7d42 100644 --- a/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_check_preconditions.cpp +++ b/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_check_preconditions.cpp @@ -1,5 +1,7 @@ #include +#include +#include #include #include @@ -17,8 +19,7 @@ int main(int argc, char* argv[]) : CGAL::data_file_path("meshes/mpi_and_sphere.off"); CGAL::Surface_mesh mesh; - std::ifstream in(filename); - if(!in || !(in >> mesh)) { + if(!CGAL::IO::read_polygon_mesh(filename, mesh)) { std::cerr << "Error: cannot read file " << filename << std::endl; return EXIT_FAILURE; } @@ -39,6 +40,10 @@ int main(int argc, char* argv[]) std::cout << "Number of constrained facets in the CDT: " << ccdt.number_of_constrained_facets() << '\n'; + std::ofstream ofs(argc > 2 ? argv[2] : "out.mesh"); + ofs.precision(17); + CGAL::IO::write_MEDIT(ofs, ccdt); + CGAL::draw(ccdt); return EXIT_SUCCESS; diff --git a/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_from_soup_fpmap.cpp b/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_from_soup_fpmap.cpp index 38ab2f31849..66ae47f6796 100644 --- a/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_from_soup_fpmap.cpp +++ b/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_from_soup_fpmap.cpp @@ -1,9 +1,11 @@ -#include #include -#include +#include +#include #include #include #include +#include +#include #include #include @@ -17,13 +19,10 @@ namespace PMP = CGAL::Polygon_mesh_processing; int main(int argc, char* argv[]) { - CGAL::Surface_mesh mesh; - std::vector points; - std::vector> polygons; - auto filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/cubes_one_patch_id_per_cc.off"); - std::ifstream in(filename); - if(!in || !(in >> mesh)) { + + CGAL::Surface_mesh mesh; + if(!CGAL::IO::read_polygon_mesh(filename, mesh)) { std::cerr << "Error: cannot read file " << filename << std::endl; return EXIT_FAILURE; } @@ -41,6 +40,9 @@ int main(int argc, char* argv[]) return fpmap[f1] < fpmap[f2]; })] + 1 << std::endl; + + std::vector points; + std::vector> polygons; PMP::polygon_mesh_to_polygon_soup(mesh, points, polygons); auto polygon_to_patch_id = [&](std::size_t i) { @@ -56,6 +58,9 @@ int main(int argc, char* argv[]) << "Number of constrained facets in the CDT: " << ccdt.number_of_constrained_facets() << '\n'; + std::ofstream ofs(argc > 2 ? argv[2] : "out.mesh"); + ofs.precision(17); + CGAL::IO::write_MEDIT(ofs, ccdt); CGAL::draw(ccdt); diff --git a/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_preprocessing.cpp b/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_preprocessing.cpp index 3532baa266e..d2367e7e1e0 100644 --- a/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_preprocessing.cpp +++ b/Constrained_triangulation_3/examples/Constrained_triangulation_3/ccdt_3_preprocessing.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -22,8 +23,7 @@ int main(int argc, char* argv[]) : CGAL::data_file_path("meshes/mpi_and_sphere.off"); CGAL::Surface_mesh mesh; - std::ifstream in(filename); - if(!in || !(in >> mesh)) { + if(!CGAL::IO::read_polygon_mesh(filename, mesh)) { std::cerr << "Error: cannot read file " << filename << std::endl; return EXIT_FAILURE; } @@ -52,6 +52,7 @@ int main(int argc, char* argv[]) } } + CGAL::Conforming_constrained_Delaunay_triangulation_3 ccdt; if(triangle_mesh && PMP::does_self_intersect(mesh)) { std::cout << "Mesh is a self-intersecting triangle mesh, perform autorefinement...\n"; @@ -64,25 +65,25 @@ int main(int argc, char* argv[]) std::cout << "Number of facets after preprocessing: " << polygons.size() << "\n"; - auto ccdt = CGAL::make_conforming_constrained_Delaunay_triangulation_3(points, polygons); + ccdt = CGAL::make_conforming_constrained_Delaunay_triangulation_3(points, polygons); - std::cout << "Number of constrained facets in the CDT: " - << ccdt.number_of_constrained_facets() << '\n'; - - CGAL::draw(ccdt); } else { std::cout << "Number of facets after preprocessing: " << mesh.number_of_faces() << "\n"; - auto ccdt = CGAL::make_conforming_constrained_Delaunay_triangulation_3(mesh); - - std::cout << "Number of constrained facets in the CDT: " - << ccdt.number_of_constrained_facets() << '\n'; - - CGAL::draw(ccdt); + ccdt = CGAL::make_conforming_constrained_Delaunay_triangulation_3(mesh); } + std::cout << "Number of constrained facets in the CDT: " + << ccdt.number_of_constrained_facets() << '\n'; + + std::ofstream ofs(argc > 2 ? argv[2] : "out.mesh"); + ofs.precision(17); + CGAL::IO::write_MEDIT(ofs, ccdt); + + CGAL::draw(ccdt); + return EXIT_SUCCESS; } diff --git a/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3.cpp b/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3.cpp index a6711bcba31..6cf56cc7bc7 100644 --- a/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3.cpp +++ b/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3.cpp @@ -9,9 +9,9 @@ using K = CGAL::Exact_predicates_inexact_constructions_kernel; int main(int argc, char* argv[]) { - CGAL::Surface_mesh mesh; - auto filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/mpi.off"); + + CGAL::Surface_mesh mesh; if(!CGAL::IO::read_polygon_mesh(filename, mesh)) { std::cerr << "Error: cannot read file " << filename << std::endl; return EXIT_FAILURE; @@ -27,7 +27,8 @@ int main(int argc, char* argv[]) << "Number of constrained facets in the CDT: " << ccdt.number_of_constrained_facets() << '\n'; - std::ofstream ofs("out.mesh"); + std::ofstream ofs(argc > 2 ? argv[2] : "out.mesh"); + ofs.precision(17); CGAL::IO::write_MEDIT(ofs, ccdt); CGAL::draw(ccdt); diff --git a/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_fpmap.cpp b/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_fpmap.cpp index 10708ca96ac..07a655da8ab 100644 --- a/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_fpmap.cpp +++ b/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_fpmap.cpp @@ -44,9 +44,9 @@ int main(int argc, char* argv[]) << "Number of constrained facets in the CDT: " << ccdt.number_of_constrained_facets() << '\n'; - std::ofstream out("ccdt.mesh"); - CGAL::IO::write_MEDIT(out, ccdt); - out.close(); + std::ofstream ofs(argc > 2 ? argv[2] : "out.mesh"); + ofs.precision(17); + CGAL::IO::write_MEDIT(ofs, ccdt); return EXIT_SUCCESS; } diff --git a/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_from_soup.cpp b/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_from_soup.cpp index 368d8772778..cbe716e5efd 100644 --- a/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_from_soup.cpp +++ b/Constrained_triangulation_3/examples/Constrained_triangulation_3/conforming_constrained_Delaunay_triangulation_3_from_soup.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -9,10 +10,10 @@ using K = CGAL::Exact_predicates_inexact_constructions_kernel; int main(int argc, char* argv[]) { + auto filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/cubes.off"); + std::vector points; std::vector> polygons; - - auto filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/cubes.off"); if(!CGAL::IO::read_polygon_soup(filename, points, polygons)) { std::cerr << "Error: cannot read file " << filename << std::endl; return EXIT_FAILURE; @@ -28,6 +29,10 @@ int main(int argc, char* argv[]) << "Number of constrained facets in the CDT: " << ccdt.number_of_constrained_facets() << '\n'; + std::ofstream ofs(argc > 2 ? argv[2] : "out.mesh"); + ofs.precision(17); + CGAL::IO::write_MEDIT(ofs, ccdt); + CGAL::draw(ccdt); return EXIT_SUCCESS;