better debug code

This commit is contained in:
Laurent Rineau 2025-11-23 14:21:15 +01:00
parent 15e431c48c
commit 3195009f59
2 changed files with 45 additions and 26 deletions

View File

@ -72,6 +72,7 @@ namespace CDT_3 {
struct Debug_options {
enum class Flags {
Steiner_points = 0,
Steiner_points_construction,
conforming,
input_faces,
missing_region,
@ -93,6 +94,8 @@ struct Debug_options {
use_epeck_for_Steiner_points,
nb_of_flags
};
bool Steiner_points_construction() const { return flags[static_cast<int>(Flags::Steiner_points_construction)]; }
void Steiner_points_construction(bool b) { flags.set(static_cast<int>(Flags::Steiner_points_construction), b); }
bool Steiner_points() const { return flags[static_cast<int>(Flags::Steiner_points)]; }
void Steiner_points(bool b) { flags.set(static_cast<int>(Flags::Steiner_points), b); }
@ -1126,7 +1129,7 @@ protected:
return {exact(midpoint_functor(pa, pb)), va->cell(), va};
}
if(debug().encroaching_vertices()) {
if(debug().Steiner_points_construction()) {
std::cerr << "construct_Steiner_point( " << display_vert(va) << " , "
<< display_vert(vb) << " )\n";
}
@ -1142,10 +1145,10 @@ protected:
pa, this->tr().point(v2), pb) == SMALLER;
});
CGAL_assertion(reference_vertex_it != vector_of_encroaching_vertices.end());
#if CGAL_CDT_3_DEBUG_CONFORMING
std::cerr << " -> reference point: " << display_vert(*reference_vertex_it)
<< '\n';
#endif // CGAL_CDT_3_DEBUG_CONFORMING
if(debug().Steiner_points_construction()) {
std::cerr << " -> reference point: " << display_vert(*reference_vertex_it)
<< '\n';
}
const auto reference_vertex = *reference_vertex_it;
const auto& reference_point = tr().point(reference_vertex);
@ -1155,36 +1158,41 @@ protected:
CGAL_assertion(reference_vertex->ccdt_3_data().number_of_incident_constraints() == 1);
const auto ref_constrained_polyline_id = reference_vertex->ccdt_3_data().constrained_polyline_id(*this);
const auto [ref_va, ref_vb] = constraint_extremities(ref_constrained_polyline_id);
#if CGAL_CDT_3_DEBUG_CONFORMING
std::cerr << " reference point is on constraint: " << display_vert(ref_va)
if(debug().Steiner_points_construction()) {
std::cerr << " reference point is on constraint: " << display_vert(ref_va)
<< " " << display_vert(ref_vb) << '\n'
<< " original constraint: " << display_vert(orig_va)
<< " " << display_vert(orig_vb) << '\n';
#endif // CGAL_CDT_3_DEBUG_CONFORMING
}
const auto vector_orig_ab = vector_functor(orig_pa, orig_pb);
const auto length_ab = CGAL::approximate_sqrt(sq_length_functor(vector_ab));
auto return_orig_result_point = [&](auto lambda_val, Point orig_pa_param,
Point orig_pb_param) -> Construct_Steiner_point_return_type {
// Compute projected point with distance-based ratio threshold check
const auto result_point = compute_projected_point_with_threshold(
orig_pa_param, orig_pb_param, // Projection segment
pa, pb, // Midpoint segment
orig_pa_param, orig_pb_param, // Projection segment
pa, pb, // Midpoint segment
[lambda_val](auto&&, auto&&) { return lambda_val; }, // Lambda computer
[&](auto, const std::optional<Point>& projected_pt) { // Threshold check based on distance ratio
[&](auto, const std::optional<Point>& projected_pt) { // Threshold check based on distance ratio
// If projected_pt is not computed yet (std::nullopt), can't check, so return false
if(!projected_pt) return false;
if(!projected_pt)
return false;
const auto dist_a_result = CGAL::approximate_sqrt(sq_length_functor(vector_functor(pa, *projected_pt)));
const auto ratio = dist_a_result / length_ab;
#if CGAL_CDT_3_DEBUG_CONFORMING
std::cerr << " ref ratio = " << ratio << '\n';
#endif
return ratio < 0.2 || ratio > 0.8;
bool use_midpoint = ratio < 0.2 || ratio > 0.8;
if(debug().Steiner_points_construction()) {
std::cerr << " ref ratio = " << ratio << '\n';
if(use_midpoint) {
std::cerr << " -> using midpoint instead of projection\n";
}
}
return use_midpoint;
});
#if CGAL_CDT_3_DEBUG_CONFORMING
std::cerr << " -> Steiner point: " << result_point << '\n';
#endif // CGAL_CDT_3_DEBUG_CONFORMING
if(debug().Steiner_points_construction()) {
std::cerr << " -> Steiner point: " << result_point << '\n';
}
return {exact(result_point), reference_vertex->cell(), reference_vertex};
};
@ -1231,12 +1239,12 @@ protected:
return result;
});
#if CGAL_CDT_3_DEBUG_CONFORMING
const auto vector_a_ref = vector_functor(pa, reference_point);
const auto lambda = sc_product_functor(vector_a_ref, vector_ab) / sq_length_functor(vector_ab);
std::cerr << " lambda = " << lambda << '\n';
std::cerr << " -> Steiner point: " << result_point << '\n';
#endif // CGAL_CDT_3_DEBUG_CONFORMING
if(debug().Steiner_points_construction()) {
const auto vector_a_ref = vector_functor(pa, reference_point);
const auto lambda = gt.compute_scalar_product_3_object()(vector_a_ref, vector_ab) / sq_length_functor(vector_ab);
std::cerr << " lambda = " << lambda << '\n';
std::cerr << " -> Steiner point: " << result_point << '\n';
}
return {exact(result_point), reference_vertex->cell(), reference_vertex};
}

View File

@ -111,6 +111,9 @@ Usage: cdt_3_from_off [options] input.off output.off
--read-mesh-with-operator: read the mesh with operator>>
--reject-self-intersections: reject self-intersecting polygon soups
--no-is-valid: do not call is_valid checks
--debug-Steiner-points: debug Steiner point insertion
--debug-Steiner-points-construction: debug Steiner point construction
--debug-input-faces: debug input faces
--debug-missing-regions: debug missing regions
--debug-regions: debug regions
@ -124,6 +127,7 @@ Usage: cdt_3_from_off [options] input.off output.off
--debug-constraint-hierarchy: debug constraint hierarchy operations
--debug-geometric-errors: debug geometric error handling
--debug-polygon-insertion: debug polygon insertion process
--use-finite-edges-map: use a hash map for finite edges (default: false)
--use-epeck-for-normals/--no-use-epeck-for-normals: use exact kernel for normal computations (default: false)
--use-epeck-for-Steiner-points/--no-use-epeck-for-Steiner-points: use exact kernel for Steiner point computations (default: false)
@ -150,6 +154,8 @@ struct CDT_options
bool reject_self_intersections = false;
bool repair_mesh = true;
bool read_mesh_with_operator = false;
bool debug_Steiner_points = false;
bool debug_Steiner_points_construction = false;
bool debug_input_faces = false;
bool debug_missing_regions = false;
bool debug_regions = false;
@ -235,6 +241,10 @@ CDT_options::CDT_options(int argc, char* argv[]) {
quiet = true;
} else if(arg == "--no-is-valid"sv) {
call_is_valid = false;
} else if(arg == "--debug-Steiner-points"sv) {
debug_Steiner_points = true;
} else if(arg == "--debug-Steiner-points-construction"sv) {
debug_Steiner_points_construction = true;
} else if(arg == "--debug-input-faces"sv) {
debug_input_faces = true;
} else if(arg == "--debug-missing-regions"sv) {
@ -296,7 +306,8 @@ CDT_options::CDT_options(int argc, char* argv[]) {
CGAL::CDT_3::Debug_options cdt_debug_options(const CDT_options& options) {
CGAL::CDT_3::Debug_options cdt_debug;
cdt_debug.Steiner_points(options.verbose_level > 0);
cdt_debug.Steiner_points(options.debug_Steiner_points || options.verbose_level > 0);
cdt_debug.Steiner_points_construction(options.debug_Steiner_points_construction);
cdt_debug.input_faces(options.debug_input_faces);
cdt_debug.missing_region(options.verbose_level > 1 || options.debug_missing_regions);
cdt_debug.regions(options.debug_regions);