From fc7f67269f55dc1051088cdcaa01c8e60115cac4 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 24 Feb 2022 15:41:47 +0100 Subject: [PATCH] Make two programs less verbose Fix #6353 --- .../CGAL/Mesh_3/Mesh_global_optimizer.h | 2 +- .../test_meshing_polyhedron_with_features.cpp | 63 ++++++++++++++++--- .../test/Voronoi_diagram_2/vda_tos2.cpp | 29 +++++++++ 3 files changed, 86 insertions(+), 8 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/Mesh_global_optimizer.h b/Mesh_3/include/CGAL/Mesh_3/Mesh_global_optimizer.h index 516976dbc5c..adf53d159c5 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Mesh_global_optimizer.h +++ b/Mesh_3/include/CGAL/Mesh_3/Mesh_global_optimizer.h @@ -975,7 +975,7 @@ update_mesh(const Moves_vector& moves, FT size = std::get<2>(*it); #ifdef CGAL_MESH_3_OPTIMIZER_VERBOSE - std::cout << "Moving #" << it - moves.begin() + std::cerr << "Moving #" << it - moves.begin() << " addr: " << &*v << " pt: " << tr_.point(v) << " move: " << move << std::endl; diff --git a/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp b/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp index 3805cf33825..bb8a6deb48b 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp @@ -23,10 +23,56 @@ #include #include +#include + +static constexpr bool verbose = +#if CGAL_MESH_3_VERBOSE + true; +#else + false; +#endif + + +std::stringstream cerr_output; template struct Polyhedron_with_features_tester : public Tester { + std::streambuf* old_cerr_buf; + std::string tag_name; + + Polyhedron_with_features_tester(std::string tag_name) + : old_cerr_buf(std::cerr.rdbuf(verbose ? cerr_output.rdbuf() : std::cerr.rdbuf())) + , tag_name(tag_name) + { + } + ~Polyhedron_with_features_tester() + { + std::cerr.rdbuf(old_cerr_buf); + if(verbose) { + const auto output = cerr_output.str(); + const auto str_size= output.size(); + const auto str_begin = output.data(); + const auto str_end = str_begin + str_size; + constexpr auto nb = static_cast(10000); + auto pos1 = str_begin + (std::min)(nb, str_size); + assert(pos1 <= str_end); + const auto pos2 = str_end - (std::min)(nb, str_size); + assert(pos2 >= str_begin); + if(pos2 <= pos1) { + pos1 = str_end; + } + std::cerr << "NOW THE FIRST AND LAST 10k CHARACTERS OF THE CERR OUTPUT:\n"; + std::cerr << "-----\n" << std::string(str_begin, pos1) << "\n-----\n"; + if(pos1 != str_end) { + std::cerr << "[...]\n-----\n" << std::string(pos2, str_end) << "\n-----\n"; + } + const auto file_name = std::string("test_meshing_verbose-") + tag_name + ".txt"; + std::ofstream file_output(file_name); + file_output << output; + std::cerr << "Full log is output to " << file_name << "\n"; + } + } void operator()() const { typedef CGAL::Mesh_3::Robust_intersection_traits_3 Gt; @@ -107,14 +153,17 @@ struct Polyhedron_with_features_tester : public Tester int main() { - Polyhedron_with_features_tester test_epic; - std::cerr << "Mesh generation from a polyhedron with edges:\n"; - test_epic(); - + { + std::cerr << "Mesh generation from a polyhedron with edges:\n"; + Polyhedron_with_features_tester test_epic("sequential"); + test_epic(); + } #ifdef CGAL_LINKED_WITH_TBB - Polyhedron_with_features_tester test_epic_p; - std::cerr << "Parallel mesh generation from a polyhedron with edges:\n"; - test_epic_p(); + { + std::cerr << "Parallel mesh generation from a polyhedron with edges:\n"; + Polyhedron_with_features_tester test_epic_p("parallel"); + test_epic_p(); + } #endif return EXIT_SUCCESS; diff --git a/Voronoi_diagram_2/test/Voronoi_diagram_2/vda_tos2.cpp b/Voronoi_diagram_2/test/Voronoi_diagram_2/vda_tos2.cpp index 18dd6ec5700..2370e1a4442 100644 --- a/Voronoi_diagram_2/test/Voronoi_diagram_2/vda_tos2.cpp +++ b/Voronoi_diagram_2/test/Voronoi_diagram_2/vda_tos2.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; @@ -170,6 +171,10 @@ int main(int argc, char** argv) std::cout << vd.number_of_faces() << " faces" << std::endl; std::cout << "dimension = " << vd.dual().dimension() << std::endl; + // redirect std::cout to cout_output + std::stringstream cout_output; + std::streambuf* old_cout_buf = std::cout.rdbuf(cout_output.rdbuf()); + VD::Vertex_iterator vit = vd.vertices_begin(), vend = vd.vertices_end(); for(; vit!=vend; ++vit) { @@ -197,5 +202,29 @@ int main(int argc, char** argv) CGAL_USE(opposite_h); } + // now restore std::cout and display the output + std::cout.rdbuf(old_cout_buf); + const auto output = cout_output.str(); + const auto str_size = output.size(); + const auto str_begin = output.data(); + const auto str_end = str_begin + str_size; + constexpr auto nb = static_cast(10000); + auto pos1 = str_begin + (std::min)(nb, str_size); + assert(pos1 <= str_end); + const auto pos2 = str_end - (std::min)(nb, str_size); + assert(pos2 >= str_begin); + if (pos2 <= pos1) { + pos1 = str_end; + } + std::cout << "NOW THE FIRST AND LAST 10k CHARACTERS OF THE COUT OUTPUT:\n"; + std::cout << "-----\n" << std::string(str_begin, pos1) << "\n-----\n"; + if (pos1 != str_end) { + std::cout << "[...]\n-----\n" << std::string(pos2, str_end) << "\n-----\n"; + } + const auto file_name = "vda_tos2_test_output.txt"; + std::ofstream file_output(file_name); + file_output << output; + std::cout << "Full log is output to " << file_name << "\n"; + return EXIT_SUCCESS; }