From f87a1026d5d1accbb6a558ef5d50f5c4c035e0d8 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 3 Dec 2019 16:51:09 +0100 Subject: Fix #134 --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/Alpha_complex/include') diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 6b4d8463..6f19cb6c 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -121,8 +121,8 @@ class Alpha_complex { // size_type type from CGAL. typedef typename Delaunay_triangulation::size_type size_type; - // Map type to switch from simplex tree vertex handle to CGAL vertex iterator. - typedef typename std::map< std::size_t, CGAL_vertex_iterator > Vector_vertex_iterator; + // Structure to switch from simplex tree vertex handle to CGAL vertex iterator. + typedef typename std::vector< CGAL_vertex_iterator > Vector_vertex_iterator; private: /** \brief Vertex iterator vector to switch from simplex tree vertex handle to CGAL vertex iterator. @@ -238,14 +238,16 @@ class Alpha_complex { hint = pos->full_cell(); } // -------------------------------------------------------------------------------------------- - // double map to retrieve simplex tree vertex handles from CGAL vertex iterator and vice versa + // structure to retrieve CGAL points from vertex handle - one vertex handle per point. + // Needs to be constructed before as vertex handles arrives in no particular order. + vertex_handle_to_iterator_.resize(point_cloud.size()); // Loop on triangulation vertices list for (CGAL_vertex_iterator vit = triangulation_->vertices_begin(); vit != triangulation_->vertices_end(); ++vit) { if (!triangulation_->is_infinite(*vit)) { #ifdef DEBUG_TRACES std::cout << "Vertex insertion - " << vit->data() << " -> " << vit->point() << std::endl; #endif // DEBUG_TRACES - vertex_handle_to_iterator_.emplace(vit->data(), vit); + vertex_handle_to_iterator_[vit->data()] = vit; } } // -------------------------------------------------------------------------------------------- -- cgit v1.2.3 From 329637d2a0a806955a29faccf38915c3fb7cd2fd Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 10 Dec 2019 10:03:53 +0100 Subject: Remove number_of_vertices method from Alpha_complex as there is no added value to Simplex_tree.num_vertices() --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 8 --- src/Alpha_complex/test/Alpha_complex_unit_test.cpp | 60 +++++++++++++++------- 2 files changed, 42 insertions(+), 26 deletions(-) (limited to 'src/Alpha_complex/include') diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 6f19cb6c..f2a05e95 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -191,14 +191,6 @@ class Alpha_complex { return vertex_handle_to_iterator_.at(vertex)->point(); } - /** \brief number_of_vertices returns the number of vertices (same as the number of points). - * - * @return The number of vertices. - */ - std::size_t number_of_vertices() const { - return vertex_handle_to_iterator_.size(); - } - private: template void init_from_range(const InputPointRange& points) { diff --git a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp index 40b3fe09..27b671dd 100644 --- a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp @@ -53,20 +53,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_from_OFF_file, TestedKernel, list_of Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_name); - std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_file.number_of_vertices() - << std::endl; - BOOST_CHECK(alpha_complex_from_file.number_of_vertices() == 7); - Gudhi::Simplex_tree<> simplex_tree_60; BOOST_CHECK(alpha_complex_from_file.create_complex(simplex_tree_60, max_alpha_square_value)); std::cout << "simplex_tree_60.dimension()=" << simplex_tree_60.dimension() << std::endl; BOOST_CHECK(simplex_tree_60.dimension() == 2); - std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_file.number_of_vertices() - << std::endl; - BOOST_CHECK(alpha_complex_from_file.number_of_vertices() == 7); - std::cout << "simplex_tree_60.num_vertices()=" << simplex_tree_60.num_vertices() << std::endl; BOOST_CHECK(simplex_tree_60.num_vertices() == 7); @@ -128,10 +120,6 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) { Gudhi::Simplex_tree<> simplex_tree; BOOST_CHECK(alpha_complex_from_points.create_complex(simplex_tree)); - std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_points.number_of_vertices() - << std::endl; - BOOST_CHECK(alpha_complex_from_points.number_of_vertices() == points.size()); - // Another way to check num_simplices std::cout << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; int num_simplices = 0; @@ -151,7 +139,7 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_from_points) { std::cout << "simplex_tree.dimension()=" << simplex_tree.dimension() << std::endl; BOOST_CHECK(simplex_tree.dimension() == 3); std::cout << "simplex_tree.num_vertices()=" << simplex_tree.num_vertices() << std::endl; - BOOST_CHECK(simplex_tree.num_vertices() == 4); + BOOST_CHECK(simplex_tree.num_vertices() == points.size()); for (auto f_simplex : simplex_tree.filtration_simplex_range()) { switch (simplex_tree.dimension(f_simplex)) { @@ -261,10 +249,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_from_empty_points, TestedKernel, lis Gudhi::Simplex_tree<> simplex_tree; BOOST_CHECK(!alpha_complex_from_points.create_complex(simplex_tree)); - std::cout << "alpha_complex_from_points.number_of_vertices()=" << alpha_complex_from_points.number_of_vertices() - << std::endl; - BOOST_CHECK(alpha_complex_from_points.number_of_vertices() == points.size()); - std::cout << "simplex_tree.num_simplices()=" << simplex_tree.num_simplices() << std::endl; BOOST_CHECK(simplex_tree.num_simplices() == 0); @@ -272,5 +256,45 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_from_empty_points, TestedKernel, lis BOOST_CHECK(simplex_tree.dimension() == -1); std::cout << "simplex_tree.num_vertices()=" << simplex_tree.num_vertices() << std::endl; - BOOST_CHECK(simplex_tree.num_vertices() == 0); + BOOST_CHECK(simplex_tree.num_vertices() == points.size()); +} + +using Inexact_kernel_2 = CGAL::Epick_d< CGAL::Dimension_tag<2> >; +using Exact_kernel_2 = CGAL::Epeck_d< CGAL::Dimension_tag<2> >; +using list_of_kernel_2_variants = boost::mpl::list; + +BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_with_duplicated_points, TestedKernel, list_of_kernel_2_variants) { + std::cout << "========== Alpha_complex_with_duplicated_points ==========" << std::endl; + + using Point = typename TestedKernel::Point_d; + using Vector_of_points = std::vector; + + // ---------------------------------------------------------------------------- + // Init of a list of points + // ---------------------------------------------------------------------------- + Vector_of_points points; + points.push_back(Point(1.0, 1.0)); + points.push_back(Point(7.0, 0.0)); + points.push_back(Point(4.0, 6.0)); + points.push_back(Point(9.0, 6.0)); + points.push_back(Point(0.0, 14.0)); + points.push_back(Point(2.0, 19.0)); + points.push_back(Point(9.0, 17.0)); + // duplicated points + points.push_back(Point(1.0, 1.0)); + points.push_back(Point(7.0, 0.0)); + + // ---------------------------------------------------------------------------- + // Init of an alpha complex from the list of points + // ---------------------------------------------------------------------------- + std::cout << "Init" << std::endl; + Gudhi::alpha_complex::Alpha_complex alpha_complex_from_points(points); + + Gudhi::Simplex_tree<> simplex_tree; + std::cout << "create_complex" << std::endl; + BOOST_CHECK(alpha_complex_from_points.create_complex(simplex_tree)); + + std::cout << "simplex_tree.num_vertices()=" << simplex_tree.num_vertices() + << std::endl; + BOOST_CHECK(simplex_tree.num_vertices() < points.size()); } -- cgit v1.2.3