diff --git a/Constrained_triangulation_3/include/CGAL/Conforming_Delaunay_triangulation_3.h b/Constrained_triangulation_3/include/CGAL/Conforming_Delaunay_triangulation_3.h index 4133f2844c6..f16b04ce729 100644 --- a/Constrained_triangulation_3/include/CGAL/Conforming_Delaunay_triangulation_3.h +++ b/Constrained_triangulation_3/include/CGAL/Conforming_Delaunay_triangulation_3.h @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -34,8 +35,112 @@ #ifndef DOXYGEN_RUNNING +#if CGAL_USE_ITT +# include +#endif + namespace CGAL { +namespace CDT_3::internal { + +auto& tasks_manager() { + struct Tasks_manager { + enum { + READ_INPUT = 0, + MERGE_FACETS, + INSERT_VERTICES, + COMPUTE_DISTANCES, + CONFORMING, + CDT, + OUTPUT, + VALIDATION, + NB_TASKS + }; + + #if CGAL_USE_ITT + __itt_domain* cdt_3_domain = __itt_domain_create("org.cgal.CDT_3"); + const std::array<__itt_string_handle*, NB_TASKS> task_handles = { + __itt_string_handle_create("CDT_3: read input file"), + __itt_string_handle_create("CDT_3: merge facets"), + __itt_string_handle_create("CDT_3: insert vertices"), + __itt_string_handle_create("CDT_3: compute distances"), + __itt_string_handle_create("CDT_3: conforming"), + __itt_string_handle_create("CDT_3: cdt"), + __itt_string_handle_create("CDT_3: outputs"), + __itt_string_handle_create("CDT_3: validation") + }; + #endif + std::array timers{}; + struct Scope_guard { + Tasks_manager *instance = nullptr; + int task_id; + Scope_guard(Tasks_manager *instance, int task_id) : instance(instance), task_id(task_id) { + instance->timers[task_id].start(); +#if CGAL_USE_ITT + __itt_task_begin(instance->cdt_3_domain, __itt_null, __itt_null, instance->task_handles[task_id]); +#endif + } + ~Scope_guard() { + instance->timers[task_id].stop(); +#if CGAL_USE_ITT + __itt_task_end(instance->cdt_3_domain); +#endif + } + }; + + Scope_guard make_task_scope_guard(int task_id) { + return Scope_guard(this, task_id); + } + + Scope_guard READ_INPUT_TASK_guard() { return make_task_scope_guard(READ_INPUT); } + Scope_guard MERGE_FACETS_TASK_guard() { return make_task_scope_guard(MERGE_FACETS); } + Scope_guard INSERT_VERTICES_TASK_guard() { return make_task_scope_guard(INSERT_VERTICES); } + Scope_guard COMPUTE_DISTANCES_TASK_guard() { return make_task_scope_guard(COMPUTE_DISTANCES); } + Scope_guard CONFORMING_TASK_guard() { return make_task_scope_guard(CONFORMING); } + Scope_guard CDT_TASK_guard() { return make_task_scope_guard(CDT); } + Scope_guard OUTPUT_TASK_guard() { return make_task_scope_guard(OUTPUT); } + Scope_guard VALIDATION_TASK_guard() { return make_task_scope_guard(VALIDATION); } + + }; // end struct Intel_OneAPI_ITT_API + + static Tasks_manager instance; + return instance; +} // end auto& tasks_manager() + +} // end namespace CDT_3::internal + +inline auto CDT_3_READ_INPUT_TASK_guard() { + return CDT_3::internal::tasks_manager().READ_INPUT_TASK_guard(); +} + +inline auto CDT_3_MERGE_FACETS_TASK_guard() { + return CDT_3::internal::tasks_manager().MERGE_FACETS_TASK_guard(); +} + +inline auto CDT_3_INSERT_VERTICES_TASK_guard() { + return CDT_3::internal::tasks_manager().INSERT_VERTICES_TASK_guard(); +} + +inline auto CDT_3_COMPUTE_DISTANCES_TASK_guard() { + return CDT_3::internal::tasks_manager().COMPUTE_DISTANCES_TASK_guard(); +} + +inline auto CDT_3_CONFORMING_TASK_guard() { + return CDT_3::internal::tasks_manager().CONFORMING_TASK_guard(); +} + +inline auto CDT_3_CDT_TASK_guard() { + return CDT_3::internal::tasks_manager().CDT_TASK_guard(); +} + +inline auto CDT_3_OUTPUT_TASK_guard() { + return CDT_3::internal::tasks_manager().OUTPUT_TASK_guard(); +} + +inline auto CDT_3_VALIDATION_TASK_guard() { + return CDT_3::internal::tasks_manager().VALIDATION_TASK_guard(); +} + template class Conforming_Delaunay_triangulation_3 : public T_3 { public: diff --git a/Constrained_triangulation_3/test/Constrained_triangulation_3/CMakeLists.txt b/Constrained_triangulation_3/test/Constrained_triangulation_3/CMakeLists.txt index b11f6c5d1d9..ac5089404b2 100644 --- a/Constrained_triangulation_3/test/Constrained_triangulation_3/CMakeLists.txt +++ b/Constrained_triangulation_3/test/Constrained_triangulation_3/CMakeLists.txt @@ -29,13 +29,6 @@ create_single_source_cgal_program( "cdt_3_from_off_with_Epeck.cpp") target_link_libraries(cdt_3_from_off_with_Epeck PRIVATE CDT_3_dependencies) create_single_source_cgal_program( "snap_and_cdt3.cpp") -if(cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES) - add_executable(cdt_3_from_off_CGAL_DEBUG_CDT_3 cdt_3_from_off) - target_compile_definitions(cdt_3_from_off_CGAL_DEBUG_CDT_3 PRIVATE CGAL_DEBUG_CDT_3=255) - target_link_libraries(cdt_3_from_off_CGAL_DEBUG_CDT_3 PRIVATE CDT_3_dependencies) - cgal_add_test(cdt_3_from_off_CGAL_DEBUG_CDT_3) -endif() - add_executable(test_CDT_3_insert_constrained_edge_from_EDG_file cdt_test_insert_constrained_edge_from_EDG_file.cpp) target_link_libraries(test_CDT_3_insert_constrained_edge_from_EDG_file PRIVATE CDT_3_dependencies) target_compile_definitions(test_CDT_3_insert_constrained_edge_from_EDG_file PUBLIC CGAL_TEST_CDT_3_USE_CDT) @@ -143,12 +136,6 @@ if (CGAL_CDT_TEST_USE_THINGI) include(./Thingi10k-CDT.cmake) endif() -if(cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES) - add_test(NAME "execution of cdt_3_from_off_CGAL_DEBUG_CDT_3 3torus" COMMAND cdt_3_from_off_CGAL_DEBUG_CDT_3 ${CGAL_DATA_DIR}/meshes/3torus.off) - cgal_add_compilation_test(cdt_3_from_off_CGAL_DEBUG_CDT_3) - cgal_setup_test_properties("execution of cdt_3_from_off_CGAL_DEBUG_CDT_3 3torus" cdt_3_from_off_CGAL_DEBUG_CDT_3) -endif() - get_directory_property(all_tests TESTS) foreach(test ${all_tests}) if(test MATCHES cdt|CDT) diff --git a/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_3_from_off.cpp b/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_3_from_off.cpp index ac650de2225..5359a58e5ff 100644 --- a/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_3_from_off.cpp +++ b/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_3_from_off.cpp @@ -2,13 +2,7 @@ #pragma warning(disable: 4455) #endif -#if defined(CGAL_DEBUG_CDT_3) && !__has_include() -#undef CGAL_DEBUG_CDT_3 -#endif - // #define CGAL_CDT_2_DEBUG_INTERSECTIONS 1 -#define NO_TRY_CATCH 1 -// #define CGAL_DEBUG_CDT_3 1 #include #include #include @@ -275,34 +269,6 @@ CDT_options::CDT_options(int argc, char* argv[]) { # define CDT_3_throw_exception_again throw #endif -#if CGAL_USE_ITT -# include -# define CGAL_CDT_3_TASK_BEGIN(task_handle) \ - std::cerr << "START " << #task_handle << '\n'; \ - __itt_task_begin(cdt_3_domain, __itt_null, __itt_null, task_handle); -# define CGAL_CDT_3_TASK_END(task_handle) \ - std::cerr << "-STOP " << #task_handle << '\n'; \ - __itt_task_end(cdt_3_domain); -# define CGAL_CDT_3_TASK_SCOPE(task_handle) \ - CGAL_CDT_3_TASK_BEGIN(task_handle) \ - auto scope_exit = CGAL::make_scope_exit([&]() { CGAL_CDT_3_TASK_END(task_handle); }); - - auto cdt_3_domain = __itt_domain_create("org.cgal.CDT_3"); - auto read_input_task_handle = __itt_string_handle_create("CDT_3: read input file"); - auto merge_facets_task_handle = __itt_string_handle_create("CDT_3: merge facets"); - auto insert_vertices_task_handle = __itt_string_handle_create("CDT_3: insert vertices"); - auto compute_distances_task_handle = __itt_string_handle_create("CDT_3: compute distances"); - auto conforming_task_handle = __itt_string_handle_create("CDT_3: conforming"); - auto cdt_task_handle = __itt_string_handle_create("CDT_3: cdt"); - auto output_task_handle = __itt_string_handle_create("CDT_3: outputs"); - auto validation_task_handle = __itt_string_handle_create("CDT_3: validation"); - -#else // no ITT -# define CGAL_CDT_3_TASK_BEGIN(task_handle) -# define CGAL_CDT_3_TASK_END(task_handle) -# define CGAL_CDT_3_TASK_SCOPE(task_handle) -#endif // no ITT - void configure_cdt_debug_options(CDT& cdt, const CDT_options& options) { cdt.debug_Steiner_points(options.verbose_level > 0); cdt.debug_input_faces(options.debug_input_faces); @@ -343,7 +309,7 @@ auto compute_bounding_box(const Mesh& mesh, const CDT_options& options) { std::function create_output_finalizer(const CDT& cdt, const CDT_options& options) { return [&cdt, &options]() { - CGAL_CDT_3_TASK_SCOPE(output_task_handle); + auto _ = CGAL::CDT_3_OUTPUT_TASK_guard(); { auto dump_tets_to_medit = [](std::string fname, const std::vector &points, @@ -725,8 +691,8 @@ Borders_of_patches maybe_merge_facets( if(!options.merge_facets) return patch_edges; - CGAL_CDT_3_TASK_BEGIN(merge_facets_task_handle); { + auto _ = CGAL::CDT_3_MERGE_FACETS_TASK_guard(); auto start_time = std::chrono::high_resolution_clock::now(); if(options.merge_facets_old_method) { @@ -743,16 +709,14 @@ Borders_of_patches maybe_merge_facets( << std::chrono::duration_cast(timing).count() << " ms\n"; } } - CGAL_CDT_3_TASK_END(merge_facets_task_handle); if(options.dump_patches_after_merge_filename.empty()) return patch_edges; - CGAL_CDT_3_TASK_BEGIN(output_task_handle); { + auto _ = CGAL::CDT_3_OUTPUT_TASK_guard(); std::ofstream out(options.dump_patches_after_merge_filename); CGAL::IO::write_PLY(out, mesh, CGAL::parameters::stream_precision(17)); } - CGAL_CDT_3_TASK_END(output_task_handle); return patch_edges; } @@ -813,15 +777,14 @@ int go(Mesh mesh, CDT_options options) { auto patch_edges = maybe_merge_facets(mesh, options, pmaps, bbox_max_span); if(!options.dump_patches_borders_prefix.empty()) { - CGAL_CDT_3_TASK_BEGIN(output_task_handle); + auto _ = CGAL::CDT_3_OUTPUT_TASK_guard(); dump_patches_borders(patch_edges, pmaps, options.dump_patches_borders_prefix); - CGAL_CDT_3_TASK_END(output_task_handle); } auto mesh_descriptor_to_vertex_handle_pmap = get(CGAL::dynamic_vertex_property_t(), mesh); - CGAL_CDT_3_TASK_BEGIN(insert_vertices_task_handle); { + auto _ = CGAL::CDT_3_INSERT_VERTICES_TASK_guard(); auto start_time = std::chrono::high_resolution_clock::now(); if(options.merge_facets) { cdt.insert_vertices_range(vertices(mesh), pmaps.mesh_vertex_point_map, mesh_descriptor_to_vertex_handle_pmap, @@ -844,10 +807,9 @@ int go(Mesh mesh, CDT_options options) { } cdt.add_bbox_points_if_not_dimension_3(); } - CGAL_CDT_3_TASK_END(insert_vertices_task_handle); - CGAL_CDT_3_TASK_BEGIN(compute_distances_task_handle); { + auto _ = CGAL::CDT_3_COMPUTE_DISTANCES_TASK_guard(); auto start_time = std::chrono::high_resolution_clock::now(); auto exit_code = validate_minimum_vertex_distances(cdt, options.vertex_vertex_epsilon * bbox_max_span, options); @@ -863,10 +825,9 @@ int go(Mesh mesh, CDT_options options) { << std::chrono::duration_cast(timing).count() << " ms\n"; } } - CGAL_CDT_3_TASK_END(compute_distances_task_handle); - CGAL_CDT_3_TASK_BEGIN(conforming_task_handle); { + auto _ = CGAL::CDT_3_CONFORMING_TASK_guard(); int poly_id = 0; auto output_on_exit_scope_guard = CGAL::make_scope_exit(create_output_finalizer(cdt, options)); auto start_time = std::chrono::high_resolution_clock::now(); @@ -904,10 +865,9 @@ int go(Mesh mesh, CDT_options options) { std::chrono::high_resolution_clock::now() - start_time).count() << " ms\n"; } } - CGAL_CDT_3_TASK_END(conforming_task_handle); if(!options.dump_after_conforming_filename.empty()) { - CGAL_CDT_3_TASK_BEGIN(output_task_handle); + auto _ = CGAL::CDT_3_OUTPUT_TASK_guard(); using Vertex_index = Mesh::Vertex_index; [[maybe_unused]] std::size_t time_stamp_counter = 0u; for(auto v: cdt.finite_vertex_handles()) { @@ -929,23 +889,21 @@ int go(Mesh mesh, CDT_options options) { out_mesh.precision(17); out_mesh << mesh; out_mesh.close(); - CGAL_CDT_3_TASK_END(output_task_handle); } if(!options.quiet) { std::cout << "Number of vertices after conforming: " << cdt.number_of_vertices() << "\n\n"; } - CGAL_CDT_3_TASK_BEGIN(validation_task_handle); { + auto _ = CGAL::CDT_3_VALIDATION_TASK_guard(); CGAL_assertion(!options.call_is_valid || cdt.Base_triantulation::is_valid(true)); CGAL_assertion(!options.call_is_valid || cdt.is_valid(true)); CGAL_assertion(!options.call_is_valid || cdt.is_conforming()); } - CGAL_CDT_3_TASK_END(validation_task_handle); - CGAL_CDT_3_TASK_BEGIN(cdt_task_handle); { + auto _ = CGAL::CDT_3_CDT_TASK_guard(); auto start_time = std::chrono::high_resolution_clock::now(); cdt.restore_constrained_Delaunay(); if(!options.quiet) { @@ -954,14 +912,12 @@ int go(Mesh mesh, CDT_options options) { std::cout << "Number of vertices after CDT: " << cdt.number_of_vertices() << "\n\n"; } } - CGAL_CDT_3_TASK_END(cdt_task_handle); - CGAL_CDT_3_TASK_BEGIN(validation_task_handle); { + auto _ = CGAL::CDT_3_VALIDATION_TASK_guard(); CGAL_assertion(!options.call_is_valid || cdt.is_conforming()); CGAL_assertion(!options.call_is_valid || cdt.is_valid(true)); } - CGAL_CDT_3_TASK_END(validation_task_handle); return EXIT_SUCCESS; } @@ -1064,56 +1020,54 @@ int main(int argc, char* argv[]) { return 0; } - CGAL_CDT_3_TASK_BEGIN(read_input_task_handle); - auto start_time = std::chrono::high_resolution_clock::now(); - CGAL::CDT_3_read_polygon_mesh_output read_mesh_result; - if(options.read_mesh_with_operator) { - std::ifstream in(options.input_filename); - if(!in) { - std::cerr << "Cannot open file: " << options.input_filename << std::endl; - return EXIT_FAILURE; - } - Mesh mesh; - in >> mesh; - if(!in) { - std::cerr << "Error reading mesh with operator>>" << std::endl; - return EXIT_FAILURE; - } - read_mesh_result.polygon_mesh = std::move(mesh); - } else { - auto read_options = CGAL::parameters::repair_polygon_soup(options.repair_mesh).verbose(options.verbose_level); - read_mesh_result = CGAL::read_polygon_mesh_for_cdt_3(options.input_filename, read_options); - } - - if (!read_mesh_result.polygon_mesh) + auto start_time = std::chrono::high_resolution_clock::now(); { - std::cerr << "Not a valid input file." << std::endl; - std::cerr << "Details:\n" << read_mesh_result.polygon_mesh.error() << std::endl; - return EXIT_FAILURE; - } - Mesh mesh = std::move(*read_mesh_result.polygon_mesh); - if(!options.quiet) { - std::cout << "[timings] read mesh in " << std::chrono::duration_cast( - std::chrono::high_resolution_clock::now() - start_time).count() << " ms\n"; - std::cout << "Number of vertices: " << mesh.number_of_vertices() << '\n'; - std::cout << "Number of edges: " << mesh.number_of_edges() << '\n'; - std::cout << "Number of faces: " << mesh.number_of_faces() << "\n\n"; + auto _ = CGAL::CDT_3_READ_INPUT_TASK_guard(); - if(!options.read_mesh_with_operator) { - std::cout << "Processing was successful.\n"; - std::cout << " Number of duplicated points: " << read_mesh_result.nb_of_duplicated_points << '\n'; - std::cout << " Number of simplified polygons: " << read_mesh_result.nb_of_simplified_polygons << '\n'; - std::cout << " Number of new polygons: " << read_mesh_result.nb_of_new_polygons << '\n'; - std::cout << " Number of removed invalid polygons: " << read_mesh_result.nb_of_removed_invalid_polygons << '\n'; - std::cout << " Number of removed duplicated polygons: " << read_mesh_result.nb_of_removed_duplicated_polygons << '\n'; - std::cout << " Number of removed isolated points: " << read_mesh_result.nb_of_removed_isolated_points << '\n'; - std::cout << " Polygon soup self-intersects: " << (read_mesh_result.polygon_soup_self_intersects ? "YES" : "no") << '\n'; - std::cout << " Polygon mesh is manifold: " << (read_mesh_result.polygon_mesh_is_manifold ? "yes" : "NO") << '\n'; - std::cout << std::endl; + if(options.read_mesh_with_operator) { + std::ifstream in(options.input_filename); + if(!in) { + std::cerr << "Cannot open file: " << options.input_filename << std::endl; + return EXIT_FAILURE; + } + in >> *read_mesh_result.polygon_mesh; + if(!in) { + std::cerr << "Error reading mesh with operator>>" << std::endl; + return EXIT_FAILURE; + } + } else { + auto read_options = CGAL::parameters::repair_polygon_soup(options.repair_mesh).verbose(options.verbose_level); + read_mesh_result = CGAL::read_polygon_mesh_for_cdt_3(options.input_filename, read_options); + } + + if (!read_mesh_result.polygon_mesh) + { + std::cerr << "Not a valid input file." << std::endl; + std::cerr << "Details:\n" << read_mesh_result.polygon_mesh.error() << std::endl; + return EXIT_FAILURE; + } + if(!options.quiet) { + std::cout << "[timings] read mesh in " << std::chrono::duration_cast( + std::chrono::high_resolution_clock::now() - start_time).count() << " ms\n"; + std::cout << "Number of vertices: " << read_mesh_result.polygon_mesh->number_of_vertices() << '\n'; + std::cout << "Number of edges: " << read_mesh_result.polygon_mesh->number_of_edges() << '\n'; + std::cout << "Number of faces: " << read_mesh_result.polygon_mesh->number_of_faces() << "\n\n"; + + if(!options.read_mesh_with_operator) { + std::cout << "Processing was successful.\n"; + std::cout << " Number of duplicated points: " << read_mesh_result.nb_of_duplicated_points << '\n'; + std::cout << " Number of simplified polygons: " << read_mesh_result.nb_of_simplified_polygons << '\n'; + std::cout << " Number of new polygons: " << read_mesh_result.nb_of_new_polygons << '\n'; + std::cout << " Number of removed invalid polygons: " << read_mesh_result.nb_of_removed_invalid_polygons << '\n'; + std::cout << " Number of removed duplicated polygons: " << read_mesh_result.nb_of_removed_duplicated_polygons << '\n'; + std::cout << " Number of removed isolated points: " << read_mesh_result.nb_of_removed_isolated_points << '\n'; + std::cout << " Polygon soup self-intersects: " << (read_mesh_result.polygon_soup_self_intersects ? "YES" : "no") << '\n'; + std::cout << " Polygon mesh is manifold: " << (read_mesh_result.polygon_mesh_is_manifold ? "yes" : "NO") << '\n'; + std::cout << std::endl; + } } } - CGAL_CDT_3_TASK_END(read_input_task_handle); if(options.reject_self_intersections && read_mesh_result.polygon_soup_self_intersects) { std::cerr << "ERROR: input mesh self-intersects\n"; @@ -1121,10 +1075,10 @@ int main(int argc, char* argv[]) { } if(!options.failure_assertion_expression.empty()) { - return bisect_errors(std::move(mesh), options); + return bisect_errors(std::move(*read_mesh_result.polygon_mesh), options); } - auto exit_code = go(std::move(mesh), options); + auto exit_code = go(std::move(*read_mesh_result.polygon_mesh), options); if(!options.quiet) { std::cout << "[timings] total time: " << std::chrono::duration_cast( std::chrono::high_resolution_clock::now() - start_time).count() << " ms\n"; diff --git a/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_test_insert_constrained_edge_from_EDG_file.cpp b/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_test_insert_constrained_edge_from_EDG_file.cpp index 56e38ba2979..fefdaf4749b 100644 --- a/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_test_insert_constrained_edge_from_EDG_file.cpp +++ b/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_test_insert_constrained_edge_from_EDG_file.cpp @@ -1,6 +1,3 @@ -#if __has_include() -#define CGAL_DEBUG_CDT_3 1 -#endif #define CGAL_TRIANGULATION_CHECK_EXPENSIVE 1 #include #include diff --git a/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_test_insert_constrained_edge_from_OFF_file.cpp b/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_test_insert_constrained_edge_from_OFF_file.cpp index 7a58a1f5667..3510cf0ea15 100644 --- a/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_test_insert_constrained_edge_from_OFF_file.cpp +++ b/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_test_insert_constrained_edge_from_OFF_file.cpp @@ -1,6 +1,3 @@ -#if __has_include() -#define CGAL_DEBUG_CDT_3 1 -#endif #define CGAL_TRIANGULATION_CHECK_EXPENSIVE 1 #include #include