From 407131249caff5928302fcad075f310c5e336cbf Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 25 Sep 2018 13:17:15 +0000 Subject: Fix unitary tests git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alpha_complex_3d_module_vincent@3902 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c14d5a04ef4abc2367d3a1707a1fcfafb07a9598 --- .../test/Alpha_complex_3d_unit_test.cpp | 607 +++++++++------------ 1 file changed, 262 insertions(+), 345 deletions(-) (limited to 'src/Alpha_complex') 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 be9c5380..d09e8c10 100644 --- a/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp @@ -40,16 +40,24 @@ #include #include +#include using Fast_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; +using Safe_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; +using Safe_weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; using Exact_weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + using Fast_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; +using Safe_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; using Exact_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + using Fast_weighted_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; +using Safe_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 @@ -112,9 +120,61 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_3d_from_points) { ++sh; } + // ----------------- + // Safe version + // ----------------- + std::cout << "Safe alpha complex 3d" << std::endl; + + Safe_alpha_complex_3d safe_alpha_complex(points); + + Gudhi::Simplex_tree<> safe_stree; + safe_alpha_complex.create_complex(safe_stree); + + // --------------------- + // Compare both versions + // --------------------- + std::cout << "Exact Alpha complex 3d is of dimension " << safe_stree.dimension() + << " - Non exact is " << stree.dimension() << std::endl; + BOOST_CHECK(safe_stree.dimension() == stree.dimension()); + std::cout << "Exact Alpha complex 3d num_simplices " << safe_stree.num_simplices() + << " - Non exact is " << stree.num_simplices() << std::endl; + BOOST_CHECK(safe_stree.num_simplices() == stree.num_simplices()); + std::cout << "Exact Alpha complex 3d num_vertices " << safe_stree.num_vertices() + << " - Non exact is " << stree.num_vertices() << std::endl; + BOOST_CHECK(safe_stree.num_vertices() == stree.num_vertices()); + + auto safe_sh = stree.filtration_simplex_range().begin(); + while(safe_sh != stree.filtration_simplex_range().end()) { + std::vector simplex; + std::vector exact_simplex; +#ifdef DEBUG_TRACES + std::cout << "Non-exact ( "; +#endif + for (auto vertex : stree.simplex_vertex_range(*safe_sh)) { + simplex.push_back(vertex); +#ifdef DEBUG_TRACES + std::cout << vertex << " "; +#endif + } +#ifdef DEBUG_TRACES + std::cout << ") -> " << "[" << stree.filtration(*safe_sh) << "] "; + std::cout << std::endl; +#endif + + // Find it in the exact structure + auto sh_exact = safe_stree.find(simplex); + BOOST_CHECK(sh_exact != safe_stree.null_simplex()); + + // Exact and non-exact version is not exactly the same due to float comparison + GUDHI_TEST_FLOAT_EQUALITY_CHECK(safe_stree.filtration(sh_exact), stree.filtration(*safe_sh)); + + ++safe_sh; + } } -typedef boost::mpl::list weighted_variants_type_list; +typedef boost::mpl::list weighted_variants_type_list; #ifdef GUDHI_DEBUG BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted_throw, Weighted_alpha_complex_3d, weighted_variants_type_list) { @@ -183,13 +243,19 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted, Weighted_alpha_complex_3d, while(sh != stree.filtration_simplex_range().end()) { std::vector simplex; std::vector exact_simplex; +#ifdef DEBUG_TRACES std::cout << " ( "; +#endif for (auto vertex : stree.simplex_vertex_range(*sh)) { simplex.push_back(vertex); +#ifdef DEBUG_TRACES std::cout << vertex << " "; +#endif } +#ifdef DEBUG_TRACES std::cout << ") -> " << "[" << stree.filtration(*sh) << "] "; std::cout << std::endl; +#endif // Find it in the exact structure auto sh_exact = stree_bis.find(simplex); @@ -204,7 +270,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted, Weighted_alpha_complex_3d, } #ifdef GUDHI_DEBUG -typedef boost::mpl::list periodic_variants_type_list; +typedef boost::mpl::list periodic_variants_type_list; BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_periodic_throw, Periodic_alpha_complex_3d, periodic_variants_type_list) { std::cout << "Periodic alpha complex 3d exception throw" << std::endl; @@ -222,6 +290,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_periodic_throw, Periodic_alpha_compl std::invalid_argument); BOOST_CHECK_THROW (Periodic_alpha_complex_3d periodic_alpha_complex(p_points, 0., 0., 0., 1., 1., 0.9), std::invalid_argument); + BOOST_CHECK_THROW (Periodic_alpha_complex_3d periodic_alpha_complex(p_points, 0., 0., 0., 1.1, 1., 1.), + std::invalid_argument); + BOOST_CHECK_THROW (Periodic_alpha_complex_3d periodic_alpha_complex(p_points, 0., 0., 0., 1., 1.1, 1.), + std::invalid_argument); + BOOST_CHECK_THROW (Periodic_alpha_complex_3d periodic_alpha_complex(p_points, 0., 0., 0., 1., 1., 1.1), + std::invalid_argument); } #endif @@ -230,135 +304,18 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_periodic) { // Fast periodic version // --------------------- std::cout << "Fast periodic alpha complex 3d" << std::endl; + + using Creator = CGAL::Creator_uniform_3; + CGAL::Random random(7); + CGAL::Random_points_in_cube_3 in_cube(1, random); std::vector p_points; - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.0, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.0, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.0, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.0, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.0, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.2, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.2, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.2, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.2, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.2, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.4, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.4, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.4, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.4, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.4, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.6, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.6, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.6, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.6, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.6, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.8, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.8, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.8, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.8, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.0, 0.8, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.0, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.0, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.0, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.0, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.0, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.2, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.2, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.2, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.2, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.2, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.4, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.4, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.4, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.4, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.4, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.6, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.6, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.6, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.6, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.6, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.8, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.8, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.8, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.8, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.2, 0.8, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.0, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.0, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.0, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.0, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.0, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.2, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.2, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.2, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.2, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.2, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.4, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.4, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.4, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.4, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.4, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.6, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.6, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.6, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.6, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.6, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.8, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.8, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.8, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.8, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.4, 0.8, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.0, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.0, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.0, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.0, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.0, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.1, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.2, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.2, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.2, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.2, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.2, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.4, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.4, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.4, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.4, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.4, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.6, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.6, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.6, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.6, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.6, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.8, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.8, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.8, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.8, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.6, 0.8, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.0, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.0, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.0, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.0, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.0, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.2, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.2, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.2, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.2, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.2, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.4, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.4, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.4, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.4, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.4, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.6, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.6, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.6, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.6, 0.6)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.6, 0.8)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.8, 0.0)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.8, 0.2)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.8, 0.4)); - p_points.push_back(Fast_periodic_alpha_complex_3d::Point_3(0.8, 0.8, 0.6)); - - Fast_periodic_alpha_complex_3d periodic_alpha_complex(p_points, 0., 0., 0., 1., 1., 1.); + for (int i=0 ; i < 50 ; i++) { + Fast_periodic_alpha_complex_3d::Point_3 p = *in_cube++; + p_points.push_back(p); + } + + Fast_periodic_alpha_complex_3d periodic_alpha_complex(p_points, -1., -1., -1., 1., 1., 1.); Gudhi::Simplex_tree<> stree; periodic_alpha_complex.create_complex(stree); @@ -370,133 +327,11 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_periodic) { std::vector e_p_points; - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.0, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.0, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.0, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.0, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.0, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.2, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.2, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.2, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.2, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.2, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.4, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.4, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.4, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.4, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.4, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.6, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.6, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.6, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.6, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.6, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.8, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.8, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.8, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.8, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.0, 0.8, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.0, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.0, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.0, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.0, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.0, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.2, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.2, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.2, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.2, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.2, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.4, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.4, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.4, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.4, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.4, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.6, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.6, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.6, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.6, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.6, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.8, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.8, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.8, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.8, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.2, 0.8, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.0, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.0, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.0, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.0, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.0, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.2, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.2, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.2, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.2, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.2, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.4, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.4, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.4, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.4, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.4, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.6, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.6, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.6, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.6, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.6, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.8, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.8, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.8, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.8, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.4, 0.8, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.0, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.0, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.0, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.0, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.0, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.1, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.2, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.2, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.2, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.2, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.2, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.4, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.4, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.4, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.4, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.4, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.6, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.6, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.6, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.6, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.6, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.8, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.8, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.8, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.8, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.6, 0.8, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.0, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.0, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.0, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.0, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.0, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.2, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.2, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.2, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.2, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.2, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.4, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.4, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.4, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.4, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.4, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.6, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.6, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.6, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.6, 0.6)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.6, 0.8)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.8, 0.0)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.8, 0.2)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.8, 0.4)); - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(0.8, 0.8, 0.6)); - - Exact_periodic_alpha_complex_3d exact_alpha_complex(e_p_points, 0., 0., 0., 1., 1., 1.); + for (auto p: p_points) { + e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(p[0], p[1], p[2])); + } + + Exact_periodic_alpha_complex_3d exact_alpha_complex(e_p_points, -1., -1., -1., 1., 1., 1.); Gudhi::Simplex_tree<> exact_stree; exact_alpha_complex.create_complex(exact_stree); @@ -514,66 +349,107 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_periodic) { << " - Non exact is " << stree.num_vertices() << std::endl; BOOST_CHECK(exact_stree.num_vertices() == stree.num_vertices()); - /*auto sh = stree.filtration_simplex_range().begin(); - while(sh != stree.filtration_simplex_range().end()) { - std::vector simplex; - std::vector exact_simplex; - std::cout << "Non-exact ( "; - for (auto vertex : stree.simplex_vertex_range(*sh)) { - simplex.push_back(vertex); - std::cout << vertex << " "; - } - std::cout << ") -> " << "[" << stree.filtration(*sh) << "] "; - std::cout << std::endl; - // Find it in the exact structure - auto sh_exact = exact_stree.find(simplex); - // TODO(VR): BOOST_CHECK(sh_exact != exact_stree.null_simplex()); + // We cannot compare as objects from dispatcher on the alpha shape is not deterministic. + // cf. https://github.com/CGAL/cgal/issues/3346 + auto sh = stree.filtration_simplex_range().begin(); + auto sh_exact = exact_stree.filtration_simplex_range().begin(); - // Exact and non-exact version is not exactly the same due to float comparison - // TODO(VR): GUDHI_TEST_FLOAT_EQUALITY_CHECK(exact_stree.filtration(sh_exact), stree.filtration(*sh)); + while(sh != stree.filtration_simplex_range().end() || sh_exact != exact_stree.filtration_simplex_range().end()) { + GUDHI_TEST_FLOAT_EQUALITY_CHECK(stree.filtration(*sh), exact_stree.filtration(*sh_exact), 1e-14); + + std::vector vh(stree.simplex_vertex_range(*sh).begin(), + stree.simplex_vertex_range(*sh).end()); + std::vector exact_vh(exact_stree.simplex_vertex_range(*sh_exact).begin(), + exact_stree.simplex_vertex_range(*sh_exact).end()); + + BOOST_CHECK(vh.size() == exact_vh.size()); ++sh; - }*/ + ++sh_exact; + } + + BOOST_CHECK(sh == stree.filtration_simplex_range().end()); + BOOST_CHECK(sh_exact == exact_stree.filtration_simplex_range().end()); + + + // ---------------------- + // Safe periodic version + // ---------------------- + std::cout << "Safe periodic alpha complex 3d" << std::endl; + + std::vector s_p_points; + + for (auto p: p_points) { + s_p_points.push_back(Safe_periodic_alpha_complex_3d::Point_3(p[0], p[1], p[2])); + } + + Safe_periodic_alpha_complex_3d safe_alpha_complex(s_p_points, -1., -1., -1., 1., 1., 1.); + Gudhi::Simplex_tree<> safe_stree; + safe_alpha_complex.create_complex(safe_stree); -//} + // --------------------- + // Compare both versions + // --------------------- + // We cannot compare as objects from dispatcher on the alpha shape is not deterministic. + // cf. https://github.com/CGAL/cgal/issues/3346 + sh = stree.filtration_simplex_range().begin(); + auto sh_safe = safe_stree.filtration_simplex_range().begin(); -typedef boost::mpl::list wp_variants_type_list; + while(sh != stree.filtration_simplex_range().end() || sh_safe != safe_stree.filtration_simplex_range().end()) { + GUDHI_TEST_FLOAT_EQUALITY_CHECK(stree.filtration(*sh), safe_stree.filtration(*sh_safe), 1e-14); + + std::vector vh(stree.simplex_vertex_range(*sh).begin(), + stree.simplex_vertex_range(*sh).end()); + std::vector safe_vh(safe_stree.simplex_vertex_range(*sh_safe).begin(), + safe_stree.simplex_vertex_range(*sh_safe).end()); + + BOOST_CHECK(vh.size() == safe_vh.size()); + ++sh; + ++sh_safe; + } + + BOOST_CHECK(sh == stree.filtration_simplex_range().end()); + BOOST_CHECK(sh_safe == safe_stree.filtration_simplex_range().end()); + +} + +typedef boost::mpl::list wp_variants_type_list; #ifdef GUDHI_DEBUG BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted_periodic_throw, Weighted_periodic_alpha_complex_3d, wp_variants_type_list) { std::cout << "Weighted periodic alpha complex 3d exception throw" << std::endl; - using Point_3 = typename Weighted_periodic_alpha_complex_3d::Point_3; - - 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(); + using Creator = CGAL::Creator_uniform_3; + CGAL::Random random(7); + CGAL::Random_points_in_cube_3 in_cube(1, random); + std::vector wp_points; + for (int i=0 ; i < 50 ; i++) { + Weighted_periodic_alpha_complex_3d::Point_3 p = *in_cube++; + wp_points.push_back(p); + } std::vector p_weights; - // 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) { 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., .9, 1., 1.), + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, -1., -1., -1., 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., .9, 1.), + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, -1., -1., -1., 1., 0.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., .9), + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, -1., -1., -1., 1., 1., 0.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.), + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, -1., -1., -1., 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.), + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, -1., -1., -1., 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), + BOOST_CHECK_THROW (Weighted_periodic_alpha_complex_3d wp_alpha_complex(wp_points, p_weights, -1., -1., -1., 1., 1., 1.1), std::invalid_argument); std::cout << "0 <= point.weight() < 1/64 * domain_size * domain_size exception" << std::endl; @@ -604,80 +480,121 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted_periodic_throw, Weighted_pe } #endif -BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted_periodic, Weighted_periodic_alpha_complex_3d, - 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; - - Gudhi::Points_3D_off_reader off_reader("bunny_1000.off"); - BOOST_CHECK(off_reader.is_valid()); - - std::vector points = off_reader.get_point_cloud(); +BOOST_AUTO_TEST_CASE(Alpha_complex_weighted_periodic) { + // --------------------- + // Fast weighted periodic version + // --------------------- + std::cout << "Fast weighted periodic alpha complex 3d" << std::endl; - std::vector weights; + using Creator = CGAL::Creator_uniform_3; + CGAL::Random random(7); + CGAL::Random_points_in_cube_3 in_cube(1, random); + std::vector p_points; + for (int i=0 ; i < 50 ; i++) { + Fast_weighted_periodic_alpha_complex_3d::Point_3 p = *in_cube++; + p_points.push_back(p); + } + std::vector p_weights; // Weights must be in range ]0, 1/64 = 0.015625[ - CGAL::Random random(8); - - for (std::size_t i = 0; i < points.size(); ++i) { - weights.push_back(0.1 * random.get_double(0., 0.01)); + for (std::size_t i = 0; i < p_points.size(); ++i) { + p_weights.push_back(random.get_double(0., 0.01)); } - Weighted_periodic_alpha_complex_3d weighted_periodic_alpha_complex(points, weights, 0., 0., 0., 1., 1., 1.); + Fast_weighted_periodic_alpha_complex_3d periodic_alpha_complex(p_points, p_weights, -1., -1., -1., 1., 1., 1.); Gudhi::Simplex_tree<> stree; - weighted_periodic_alpha_complex.create_complex(stree); + periodic_alpha_complex.create_complex(stree); - std::cout << "Weighted periodic alpha complex 3d from weighted points" << std::endl; - using Weighted_point_3 = typename Weighted_periodic_alpha_complex_3d::Triangulation_3::Weighted_point; + // ---------------------- + // Exact weighted periodic version + // ---------------------- + std::cout << "Exact weighted periodic alpha complex 3d" << std::endl; - std::vector weighted_points; + std::vector e_p_points; - for (std::size_t i=0; i < points.size(); i++) { - weighted_points.push_back(Weighted_point_3(points[i], weights[i])); + for (auto p: p_points) { + e_p_points.push_back(Exact_weighted_periodic_alpha_complex_3d::Point_3(p[0], p[1], p[2])); } - Weighted_periodic_alpha_complex_3d alpha_complex_w_p(weighted_points, 0., 0., 0., 1., 1., 1.); - Gudhi::Simplex_tree<> stree_bis; - alpha_complex_w_p.create_complex(stree_bis); + Exact_weighted_periodic_alpha_complex_3d exact_alpha_complex(e_p_points, p_weights, -1., -1., -1., 1., 1., 1.); + + Gudhi::Simplex_tree<> exact_stree; + exact_alpha_complex.create_complex(exact_stree); // --------------------- // Compare both versions // --------------------- - std::cout << "Weighted periodic alpha complex 3d is of dimension " << stree_bis.dimension() - << " - versus " << stree.dimension() << std::endl; - 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; - 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()); + std::cout << "Exact weighted periodic alpha complex 3d is of dimension " << exact_stree.dimension() + << " - Non exact is " << stree.dimension() << std::endl; + BOOST_CHECK(exact_stree.dimension() == stree.dimension()); + std::cout << "Exact weighted periodic alpha complex 3d num_simplices " << exact_stree.num_simplices() + << " - Non exact is " << stree.num_simplices() << std::endl; + BOOST_CHECK(exact_stree.num_simplices() == stree.num_simplices()); + std::cout << "Exact weighted periodic alpha complex 3d num_vertices " << exact_stree.num_vertices() + << " - Non exact is " << stree.num_vertices() << std::endl; + BOOST_CHECK(exact_stree.num_vertices() == stree.num_vertices()); + + // We cannot compare as objects from dispatcher on the alpha shape is not deterministic. + // cf. https://github.com/CGAL/cgal/issues/3346 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 + auto sh_exact = exact_stree.filtration_simplex_range().begin(); - // Find it in the exact structure - auto sh_exact = stree_bis.find(simplex); - BOOST_CHECK(sh_exact != stree_bis.null_simplex()); + while(sh != stree.filtration_simplex_range().end() || sh_exact != exact_stree.filtration_simplex_range().end()) { + GUDHI_TEST_FLOAT_EQUALITY_CHECK(stree.filtration(*sh), exact_stree.filtration(*sh_exact), 1e-14); - // 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); + std::vector vh(stree.simplex_vertex_range(*sh).begin(), + stree.simplex_vertex_range(*sh).end()); + std::vector exact_vh(exact_stree.simplex_vertex_range(*sh_exact).begin(), + exact_stree.simplex_vertex_range(*sh_exact).end()); + + BOOST_CHECK(vh.size() == exact_vh.size()); ++sh; + ++sh_exact; } + + BOOST_CHECK(sh == stree.filtration_simplex_range().end()); + BOOST_CHECK(sh_exact == exact_stree.filtration_simplex_range().end()); + + + // ---------------------- + // Safe weighted periodic version + // ---------------------- + std::cout << "Safe weighted periodic alpha complex 3d" << std::endl; + + std::vector s_p_points; + + for (auto p: p_points) { + s_p_points.push_back(Safe_weighted_periodic_alpha_complex_3d::Point_3(p[0], p[1], p[2])); + } + + Safe_weighted_periodic_alpha_complex_3d safe_alpha_complex(s_p_points, p_weights, -1., -1., -1., 1., 1., 1.); + + Gudhi::Simplex_tree<> safe_stree; + safe_alpha_complex.create_complex(safe_stree); + + // --------------------- + // Compare both versions + // --------------------- + // We cannot compare as objects from dispatcher on the alpha shape is not deterministic. + // cf. https://github.com/CGAL/cgal/issues/3346 + sh = stree.filtration_simplex_range().begin(); + auto sh_safe = safe_stree.filtration_simplex_range().begin(); + + while(sh != stree.filtration_simplex_range().end() || sh_safe != safe_stree.filtration_simplex_range().end()) { + GUDHI_TEST_FLOAT_EQUALITY_CHECK(stree.filtration(*sh), safe_stree.filtration(*sh_safe), 1e-14); + + std::vector vh(stree.simplex_vertex_range(*sh).begin(), + stree.simplex_vertex_range(*sh).end()); + std::vector safe_vh(safe_stree.simplex_vertex_range(*sh_safe).begin(), + safe_stree.simplex_vertex_range(*sh_safe).end()); + + BOOST_CHECK(vh.size() == safe_vh.size()); + ++sh; + ++sh_safe; + } + + BOOST_CHECK(sh == stree.filtration_simplex_range().end()); + BOOST_CHECK(sh_safe == safe_stree.filtration_simplex_range().end()); } -- cgit v1.2.3