-
Notifications
You must be signed in to change notification settings - Fork 1.5k
STL_Extension: Add bisect_failures debugging utility #9118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lrineau
wants to merge
21
commits into
CGAL:main
Choose a base branch
from
lrineau:STL_Extension-bisect_failures-lrineau
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+676
−5
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
669c7c8
STL_Extension: Add bisect_failures debugging utility
lrineau 04cb44b
fix license: LGPL
lrineau c89c212
bisect_failures: fix documentation
lrineau afff966
fix errors in the testsuite
lrineau 5bd39bf
address Andreas' review, except for STL_Extension vs Profiling_tools
lrineau 919bfa2
Update STL_Extension/test/STL_Extension/test_bisect_failures.cpp
lrineau 5318889
fixes after Andreas's second review
lrineau 66d16fc
avoid failures in the testsuite
lrineau b6c40b3
undef NDEBUG and CGAL_NDEBUG
lrineau 14ecf5f
use std::endl to flush cout
lrineau c6a9a1d
fix compilation error
lrineau 0a6eecd
explain why NDEBUG must not be defined
lrineau d322544
commit suggestions
lrineau 088bf68
tweak SKIP message
lrineau 67ee46f
WIP: rewrite the documentation after review
lrineau 15faab0
fix error
lrineau 30699f6
remove the `*Fn`/`*_fn` suffixes
lrineau d05e6ba
rewrite the doc after review
lrineau 0077f64
tie clog to cerr in bisect_failures
lrineau 3e0e6d6
fix the Github action demo.yml
lrineau b02f873
apply suggestions during reviews
lrineau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| OFF | ||
| 8 4 0 | ||
|
|
||
| 0 0 0 | ||
| 1 0 0 | ||
| 1 1 0 | ||
| 2 0 0 | ||
| 0 0 0 | ||
| 1 0 0 | ||
| 1 1 0 | ||
| 2 0 0 | ||
|
|
||
| 3 0 1 2 | ||
| 3 2 1 3 | ||
| 3 5 4 6 | ||
| 3 5 6 7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
STL_Extension/examples/STL_Extension/bisect_failures.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // CGAL::bisect_failures requires the code to be compiled with assertions | ||
| // enabled. That means NDEBUG and CGAL_NDEBUG should not be defined. | ||
| #if defined(NDEBUG) | ||
| # undef NDEBUG | ||
| #endif | ||
| #if defined(CGAL_NDEBUG) | ||
| # undef CGAL_NDEBUG | ||
| #endif | ||
| #include <CGAL/config.h> | ||
| #include <CGAL/bisect_failures.h> | ||
| #include <CGAL/boost/graph/Euler_operations.h> | ||
| #include <CGAL/boost/graph/graph_traits_Surface_mesh.h> | ||
| #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> | ||
| #include <CGAL/IO/polygon_mesh_io.h> | ||
| #include <CGAL/Polygon_mesh_processing/clip.h> | ||
| #include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h> | ||
| #include <CGAL/Surface_mesh/Surface_mesh.h> | ||
|
|
||
| #include <cstdlib> | ||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; | ||
| using Point = Kernel::Point_3; | ||
| using Mesh = CGAL::Surface_mesh<Point>; | ||
|
|
||
|
|
||
| int main(int argc, char* argv[]) { | ||
| const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/non_manifold.off"); | ||
|
|
||
| Mesh mesh_a; | ||
| if(!CGAL::IO::read_polygon_mesh(filename, mesh_a)) { | ||
| std::cerr << "Error: cannot read file " << filename << std::endl; | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| std::cout << "Loaded mesh with " << mesh_a.number_of_vertices() << " vertices and " | ||
| << mesh_a.number_of_faces() << " faces" << std::endl; | ||
|
|
||
| const std::string clip_name = (argc > 2) ? argv[2] : CGAL::data_file_path("meshes/cube.off"); | ||
| Mesh mesh_b; | ||
| if(!CGAL::IO::read_polygon_mesh(clip_name, mesh_b)) { | ||
| std::cerr << "Error: cannot read file " << clip_name << std::endl; | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
| std::cout << "Loaded clipping mesh mesh with " << mesh_b.number_of_vertices() << " vertices and " | ||
| << mesh_b.number_of_faces() << " faces" << std::endl; | ||
|
|
||
| //! [bisect_failures_snippet] | ||
| // Define the callbacks for bisect_failures | ||
|
|
||
| auto get_size = [](const Mesh& m) -> std::size_t { | ||
| return m.number_of_faces(); | ||
| }; | ||
|
|
||
| auto simplify = [](Mesh& m, int start, int end) -> bool { | ||
| for(auto i = end - 1; i >= start; --i) { | ||
| const auto f = m.faces().begin() + i; | ||
| CGAL::Euler::remove_face(halfedge(*f, m), m); | ||
| } | ||
|
|
||
| return m.is_valid(); | ||
| }; | ||
|
|
||
| auto run = [&mesh_b](Mesh& mesh) -> int { | ||
| return CGAL::Polygon_mesh_processing::clip(mesh, mesh_b) ? EXIT_SUCCESS : EXIT_FAILURE; | ||
| }; | ||
|
|
||
| auto save = [](const Mesh& m, CGAL::Bisection_event event) { | ||
| std::string prefix; | ||
| switch(event) { | ||
| case CGAL::BAD_DATA: | ||
| prefix = "bad_data"; | ||
| break; | ||
| case CGAL::FINAL_BAD_DATA: | ||
| prefix = "final_bad_data"; | ||
| break; | ||
| case CGAL::ERROR_DATA: | ||
| prefix = "error_data"; | ||
| break; | ||
| case CGAL::CURRENT_DATA: | ||
| prefix = "current_data"; | ||
| break; | ||
| default: | ||
| CGAL_UNREACHABLE(); | ||
| } | ||
| std::string out_filename = prefix + ".off"; | ||
| if(!CGAL::IO::write_polygon_mesh(out_filename, m)) { | ||
| std::cerr << "Warning: Could not save mesh to " << out_filename << std::endl; | ||
| } else { | ||
| std::cout << "Saved mesh with " << m.number_of_faces() | ||
| << " faces to " << out_filename << std::endl; | ||
| } | ||
| }; | ||
|
|
||
| std::cout << "\n=== Starting bisection to find smaller failing case ===\n" << std::endl; | ||
|
|
||
| int result = CGAL::bisect_failures(mesh_a, get_size, simplify, run, save); | ||
| //! [bisect_failures_snippet] | ||
|
|
||
| if(result == EXIT_SUCCESS) { | ||
| std::cout << "\nNo failure detected during bisection." << std::endl; | ||
| } else { | ||
| std::cout << "\nFailure detected during bisection. Result code: " << result << std::endl; | ||
| } | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.