diff --git a/Shape_detection/test/Shape_detection/test_region_growing_deprecated_constructors.cpp b/Shape_detection/test/Shape_detection/test_region_growing_deprecated_constructors.cpp index ac00d003fdc..ae65c4f2ef9 100644 --- a/Shape_detection/test/Shape_detection/test_region_growing_deprecated_constructors.cpp +++ b/Shape_detection/test/Shape_detection/test_region_growing_deprecated_constructors.cpp @@ -48,14 +48,26 @@ using RT1 = SD::Point_set::Least_squares_line_fit_region; using RT3 = SD::Polygon_mesh::Least_squares_plane_fit_region; +using RT4 = SD::Point_set::Least_squares_circle_fit_region; +using RT5 = SD::Point_set::Least_squares_sphere_fit_region; +using RT6 = SD::Point_set::Least_squares_cylinder_fit_region; + using S1 = SD::Point_set::Least_squares_line_fit_sorting; using S2 = SD::Point_set::Least_squares_plane_fit_sorting; using S3 = SD::Polygon_mesh::Least_squares_plane_fit_sorting; +using S4 = SD::Point_set::Least_squares_circle_fit_sorting; +using S5 = SD::Point_set::Least_squares_sphere_fit_sorting; +using S6 = SD::Point_set::Least_squares_cylinder_fit_sorting; + using RG1 = SD::Region_growing; using RG2 = SD::Region_growing; using RG3 = SD::Region_growing; +using RG4 = SD::Region_growing; +using RG5 = SD::Region_growing; +using RG6 = SD::Region_growing; + int main() { // Default parameter values. @@ -64,6 +76,8 @@ int main() { const FT angle_threshold = FT(15); const std::size_t min_region_size = 1; const FT sphere_radius = FT(2); + const FT min_radius = FT(0); + const FT max_radius = FT(1000000); const Kernel traits; const Input_range_2 input_range_2 = { @@ -106,29 +120,64 @@ int main() { distance_threshold, angle_threshold, min_region_size, vertex_to_point_map, traits); + RT4 rt4(input_range_2, + distance_threshold, angle_threshold, min_region_size, min_radius, max_radius, + point_map_2, normal_map_2, traits); + RT5 rt5(input_range_3, + distance_threshold, angle_threshold, min_region_size, min_radius, max_radius, + point_map_3, normal_map_3, traits); + RT6 rt6(input_range_3, + distance_threshold, angle_threshold, min_region_size, min_radius, max_radius, + point_map_3, normal_map_3, traits); + S1 s1(input_range_2, nq1, point_map_2); S2 s2(input_range_3, nq2, point_map_3); S3 s3(polygon_mesh , nq3, vertex_to_point_map); + S4 s4(input_range_2, nq1, point_map_2); + S5 s5(input_range_3, nq2, point_map_3); + S6 s6(input_range_3, nq2, point_map_3); + s1.sort(); s2.sort(); s3.sort(); + s4.sort(); + s5.sort(); + s6.sort(); + RG1 rg1(input_range_2, nq1, rt1, s1.seed_map()); RG2 rg2(input_range_3, nq2, rt2, s2.seed_map()); RG3 rg3(face_range , nq3, rt3, s3.seed_map()); + RG4 rg4(input_range_2, nq1, rt4, s4.seed_map()); + RG5 rg5(input_range_3, nq2, rt5, s5.seed_map()); + RG6 rg6(input_range_3, nq2, rt6, s6.seed_map()); + std::vector< std::vector > regions1; std::vector< std::vector > regions2; std::vector< std::vector > regions3; + + std::vector< std::vector > regions4; + std::vector< std::vector > regions5; + std::vector< std::vector > regions6; + rg1.detect(std::back_inserter(regions1)); rg2.detect(std::back_inserter(regions2)); rg3.detect(std::back_inserter(regions3)); + rg4.detect(std::back_inserter(regions4)); + rg5.detect(std::back_inserter(regions5)); + rg6.detect(std::back_inserter(regions6)); + assert(regions1.size() == 1); assert(regions2.size() == 1); assert(regions3.size() == 4); + assert(regions4.size() > 0); + assert(regions5.size() > 0); + assert(regions6.size() > 0); + std::cout << "rg_deprecated, sc_test_success: " << true << std::endl; return EXIT_SUCCESS; } diff --git a/Shape_detection/test/Shape_detection/test_region_growing_on_point_set_2_with_sorting.cpp b/Shape_detection/test/Shape_detection/test_region_growing_on_point_set_2_with_sorting.cpp index fd140f316a1..e36707686fd 100644 --- a/Shape_detection/test/Shape_detection/test_region_growing_on_point_set_2_with_sorting.cpp +++ b/Shape_detection/test/Shape_detection/test_region_growing_on_point_set_2_with_sorting.cpp @@ -35,16 +35,15 @@ using Line_sorting = SD::Point_set::Least_squares_line_fit_sorting; using Circle_sorting = SD::Point_set::Least_squares_circle_fit_sorting; -template -bool test (int argc, char** argv, const std::size_t minr, const std::size_t maxr) -{ +template +bool test(int argc, char** argv, const std::string name, const std::size_t minr, const std::size_t maxr) { using Region_growing = SD::Region_growing; // Default parameter values. - const std::size_t k = 12; - const FT distance_threshold = FT(45) / FT(10); - const FT angle_threshold = FT(45); - const std::size_t min_region_size = 5; + const std::size_t k = 12; + const FT max_distance = FT(45) / FT(10); + const FT max_angle = FT(45); + const std::size_t min_region_size = 5; // Load data. std::ifstream in(argc > 1 ? argv[1] : "data/point_set_2.xyz"); @@ -66,8 +65,8 @@ bool test (int argc, char** argv, const std::size_t minr, const std::size_t maxr Region_type region_type( input_range, CGAL::parameters:: - maximum_distance(distance_threshold). - maximum_angle(angle_threshold). + maximum_distance(max_distance). + maximum_angle(max_angle). minimum_region_size(min_region_size)); // Sort indices. @@ -82,7 +81,9 @@ bool test (int argc, char** argv, const std::size_t minr, const std::size_t maxr std::vector< std::vector > regions; region_growing.detect(std::back_inserter(regions)); region_growing.clear(); - assert(regions.size() == 62); + + std::cout << "- num regions " + name + ": " << regions.size() << std::endl; + assert(regions.size() >= minr && regions.size() <= maxr); // Test free functions and stability. for (std::size_t k = 0; k < 3; ++k) { @@ -90,25 +91,21 @@ bool test (int argc, char** argv, const std::size_t minr, const std::size_t maxr SD::internal::region_growing_lines( input_range, std::back_inserter(regions), CGAL::parameters:: - maximum_distance(distance_threshold). - maximum_angle(angle_threshold). + maximum_distance(max_distance). + maximum_angle(max_angle). minimum_region_size(min_region_size)); assert(regions.size() == 62); } - assert(regions.size() >= minr && regions.size() <= maxr); - const bool cartesian_double_test_success = (regions.size() >= minr && regions.size() <= maxr); - std::cout << "cartesian_double_test_success: " << cartesian_double_test_success << std::endl; - - const bool success = cartesian_double_test_success; + const bool success = true; + std::cout << "rg_" + name + "_sortpoints2, sc_test_success: " << success << std::endl; return success; } int main(int argc, char *argv[]) { return (( - test(argc, argv, 62, 66) && - test(argc, argv, 196, 200) + test(argc, argv, "lines", 62, 66) && // test lines + test(argc, argv, "circles", 62, 66) // test circles ) ? EXIT_SUCCESS : EXIT_FAILURE ); - } diff --git a/Shape_detection/test/Shape_detection/test_region_growing_on_point_set_3_with_sorting.cpp b/Shape_detection/test/Shape_detection/test_region_growing_on_point_set_3_with_sorting.cpp index 9baede56975..754a1599470 100644 --- a/Shape_detection/test/Shape_detection/test_region_growing_on_point_set_3_with_sorting.cpp +++ b/Shape_detection/test/Shape_detection/test_region_growing_on_point_set_3_with_sorting.cpp @@ -37,17 +37,20 @@ using Sphere_sorting = SD::Point_set::Least_squares_sphere_fit_sorting; using Cylinder_sorting = SD::Point_set::Least_squares_cylinder_fit_sorting; -template -bool test (int argc, char** argv, const SortingCode& /*sc*/, const RegionCode& /*reg*/, const AssertionCode& assertion) -{ +template< +typename Region_type, +typename Sorting, +typename Lambda_region, +typename Lambda_assertion> +bool test( + int argc, char** argv, const std::string name, + const Lambda_region& lambda_region, + const Lambda_assertion& lambda_assertion) { + using Region_growing = SD::Region_growing; // Default parameter values. - const std::size_t k = 12; - const FT distance_threshold = FT(2); - const FT angle_threshold = FT(20); - const std::size_t min_region_size = 50; + const std::size_t k = 12; // Load data. std::ifstream in(argc > 1 ? argv[1] : "data/point_set_3.xyz"); @@ -66,29 +69,29 @@ bool test (int argc, char** argv, const SortingCode& /*sc*/, const RegionCode& / k_neighbors(k). point_map(input_range.point_map())); - Region_type region_type( - input_range, - CGAL::parameters:: - maximum_distance(distance_threshold). - maximum_angle(angle_threshold). - minimum_region_size(min_region_size). - point_map(input_range.point_map()). - normal_map(input_range.normal_map())); - // Sort indices. Sorting sorting( input_range, neighbor_query, - CGAL::parameters::point_map(input_range.point_map())); + CGAL::parameters:: + point_map(input_range.point_map()). + normal_map(input_range.normal_map())); sorting.sort(); // Run region growing. + Region_type region_type = lambda_region(input_range); Region_growing region_growing( input_range, neighbor_query, region_type, sorting.seed_map()); std::vector< std::vector > regions; region_growing.detect(std::back_inserter(regions)); region_growing.clear(); - assert(regions.size() == 7); + const bool result = lambda_assertion(regions); + assert(result); + + // Default parameter values. + const FT max_distance = FT(2); + const FT max_angle = FT(20); + const std::size_t min_region_size = 50; // Test free functions and stability. for (std::size_t k = 0; k < 3; ++k) { @@ -96,103 +99,92 @@ bool test (int argc, char** argv, const SortingCode& /*sc*/, const RegionCode& / SD::internal::region_growing_planes( input_range, std::back_inserter(regions), CGAL::parameters:: - maximum_distance(distance_threshold). - maximum_angle(angle_threshold). + maximum_distance(max_distance). + maximum_angle(max_angle). minimum_region_size(min_region_size). point_map(input_range.point_map()). normal_map(input_range.normal_map())); assert(regions.size() == 7); } - bool result = assertion(regions); - assert (result); - std::cout << "exact_inexact_test_success: " << result << std::endl; - return result; + const bool success = true; + std::cout << "rg_" + name + "_sortpoints3, epick_test_success: " << success << std::endl; + return success; } int main(int argc, char *argv[]) { + bool success = true; - bool success = - test - (argc, argv, - [](const auto& input_range, auto& neighbor_query) -> Plane_sorting - { - return Plane_sorting (input_range, neighbor_query, - input_range.point_map()); - }, - [](const auto& input_range) -> Plane_region - { - // Default parameter values for the data file point_set_3.xyz. - const FT distance_threshold = FT(2); - const FT angle_threshold = FT(20); - const std::size_t min_region_size = 50; - return Plane_region - (input_range, - distance_threshold, angle_threshold, min_region_size, - input_range.point_map(), input_range.normal_map()); - }, - [](const auto& r) -> bool { - std::cout << "- num regions planes: " << r.size() << std::endl; - return (r.size() >= 6 && r.size() <= 8); - }); - if (!success) - return EXIT_FAILURE; + // Test planes. + success = test(argc, argv, "planes", + [](const auto& input_range) -> Plane_region { - success = - test - (argc, argv, - [](const auto& input_range, auto& neighbor_query) -> Sphere_sorting - { - return Sphere_sorting (input_range, neighbor_query, - input_range.point_map()); - }, - [](const auto& input_range) -> Sphere_region - { - const double tolerance = 0.01; - const double max_angle = 10.; + const FT max_distance = FT(2); + const FT max_angle = FT(20); const std::size_t min_region_size = 50; - // No constraint on radius - const double min_radius = 0.; - const double max_radius = std::numeric_limits::max(); - return Sphere_region - (input_range, tolerance, max_angle, min_region_size, - min_radius, max_radius, - input_range.point_map(), input_range.normal_map()); - }, - [](const auto& r) -> bool { - std::cout << "- num regions spheres: " << r.size() << std::endl; - return (r.size() > 10 && r.size() < 90); - }); - if (!success) - return EXIT_FAILURE; + return Plane_region(input_range, CGAL::parameters:: + maximum_distance(max_distance). + maximum_angle(max_angle). + minimum_region_size(min_region_size). + point_map(input_range.point_map()). + normal_map(input_range.normal_map())); + }, + [](const auto& region) -> bool { + std::cout << "- num regions planes: " << region.size() << std::endl; + return (region.size() >= 6 && region.size() <= 8); + } + ); - success = - test - (argc, argv, - [](const auto& input_range, auto& neighbor_query) -> Cylinder_sorting - { - return Cylinder_sorting (input_range, neighbor_query, - input_range.point_map(), input_range.normal_map()); - }, - [](const auto& input_range) -> Cylinder_region - { - const double tolerance = 0.05; - const double max_angle = 5.; + if (!success) { + return EXIT_FAILURE; + } + + // Test spheres. + success = test(argc, argv, "spheres", + [](const auto& input_range) -> Sphere_region { + + const FT max_distance = FT(1) / FT(100); + const FT max_angle = FT(10); + const std::size_t min_region_size = 50; + return Sphere_region(input_range, CGAL::parameters:: + maximum_distance(max_distance). + maximum_angle(max_angle). + minimum_region_size(min_region_size). + point_map(input_range.point_map()). + normal_map(input_range.normal_map())); + }, + [](const auto& region) -> bool { + std::cout << "- num regions spheres: " << region.size() << std::endl; + return (region.size() > 36 && region.size() < 40); + } + ); + + if (!success) { + return EXIT_FAILURE; + } + + // Test cylinders. + success = test(argc, argv, "cylinders", + [](const auto& input_range) -> Cylinder_region { + + const FT max_distance = FT(1) / FT(20); + const FT max_angle = FT(5); const std::size_t min_region_size = 200; - // No constraint on radius - const double min_radius = 0.; - const double max_radius = std::numeric_limits::max(); - return Cylinder_region - (input_range, tolerance, max_angle, min_region_size, - min_radius, max_radius, - input_range.point_map(), input_range.normal_map()); - }, - [](const auto& r) -> bool { - std::cout << "- num regions cylinders: " << r.size() << std::endl; - return (r.size() > 2 && r.size() < 30); - }); - if (!success) - return EXIT_FAILURE; + return Cylinder_region(input_range, CGAL::parameters:: + maximum_distance(max_distance). + maximum_angle(max_angle). + minimum_region_size(min_region_size). + point_map(input_range.point_map()). + normal_map(input_range.normal_map())); + }, + [](const auto& region) -> bool { + std::cout << "- num regions cylinders: " << region.size() << std::endl; + return (region.size() > 6 && region.size() < 10); + } + ); + if (!success) { + return EXIT_FAILURE; + } return EXIT_SUCCESS; }