From 9ded4522e4be2b018172c0563b2acf9d5cdc5b44 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 17 Sep 2018 20:58:41 +0000 Subject: Add benchmark Safe version for Alpha complex 3d (missing part if not weighted and not periodic) Need to fix Alpha_complex_3d_unit_test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alpha_complex_3d_module_vincent@3893 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 304c9f89826008eab67a72f3742caa8d6d80f36b --- .../benchmark/Alpha_complex_3d_benchmark.cpp | 162 ++++++++++ src/Alpha_complex/benchmark/CMakeLists.txt | 9 + src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 119 ++++---- .../include/gudhi/Alpha_complex_options.h | 13 - .../test/Alpha_complex_3d_unit_test.cpp | 334 +++------------------ src/Alpha_complex/test/CMakeLists.txt | 1 + 6 files changed, 285 insertions(+), 353 deletions(-) create mode 100644 src/Alpha_complex/benchmark/Alpha_complex_3d_benchmark.cpp create mode 100644 src/Alpha_complex/benchmark/CMakeLists.txt (limited to 'src/Alpha_complex') diff --git a/src/Alpha_complex/benchmark/Alpha_complex_3d_benchmark.cpp b/src/Alpha_complex/benchmark/Alpha_complex_3d_benchmark.cpp new file mode 100644 index 00000000..18802ee5 --- /dev/null +++ b/src/Alpha_complex/benchmark/Alpha_complex_3d_benchmark.cpp @@ -0,0 +1,162 @@ +#include +// to construct a simplex_tree from alpha complex +#include +#include +#include + +#include +#include +#include +#include // for numeric limits + +#include +#include + +template +void benchmark_points_on_torus_3D(const std::string& msg ) { + using K = CGAL::Epick_d< CGAL::Dimension_tag<3> >; + std::cout << msg << std::endl; + for (int nb_points = 1000; nb_points <= /*12*/5000 ; nb_points *= 5) { + std::cout << "### Alpha complex 3d on torus with " << nb_points << " points." << std::endl; + std::vector points_on_torus = Gudhi::generate_points_on_torus_3D(nb_points, 1.0, 0.5); + std::vector points; + + for(auto p:points_on_torus) { + points.push_back(typename Alpha_complex_3d::Point_3(p[0],p[1],p[2])); + } + + Gudhi::Clock ac_create_clock("benchmark_points_on_torus_3D - Alpha complex 3d creation"); ac_create_clock.begin(); + Alpha_complex_3d alpha_complex_from_points(points); + ac_create_clock.end(); std::cout << ac_create_clock; + + Gudhi::Simplex_tree<> simplex; + Gudhi::Clock st_create_clock("benchmark_points_on_torus_3D - simplex tree creation"); st_create_clock.begin(); + alpha_complex_from_points.create_complex(simplex); + st_create_clock.end(); std::cout << st_create_clock; + } + +} + +template +void benchmark_weighted_points_on_torus_3D(const std::string& msg ) { + using K = CGAL::Epick_d< CGAL::Dimension_tag<3> >; + + CGAL::Random random(8); + + std::cout << msg << std::endl; + for (int nb_points = 1000; nb_points <= 125000 ; nb_points *= 5) { + std::cout << "### Alpha complex 3d on torus with " << nb_points << " points." << std::endl; + std::vector points_on_torus = Gudhi::generate_points_on_torus_3D(nb_points, 1.0, 0.5); + + using Point = typename Weighted_alpha_complex_3d::Point_3; + using Weighted_point = typename Weighted_alpha_complex_3d::Triangulation_3::Weighted_point; + + std::vector points; + + for(auto p:points_on_torus) { + points.push_back(Weighted_point(Point(p[0],p[1],p[2]), 0.9 + random.get_double(0., 0.01))); + } + + Gudhi::Clock ac_create_clock("benchmark_weighted_points_on_torus_3D - Alpha complex 3d creation"); ac_create_clock.begin(); + Weighted_alpha_complex_3d alpha_complex_from_points(points); + ac_create_clock.end(); std::cout << ac_create_clock; + + Gudhi::Simplex_tree<> simplex; + Gudhi::Clock st_create_clock("benchmark_weighted_points_on_torus_3D - simplex tree creation"); st_create_clock.begin(); + alpha_complex_from_points.create_complex(simplex); + st_create_clock.end(); std::cout << st_create_clock; + } + +} + +template +void benchmark_periodic_points(const std::string& msg ) { + std::cout << msg << std::endl; + for (double nb_points = 10.; nb_points <= 40. ; nb_points += 10.) { + std::cout << "### Periodic alpha complex 3d with " << nb_points*nb_points*nb_points << " points." << std::endl; + using Point = typename Periodic_alpha_complex_3d::Point_3; + std::vector points; + + for (double i = 0; i < nb_points; i++) { + for (double j = 0; j < nb_points; j++) { + for (double k = 0; k < nb_points; k++) { + points.push_back(Point(i,j,k)); + } + } + } + + Gudhi::Clock ac_create_clock("benchmark_periodic_points - Alpha complex 3d creation"); ac_create_clock.begin(); + Periodic_alpha_complex_3d alpha_complex_from_points(points, 0., 0., 0., nb_points, nb_points, nb_points); + ac_create_clock.end(); std::cout << ac_create_clock; + + Gudhi::Simplex_tree<> simplex; + Gudhi::Clock st_create_clock("benchmark_periodic_points - simplex tree creation"); st_create_clock.begin(); + alpha_complex_from_points.create_complex(simplex); + st_create_clock.end(); std::cout << st_create_clock; + } + +} + +template +void benchmark_weighted_periodic_points(const std::string& msg ) { + std::cout << msg << std::endl; + CGAL::Random random(8); + + for (double nb_points = 10.; nb_points <= 40. ; nb_points += 10.) { + std::cout << "### Weighted periodic alpha complex 3d with " << nb_points*nb_points*nb_points << " points." << std::endl; + + using Point = typename Weighted_periodic_alpha_complex_3d::Point_3; + using Weighted_point = typename Weighted_periodic_alpha_complex_3d::Triangulation_3::Weighted_point; + std::vector points; + + for (double i = 0; i < nb_points; i++) { + for (double j = 0; j < nb_points; j++) { + for (double k = 0; k < nb_points; k++) { + points.push_back(Weighted_point(Point(i,j,k), random.get_double(0., (nb_points*nb_points)/64.))); + } + } + } + + Gudhi::Clock ac_create_clock("benchmark_weighted_periodic_points - Alpha complex 3d creation"); ac_create_clock.begin(); + Weighted_periodic_alpha_complex_3d alpha_complex_from_points(points, 0., 0., 0., nb_points, nb_points, nb_points); + ac_create_clock.end(); std::cout << ac_create_clock; + + Gudhi::Simplex_tree<> simplex; + Gudhi::Clock st_create_clock("benchmark_weighted_periodic_points - simplex tree creation"); st_create_clock.begin(); + alpha_complex_from_points.create_complex(simplex); + st_create_clock.end(); std::cout << st_create_clock; + } + +} + +int main(int argc, char **argv) { + /* + benchmark_points_on_torus_3D>("### Fast version"); + benchmark_points_on_torus_3D>("### Safe version"); + benchmark_points_on_torus_3D>("### Exact version"); + + benchmark_weighted_points_on_torus_3D>("### Fast version"); + benchmark_weighted_points_on_torus_3D>("### Safe version"); + benchmark_weighted_points_on_torus_3D>("### Exact version"); + */ + benchmark_periodic_points>("### Fast version"); + benchmark_periodic_points>("### Safe version"); + benchmark_periodic_points>("### Exact version"); + + benchmark_weighted_periodic_points>("### Fast version"); + benchmark_weighted_periodic_points>("### Safe version"); + benchmark_weighted_periodic_points>("### Exact version"); + return 0; +} diff --git a/src/Alpha_complex/benchmark/CMakeLists.txt b/src/Alpha_complex/benchmark/CMakeLists.txt new file mode 100644 index 00000000..622963dc --- /dev/null +++ b/src/Alpha_complex/benchmark/CMakeLists.txt @@ -0,0 +1,9 @@ +project(Alpha_complex_benchmark) + +if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) + add_executable(Alpha_complex_3d_benchmark Alpha_complex_3d_benchmark.cpp) + target_link_libraries(Alpha_complex_3d_benchmark ${CGAL_LIBRARY}) + if (TBB_FOUND) + target_link_libraries(Alpha_complex_3d_benchmark ${TBB_LIBRARIES}) + endif() +endif () diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index 6e25814f..3f145272 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -33,6 +33,18 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include @@ -57,6 +69,40 @@ namespace Gudhi { namespace alpha_complex { +template +struct Value_from_iterator +{ + template + static double perform(Iterator it) + { + // Default behaviour is to return the value pointed by the given iterator + return *it; + } +}; + +template <> +struct Value_from_iterator +{ + template + static double perform(Iterator it) + { + // In safe mode, we are with Epeck or Epick with exact value set to CGAL::Tag_true. + return CGAL::to_double(*it); + } +}; + +template <> +struct Value_from_iterator +{ + template + static double perform(Iterator it) + { + // In exact mode, we are with Epeck or Epick with exact value set to CGAL::Tag_true. + return CGAL::to_double(it->exact()); + } +}; + + /** * \class Alpha_complex_3d * \brief Alpha complex data structure for 3d specific case. @@ -207,14 +253,6 @@ public: alpha_shape_3_ptr_ = std::unique_ptr(new Alpha_shape_3(std::begin(points), std::end(points), 0, Alpha_shape_3::GENERAL)); - Dispatch dispatcher = CGAL::dispatch_output(std::back_inserter(objects_), - std::back_inserter(alpha_values_)); - - alpha_shape_3_ptr_->filtration_with_alpha_values(dispatcher); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << objects_.size() << " objects" << std::endl; -#endif // DEBUG_TRACES - } /** \brief Alpha_complex constructor from a list of points and associated weights. @@ -254,14 +292,6 @@ public: std::end(weighted_points_3), 0, Alpha_shape_3::GENERAL)); - - Dispatch dispatcher = CGAL::dispatch_output(std::back_inserter(objects_), - std::back_inserter(alpha_values_)); - - alpha_shape_3_ptr_->filtration_with_alpha_values(dispatcher); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << objects_.size() << " objects" << std::endl; -#endif // DEBUG_TRACES } /** \brief Alpha_complex constructor from a list of points and an iso-cuboid coordinates. @@ -311,15 +341,6 @@ public: // Maybe need to set it to GENERAL mode alpha_shape_3_ptr_ = std::unique_ptr(new Alpha_shape_3(pdt, 0, Alpha_shape_3::GENERAL)); - - Dispatch dispatcher = CGAL::dispatch_output(std::back_inserter(objects_), - std::back_inserter(alpha_values_)); - - alpha_shape_3_ptr_->filtration_with_alpha_values(dispatcher); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << objects_.size() << " objects" << std::endl; -#endif // DEBUG_TRACES - } /** \brief Alpha_complex constructor from a list of points, associated weights and an iso-cuboid coordinates. @@ -396,31 +417,8 @@ public: // Maybe need to set it to GENERAL mode alpha_shape_3_ptr_ = std::unique_ptr(new Alpha_shape_3(pdt, 0, Alpha_shape_3::GENERAL)); - - Dispatch dispatcher = CGAL::dispatch_output(std::back_inserter(objects_), - std::back_inserter(alpha_values_)); - - alpha_shape_3_ptr_->filtration_with_alpha_values(dispatcher); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << objects_.size() << " objects" << std::endl; -#endif // DEBUG_TRACES } - template - typename std::enable_if::value, Filtration_value>::type - value_from_iterator(Alpha_value_iterator the_alpha_value_iterator) - { - return *(the_alpha_value_iterator); - } - - template - typename std::enable_if::value, Filtration_value>::type - value_from_iterator(Alpha_value_iterator the_alpha_value_iterator) - { - return CGAL::to_double(the_alpha_value_iterator->exact()); - } - - /** \brief Inserts all Delaunay triangulation into the simplicial complex. * It also computes the filtration values accordingly to the \ref createcomplexalgorithm * @@ -457,10 +455,21 @@ public: std::size_t count_facets = 0; std::size_t count_cells = 0; #endif // DEBUG_TRACES + std::vector objects; + std::vector alpha_values; + + Dispatch dispatcher = CGAL::dispatch_output(std::back_inserter(objects), + std::back_inserter(alpha_values)); + alpha_shape_3_ptr_->filtration_with_alpha_values(dispatcher); +#ifdef DEBUG_TRACES + std::cout << "filtration_with_alpha_values returns : " << objects.size() << " objects" << std::endl; +#endif // DEBUG_TRACES + Alpha_shape_simplex_tree_map map_cgal_simplex_tree; - auto the_alpha_value_iterator = alpha_values_.begin(); - for (auto object_iterator : objects_) { + using Alpha_value_iterator = typename std::vector::const_iterator; + Alpha_value_iterator alpha_value_iterator = alpha_values.begin(); + for (auto object_iterator : objects) { Vertex_list vertex_list; // Retrieve Alpha shape vertex list from object @@ -525,14 +534,14 @@ public: } } // Construction of the simplex_tree - Filtration_value filtr = value_from_iterator(the_alpha_value_iterator); + Filtration_value filtr = Value_from_iterator::perform(alpha_value_iterator); #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; #endif // DEBUG_TRACES complex.insert_simplex(the_simplex, static_cast(filtr)); - GUDHI_CHECK(the_alpha_value_iterator != alpha_values_.end(), "CGAL provided more simplices than values"); - ++the_alpha_value_iterator; + GUDHI_CHECK(alpha_value_iterator != alpha_values.end(), "CGAL provided more simplices than values"); + ++alpha_value_iterator; } #ifdef DEBUG_TRACES @@ -551,10 +560,8 @@ public: } private: - // Needs to store alpha_shape_3_ptr_ as objects_ are freed with alpha_shape_3_ptr_ + // use of a unique_ptr on cgal Alpha_shape_3, as copy and default constructor is not available - no need to be freed std::unique_ptr alpha_shape_3_ptr_; - std::vector objects_; - std::vector alpha_values_; }; diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_options.h b/src/Alpha_complex/include/gudhi/Alpha_complex_options.h index 32980fa7..cd9fe799 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_options.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_options.h @@ -24,23 +24,10 @@ #define ALPHA_COMPLEX_OPTIONS_H_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - namespace Gudhi { namespace alpha_complex { - /** * \class complexity * \brief Alpha complex complexity template parameter possible values. diff --git a/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp b/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp index ac9b383c..be9c5380 100644 --- a/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp @@ -36,8 +36,11 @@ #include #include #include +// to construct Alpha_complex from a OFF file of points #include +#include + using Fast_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; using Exact_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; using Fast_weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; @@ -46,7 +49,7 @@ using Fast_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; using Fast_weighted_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; using Exact_weighted_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; - +/* BOOST_AUTO_TEST_CASE(Alpha_complex_3d_from_points) { // ----------------- // Fast version @@ -533,7 +536,7 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_periodic) { }*/ -} +//} typedef boost::mpl::list wp_variants_type_list; @@ -543,170 +546,54 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted_periodic_throw, Weighted_pe std::cout << "Weighted periodic alpha complex 3d exception throw" << std::endl; using Point_3 = typename Weighted_periodic_alpha_complex_3d::Point_3; - std::vector wp_points; - wp_points.push_back(Point_3(0.0, 0.0, 0.0)); - wp_points.push_back(Point_3(0.0, 0.0, 0.2)); - wp_points.push_back(Point_3(0.0, 0.0, 0.4)); - wp_points.push_back(Point_3(0.0, 0.0, 0.6)); - wp_points.push_back(Point_3(0.0, 0.0, 0.8)); - wp_points.push_back(Point_3(0.0, 0.2, 0.0)); - wp_points.push_back(Point_3(0.0, 0.2, 0.2)); - wp_points.push_back(Point_3(0.0, 0.2, 0.4)); - wp_points.push_back(Point_3(0.0, 0.2, 0.6)); - wp_points.push_back(Point_3(0.0, 0.2, 0.8)); - wp_points.push_back(Point_3(0.0, 0.4, 0.0)); - wp_points.push_back(Point_3(0.0, 0.4, 0.2)); - wp_points.push_back(Point_3(0.0, 0.4, 0.4)); - wp_points.push_back(Point_3(0.0, 0.4, 0.6)); - wp_points.push_back(Point_3(0.0, 0.4, 0.8)); - wp_points.push_back(Point_3(0.0, 0.6, 0.0)); - wp_points.push_back(Point_3(0.0, 0.6, 0.2)); - wp_points.push_back(Point_3(0.0, 0.6, 0.4)); - wp_points.push_back(Point_3(0.0, 0.6, 0.6)); - wp_points.push_back(Point_3(0.0, 0.6, 0.8)); - wp_points.push_back(Point_3(0.0, 0.8, 0.0)); - wp_points.push_back(Point_3(0.0, 0.8, 0.2)); - wp_points.push_back(Point_3(0.0, 0.8, 0.4)); - wp_points.push_back(Point_3(0.0, 0.8, 0.6)); - wp_points.push_back(Point_3(0.0, 0.8, 0.8)); - wp_points.push_back(Point_3(0.2, 0.0, 0.0)); - wp_points.push_back(Point_3(0.2, 0.0, 0.2)); - wp_points.push_back(Point_3(0.2, 0.0, 0.4)); - wp_points.push_back(Point_3(0.2, 0.0, 0.6)); - wp_points.push_back(Point_3(0.2, 0.0, 0.8)); - wp_points.push_back(Point_3(0.2, 0.2, 0.0)); - wp_points.push_back(Point_3(0.2, 0.2, 0.2)); - wp_points.push_back(Point_3(0.2, 0.2, 0.4)); - wp_points.push_back(Point_3(0.2, 0.2, 0.6)); - wp_points.push_back(Point_3(0.2, 0.2, 0.8)); - wp_points.push_back(Point_3(0.2, 0.4, 0.0)); - wp_points.push_back(Point_3(0.2, 0.4, 0.2)); - wp_points.push_back(Point_3(0.2, 0.4, 0.4)); - wp_points.push_back(Point_3(0.2, 0.4, 0.6)); - wp_points.push_back(Point_3(0.2, 0.4, 0.8)); - wp_points.push_back(Point_3(0.2, 0.6, 0.0)); - wp_points.push_back(Point_3(0.2, 0.6, 0.2)); - wp_points.push_back(Point_3(0.2, 0.6, 0.4)); - wp_points.push_back(Point_3(0.2, 0.6, 0.6)); - wp_points.push_back(Point_3(0.2, 0.6, 0.8)); - wp_points.push_back(Point_3(0.2, 0.8, 0.0)); - wp_points.push_back(Point_3(0.2, 0.8, 0.2)); - wp_points.push_back(Point_3(0.2, 0.8, 0.4)); - wp_points.push_back(Point_3(0.2, 0.8, 0.6)); - wp_points.push_back(Point_3(0.2, 0.8, 0.8)); - wp_points.push_back(Point_3(0.4, 0.0, 0.0)); - wp_points.push_back(Point_3(0.4, 0.0, 0.2)); - wp_points.push_back(Point_3(0.4, 0.0, 0.4)); - wp_points.push_back(Point_3(0.4, 0.0, 0.6)); - wp_points.push_back(Point_3(0.4, 0.0, 0.8)); - wp_points.push_back(Point_3(0.4, 0.2, 0.0)); - wp_points.push_back(Point_3(0.4, 0.2, 0.2)); - wp_points.push_back(Point_3(0.4, 0.2, 0.4)); - wp_points.push_back(Point_3(0.4, 0.2, 0.6)); - wp_points.push_back(Point_3(0.4, 0.2, 0.8)); - wp_points.push_back(Point_3(0.4, 0.4, 0.0)); - wp_points.push_back(Point_3(0.4, 0.4, 0.2)); - wp_points.push_back(Point_3(0.4, 0.4, 0.4)); - wp_points.push_back(Point_3(0.4, 0.4, 0.6)); - wp_points.push_back(Point_3(0.4, 0.4, 0.8)); - wp_points.push_back(Point_3(0.4, 0.6, 0.0)); - wp_points.push_back(Point_3(0.4, 0.6, 0.2)); - wp_points.push_back(Point_3(0.4, 0.6, 0.4)); - wp_points.push_back(Point_3(0.4, 0.6, 0.6)); - wp_points.push_back(Point_3(0.4, 0.6, 0.8)); - wp_points.push_back(Point_3(0.4, 0.8, 0.0)); - wp_points.push_back(Point_3(0.4, 0.8, 0.2)); - wp_points.push_back(Point_3(0.4, 0.8, 0.4)); - wp_points.push_back(Point_3(0.4, 0.8, 0.6)); - wp_points.push_back(Point_3(0.4, 0.8, 0.8)); - wp_points.push_back(Point_3(0.6, 0.0, 0.0)); - wp_points.push_back(Point_3(0.6, 0.0, 0.2)); - wp_points.push_back(Point_3(0.6, 0.0, 0.4)); - wp_points.push_back(Point_3(0.6, 0.0, 0.6)); - wp_points.push_back(Point_3(0.6, 0.0, 0.8)); - wp_points.push_back(Point_3(0.6, 0.1, 0.0)); - wp_points.push_back(Point_3(0.6, 0.2, 0.0)); - wp_points.push_back(Point_3(0.6, 0.2, 0.2)); - wp_points.push_back(Point_3(0.6, 0.2, 0.4)); - wp_points.push_back(Point_3(0.6, 0.2, 0.6)); - wp_points.push_back(Point_3(0.6, 0.2, 0.8)); - wp_points.push_back(Point_3(0.6, 0.4, 0.0)); - wp_points.push_back(Point_3(0.6, 0.4, 0.2)); - wp_points.push_back(Point_3(0.6, 0.4, 0.4)); - wp_points.push_back(Point_3(0.6, 0.4, 0.6)); - wp_points.push_back(Point_3(0.6, 0.4, 0.8)); - wp_points.push_back(Point_3(0.6, 0.6, 0.0)); - wp_points.push_back(Point_3(0.6, 0.6, 0.2)); - wp_points.push_back(Point_3(0.6, 0.6, 0.4)); - wp_points.push_back(Point_3(0.6, 0.6, 0.6)); - wp_points.push_back(Point_3(0.6, 0.6, 0.8)); - wp_points.push_back(Point_3(0.6, 0.8, 0.0)); - wp_points.push_back(Point_3(0.6, 0.8, 0.2)); - wp_points.push_back(Point_3(0.6, 0.8, 0.4)); - wp_points.push_back(Point_3(0.6, 0.8, 0.6)); - wp_points.push_back(Point_3(0.6, 0.8, 0.8)); - wp_points.push_back(Point_3(0.8, 0.0, 0.0)); - wp_points.push_back(Point_3(0.8, 0.0, 0.2)); - wp_points.push_back(Point_3(0.8, 0.0, 0.4)); - wp_points.push_back(Point_3(0.8, 0.0, 0.6)); - wp_points.push_back(Point_3(0.8, 0.0, 0.8)); - wp_points.push_back(Point_3(0.8, 0.2, 0.0)); - wp_points.push_back(Point_3(0.8, 0.2, 0.2)); - wp_points.push_back(Point_3(0.8, 0.2, 0.4)); - wp_points.push_back(Point_3(0.8, 0.2, 0.6)); - wp_points.push_back(Point_3(0.8, 0.2, 0.8)); - wp_points.push_back(Point_3(0.8, 0.4, 0.0)); - wp_points.push_back(Point_3(0.8, 0.4, 0.2)); - wp_points.push_back(Point_3(0.8, 0.4, 0.4)); - wp_points.push_back(Point_3(0.8, 0.4, 0.6)); - wp_points.push_back(Point_3(0.8, 0.4, 0.8)); - wp_points.push_back(Point_3(0.8, 0.6, 0.0)); - wp_points.push_back(Point_3(0.8, 0.6, 0.2)); - wp_points.push_back(Point_3(0.8, 0.6, 0.4)); - wp_points.push_back(Point_3(0.8, 0.6, 0.6)); - wp_points.push_back(Point_3(0.8, 0.6, 0.8)); - wp_points.push_back(Point_3(0.8, 0.8, 0.0)); - wp_points.push_back(Point_3(0.8, 0.8, 0.2)); - wp_points.push_back(Point_3(0.8, 0.8, 0.4)); - wp_points.push_back(Point_3(0.8, 0.8, 0.6)); + + Gudhi::Points_3D_off_reader off_reader("bunny_1000.off"); + BOOST_CHECK(off_reader.is_valid()); + + std::vector wp_points = off_reader.get_point_cloud(); std::vector p_weights; - std::random_device rd; - std::mt19937 mt(rd()); - // Weights must be in range [0, <1/64] - std::uniform_real_distribution dist(0.0, 0.0156245); + // Weights must be in range ]0, 1/64 = 0.015625[ + CGAL::Random random(8); for (std::size_t i = 0; i < wp_points.size(); ++i) { - double value = dist(mt); - p_weights.push_back(value); + p_weights.push_back(random.get_double(0., 0.01)); } std::cout << "Cuboid is not iso exception" << std::endl; // Check it throws an exception when the cuboid is not iso - BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 0.9, 1., 1.), + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., .9, 1., 1.), std::invalid_argument); - BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 1., 0.9, 1.), + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 1., .9, 1.), std::invalid_argument); - BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 1., 1., 0.9), + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 1., 1., .9), + std::invalid_argument); + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 1.1, 1., 1.), + std::invalid_argument); + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 1., 1.1, 1.), + std::invalid_argument); + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 1., 1., 1.1), std::invalid_argument); std::cout << "0 <= point.weight() < 1/64 * domain_size * domain_size exception" << std::endl; - // Weights must be in range [0, <1/64] + // Weights must be in range ]0, 1/64 = 0.015625[ + double temp = p_weights[25]; p_weights[25] = 1.0; BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 1., 1., 1.), std::invalid_argument); - // Weights must be in range [0, <1/64] - p_weights[25] = 0.012; - p_weights[14] = -0.012; + // Weights must be in range ]0, 1/64 = 0.015625[ + p_weights[25] = temp; + temp = p_weights[14]; + p_weights[14] = -1e-10; BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 1., 1., 1.), std::invalid_argument); - p_weights[14] = 0.005; + p_weights[14] = temp; std::cout << "wp_points and p_weights size exception" << std::endl; // Weights and points must have the same size // + 1 - p_weights.push_back(0.007); + p_weights.push_back(1e-10); BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, 0., 0., 0., 1., 1., 1.), std::invalid_argument); // - 1 @@ -721,144 +608,19 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted_periodic, Weighted_periodic wp_variants_type_list) { std::cout << "Weighted Periodic alpha complex 3d from points and weights" << std::endl; using Point_3 = typename Weighted_periodic_alpha_complex_3d::Point_3; - std::vector points; - - points.push_back(Point_3(0.0, 0.0, 0.2)); - points.push_back(Point_3(0.0, 0.0, 0.4)); - points.push_back(Point_3(0.0, 0.0, 0.6)); - points.push_back(Point_3(0.0, 0.0, 0.8)); - points.push_back(Point_3(0.0, 0.2, 0.0)); - points.push_back(Point_3(0.0, 0.2, 0.2)); - points.push_back(Point_3(0.0, 0.2, 0.4)); - points.push_back(Point_3(0.0, 0.2, 0.6)); - points.push_back(Point_3(0.0, 0.2, 0.8)); - points.push_back(Point_3(0.0, 0.4, 0.0)); - points.push_back(Point_3(0.0, 0.4, 0.2)); - points.push_back(Point_3(0.0, 0.4, 0.4)); - points.push_back(Point_3(0.0, 0.4, 0.6)); - points.push_back(Point_3(0.0, 0.4, 0.8)); - points.push_back(Point_3(0.0, 0.6, 0.0)); - points.push_back(Point_3(0.0, 0.6, 0.2)); - points.push_back(Point_3(0.0, 0.6, 0.4)); - points.push_back(Point_3(0.0, 0.6, 0.6)); - points.push_back(Point_3(0.0, 0.6, 0.8)); - points.push_back(Point_3(0.0, 0.8, 0.0)); - points.push_back(Point_3(0.0, 0.8, 0.2)); - points.push_back(Point_3(0.0, 0.8, 0.4)); - points.push_back(Point_3(0.0, 0.8, 0.6)); - points.push_back(Point_3(0.0, 0.8, 0.8)); - points.push_back(Point_3(0.2, 0.0, 0.0)); - points.push_back(Point_3(0.2, 0.0, 0.2)); - points.push_back(Point_3(0.2, 0.0, 0.4)); - points.push_back(Point_3(0.2, 0.0, 0.6)); - points.push_back(Point_3(0.2, 0.0, 0.8)); - points.push_back(Point_3(0.2, 0.2, 0.0)); - points.push_back(Point_3(0.2, 0.2, 0.2)); - points.push_back(Point_3(0.2, 0.2, 0.4)); - points.push_back(Point_3(0.2, 0.2, 0.6)); - points.push_back(Point_3(0.2, 0.2, 0.8)); - points.push_back(Point_3(0.2, 0.4, 0.0)); - points.push_back(Point_3(0.2, 0.4, 0.2)); - points.push_back(Point_3(0.2, 0.4, 0.4)); - points.push_back(Point_3(0.2, 0.4, 0.6)); - points.push_back(Point_3(0.2, 0.4, 0.8)); - points.push_back(Point_3(0.2, 0.6, 0.0)); - points.push_back(Point_3(0.2, 0.6, 0.2)); - points.push_back(Point_3(0.2, 0.6, 0.4)); - points.push_back(Point_3(0.2, 0.6, 0.6)); - points.push_back(Point_3(0.2, 0.6, 0.8)); - points.push_back(Point_3(0.0, 0.0, 0.0)); - points.push_back(Point_3(0.2, 0.8, 0.0)); - points.push_back(Point_3(0.2, 0.8, 0.2)); - points.push_back(Point_3(0.2, 0.8, 0.4)); - points.push_back(Point_3(0.2, 0.8, 0.6)); - points.push_back(Point_3(0.2, 0.8, 0.8)); - points.push_back(Point_3(0.4, 0.0, 0.0)); - points.push_back(Point_3(0.4, 0.0, 0.2)); - points.push_back(Point_3(0.4, 0.0, 0.4)); - points.push_back(Point_3(0.4, 0.0, 0.6)); - points.push_back(Point_3(0.4, 0.0, 0.8)); - points.push_back(Point_3(0.4, 0.2, 0.0)); - points.push_back(Point_3(0.4, 0.2, 0.2)); - points.push_back(Point_3(0.4, 0.2, 0.4)); - points.push_back(Point_3(0.4, 0.2, 0.6)); - points.push_back(Point_3(0.4, 0.2, 0.8)); - points.push_back(Point_3(0.4, 0.4, 0.0)); - points.push_back(Point_3(0.4, 0.4, 0.2)); - points.push_back(Point_3(0.4, 0.4, 0.4)); - points.push_back(Point_3(0.4, 0.4, 0.6)); - points.push_back(Point_3(0.4, 0.4, 0.8)); - points.push_back(Point_3(0.4, 0.6, 0.0)); - points.push_back(Point_3(0.4, 0.6, 0.2)); - points.push_back(Point_3(0.4, 0.6, 0.4)); - points.push_back(Point_3(0.4, 0.6, 0.6)); - points.push_back(Point_3(0.4, 0.6, 0.8)); - points.push_back(Point_3(0.4, 0.8, 0.0)); - points.push_back(Point_3(0.4, 0.8, 0.2)); - points.push_back(Point_3(0.4, 0.8, 0.4)); - points.push_back(Point_3(0.4, 0.8, 0.6)); - points.push_back(Point_3(0.4, 0.8, 0.8)); - points.push_back(Point_3(0.6, 0.0, 0.0)); - points.push_back(Point_3(0.6, 0.0, 0.2)); - points.push_back(Point_3(0.6, 0.0, 0.4)); - points.push_back(Point_3(0.6, 0.0, 0.6)); - points.push_back(Point_3(0.6, 0.0, 0.8)); - points.push_back(Point_3(0.6, 0.1, 0.0)); - points.push_back(Point_3(0.6, 0.2, 0.0)); - points.push_back(Point_3(0.6, 0.2, 0.2)); - points.push_back(Point_3(0.6, 0.2, 0.4)); - points.push_back(Point_3(0.6, 0.2, 0.6)); - points.push_back(Point_3(0.6, 0.2, 0.8)); - points.push_back(Point_3(0.6, 0.4, 0.0)); - points.push_back(Point_3(0.6, 0.4, 0.2)); - points.push_back(Point_3(0.6, 0.4, 0.4)); - points.push_back(Point_3(0.6, 0.4, 0.6)); - points.push_back(Point_3(0.6, 0.4, 0.8)); - points.push_back(Point_3(0.6, 0.6, 0.0)); - points.push_back(Point_3(0.6, 0.6, 0.2)); - points.push_back(Point_3(0.6, 0.6, 0.4)); - points.push_back(Point_3(0.6, 0.6, 0.6)); - points.push_back(Point_3(0.6, 0.6, 0.8)); - points.push_back(Point_3(0.6, 0.8, 0.0)); - points.push_back(Point_3(0.6, 0.8, 0.2)); - points.push_back(Point_3(0.6, 0.8, 0.4)); - points.push_back(Point_3(0.6, 0.8, 0.6)); - points.push_back(Point_3(0.6, 0.8, 0.8)); - points.push_back(Point_3(0.8, 0.0, 0.0)); - points.push_back(Point_3(0.8, 0.0, 0.2)); - points.push_back(Point_3(0.8, 0.0, 0.4)); - points.push_back(Point_3(0.8, 0.0, 0.6)); - points.push_back(Point_3(0.8, 0.0, 0.8)); - points.push_back(Point_3(0.8, 0.2, 0.0)); - points.push_back(Point_3(0.8, 0.2, 0.2)); - points.push_back(Point_3(0.8, 0.2, 0.4)); - points.push_back(Point_3(0.8, 0.2, 0.6)); - points.push_back(Point_3(0.8, 0.2, 0.8)); - points.push_back(Point_3(0.8, 0.4, 0.0)); - points.push_back(Point_3(0.8, 0.4, 0.2)); - points.push_back(Point_3(0.8, 0.4, 0.4)); - points.push_back(Point_3(0.8, 0.4, 0.6)); - points.push_back(Point_3(0.8, 0.4, 0.8)); - points.push_back(Point_3(0.8, 0.6, 0.0)); - points.push_back(Point_3(0.8, 0.6, 0.2)); - points.push_back(Point_3(0.8, 0.6, 0.4)); - points.push_back(Point_3(0.8, 0.6, 0.6)); - points.push_back(Point_3(0.8, 0.6, 0.8)); - points.push_back(Point_3(0.8, 0.8, 0.0)); - points.push_back(Point_3(0.8, 0.8, 0.2)); - points.push_back(Point_3(0.8, 0.8, 0.4)); - points.push_back(Point_3(0.8, 0.8, 0.6)); + + Gudhi::Points_3D_off_reader off_reader("bunny_1000.off"); + BOOST_CHECK(off_reader.is_valid()); + + std::vector points = off_reader.get_point_cloud(); std::vector weights; - std::random_device rd; - std::mt19937 mt(rd()); - // Weights must be in range [0, <1/64] - std::uniform_real_distribution dist(0.01, 0.0156245); + // Weights must be in range ]0, 1/64 = 0.015625[ + CGAL::Random random(8); for (std::size_t i = 0; i < points.size(); ++i) { - double value = dist(mt); - weights.push_back(value); + weights.push_back(0.1 * random.get_double(0., 0.01)); } Weighted_periodic_alpha_complex_3d weighted_periodic_alpha_complex(points, weights, 0., 0., 0., 1., 1., 1.); @@ -887,31 +649,35 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted_periodic, Weighted_periodic BOOST_CHECK(stree_bis.dimension() == stree.dimension()); std::cout << "Weighted periodic alpha complex 3d num_simplices " << stree_bis.num_simplices() << " - versus " << stree.num_simplices() << std::endl; - // TODO(VR): BOOST_CHECK(stree_bis.num_simplices() == stree.num_simplices()); + BOOST_CHECK(stree_bis.num_simplices() == stree.num_simplices()); std::cout << "Weighted periodic alpha complex 3d num_vertices " << stree_bis.num_vertices() << " - versus " << stree.num_vertices() << std::endl; BOOST_CHECK(stree_bis.num_vertices() == stree.num_vertices()); - /*auto sh = stree.filtration_simplex_range().begin(); + auto sh = stree.filtration_simplex_range().begin(); while(sh != stree.filtration_simplex_range().end()) { std::vector simplex; std::vector exact_simplex; +#ifdef DEBUG_TRACES std::cout << " ( "; +#endif // DEBUG_TRACES for (auto vertex : stree.simplex_vertex_range(*sh)) { simplex.push_back(vertex); +#ifdef DEBUG_TRACES std::cout << vertex << " "; +#endif // DEBUG_TRACES } +#ifdef DEBUG_TRACES std::cout << ") -> " << "[" << stree.filtration(*sh) << "] "; std::cout << std::endl; +#endif // DEBUG_TRACES // Find it in the exact structure auto sh_exact = stree_bis.find(simplex); - // TODO(VR): BOOST_CHECK(sh_exact != stree_bis.null_simplex()); - - // Exact and non-exact version is not exactly the same due to float comparison - // TODO(VR): GUDHI_TEST_FLOAT_EQUALITY_CHECK(stree_bis.filtration(sh_exact), stree.filtration(*sh)); + BOOST_CHECK(sh_exact != stree_bis.null_simplex()); + // Shall be the same, but not exactly in fast version as it is an approximation + GUDHI_TEST_FLOAT_EQUALITY_CHECK(stree_bis.filtration(sh_exact), stree.filtration(*sh), 1e-15); ++sh; - }*/ - + } } diff --git a/src/Alpha_complex/test/CMakeLists.txt b/src/Alpha_complex/test/CMakeLists.txt index 7b6de748..61a9e6b5 100644 --- a/src/Alpha_complex/test/CMakeLists.txt +++ b/src/Alpha_complex/test/CMakeLists.txt @@ -17,6 +17,7 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) # Do not forget to copy test files in current binary dir file(COPY "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + file(COPY "${CMAKE_SOURCE_DIR}/data/points/grid_5_5_5_in_0_1.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) gudhi_add_coverage_test(Alpha_complex_test_unit) gudhi_add_coverage_test(Alpha_complex_3d_test_unit) -- cgit v1.2.3