diff --git a/Classification/test/Classification/CMakeLists.txt b/Classification/test/Classification/CMakeLists.txt index f0d98753787..7228277f158 100644 --- a/Classification/test/Classification/CMakeLists.txt +++ b/Classification/test/Classification/CMakeLists.txt @@ -53,5 +53,5 @@ include( CGAL_CreateSingleSourceCGALProgram ) create_single_source_cgal_program( "test_classifier.cpp" ) - +create_single_source_cgal_program( "test_point_set_classifier.cpp" ) diff --git a/Classification/test/Classification/test_point_set_classifier.cpp b/Classification/test/Classification/test_point_set_classifier.cpp new file mode 100644 index 00000000000..33ab790cce3 --- /dev/null +++ b/Classification/test/Classification/test_point_set_classifier.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; +typedef Kernel::Vector_3 Vector; +typedef CGAL::cpp11::array Color; +typedef Kernel::Iso_cuboid_3 Iso_cuboid_3; + +typedef boost::tuple Point_with_info; +typedef std::vector Point_range; + +typedef CGAL::Nth_of_tuple_property_map<0, Point_with_info> Pmap; +typedef CGAL::Nth_of_tuple_property_map<1, Point_with_info> Nmap; +typedef CGAL::Nth_of_tuple_property_map<2, Point_with_info> Cmap; +typedef CGAL::Nth_of_tuple_property_map<3, Point_with_info> Emap; + +typedef CGAL::Point_set_classifier PSC; + +typedef CGAL::Classification::Type_handle Type_handle; +typedef CGAL::Classification::Attribute_handle Attribute_handle; + +typedef CGAL::Classification::Attribute::Effect Attribute_effect; + +int main (int, char**) +{ + Point_range range; + range.reserve(10000); + for (std::size_t i = 0; i < 10000; ++ i) + range.push_back (boost::make_tuple + (Point (CGAL::get_default_random().get_double(), + CGAL::get_default_random().get_double(), + CGAL::get_default_random().get_double()), + Vector (CGAL::get_default_random().get_double(), + CGAL::get_default_random().get_double(), + CGAL::get_default_random().get_double()), + CGAL::make_array ((unsigned char)(CGAL::get_default_random().get_int(0, 255)), + (unsigned char)(CGAL::get_default_random().get_int(0, 255)), + (unsigned char)(CGAL::get_default_random().get_int(0, 255))), + std::size_t(CGAL::get_default_random().get_int(0, 10)))); + + PSC classifier (range, Pmap()); + classifier.generate_attributes (5, Nmap(), Cmap(), Emap()); + assert (classifier.number_of_scales() == 5); + + std::vector types; + types.push_back (classifier.add_classification_type ("type1")); + types.push_back (classifier.add_classification_type ("type2")); + types.push_back (classifier.add_classification_type ("type3")); + types.push_back (classifier.add_classification_type ("type4")); + types.push_back (classifier.add_classification_type ("type5")); + + for (std::size_t i = 0; i < 100; ++ i) + classifier.set_inlier (types[CGAL::get_default_random().get_int(0, types.size())], i); + + classifier.train(500); + + + std::ofstream fconfig ("config.xml"); + classifier.save_configuration (fconfig); + fconfig.close(); + + std::ofstream fclassif ("classif.ply"); + classifier.write_classification_to_ply(fclassif); + fclassif.close(); + + classifier.clear(); + + std::ifstream fconfig2 ("config.xml"); + assert (classifier.load_configuration (fconfig2, Nmap(), Cmap(), Emap())); + + + return EXIT_SUCCESS; +}