diff --git a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Expectation_maximization_test.cpp b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Expectation_maximization_test.cpp index 584df275bfd..d1779126d02 100644 --- a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Expectation_maximization_test.cpp +++ b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/Expectation_maximization_test.cpp @@ -8,12 +8,11 @@ * Then applies gmm fitting on these generated points. * Provides a heuristic score for each gmm fitting result. * - * Note that it always return EXIT_SUCCESS */ int main(void) { boost::mt19937 engine; - engine.seed(1340818006); + engine.seed(1340818006); // generate random data using gauissians below std::vector< boost::normal_distribution > distributions; @@ -35,7 +34,7 @@ int main(void) // calculate closest center (using above gauissians) for each generated points // we will compare it with gmm fitting results - // also we might want to compute mixing coef for each center and select centers according to mixing_coef * prob(data) + // also we might want to compute mixing coef for each center and select centers according to mixing_coef * prob(data) std::vector data_centers; for(std::vector::iterator it = data.begin(); it != data.end(); ++it) { @@ -79,6 +78,11 @@ int main(void) { if( (*it) == (*calculated_it) ) { ++true_count; } } - std::cout << "[0,1]: " << static_cast(true_count) / data_centers.size() << std::endl; + double app_fit = static_cast(true_count) / data_centers.size(); + std::cout << "[0,1]: " << app_fit << std::endl; + if(app_fit < 0.7) { + std::cerr << "There might be a problem if above printed comparison is too low." << std::endl; + return EXIT_FAILURE; + } } } \ No newline at end of file diff --git a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/K_means_clustering_test.cpp b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/K_means_clustering_test.cpp index 78236e9e5cc..9d78c56dca2 100644 --- a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/K_means_clustering_test.cpp +++ b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/K_means_clustering_test.cpp @@ -1,4 +1,4 @@ - +// #include #include @@ -8,12 +8,12 @@ * Then applies k-means on these generated points. * Provides a heuristic score for each k-means clustering result. * - * Note that it always return EXIT_SUCCESS + * EXIT_FAILURE does not mean failure but if approximate matching is too low it is best to check */ int main(void) { boost::mt19937 engine; - engine.seed(1340818006); + engine.seed(1340818006); // generate random data using gauissians below std::vector< boost::normal_distribution > distributions; @@ -57,9 +57,7 @@ int main(void) typedef CGAL::internal::K_means_clustering K_means; std::vector k_means; k_means.push_back(K_means(distributions.size(), data, K_means::PLUS_INITIALIZATION)); - k_means.push_back(K_means(distributions.size(), data, K_means::PLUS_INITIALIZATION, 2, 5)); k_means.push_back(K_means(distributions.size(), data, K_means::RANDOM_INITIALIZATION)); - k_means.push_back(K_means(distributions.size(), data, K_means::RANDOM_INITIALIZATION, 2, 5)); std::vector< std::vector > calculated_centers(k_means.size()); std::vector< std::vector >::iterator calc_centers_it = calculated_centers.begin(); @@ -79,6 +77,11 @@ int main(void) { if( (*it) == (*calculated_it) ) { ++true_count; } } - std::cout << "[0,1]: " << static_cast(true_count) / data_centers.size() << std::endl; + double app_fit = static_cast(true_count) / data_centers.size(); + std::cout << "[0,1]: " << app_fit << std::endl; + if(app_fit < 0.7) { + std::cerr << "There might be a problem if above printed comparison is too low." << std::endl; + return EXIT_FAILURE; + } } } \ No newline at end of file diff --git a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/K_means_clustering_test_2.cpp b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/K_means_clustering_test_2.cpp new file mode 100644 index 00000000000..7cd4590d678 --- /dev/null +++ b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/K_means_clustering_test_2.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +typedef CGAL::internal::K_means_clustering K_means; +/** + * Test degenerate cases + */ + +int main(void) +{ + for(int init_type = 0; init_type < 2; ++init_type) + { + K_means::Initialization_types init_type_enum = init_type == 0 ? K_means::RANDOM_INITIALIZATION : + K_means::PLUS_INITIALIZATION; + for(int i = 1; i < 100; ++i) { + std::vector points(i, 1.0); // generate point set with same points + K_means kmeans(points.size(), points, init_type_enum); // should not crash + } + } + + for(int init_type = 0; init_type < 2; ++init_type) + { + K_means::Initialization_types init_type_enum = init_type == 0 ? K_means::RANDOM_INITIALIZATION : + K_means::PLUS_INITIALIZATION; + // Test case: number of points equals to number of clusters + // and all points are unique + for(int center_size = 1; center_size < 100; ++center_size) + { + // unique point generate + std::vector points; + for(int i = 0; i < center_size; ++i) { + points.push_back(i); + } + + // test kmeans, expected result: each point has its own cluster + K_means kmeans(center_size, points, init_type_enum); + std::vector center_ids; + kmeans.fill_with_center_ids(center_ids); + + for(int i = 0; i < center_size -1; ++i) { + if(center_ids[i] >= center_ids[i +1]) // center ids are ordered according to mean + { // and since points are generated ascendingly ... + std::string init_type_s = init_type_enum == K_means::RANDOM_INITIALIZATION ? "Random " : + "Plus plus "; + std::cerr << "Init type: " << init_type_s << "center size: " << center_size << std::endl; + CGAL_assertion(false); + } + } + } + } +} \ No newline at end of file diff --git a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/mesh_segmentation_test.cpp b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/mesh_segmentation_test.cpp index d261a1c03e7..cd961b9b5eb 100644 --- a/Surface_mesh_segmentation/test/Surface_mesh_segmentation/mesh_segmentation_test.cpp +++ b/Surface_mesh_segmentation/test/Surface_mesh_segmentation/mesh_segmentation_test.cpp @@ -18,34 +18,26 @@ typedef CGAL::Polyhedron_3 Polyhedron; */ int main(void) { - Polyhedron mesh; - if( !read_to_polyhedron("./data/cactus.off", mesh) ) { return 1; } - - typedef std::map Facet_double_map; + Polyhedron mesh; + if( !read_to_polyhedron("./data/cactus.off", mesh) ) { return 1; } + + typedef std::map Facet_double_map; Facet_double_map internal_map; boost::associative_property_map sdf_property_map(internal_map); - - std::pair min_max_sdf = CGAL::sdf_values_computation(mesh, sdf_property_map); - std::cout << "minimum sdf: " << min_max_sdf.first << " maximum sdf: " << min_max_sdf.second << std::endl; - - - typedef std::map Facet_int_map; - Facet_int_map internal_segment_map; + + std::pair min_max_sdf = CGAL::sdf_values_computation(mesh, sdf_property_map); + std::cout << "minimum sdf: " << min_max_sdf.first << " maximum sdf: " << min_max_sdf.second << std::endl; + + typedef std::map Facet_int_map; + Facet_int_map internal_segment_map; boost::associative_property_map segment_property_map(internal_segment_map); - + int nb_segments = CGAL::surface_mesh_segmentation_from_sdf_values( - mesh, sdf_property_map, segment_property_map); - - if(nb_segments != 3) - { - std::cout << "Number of segments should be 3 for cactus model (since it is pretty easy model to segment)" << std::endl; - } - - int nb_segments_2 = CGAL::surface_mesh_segmentation(mesh, segment_property_map); - - if(nb_segments_2 != nb_segments) - { - std::cout << "Inconsistency between 'surface_mesh_segmentation' and 'surface_mesh_segmentation_from_sdf_values'" - << std::endl; - } + mesh, sdf_property_map, segment_property_map); + + if(nb_segments != 3) + { + std::cerr << "Number of segments should be 3 for cactus model (since it is pretty easy model to segment)" << std::endl; + return EXIT_FAILURE; + } } \ No newline at end of file