From 88a36ffad6c11279990c1c96df32b95c1f6f526c Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Fri, 3 Jul 2020 13:57:49 +0200 Subject: A fix proposal for boudaries of a simplex python version --- .../include/gudhi/Simplex_tree/Simplex_tree_iterators.h | 5 +++++ src/python/gudhi/simplex_tree.pxd | 8 ++++++++ src/python/gudhi/simplex_tree.pyx | 16 ++++++++++++++++ src/python/include/Simplex_tree_interface.h | 11 +++++++++++ src/python/test/test_simplex_tree.py | 9 +++++++++ 5 files changed, 49 insertions(+) diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h index 9007b6bd..9c864454 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h @@ -85,6 +85,11 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< typedef typename SimplexTree::Vertex_handle Vertex_handle; typedef typename SimplexTree::Siblings Siblings; + Simplex_tree_boundary_simplex_iterator() + : sib_(nullptr), + st_(nullptr) { + } + // any end() iterator explicit Simplex_tree_boundary_simplex_iterator(SimplexTree * st) : last_(st->null_vertex()), diff --git a/src/python/gudhi/simplex_tree.pxd b/src/python/gudhi/simplex_tree.pxd index e748ac40..a64599e7 100644 --- a/src/python/gudhi/simplex_tree.pxd +++ b/src/python/gudhi/simplex_tree.pxd @@ -36,6 +36,12 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": Simplex_tree_skeleton_iterator operator++() nogil bint operator!=(Simplex_tree_skeleton_iterator) nogil + cdef cppclass Simplex_tree_boundary_iterator "Gudhi::Simplex_tree_interface::Boundary_simplex_iterator": + Simplex_tree_boundary_iterator() nogil + Simplex_tree_simplex_handle& operator*() nogil + Simplex_tree_boundary_iterator operator++() nogil + bint operator!=(Simplex_tree_boundary_iterator) nogil + cdef cppclass Simplex_tree_interface_full_featured "Gudhi::Simplex_tree_interface": Simplex_tree() nogil @@ -65,6 +71,8 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": vector[Simplex_tree_simplex_handle].const_iterator get_filtration_iterator_end() nogil Simplex_tree_skeleton_iterator get_skeleton_iterator_begin(int dimension) nogil Simplex_tree_skeleton_iterator get_skeleton_iterator_end(int dimension) nogil + Simplex_tree_boundary_iterator get_boundary_iterator_begin(vector[int] simplex) nogil + Simplex_tree_boundary_iterator get_boundary_iterator_end(vector[int] simplex) nogil cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi": cdef cppclass Simplex_tree_persistence_interface "Gudhi::Persistent_cohomology_interface>": diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx index 20e66d9f..da445a12 100644 --- a/src/python/gudhi/simplex_tree.pyx +++ b/src/python/gudhi/simplex_tree.pyx @@ -285,6 +285,22 @@ cdef class SimplexTree: ct.append((v, filtered_simplex.second)) return ct + def get_boundaries(self, simplex): + """This function returns a generator with the boundaries of a given N-simplex. + + :param simplex: The N-simplex, represented by a list of vertex. + :type simplex: list of int. + :returns: The (simplices of the) boundaries of a simplex + :rtype: generator with tuples(simplex, filtration) + """ + cdef Simplex_tree_boundary_iterator it = self.get_ptr().get_boundary_iterator_begin(simplex) + cdef Simplex_tree_boundary_iterator end = self.get_ptr().get_boundary_iterator_end(simplex) + + while it != end: + yield self.get_ptr().get_simplex_and_filtration(dereference(it)) + preincrement(it) + + def remove_maximal_simplex(self, simplex): """This function removes a given maximal N-simplex from the simplicial complex. diff --git a/src/python/include/Simplex_tree_interface.h b/src/python/include/Simplex_tree_interface.h index 56d7c41d..c4f18eeb 100644 --- a/src/python/include/Simplex_tree_interface.h +++ b/src/python/include/Simplex_tree_interface.h @@ -36,6 +36,7 @@ class Simplex_tree_interface : public Simplex_tree { using Skeleton_simplex_iterator = typename Base::Skeleton_simplex_iterator; using Complex_simplex_iterator = typename Base::Complex_simplex_iterator; using Extended_filtration_data = typename Base::Extended_filtration_data; + using Boundary_simplex_iterator = typename Base::Boundary_simplex_iterator; public: @@ -188,6 +189,16 @@ class Simplex_tree_interface : public Simplex_tree { // this specific case works because the range is just a pair of iterators - won't work if range was a vector return Base::skeleton_simplex_range(dimension).end(); } + + Boundary_simplex_iterator get_boundary_iterator_begin(const Simplex& simplex) { + // this specific case works because the range is just a pair of iterators - won't work if range was a vector + return Base::boundary_simplex_range(Base::find(simplex)).begin(); + } + + Boundary_simplex_iterator get_boundary_iterator_end(const Simplex& simplex) { + // this specific case works because the range is just a pair of iterators - won't work if range was a vector + return Base::boundary_simplex_range(Base::find(simplex)).end(); + } }; } // namespace Gudhi diff --git a/src/python/test/test_simplex_tree.py b/src/python/test/test_simplex_tree.py index 2137d822..7c49cb1a 100755 --- a/src/python/test/test_simplex_tree.py +++ b/src/python/test/test_simplex_tree.py @@ -340,3 +340,12 @@ def test_simplices_iterator(): assert st.find(simplex[0]) == True print("filtration is: ", simplex[1]) assert st.filtration(simplex[0]) == simplex[1] + +def test_boundaries_iterator(): + st = SimplexTree() + + assert st.insert([0, 1, 2, 3], filtration=1.0) == True + assert st.insert([1, 2, 3, 4], filtration=2.0) == True + + assert list(st.get_boundaries([1, 2, 3])) == [([1, 2], 1.0), ([1, 3], 1.0), ([2, 3], 1.0)] + assert list(st.get_boundaries([2, 3, 4])) == [([2, 3], 1.0), ([2, 4], 2.0), ([3, 4], 2.0)] -- cgit v1.2.3 From 77cda62efd84ca7090d8796ca0197b03dbc22350 Mon Sep 17 00:00:00 2001 From: Vincent Rouvreau <10407034+VincentRouvreau@users.noreply.github.com> Date: Wed, 12 Aug 2020 07:28:31 +0200 Subject: Update src/python/gudhi/simplex_tree.pyx Co-authored-by: Marc Glisse --- src/python/gudhi/simplex_tree.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx index da445a12..3ebae923 100644 --- a/src/python/gudhi/simplex_tree.pyx +++ b/src/python/gudhi/simplex_tree.pyx @@ -290,7 +290,7 @@ cdef class SimplexTree: :param simplex: The N-simplex, represented by a list of vertex. :type simplex: list of int. - :returns: The (simplices of the) boundaries of a simplex + :returns: The (simplices of the) boundary of a simplex :rtype: generator with tuples(simplex, filtration) """ cdef Simplex_tree_boundary_iterator it = self.get_ptr().get_boundary_iterator_begin(simplex) -- cgit v1.2.3 From 1f31e5ce995b0e7683c4eab7077317e28ee5b1b3 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 12 Aug 2020 08:02:00 +0200 Subject: code review: add a comment about Simplex_tree_boundary_simplex_iterator default ctor --- src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h index 9c864454..ee64a277 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h @@ -85,6 +85,7 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< typedef typename SimplexTree::Vertex_handle Vertex_handle; typedef typename SimplexTree::Siblings Siblings; + // For cython purpose only. The object it initializes should be overwritten ASAP and never used before it is overwritten. Simplex_tree_boundary_simplex_iterator() : sib_(nullptr), st_(nullptr) { -- cgit v1.2.3 From 8f9c065df7f4629555ef09292c14c293891f1bdc Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 12 Aug 2020 10:03:26 +0200 Subject: code review: Add test to get boundaries from a vertex --- src/python/test/test_simplex_tree.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python/test/test_simplex_tree.py b/src/python/test/test_simplex_tree.py index 7c49cb1a..036e88df 100755 --- a/src/python/test/test_simplex_tree.py +++ b/src/python/test/test_simplex_tree.py @@ -349,3 +349,4 @@ def test_boundaries_iterator(): assert list(st.get_boundaries([1, 2, 3])) == [([1, 2], 1.0), ([1, 3], 1.0), ([2, 3], 1.0)] assert list(st.get_boundaries([2, 3, 4])) == [([2, 3], 1.0), ([2, 4], 2.0), ([3, 4], 2.0)] + assert list(st.get_boundaries([2])) == [] -- cgit v1.2.3 From 458bc2dcf5044e1d5fde5326b2be35e526abd457 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 12 Aug 2020 13:06:03 +0200 Subject: code review: boundaries uses only once find and return a pair of iterator. Exception is raised when not found. tested --- src/python/gudhi/simplex_tree.pxd | 3 +-- src/python/gudhi/simplex_tree.pyx | 14 ++++++++------ src/python/include/Simplex_tree_interface.h | 12 +++++------- src/python/test/test_simplex_tree.py | 9 +++++++++ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/python/gudhi/simplex_tree.pxd b/src/python/gudhi/simplex_tree.pxd index a64599e7..e1b03391 100644 --- a/src/python/gudhi/simplex_tree.pxd +++ b/src/python/gudhi/simplex_tree.pxd @@ -71,8 +71,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": vector[Simplex_tree_simplex_handle].const_iterator get_filtration_iterator_end() nogil Simplex_tree_skeleton_iterator get_skeleton_iterator_begin(int dimension) nogil Simplex_tree_skeleton_iterator get_skeleton_iterator_end(int dimension) nogil - Simplex_tree_boundary_iterator get_boundary_iterator_begin(vector[int] simplex) nogil - Simplex_tree_boundary_iterator get_boundary_iterator_end(vector[int] simplex) nogil + pair[Simplex_tree_boundary_iterator, Simplex_tree_boundary_iterator] get_boundary_iterators(vector[int] simplex) nogil except + cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi": cdef cppclass Simplex_tree_persistence_interface "Gudhi::Persistent_cohomology_interface>": diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx index 3ebae923..bc5b43f4 100644 --- a/src/python/gudhi/simplex_tree.pyx +++ b/src/python/gudhi/simplex_tree.pyx @@ -293,12 +293,14 @@ cdef class SimplexTree: :returns: The (simplices of the) boundary of a simplex :rtype: generator with tuples(simplex, filtration) """ - cdef Simplex_tree_boundary_iterator it = self.get_ptr().get_boundary_iterator_begin(simplex) - cdef Simplex_tree_boundary_iterator end = self.get_ptr().get_boundary_iterator_end(simplex) - - while it != end: - yield self.get_ptr().get_simplex_and_filtration(dereference(it)) - preincrement(it) + cdef pair[Simplex_tree_boundary_iterator, Simplex_tree_boundary_iterator] it = self.get_ptr().get_boundary_iterators(simplex) + + try: + while it.first != it.second: + yield self.get_ptr().get_simplex_and_filtration(dereference(it.first)) + preincrement(it.first) + except RuntimeError: + print("simplex not found - cannot find boundaries") def remove_maximal_simplex(self, simplex): diff --git a/src/python/include/Simplex_tree_interface.h b/src/python/include/Simplex_tree_interface.h index c4f18eeb..2c695d1b 100644 --- a/src/python/include/Simplex_tree_interface.h +++ b/src/python/include/Simplex_tree_interface.h @@ -190,14 +190,12 @@ class Simplex_tree_interface : public Simplex_tree { return Base::skeleton_simplex_range(dimension).end(); } - Boundary_simplex_iterator get_boundary_iterator_begin(const Simplex& simplex) { + std::pair get_boundary_iterators(const Simplex& simplex) { + auto bd_sh = Base::find(simplex); + if (bd_sh == Base::null_simplex()) + throw std::runtime_error("simplex not found - cannot find boundaries"); // this specific case works because the range is just a pair of iterators - won't work if range was a vector - return Base::boundary_simplex_range(Base::find(simplex)).begin(); - } - - Boundary_simplex_iterator get_boundary_iterator_end(const Simplex& simplex) { - // this specific case works because the range is just a pair of iterators - won't work if range was a vector - return Base::boundary_simplex_range(Base::find(simplex)).end(); + return std::make_pair(Base::boundary_simplex_range(bd_sh).begin(), Base::boundary_simplex_range(bd_sh).end()); } }; diff --git a/src/python/test/test_simplex_tree.py b/src/python/test/test_simplex_tree.py index 036e88df..828400fb 100755 --- a/src/python/test/test_simplex_tree.py +++ b/src/python/test/test_simplex_tree.py @@ -350,3 +350,12 @@ def test_boundaries_iterator(): assert list(st.get_boundaries([1, 2, 3])) == [([1, 2], 1.0), ([1, 3], 1.0), ([2, 3], 1.0)] assert list(st.get_boundaries([2, 3, 4])) == [([2, 3], 1.0), ([2, 4], 2.0), ([3, 4], 2.0)] assert list(st.get_boundaries([2])) == [] + + with pytest.raises(RuntimeError): + list(st.get_boundaries([])) + + with pytest.raises(RuntimeError): + list(st.get_boundaries([0, 4])) # (0, 4) does not exist + + with pytest.raises(RuntimeError): + list(st.get_boundaries([6])) # (6) does not exist -- cgit v1.2.3 From d9ae2cb822631d68e4ef1cec7eed0124080c0020 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 24 Aug 2020 09:17:23 +0200 Subject: code review: call boundary_simplex_range only once --- src/python/include/Simplex_tree_interface.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python/include/Simplex_tree_interface.h b/src/python/include/Simplex_tree_interface.h index ab3f13f1..baff3850 100644 --- a/src/python/include/Simplex_tree_interface.h +++ b/src/python/include/Simplex_tree_interface.h @@ -226,7 +226,8 @@ class Simplex_tree_interface : public Simplex_tree { if (bd_sh == Base::null_simplex()) throw std::runtime_error("simplex not found - cannot find boundaries"); // this specific case works because the range is just a pair of iterators - won't work if range was a vector - return std::make_pair(Base::boundary_simplex_range(bd_sh).begin(), Base::boundary_simplex_range(bd_sh).end()); + auto boundary_srange = Base::boundary_simplex_range(bd_sh); + return std::make_pair(boundary_srange.begin(), boundary_srange.end()); } }; -- cgit v1.2.3 From db938dbd74460e7a0fd705be8628984052f71dc0 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Fri, 4 Sep 2020 17:23:16 +0200 Subject: Alpha_kernel_d, its tests and Alpha complex to use it --- src/Alpha_complex/example/CMakeLists.txt | 3 + .../example/Weighted_alpha_complex_from_points.cpp | 54 ++++++++ src/Alpha_complex/include/gudhi/Alpha_complex.h | 106 ++++++++-------- .../include/gudhi/Alpha_complex/Alpha_kernel_d.h | 137 +++++++++++++++++++++ .../test/Alpha_kernel_d_unit_test.cpp | 132 ++++++++++++++++++++ src/Alpha_complex/test/CMakeLists.txt | 4 + 6 files changed, 387 insertions(+), 49 deletions(-) create mode 100644 src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp create mode 100644 src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h create mode 100644 src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp diff --git a/src/Alpha_complex/example/CMakeLists.txt b/src/Alpha_complex/example/CMakeLists.txt index 2eecd50c..c9b937ed 100644 --- a/src/Alpha_complex/example/CMakeLists.txt +++ b/src/Alpha_complex/example/CMakeLists.txt @@ -7,10 +7,13 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) target_link_libraries(Alpha_complex_example_from_off ${CGAL_LIBRARY}) add_executable ( Alpha_complex_example_fast_from_off Fast_alpha_complex_from_off.cpp ) target_link_libraries(Alpha_complex_example_fast_from_off ${CGAL_LIBRARY}) + add_executable ( Weighted_alpha_complex_example_from_points Weighted_alpha_complex_from_points.cpp ) + target_link_libraries(Weighted_alpha_complex_example_from_points ${CGAL_LIBRARY}) if (TBB_FOUND) target_link_libraries(Alpha_complex_example_from_points ${TBB_LIBRARIES}) target_link_libraries(Alpha_complex_example_from_off ${TBB_LIBRARIES}) target_link_libraries(Alpha_complex_example_fast_from_off ${TBB_LIBRARIES}) + target_link_libraries(Weighted_alpha_complex_example_from_points ${TBB_LIBRARIES}) endif() add_test(NAME Alpha_complex_example_from_points COMMAND $) diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp new file mode 100644 index 00000000..19a04282 --- /dev/null +++ b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp @@ -0,0 +1,54 @@ +#include +// to construct a simplex_tree from alpha complex +#include + +#include + +#include +#include + +// Explicit dimension 2 Epeck_d kernel +using Kernel = CGAL::Epeck_d< CGAL::Dimension_tag<2> >; +using Bare_point = Kernel::Point_d; +using Weighted_point = Kernel::Weighted_point_d; +using Vector_of_points = std::vector; + +int main() { + // ---------------------------------------------------------------------------- + // Init of a list of points + // ---------------------------------------------------------------------------- + Vector_of_points points; + points.push_back(Weighted_point(Bare_point(1.0, 1.0) , 1.)); + points.push_back(Weighted_point(Bare_point(7.0, 0.0) , 1.)); + points.push_back(Weighted_point(Bare_point(4.0, 6.0) , 1.)); + points.push_back(Weighted_point(Bare_point(9.0, 6.0) , 1.)); + points.push_back(Weighted_point(Bare_point(0.0, 14.0), 1.)); + points.push_back(Weighted_point(Bare_point(2.0, 19.0), 1.)); + points.push_back(Weighted_point(Bare_point(9.0, 17.0), 1.)); + + // ---------------------------------------------------------------------------- + // Init of an alpha complex from the list of points + // ---------------------------------------------------------------------------- + Gudhi::alpha_complex::Alpha_complex alpha_complex_from_weighted_points(points); + + Gudhi::Simplex_tree<> simplex; + if (alpha_complex_from_weighted_points.create_complex(simplex)) { + // ---------------------------------------------------------------------------- + // Display information about the alpha complex + // ---------------------------------------------------------------------------- + std::clog << "Weighted alpha complex is of dimension " << simplex.dimension() << + " - " << simplex.num_simplices() << " simplices - " << + simplex.num_vertices() << " vertices." << std::endl; + + std::clog << "Iterator on weighted alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; + for (auto f_simplex : simplex.filtration_simplex_range()) { + std::clog << " ( "; + for (auto vertex : simplex.simplex_vertex_range(f_simplex)) { + std::clog << vertex << " "; + } + std::clog << ") -> " << "[" << simplex.filtration(f_simplex) << "] "; + std::clog << std::endl; + } + } + return 0; +} diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index ba91998d..8e9fe773 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -12,6 +12,7 @@ #ifndef ALPHA_COMPLEX_H_ #define ALPHA_COMPLEX_H_ +#include #include // to construct Alpha_complex from a OFF file of points #include @@ -20,6 +21,7 @@ #include // isnan, fmax #include +#include // aka. Weighted Delaunay triangulation #include // For EXACT or SAFE version #include // For FAST version #include @@ -91,49 +93,55 @@ template struct Is_Epeck_D> { static const bool val * guarantee that the output is a valid filtration (faces have a filtration value no larger than their cofaces). * - For performances reasons, it is advised to use `Alpha_complex` with \ref cgal ≥ 5.0.0. */ -template> +template, bool Weighted = false> class Alpha_complex { public: + /** \brief Geometric traits class that provides the geometric types and predicates needed by the triangulations.*/ + using Geom_traits = typename std::conditional, + Kernel>::type; // Add an int in TDS to save point index in the structure - typedef CGAL::Triangulation_data_structure, - CGAL::Triangulation_full_cell > TDS; - /** \brief A Delaunay triangulation of a set of points in \f$ \mathbb{R}^D\f$.*/ - typedef CGAL::Delaunay_triangulation Delaunay_triangulation; + using TDS = CGAL::Triangulation_data_structure, + CGAL::Triangulation_full_cell >; + /** \brief A (Weighted or not) Delaunay triangulation of a set of points in \f$ \mathbb{R}^D\f$.*/ + using Triangulation = typename std::conditional, + CGAL::Delaunay_triangulation>::type; + + using A_kernel_d = Alpha_kernel_d; + + // Numeric type of coordinates in the kernel + using FT = typename A_kernel_d::FT; + + /** \brief If Weighted, the weighted point is cached (point + weight [= squared radius]), + * else a pair of point and squared radius is cached. + */ + using Sphere = typename A_kernel_d::Sphere; /** \brief A point in Euclidean space.*/ - typedef typename Kernel::Point_d Point_d; - /** \brief Geometric traits class that provides the geometric types and predicates needed by Delaunay - * triangulations.*/ - typedef Kernel Geom_traits; + using Point_d = typename std::conditional::type; private: - typedef typename Kernel::Compute_squared_radius_d Squared_Radius; - typedef typename Kernel::Side_of_bounded_sphere_d Is_Gabriel; - typedef typename Kernel::Point_dimension_d Point_Dimension; - // Vertex_iterator type from CGAL. - typedef typename Delaunay_triangulation::Vertex_iterator CGAL_vertex_iterator; + using CGAL_vertex_iterator = typename Triangulation::Vertex_iterator; // size_type type from CGAL. - typedef typename Delaunay_triangulation::size_type size_type; + using size_type = typename Triangulation::size_type; // Structure to switch from simplex tree vertex handle to CGAL vertex iterator. - typedef typename std::vector< CGAL_vertex_iterator > Vector_vertex_iterator; - - // Numeric type of coordinates in the kernel - typedef typename Kernel::FT FT; + using Vector_vertex_iterator = typename std::vector< CGAL_vertex_iterator >; private: /** \brief Vertex iterator vector to switch from simplex tree vertex handle to CGAL vertex iterator. * Vertex handles are inserted sequentially, starting at 0.*/ Vector_vertex_iterator vertex_handle_to_iterator_; /** \brief Pointer on the CGAL Delaunay triangulation.*/ - Delaunay_triangulation* triangulation_; + Triangulation* triangulation_; /** \brief Kernel for triangulation_ functions access.*/ - Kernel kernel_; + A_kernel_d kernel_; + /** \brief Cache for geometric constructions: circumcenter and squared radius of a simplex.*/ - std::vector> cache_, old_cache_; + std::vector cache_, old_cache_; public: /** \brief Alpha_complex constructor from an OFF file name. @@ -160,10 +168,10 @@ class Alpha_complex { * * Duplicate points are inserted once in the Alpha_complex. This is the reason why the vertices may be not contiguous. * - * @param[in] points Range of points to triangulate. Points must be in Kernel::Point_d + * @param[in] points Range of points to triangulate. Points must be in Kernel::Point_d or Kernel::Weighted_point_d. * * The type InputPointRange must be a range for which std::begin and - * std::end return input iterators on a Kernel::Point_d. + * std::end return input iterators on a Kernel::Point_d or Kernel::Weighted_point_d. */ template Alpha_complex(const InputPointRange& points) @@ -206,11 +214,8 @@ class Alpha_complex { auto last = std::end(points); if (first != last) { - // point_dimension function initialization - Point_Dimension point_dimension = kernel_.point_dimension_d_object(); - - // Delaunay triangulation is point dimension. - triangulation_ = new Delaunay_triangulation(point_dimension(*first)); + // Delaunay triangulation init with point dimension. + triangulation_ = new Triangulation(kernel_.get_dimension(*first)); std::vector point_cloud(first, last); @@ -218,18 +223,22 @@ class Alpha_complex { std::vector indices(boost::counting_iterator(0), boost::counting_iterator(point_cloud.size())); - typedef boost::iterator_property_map::iterator, - CGAL::Identity_property_map> Point_property_map; - typedef CGAL::Spatial_sort_traits_adapter_d Search_traits_d; + using Point_property_map = boost::iterator_property_map::iterator, + CGAL::Identity_property_map>; + using Search_traits_d = CGAL::Spatial_sort_traits_adapter_d; CGAL::spatial_sort(indices.begin(), indices.end(), Search_traits_d(std::begin(point_cloud))); - typename Delaunay_triangulation::Full_cell_handle hint; + typename Triangulation::Full_cell_handle hint; for (auto index : indices) { - typename Delaunay_triangulation::Vertex_handle pos = triangulation_->insert(point_cloud[index], hint); - // Save index value as data to retrieve it after insertion - pos->data() = index; - hint = pos->full_cell(); + typename Triangulation::Vertex_handle pos = triangulation_->insert(point_cloud[index], hint); + if (pos != nullptr) { + // Save index value as data to retrieve it after insertion + pos->data() = index; + hint = pos->full_cell(); + } else { + std::cout << "NULLPTR" << std::endl; + } } // -------------------------------------------------------------------------------------------- // structure to retrieve CGAL points from vertex handle - one vertex handle per point. @@ -270,9 +279,7 @@ class Alpha_complex { v.clear(); for (auto vertex : cplx.simplex_vertex_range(s)) v.push_back(get_point_(vertex)); - Point_d c = kernel_.construct_circumcenter_d_object()(v.cbegin(), v.cend()); - FT r = kernel_.squared_distance_d_object()(c, v[0]); - cache_.emplace_back(std::move(c), std::move(r)); + cache_.emplace_back(kernel_.get_sphere(v.cbegin(), v.cend())); } return cache_[k]; } @@ -282,13 +289,13 @@ class Alpha_complex { auto radius(SimplicialComplexForAlpha& cplx, typename SimplicialComplexForAlpha::Simplex_handle s) { auto k = cplx.key(s); if(k!=cplx.null_key()) - return old_cache_[k].second; + return kernel_.get_squared_radius(old_cache_[k]); // Using a transform_range is slower, currently. thread_local std::vector v; v.clear(); for (auto vertex : cplx.simplex_vertex_range(s)) v.push_back(get_point_(vertex)); - return kernel_.compute_squared_radius_d_object()(v.cbegin(), v.cend()); + return kernel_.get_squared_radius(v.cbegin(), v.cend()); } public: @@ -322,9 +329,9 @@ class Alpha_complex { bool exact = false, bool default_filtration_value = false) { // From SimplicialComplexForAlpha type required to insert into a simplicial complex (with or without subfaces). - typedef typename SimplicialComplexForAlpha::Vertex_handle Vertex_handle; - typedef typename SimplicialComplexForAlpha::Simplex_handle Simplex_handle; - typedef std::vector Vector_vertex; + using Vertex_handle = typename SimplicialComplexForAlpha::Vertex_handle; + using Simplex_handle = typename SimplicialComplexForAlpha::Simplex_handle; + using Vector_vertex = std::vector; if (triangulation_ == nullptr) { std::cerr << "Alpha_complex cannot create_complex from a NULL triangulation\n"; @@ -416,8 +423,8 @@ class Alpha_complex { template void propagate_alpha_filtration(SimplicialComplexForAlpha& complex, Simplex_handle f_simplex) { // From SimplicialComplexForAlpha type required to assign filtration values. - typedef typename SimplicialComplexForAlpha::Filtration_value Filtration_value; - typedef typename SimplicialComplexForAlpha::Vertex_handle Vertex_handle; + using Filtration_value = typename SimplicialComplexForAlpha::Filtration_value; + using Vertex_handle = typename SimplicialComplexForAlpha::Vertex_handle; // ### Foreach Tau face of Sigma for (auto f_boundary : complex.boundary_simplex_range(f_simplex)) { @@ -450,7 +457,8 @@ class Alpha_complex { while(shortiter != enditer && *longiter == *shortiter) { ++longiter; ++shortiter; } Vertex_handle extra = *longiter; auto const& cache=get_cache(complex, f_boundary); - bool is_gab = kernel_.squared_distance_d_object()(cache.first, get_point_(extra)) >= cache.second; + bool is_gab = kernel_.get_squared_distance(kernel_.get_circumcenter(cache), get_point_(extra)) >= + kernel_.get_squared_radius(cache); #ifdef DEBUG_TRACES std::clog << " | Tau is_gabriel(Sigma)=" << is_gab << " - vertexForGabriel=" << extra << std::endl; #endif // DEBUG_TRACES diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h new file mode 100644 index 00000000..87604ec4 --- /dev/null +++ b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h @@ -0,0 +1,137 @@ +/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. + * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2020 Inria + * + * Modification(s): + * - YYYY/MM Author: Description of the modification + */ + +#ifndef ALPHA_COMPLEX_ALPHA_KERNEL_D_H_ +#define ALPHA_COMPLEX_ALPHA_KERNEL_D_H_ + +#include // For EXACT or SAFE version +#include // For FAST version +#include // for CGAL_VERSION_NR + +#include // for EIGEN_VERSION_AT_LEAST + +#include // for std::make_pair + +// Make compilation fail - required for external projects - https://github.com/GUDHI/gudhi-devel/issues/10 +#if CGAL_VERSION_NR < 1041101000 +# error Alpha_complex is only available for CGAL >= 4.11 +#endif + +#if !EIGEN_VERSION_AT_LEAST(3,1,0) +# error Alpha_complex is only available for Eigen3 >= 3.1.0 installed with CGAL +#endif + +namespace Gudhi { + +namespace alpha_complex { + +template < typename Kernel, bool Weighted = false > +class Alpha_kernel_d { +}; + +// Unweighted Kernel_d version +template < typename Kernel > +class Alpha_kernel_d { + private: + // Kernel for functions access. + Kernel kernel_; + public: + // Fake type for compilation to succeed (cf. std::conditional in Alpha_complex.h) + using Weighted_point_d = void; + using Point_d = typename Kernel::Point_d; + // Numeric type of coordinates in the kernel + using FT = typename Kernel::FT; + // Sphere is a pair of point and squared radius. + using Sphere = typename std::pair; + + int get_dimension(const Point_d& p0) const { + return kernel_.point_dimension_d_object()(p0); + } + + template + Sphere get_sphere(PointIterator begin, PointIterator end) const { + Point_d c = kernel_.construct_circumcenter_d_object()(begin, end); + FT r = kernel_.squared_distance_d_object()(c, *begin); + return std::make_pair(std::move(c), std::move(r)); + } + + template + FT get_squared_radius(PointIterator begin, PointIterator end) const { + return kernel_.compute_squared_radius_d_object()(begin, end); + } + + FT get_squared_radius(const Sphere& sph) const { + return sph.second; + } + + template + Point get_circumcenter(const Sphere& sph) const { + return sph.first; + } + + template + FT get_squared_distance(const Point& first, const Point& second) const { + return kernel_.squared_distance_d_object()(first, second); + } +}; + +// Weighted Kernel_d version +template < typename Kernel > +class Alpha_kernel_d { + private: + // Kernel for functions access. + Kernel kernel_; + public: + // Fake type for compilation to succeed (cf. std::conditional in Alpha_complex.h) + using Point_d = void; + using Weighted_point_d = typename Kernel::Weighted_point_d; + using Bare_point_d = typename Kernel::Point_d; + // Numeric type of coordinates in the kernel + using FT = typename Kernel::FT; + // Sphere is a weighted point (point + weight [= squared radius]). + using Sphere = Weighted_point_d; + + int get_dimension(const Weighted_point_d& p0) const { + return kernel_.point_dimension_d_object()(p0.point()); + } + + template + Sphere get_sphere(PointIterator begin, PointIterator end) const { + return kernel_.power_center_d_object()(begin, end); + } + + template + FT get_squared_radius(PointIterator begin, PointIterator end) const { + Sphere sph = get_sphere(begin, end); + return sph.weight(); + } + + FT get_squared_radius(const Sphere& sph) const { + return sph.weight(); + } + + template + Point get_circumcenter(const Sphere& sph) const { + return sph.point(); + } + + template + FT get_squared_distance(const Point& first, const Point& second) const { + return kernel_.power_distance_d_object()(first, second); + } +}; + +} // namespace alpha_complex + +namespace alphacomplex = alpha_complex; + +} // namespace Gudhi + +#endif // ALPHA_COMPLEX_ALPHA_KERNEL_D_H_ \ No newline at end of file diff --git a/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp b/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp new file mode 100644 index 00000000..70b65aad --- /dev/null +++ b/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp @@ -0,0 +1,132 @@ +/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. + * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2020 Inria + * + * Modification(s): + * - YYYY/MM Author: Description of the modification + */ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "alpha_kernel_d" +#include +#include + +#include +#include +#include + +#include +#include +#include // for std::pair + +#include +#include + +// Use dynamic_dimension_tag for the user to be able to set dimension +typedef CGAL::Epeck_d< CGAL::Dynamic_dimension_tag > Exact_kernel_d; +// Use static dimension_tag for the user not to be able to set dimension +typedef CGAL::Epeck_d< CGAL::Dimension_tag<4> > Exact_kernel_s; +// Use dynamic_dimension_tag for the user to be able to set dimension +typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Inexact_kernel_d; +// Use static dimension_tag for the user not to be able to set dimension +typedef CGAL::Epick_d< CGAL::Dimension_tag<4> > Inexact_kernel_s; +// The triangulation uses the default instantiation of the TriangulationDataStructure template parameter + +typedef boost::mpl::list list_of_kernel_variants; + +BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_dimension, TestedKernel, list_of_kernel_variants) { + Gudhi::alpha_complex::Alpha_kernel_d kernel; + std::vector p0 {0., 1., 2., 3.}; + typename TestedKernel::Point_d p0_d(p0.begin(), p0.end()); + + std::clog << "Dimension is " << kernel.get_dimension(p0_d) << std::endl; + BOOST_CHECK(kernel.get_dimension(p0_d) == 4); + + Gudhi::alpha_complex::Alpha_kernel_d w_kernel; + typename TestedKernel::Weighted_point_d w_p0_d(p0_d, 10.); + + std::clog << "Dimension is " << w_kernel.get_dimension(w_p0_d) << std::endl; + BOOST_CHECK(w_kernel.get_dimension(w_p0_d) == 4); +} + +BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_sphere, TestedKernel, list_of_kernel_variants) { + using Unweighted_kernel = Gudhi::alpha_complex::Alpha_kernel_d; + // Sphere: (x-1)² + (y-1)² + z² + t² = 1 + // At least 5 points for a 3-sphere + std::vector p0 {1., 0., 0., 0.}; + std::vector p1 {0., 1., 0., 0.}; + std::vector p2 {1., 1., 1., 0.}; + std::vector p3 {1., 1., 0., 1.}; + std::vector p4 {1., 1., -1., 0.}; + + using Point_d = typename Unweighted_kernel::Point_d; + std::vector unw_pts; + unw_pts.push_back(Point_d(p0.begin(), p0.end())); + unw_pts.push_back(Point_d(p1.begin(), p1.end())); + unw_pts.push_back(Point_d(p2.begin(), p2.end())); + unw_pts.push_back(Point_d(p3.begin(), p3.end())); + unw_pts.push_back(Point_d(p4.begin(), p4.end())); + + Unweighted_kernel kernel; + auto unw_sphere = kernel.get_sphere(unw_pts.cbegin(), unw_pts.cend()); + + std::clog << "Center is " << unw_sphere.first << " - squared radius is " << unw_sphere.second << std::endl; + + using Weighted_kernel = Gudhi::alpha_complex::Alpha_kernel_d; + + using Weighted_point_d = typename Weighted_kernel::Weighted_point_d; + using Bare_point_d = typename Weighted_kernel::Bare_point_d; + std::vector w_pts; + w_pts.push_back(Weighted_point_d(Bare_point_d(p0.begin(), p0.end()), 0.)); + w_pts.push_back(Weighted_point_d(Bare_point_d(p1.begin(), p1.end()), 0.)); + w_pts.push_back(Weighted_point_d(Bare_point_d(p2.begin(), p2.end()), 0.)); + w_pts.push_back(Weighted_point_d(Bare_point_d(p3.begin(), p3.end()), 0.)); + w_pts.push_back(Weighted_point_d(Bare_point_d(p4.begin(), p4.end()), 0.)); + + Weighted_kernel w_kernel; + auto w_sphere = w_kernel.get_sphere(w_pts.cbegin(), w_pts.cend()); + + std::clog << "Center is " << w_sphere.point() << " - squared radius is " << w_sphere.weight() << std::endl; + + CGAL::NT_converter cast_to_double; + // The results shall be the same with weights = 0. + GUDHI_TEST_FLOAT_EQUALITY_CHECK(cast_to_double(unw_sphere.second), cast_to_double(w_sphere.weight())); + BOOST_CHECK(unw_sphere.first == w_sphere.point()); + + auto unw_sq_rd = kernel.get_squared_radius(unw_pts.cbegin(), unw_pts.cend()); + std::clog << "Squared radius is " << unw_sq_rd << std::endl; + GUDHI_TEST_FLOAT_EQUALITY_CHECK(cast_to_double(unw_sphere.second), cast_to_double(unw_sq_rd)); + auto w_sq_rd = w_kernel.get_squared_radius(w_pts.cbegin(), w_pts.cend()); + std::clog << "Squared radius is " << w_sq_rd << std::endl; + GUDHI_TEST_FLOAT_EQUALITY_CHECK(cast_to_double(w_sphere.weight()), cast_to_double(w_sq_rd)); +} + + +BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_distance, TestedKernel, list_of_kernel_variants) { + using Unweighted_kernel = Gudhi::alpha_complex::Alpha_kernel_d; + + std::vector p0 {1., 0., 0., 0.}; + std::vector p1 {0., 1., 0., 0.}; + + using Point_d = typename Unweighted_kernel::Point_d; + Unweighted_kernel kernel; + auto dist_01 = kernel.get_squared_distance(Point_d(p0.begin(), p0.end()), Point_d(p1.begin(), p1.end())); + std::clog << "Distance is " << dist_01 << std::endl; + + using Weighted_kernel = Gudhi::alpha_complex::Alpha_kernel_d; + + using Weighted_point_d = typename Weighted_kernel::Weighted_point_d; + using Bare_point_d = typename Weighted_kernel::Bare_point_d; + std::vector w_pts; + + Weighted_kernel w_kernel; + auto w_dist_01 = w_kernel.get_squared_distance(Weighted_point_d(Bare_point_d(p0.begin(), p0.end()), 0.), + Weighted_point_d(Bare_point_d(p1.begin(), p1.end()), 0.)); + std::clog << "Distance is " << w_dist_01 << std::endl; + + CGAL::NT_converter cast_to_double; + // The results shall be the same with weights = 0. + GUDHI_TEST_FLOAT_EQUALITY_CHECK(cast_to_double(dist_01), cast_to_double(w_dist_01)); +} diff --git a/src/Alpha_complex/test/CMakeLists.txt b/src/Alpha_complex/test/CMakeLists.txt index fe4b23e4..bd61c0d8 100644 --- a/src/Alpha_complex/test/CMakeLists.txt +++ b/src/Alpha_complex/test/CMakeLists.txt @@ -10,13 +10,17 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) target_link_libraries(Alpha_complex_test_unit ${CGAL_LIBRARY}) add_executable ( Delaunay_complex_test_unit Delaunay_complex_unit_test.cpp ) target_link_libraries(Delaunay_complex_test_unit ${CGAL_LIBRARY}) + add_executable ( Alpha_kernel_d_test_unit Alpha_kernel_d_unit_test.cpp ) + target_link_libraries(Alpha_kernel_d_test_unit ${CGAL_LIBRARY}) if (TBB_FOUND) target_link_libraries(Alpha_complex_test_unit ${TBB_LIBRARIES}) target_link_libraries(Delaunay_complex_test_unit ${TBB_LIBRARIES}) + target_link_libraries(Alpha_kernel_d_test_unit ${TBB_LIBRARIES}) endif() gudhi_add_boost_test(Alpha_complex_test_unit) gudhi_add_boost_test(Delaunay_complex_test_unit) + gudhi_add_boost_test(Alpha_kernel_d_test_unit) add_executable ( Alpha_complex_3d_test_unit Alpha_complex_3d_unit_test.cpp ) target_link_libraries(Alpha_complex_3d_test_unit ${CGAL_LIBRARY}) -- cgit v1.2.3 From 9922407fe6f5d8872522157555c3573e95930ac3 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 7 Sep 2020 10:31:11 +0200 Subject: Fix compilation error and test with 0. weights --- src/Alpha_complex/example/CMakeLists.txt | 4 +++- .../example/Weighted_alpha_complex_from_points.cpp | 14 +++++++------- .../include/gudhi/Alpha_complex/Alpha_kernel_d.h | 11 ++++------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Alpha_complex/example/CMakeLists.txt b/src/Alpha_complex/example/CMakeLists.txt index 08eb979e..17dc896c 100644 --- a/src/Alpha_complex/example/CMakeLists.txt +++ b/src/Alpha_complex/example/CMakeLists.txt @@ -28,6 +28,8 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) add_test(NAME Alpha_complex_example_fast_from_off_32 COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" "32.0" "${CMAKE_CURRENT_BINARY_DIR}/fastalphaoffreader_result_32.txt") + add_test(NAME Weighted_alpha_complex_example_from_points COMMAND $) + if (DIFF_PATH) # Do not forget to copy test results files in current binary dir file(COPY "alphaoffreader_for_doc_32.txt" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) @@ -47,7 +49,7 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) ${CMAKE_CURRENT_BINARY_DIR}/fastalphaoffreader_result_32.txt ${CMAKE_CURRENT_BINARY_DIR}/alphaoffreader_for_doc_32.txt) set_tests_properties(Alpha_complex_example_fast_from_off_32_diff_files PROPERTIES DEPENDS Alpha_complex_example_fast_from_off_32) endif() - endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) +endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) if (NOT CGAL_VERSION VERSION_LESS 4.11.0) add_executable ( Alpha_complex_example_weighted_3d_from_points Weighted_alpha_complex_3d_from_points.cpp ) diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp index 19a04282..05858084 100644 --- a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp +++ b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp @@ -18,13 +18,13 @@ int main() { // Init of a list of points // ---------------------------------------------------------------------------- Vector_of_points points; - points.push_back(Weighted_point(Bare_point(1.0, 1.0) , 1.)); - points.push_back(Weighted_point(Bare_point(7.0, 0.0) , 1.)); - points.push_back(Weighted_point(Bare_point(4.0, 6.0) , 1.)); - points.push_back(Weighted_point(Bare_point(9.0, 6.0) , 1.)); - points.push_back(Weighted_point(Bare_point(0.0, 14.0), 1.)); - points.push_back(Weighted_point(Bare_point(2.0, 19.0), 1.)); - points.push_back(Weighted_point(Bare_point(9.0, 17.0), 1.)); + points.push_back(Weighted_point(Bare_point(1.0, 1.0) , 0.)); + points.push_back(Weighted_point(Bare_point(7.0, 0.0) , 0.)); + points.push_back(Weighted_point(Bare_point(4.0, 6.0) , 0.)); + points.push_back(Weighted_point(Bare_point(9.0, 6.0) , 0.)); + points.push_back(Weighted_point(Bare_point(0.0, 14.0), 0.)); + points.push_back(Weighted_point(Bare_point(2.0, 19.0), 0.)); + points.push_back(Weighted_point(Bare_point(9.0, 17.0), 0.)); // ---------------------------------------------------------------------------- // Init of an alpha complex from the list of points diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h index 87604ec4..a3e3845a 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h @@ -71,8 +71,7 @@ class Alpha_kernel_d { return sph.second; } - template - Point get_circumcenter(const Sphere& sph) const { + auto get_circumcenter(const Sphere& sph) const { return sph.first; } @@ -117,13 +116,11 @@ class Alpha_kernel_d { return sph.weight(); } - template - Point get_circumcenter(const Sphere& sph) const { - return sph.point(); + auto get_circumcenter(const Sphere& sph) const { + return sph; } - template - FT get_squared_distance(const Point& first, const Point& second) const { + FT get_squared_distance(const Weighted_point_d& first, const Weighted_point_d& second) const { return kernel_.power_distance_d_object()(first, second); } }; -- cgit v1.2.3 From 171ddab9b7a50f0303d7201fa547dbfb445f9698 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Fri, 11 Sep 2020 11:55:55 +0200 Subject: Requires CGAL >= 5.1. Fix is_gabriel computation --- src/Alpha_complex/example/CMakeLists.txt | 14 +++++++++----- .../example/Weighted_alpha_complex_from_points.cpp | 14 +++++++------- src/Alpha_complex/include/gudhi/Alpha_complex.h | 8 ++++++-- .../include/gudhi/Alpha_complex/Alpha_kernel_d.h | 17 ++++------------- src/Alpha_complex/test/CMakeLists.txt | 13 +++++++++---- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/Alpha_complex/example/CMakeLists.txt b/src/Alpha_complex/example/CMakeLists.txt index 17dc896c..1fc2330a 100644 --- a/src/Alpha_complex/example/CMakeLists.txt +++ b/src/Alpha_complex/example/CMakeLists.txt @@ -7,13 +7,10 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) target_link_libraries(Alpha_complex_example_from_off ${CGAL_LIBRARY}) add_executable ( Alpha_complex_example_fast_from_off Fast_alpha_complex_from_off.cpp ) target_link_libraries(Alpha_complex_example_fast_from_off ${CGAL_LIBRARY}) - add_executable ( Weighted_alpha_complex_example_from_points Weighted_alpha_complex_from_points.cpp ) - target_link_libraries(Weighted_alpha_complex_example_from_points ${CGAL_LIBRARY}) if (TBB_FOUND) target_link_libraries(Alpha_complex_example_from_points ${TBB_LIBRARIES}) target_link_libraries(Alpha_complex_example_from_off ${TBB_LIBRARIES}) target_link_libraries(Alpha_complex_example_fast_from_off ${TBB_LIBRARIES}) - target_link_libraries(Weighted_alpha_complex_example_from_points ${TBB_LIBRARIES}) endif() add_test(NAME Alpha_complex_example_from_points COMMAND $) @@ -28,8 +25,6 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) add_test(NAME Alpha_complex_example_fast_from_off_32 COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" "32.0" "${CMAKE_CURRENT_BINARY_DIR}/fastalphaoffreader_result_32.txt") - add_test(NAME Weighted_alpha_complex_example_from_points COMMAND $) - if (DIFF_PATH) # Do not forget to copy test results files in current binary dir file(COPY "alphaoffreader_for_doc_32.txt" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) @@ -69,3 +64,12 @@ if (NOT CGAL_VERSION VERSION_LESS 4.11.0) COMMAND $) endif(NOT CGAL_VERSION VERSION_LESS 4.11.0) + +if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) + add_executable ( Weighted_alpha_complex_example_from_points Weighted_alpha_complex_from_points.cpp ) + target_link_libraries(Weighted_alpha_complex_example_from_points ${CGAL_LIBRARY}) + if (TBB_FOUND) + target_link_libraries(Weighted_alpha_complex_example_from_points ${TBB_LIBRARIES}) + endif() + add_test(NAME Weighted_alpha_complex_example_from_points COMMAND $) +endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp index 05858084..19a04282 100644 --- a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp +++ b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp @@ -18,13 +18,13 @@ int main() { // Init of a list of points // ---------------------------------------------------------------------------- Vector_of_points points; - points.push_back(Weighted_point(Bare_point(1.0, 1.0) , 0.)); - points.push_back(Weighted_point(Bare_point(7.0, 0.0) , 0.)); - points.push_back(Weighted_point(Bare_point(4.0, 6.0) , 0.)); - points.push_back(Weighted_point(Bare_point(9.0, 6.0) , 0.)); - points.push_back(Weighted_point(Bare_point(0.0, 14.0), 0.)); - points.push_back(Weighted_point(Bare_point(2.0, 19.0), 0.)); - points.push_back(Weighted_point(Bare_point(9.0, 17.0), 0.)); + points.push_back(Weighted_point(Bare_point(1.0, 1.0) , 1.)); + points.push_back(Weighted_point(Bare_point(7.0, 0.0) , 1.)); + points.push_back(Weighted_point(Bare_point(4.0, 6.0) , 1.)); + points.push_back(Weighted_point(Bare_point(9.0, 6.0) , 1.)); + points.push_back(Weighted_point(Bare_point(0.0, 14.0), 1.)); + points.push_back(Weighted_point(Bare_point(2.0, 19.0), 1.)); + points.push_back(Weighted_point(Bare_point(9.0, 17.0), 1.)); // ---------------------------------------------------------------------------- // Init of an alpha complex from the list of points diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 8e9fe773..4316d9bc 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -210,6 +210,11 @@ class Alpha_complex { << std::endl; #endif +#if CGAL_VERSION_NR < 1050101000 + // Make compilation fail if weighted and CGAL < 5.1 + static_assert(!Weighted, "Weighted Alpha_complex is only available for CGAL >= 5.1"); +#endif + auto first = std::begin(points); auto last = std::end(points); @@ -457,8 +462,7 @@ class Alpha_complex { while(shortiter != enditer && *longiter == *shortiter) { ++longiter; ++shortiter; } Vertex_handle extra = *longiter; auto const& cache=get_cache(complex, f_boundary); - bool is_gab = kernel_.get_squared_distance(kernel_.get_circumcenter(cache), get_point_(extra)) >= - kernel_.get_squared_radius(cache); + bool is_gab = kernel_.is_gabriel(cache, get_point_(extra)); #ifdef DEBUG_TRACES std::clog << " | Tau is_gabriel(Sigma)=" << is_gab << " - vertexForGabriel=" << extra << std::endl; #endif // DEBUG_TRACES diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h index a3e3845a..b64e4f59 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h @@ -71,13 +71,8 @@ class Alpha_kernel_d { return sph.second; } - auto get_circumcenter(const Sphere& sph) const { - return sph.first; - } - - template - FT get_squared_distance(const Point& first, const Point& second) const { - return kernel_.squared_distance_d_object()(first, second); + bool is_gabriel(const Sphere& circumcenter, const Point_d& point) { + return kernel_.squared_distance_d_object()(circumcenter.first, point) >= circumcenter.second; } }; @@ -116,12 +111,8 @@ class Alpha_kernel_d { return sph.weight(); } - auto get_circumcenter(const Sphere& sph) const { - return sph; - } - - FT get_squared_distance(const Weighted_point_d& first, const Weighted_point_d& second) const { - return kernel_.power_distance_d_object()(first, second); + bool is_gabriel(const Sphere& circumcenter, const Weighted_point_d& point) { + return kernel_.power_distance_d_object()(circumcenter, point) >= 0; } }; diff --git a/src/Alpha_complex/test/CMakeLists.txt b/src/Alpha_complex/test/CMakeLists.txt index 71e4ea7c..837d2948 100644 --- a/src/Alpha_complex/test/CMakeLists.txt +++ b/src/Alpha_complex/test/CMakeLists.txt @@ -10,17 +10,13 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) target_link_libraries(Alpha_complex_test_unit ${CGAL_LIBRARY}) add_executable ( Delaunay_complex_test_unit Delaunay_complex_unit_test.cpp ) target_link_libraries(Delaunay_complex_test_unit ${CGAL_LIBRARY}) - add_executable ( Alpha_kernel_d_test_unit Alpha_kernel_d_unit_test.cpp ) - target_link_libraries(Alpha_kernel_d_test_unit ${CGAL_LIBRARY}) if (TBB_FOUND) target_link_libraries(Alpha_complex_test_unit ${TBB_LIBRARIES}) target_link_libraries(Delaunay_complex_test_unit ${TBB_LIBRARIES}) - target_link_libraries(Alpha_kernel_d_test_unit ${TBB_LIBRARIES}) endif() gudhi_add_boost_test(Alpha_complex_test_unit) gudhi_add_boost_test(Delaunay_complex_test_unit) - gudhi_add_boost_test(Alpha_kernel_d_test_unit) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) @@ -47,3 +43,12 @@ if (NOT CGAL_VERSION VERSION_LESS 4.11.0) gudhi_add_boost_test(Weighted_periodic_alpha_complex_3d_test_unit) endif (NOT CGAL_VERSION VERSION_LESS 4.11.0) + +if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) + add_executable ( Alpha_kernel_d_test_unit Alpha_kernel_d_unit_test.cpp ) + target_link_libraries(Alpha_kernel_d_test_unit ${CGAL_LIBRARY}) + if (TBB_FOUND) + target_link_libraries(Alpha_kernel_d_test_unit ${TBB_LIBRARIES}) + endif() + gudhi_add_boost_test(Alpha_kernel_d_test_unit) +endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) \ No newline at end of file -- cgit v1.2.3 From d299e943d6fd07a58a270fe685dac7b5d5d23964 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Fri, 11 Sep 2020 14:35:39 +0200 Subject: fonction was renamed between 5.1 and 5.2 --- .../include/gudhi/Alpha_complex/Alpha_kernel_d.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h index b64e4f59..a4824207 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h @@ -82,6 +82,7 @@ class Alpha_kernel_d { private: // Kernel for functions access. Kernel kernel_; + public: // Fake type for compilation to succeed (cf. std::conditional in Alpha_complex.h) using Point_d = void; @@ -98,7 +99,13 @@ class Alpha_kernel_d { template Sphere get_sphere(PointIterator begin, PointIterator end) const { + // power_center_d_object has been renamed between CGAL 5.1 and 5.2 +#if defined CGAL_VERSION_NR >= 1050101000 && defined CGAL_VERSION_NR < 1050201000 return kernel_.power_center_d_object()(begin, end); +#endif +#if CGAL_VERSION_NR >= 1050201000 + return kernel_.construct_power_sphere_d_object()(begin, end); +#endif } template @@ -112,7 +119,13 @@ class Alpha_kernel_d { } bool is_gabriel(const Sphere& circumcenter, const Weighted_point_d& point) { + // power_center_d_object has been renamed between CGAL 5.1 and 5.2 +#if defined CGAL_VERSION_NR >= 1050101000 && defined CGAL_VERSION_NR < 1050201000 return kernel_.power_distance_d_object()(circumcenter, point) >= 0; +#endif +#if CGAL_VERSION_NR >= 1050201000 + return kernel_.compute_power_product_d_object()(circumcenter, point) >= 0; +#endif } }; -- cgit v1.2.3 From 54e0cec31e556c88d9f8107394ad972883fdbbdf Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Fri, 11 Sep 2020 17:41:39 +0200 Subject: Add weighted ctor and its test --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 26 +++++++ src/Alpha_complex/test/CMakeLists.txt | 8 +++ .../test/Weighted_alpha_complex_unit_test.cpp | 82 ++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 4316d9bc..00231e1c 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -31,6 +31,10 @@ #include // for EIGEN_VERSION_AT_LEAST +#include +#include +#include + #include #include #include @@ -179,6 +183,28 @@ class Alpha_complex { init_from_range(points); } + /** \brief Alpha_complex constructor from a list of points and weights. + * + * Duplicate points are inserted once in the Alpha_complex. This is the reason why the vertices may be not contiguous. + * + * @param[in] points Range of points to triangulate. Points must be in Kernel::Point_d or Kernel::Weighted_point_d. + * + * @param[in] weights Range of points weights. Weights must be in Kernel::FT. + * + * The type InputPointRange must be a range for which std::begin and + * std::end return input iterators on a Kernel::Point_d. + */ + template + Alpha_complex(const InputPointRange& points, WeightRange weights) { + static_assert(Weighted, "This constructor is not available for non-weighted versions of Alpha_complex_3d"); + // FIXME: this test is only valid if we have a forward range + GUDHI_CHECK(boost::size(weights) == boost::size(points), + std::invalid_argument("Points number in range different from weights range number")); + auto weighted_points = boost::range::combine(points, weights) + | boost::adaptors::transformed([](auto const&t){return Point_d(boost::get<0>(t), boost::get<1>(t));}); + init_from_range(weighted_points); + } + /** \brief Alpha_complex destructor deletes the Delaunay triangulation. */ ~Alpha_complex() { diff --git a/src/Alpha_complex/test/CMakeLists.txt b/src/Alpha_complex/test/CMakeLists.txt index 837d2948..db5d840f 100644 --- a/src/Alpha_complex/test/CMakeLists.txt +++ b/src/Alpha_complex/test/CMakeLists.txt @@ -51,4 +51,12 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) target_link_libraries(Alpha_kernel_d_test_unit ${TBB_LIBRARIES}) endif() gudhi_add_boost_test(Alpha_kernel_d_test_unit) + + add_executable ( Weighted_alpha_complex_test_unit Weighted_alpha_complex_unit_test.cpp ) + target_link_libraries(Weighted_alpha_complex_test_unit ${CGAL_LIBRARY}) + if (TBB_FOUND) + target_link_libraries(Weighted_alpha_complex_test_unit ${TBB_LIBRARIES}) + endif() + gudhi_add_boost_test(Weighted_alpha_complex_test_unit) + endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) \ No newline at end of file diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp new file mode 100644 index 00000000..b4fc76de --- /dev/null +++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp @@ -0,0 +1,82 @@ +/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. + * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2020 Inria + * + * Modification(s): + * - YYYY/MM Author: Description of the modification + */ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "weighted_alpha_complex" +#include +#include + +#include +#include + +#include // float comparison +#include +#include + +#include +#include +#include + +// Use dynamic_dimension_tag for the user to be able to set dimension +typedef CGAL::Epeck_d< CGAL::Dynamic_dimension_tag > Exact_kernel_d; +// Use static dimension_tag for the user not to be able to set dimension +typedef CGAL::Epeck_d< CGAL::Dimension_tag<4> > Exact_kernel_s; +// Use dynamic_dimension_tag for the user to be able to set dimension +typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Inexact_kernel_d; +// Use static dimension_tag for the user not to be able to set dimension +typedef CGAL::Epick_d< CGAL::Dimension_tag<4> > Inexact_kernel_s; +// The triangulation uses the default instantiation of the TriangulationDataStructure template parameter + +typedef boost::mpl::list list_of_kernel_variants; + +BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_kernel_variants) { + // Random points construction + using Point_d = typename Kernel::Point_d; + std::vector points; + std::uniform_real_distribution rd_pts(-10., 10.); + std::random_device rand_dev; + std::mt19937 rand_engine(rand_dev()); + for (int idx = 0; idx < 20; idx++) { + std::vector point {rd_pts(rand_engine), rd_pts(rand_engine), rd_pts(rand_engine), rd_pts(rand_engine)}; + points.emplace_back(Point_d(point.begin(), point.end())); + } + + // Alpha complex from points + Gudhi::alpha_complex::Alpha_complex alpha_complex_from_points(points); + Gudhi::Simplex_tree<> simplex; + BOOST_CHECK(alpha_complex_from_points.create_complex(simplex)); + std::clog << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; + for (auto f_simplex : simplex.filtration_simplex_range()) { + std::clog << " ( "; + for (auto vertex : simplex.simplex_vertex_range(f_simplex)) { + std::clog << vertex << " "; + } + std::clog << ") -> " << "[" << simplex.filtration(f_simplex) << "] "; + std::clog << std::endl; + } + + // Alpha complex from zero weighted points + std::vector weights(20, 0.); + Gudhi::alpha_complex::Alpha_complex alpha_complex_from_zero_weighted_points(points, weights); + Gudhi::Simplex_tree<> zw_simplex; + BOOST_CHECK(alpha_complex_from_zero_weighted_points.create_complex(zw_simplex)); + + std::clog << "Iterator on zero weighted alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; + for (auto f_simplex : zw_simplex.filtration_simplex_range()) { + std::clog << " ( "; + for (auto vertex : zw_simplex.simplex_vertex_range(f_simplex)) { + std::clog << vertex << " "; + } + std::clog << ") -> " << "[" << zw_simplex.filtration(f_simplex) << "] "; + std::clog << std::endl; + } + + BOOST_CHECK(zw_simplex == simplex); +} \ No newline at end of file -- cgit v1.2.3 From 5e3871c2d99249bd7560faa4e1229d3b3751b0ff Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 14 Sep 2020 11:17:40 +0200 Subject: alpha_complex_persistence utils can use weighted points. Update Alpha_kernel_d_unit_test to work --- .../test/Alpha_kernel_d_unit_test.cpp | 28 ------ .../test/Weighted_alpha_complex_unit_test.cpp | 2 +- .../utilities/alpha_complex_persistence.cpp | 101 ++++++++++++++++----- src/Alpha_complex/utilities/alphacomplex.md | 7 ++ 4 files changed, 84 insertions(+), 54 deletions(-) diff --git a/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp b/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp index 70b65aad..192834b3 100644 --- a/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp @@ -102,31 +102,3 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_sphere, TestedKernel, list_of_kerne std::clog << "Squared radius is " << w_sq_rd << std::endl; GUDHI_TEST_FLOAT_EQUALITY_CHECK(cast_to_double(w_sphere.weight()), cast_to_double(w_sq_rd)); } - - -BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_distance, TestedKernel, list_of_kernel_variants) { - using Unweighted_kernel = Gudhi::alpha_complex::Alpha_kernel_d; - - std::vector p0 {1., 0., 0., 0.}; - std::vector p1 {0., 1., 0., 0.}; - - using Point_d = typename Unweighted_kernel::Point_d; - Unweighted_kernel kernel; - auto dist_01 = kernel.get_squared_distance(Point_d(p0.begin(), p0.end()), Point_d(p1.begin(), p1.end())); - std::clog << "Distance is " << dist_01 << std::endl; - - using Weighted_kernel = Gudhi::alpha_complex::Alpha_kernel_d; - - using Weighted_point_d = typename Weighted_kernel::Weighted_point_d; - using Bare_point_d = typename Weighted_kernel::Bare_point_d; - std::vector w_pts; - - Weighted_kernel w_kernel; - auto w_dist_01 = w_kernel.get_squared_distance(Weighted_point_d(Bare_point_d(p0.begin(), p0.end()), 0.), - Weighted_point_d(Bare_point_d(p1.begin(), p1.end()), 0.)); - std::clog << "Distance is " << w_dist_01 << std::endl; - - CGAL::NT_converter cast_to_double; - // The results shall be the same with weights = 0. - GUDHI_TEST_FLOAT_EQUALITY_CHECK(cast_to_double(dist_01), cast_to_double(w_dist_01)); -} diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp index b4fc76de..57a57058 100644 --- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -32,7 +33,6 @@ typedef CGAL::Epeck_d< CGAL::Dimension_tag<4> > Exact_kernel_s; typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Inexact_kernel_d; // Use static dimension_tag for the user not to be able to set dimension typedef CGAL::Epick_d< CGAL::Dimension_tag<4> > Inexact_kernel_s; -// The triangulation uses the default instantiation of the TriangulationDataStructure template parameter typedef boost::mpl::list list_of_kernel_variants; diff --git a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp index e17831d9..e86b34e2 100644 --- a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp @@ -17,19 +17,82 @@ #include // to construct a simplex_tree from alpha complex #include +#include #include #include #include // for numeric_limits +#include +#include using Simplex_tree = Gudhi::Simplex_tree<>; using Filtration_value = Simplex_tree::Filtration_value; void program_options(int argc, char *argv[], std::string &off_file_points, bool &exact, bool &fast, - std::string &output_file_diag, Filtration_value &alpha_square_max_value, + std::string &weight_file, std::string &output_file_diag, Filtration_value &alpha_square_max_value, int &coeff_field_characteristic, Filtration_value &min_persistence); +template +std::vector read_off(const std::string &off_file_points) { + Gudhi::Points_off_reader off_reader(off_file_points); + if (!off_reader.is_valid()) { + std::cerr << "Alpha_complex - Unable to read file " << off_file_points << "\n"; + exit(-1); // ----- >> + } + return off_reader.get_point_cloud(); +} + +std::vector read_weight_file(const std::string &weight_file) { + std::vector weights; + // Read weights information from file + std::ifstream weights_ifstr(weight_file); + if (weights_ifstr.good()) { + double weight = 0.0; + // Attempt read the weight in a double format, return false if it fails + while (weights_ifstr >> weight) { + weights.push_back(weight); + } + } else { + std::cerr << "Unable to read weights file " << weight_file << std::endl; + exit(-1); + } + return weights; +} + +template +Simplex_tree create_simplex_tree(const std::string &off_file_points, const std::string &weight_file, + bool exact_version, Filtration_value alpha_square_max_value) { + Simplex_tree stree; + auto points = read_off(off_file_points); + + if (weight_file != std::string()) { + std::vector weights = read_weight_file(weight_file); + if (points.size() != weights.size()) { + std::cerr << "Alpha_complex - Inconsistency between number of points (" << points.size() + << ") and number of weights (" << weights.size() << ")" << "\n"; + exit(-1); // ----- >> + } + // Init of an alpha complex from an OFF file + Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(points, weights); + + if (!alpha_complex_from_file.create_complex(stree, alpha_square_max_value, exact_version)) { + std::cerr << "Alpha complex simplicial complex creation failed." << std::endl; + exit(-1); + } + } else { + // Init of an alpha complex from an OFF file + Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(points); + + if (!alpha_complex_from_file.create_complex(stree, alpha_square_max_value, exact_version)) { + std::cerr << "Alpha complex simplicial complex creation failed." << std::endl; + exit(-1); + } + } + return stree; +} + int main(int argc, char **argv) { + std::string weight_file; std::string off_file_points; std::string output_file_diag; bool exact_version = false; @@ -38,48 +101,34 @@ int main(int argc, char **argv) { int coeff_field_characteristic; Filtration_value min_persistence; - program_options(argc, argv, off_file_points, exact_version, fast_version, output_file_diag, alpha_square_max_value, - coeff_field_characteristic, min_persistence); + program_options(argc, argv, off_file_points, exact_version, fast_version, weight_file, output_file_diag, + alpha_square_max_value, coeff_field_characteristic, min_persistence); if ((exact_version) && (fast_version)) { std::cerr << "You cannot set the exact and the fast version." << std::endl; exit(-1); } - Simplex_tree simplex; + Simplex_tree stree; if (fast_version) { // WARNING : CGAL::Epick_d is fast but not safe (unlike CGAL::Epeck_d) // (i.e. when the points are on a grid) using Fast_kernel = CGAL::Epick_d; - - // Init of an alpha complex from an OFF file - Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_points); - - if (!alpha_complex_from_file.create_complex(simplex, alpha_square_max_value)) { - std::cerr << "Fast Alpha complex simplicial complex creation failed." << std::endl; - exit(-1); - } + stree = create_simplex_tree(off_file_points, weight_file, exact_version, alpha_square_max_value); } else { using Kernel = CGAL::Epeck_d; - - // Init of an alpha complex from an OFF file - Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_points); - - if (!alpha_complex_from_file.create_complex(simplex, alpha_square_max_value, exact_version)) { - std::cerr << "Alpha complex simplicial complex creation failed." << std::endl; - exit(-1); - } + stree = create_simplex_tree(off_file_points, weight_file, exact_version, alpha_square_max_value); } // ---------------------------------------------------------------------------- // Display information about the alpha complex // ---------------------------------------------------------------------------- - std::clog << "Simplicial complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices() - << " simplices - " << simplex.num_vertices() << " vertices." << std::endl; + std::clog << "Simplicial complex is of dimension " << stree.dimension() << " - " << stree.num_simplices() + << " simplices - " << stree.num_vertices() << " vertices." << std::endl; - std::clog << "Simplex_tree dim: " << simplex.dimension() << std::endl; + std::clog << "Simplex_tree dim: " << stree.dimension() << std::endl; // Compute the persistence diagram of the complex Gudhi::persistent_cohomology::Persistent_cohomology pcoh( - simplex); + stree); // initializes the coefficient field for homology pcoh.init_coefficients(coeff_field_characteristic); @@ -98,7 +147,7 @@ int main(int argc, char **argv) { } void program_options(int argc, char *argv[], std::string &off_file_points, bool &exact, bool &fast, - std::string &output_file_diag, Filtration_value &alpha_square_max_value, + std::string &weight_file, std::string &output_file_diag, Filtration_value &alpha_square_max_value, int &coeff_field_characteristic, Filtration_value &min_persistence) { namespace po = boost::program_options; po::options_description hidden("Hidden options"); @@ -111,6 +160,8 @@ void program_options(int argc, char *argv[], std::string &off_file_points, bool "To activate exact version of Alpha complex (default is false, not available if fast is set)")( "fast,f", po::bool_switch(&fast), "To activate fast version of Alpha complex (default is false, not available if exact is set)")( + "weight-file,w", po::value(&weight_file)->default_value(std::string()), + "Name of file containing a point weights. Format is one weight per line:\n W1\n ...\n Wn ")( "output-file,o", po::value(&output_file_diag)->default_value(std::string()), "Name of file in which the persistence diagram is written. Default print in std::clog")( "max-alpha-square-value,r", po::value(&alpha_square_max_value) diff --git a/src/Alpha_complex/utilities/alphacomplex.md b/src/Alpha_complex/utilities/alphacomplex.md index 527598a9..0d3c6027 100644 --- a/src/Alpha_complex/utilities/alphacomplex.md +++ b/src/Alpha_complex/utilities/alphacomplex.md @@ -46,6 +46,9 @@ for the Alpha complex construction. coefficient field Z/pZ for computing homology. * `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. +* `-w [ --weight-file ]` is the path to the file containing the weights of the +points (one value per line). +Default version is not weighted. * `-e [ --exact ]` for the exact computation version. * `-f [ --fast ]` for the fast computation version. @@ -58,6 +61,10 @@ to be recorded. Enter a negative value to see zero length intervals. N.B.: * Filtration values are alpha square values. +* Weights values are explained on CGAL +[dD Triangulations](https://doc.cgal.org/latest/Triangulation/index.html) +and +[Regular triangulation](https://doc.cgal.org/latest/Triangulation/index.html#title20) documentation. ## alpha_complex_3d_persistence ## -- cgit v1.2.3 From de39546182c20a69e45aa07830351f6e9d2e4b84 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 14 Sep 2020 17:27:40 +0200 Subject: Add but comment a test to compare dD and 3D alpha complex --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 2 - .../test/Weighted_alpha_complex_unit_test.cpp | 79 +++++++++++++++++++++- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 00231e1c..e1aae2d4 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -267,8 +267,6 @@ class Alpha_complex { // Save index value as data to retrieve it after insertion pos->data() = index; hint = pos->full_cell(); - } else { - std::cout << "NULLPTR" << std::endl; } } // -------------------------------------------------------------------------------------------- diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp index 57a57058..bf659ef7 100644 --- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp @@ -79,4 +79,81 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_kerne } BOOST_CHECK(zw_simplex == simplex); -} \ No newline at end of file +} + +template +bool cgal_3d_point_sort (Point_d a,Point_d b) { + if (a[0] != b[0]) + return a[0] < b[0]; + if (a[1] != b[1]) + return a[1] < b[1]; + return a[2] < b[2]; +} + +/*BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { + // Random points construction + using Kernel_dD = CGAL::Epeck_d< CGAL::Dimension_tag<3> >; + using Bare_point_d = typename Kernel_dD::Point_d; + using Weighted_point_d = typename Kernel_dD::Weighted_point_d; + std::vector w_points_d; + + using Exact_weighted_alpha_complex_3d = + Gudhi::alpha_complex::Alpha_complex_3d; + using Bare_point_3 = typename Exact_weighted_alpha_complex_3d::Bare_point_3; + using Weighted_point_3 = typename Exact_weighted_alpha_complex_3d::Weighted_point_3; + std::vector w_points_3; + + std::uniform_real_distribution rd_pts(-10., 10.); + std::uniform_real_distribution rd_wghts(-0.5, 0.5); + std::random_device rand_dev; + std::mt19937 rand_engine(rand_dev()); + for (int idx = 0; idx < 20; idx++) { + std::vector point {rd_pts(rand_engine), rd_pts(rand_engine), rd_pts(rand_engine)}; + double weight = rd_wghts(rand_engine); + w_points_d.emplace_back(Weighted_point_d(Bare_point_d(point.begin(), point.end()), weight)); + w_points_3.emplace_back(Weighted_point_3(Bare_point_3(point[0], point[1], point[2]), weight)); + } + + // Weighted alpha complex for dD version + Gudhi::alpha_complex::Alpha_complex alpha_complex_dD_from_weighted_points(w_points_d); + Gudhi::Simplex_tree<> w_simplex_d; + BOOST_CHECK(alpha_complex_dD_from_weighted_points.create_complex(w_simplex_d)); + + std::clog << "Iterator on weighted alpha complex dD simplices in the filtration order, with [filtration value]:" << std::endl; + for (auto f_simplex : w_simplex_d.filtration_simplex_range()) { + std::clog << " ( "; + std::vector points; + for (auto vertex : w_simplex_d.simplex_vertex_range(f_simplex)) { + points.emplace_back(alpha_complex_dD_from_weighted_points.get_point(vertex).point()); + } + std::sort (points.begin(), points.end(), cgal_3d_point_sort); + for (auto point : points) { + std::clog << point[0] << " " << point[1] << " " << point[2] << " | "; + } + std::clog << ") -> " << "[" << w_simplex_d.filtration(f_simplex) << "] "; + std::clog << std::endl; + } + + // Weighted alpha complex for 3D version + Exact_weighted_alpha_complex_3d alpha_complex_3D_from_weighted_points(w_points_3); + Gudhi::Simplex_tree<> w_simplex_3; + BOOST_CHECK(alpha_complex_3D_from_weighted_points.create_complex(w_simplex_3)); + + std::clog << "Iterator on weighted alpha complex 3D simplices in the filtration order, with [filtration value]:" << std::endl; + for (auto f_simplex : w_simplex_3.filtration_simplex_range()) { + std::clog << " ( "; + std::vector points; + for (auto vertex : w_simplex_3.simplex_vertex_range(f_simplex)) { + points.emplace_back(alpha_complex_3D_from_weighted_points.get_point(vertex).point()); + } + std::sort (points.begin(), points.end()); + for (auto point : points) { + std::clog << point[0] << " " << point[1] << " " << point[2] << " | "; + } + std::clog << ") -> " << "[" << w_simplex_3.filtration(f_simplex) << "] "; + std::clog << std::endl; + } + + BOOST_CHECK(w_simplex_d == w_simplex_3); + +}*/ \ No newline at end of file -- cgit v1.2.3 From 53d09e2f7770f7e95d765d527712ef3c0758cf08 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 14 Sep 2020 21:35:23 +0200 Subject: Fix Alpha complex to have the same results than Alpha complex 3d --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 31 +++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index e1aae2d4..f43cd071 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -60,6 +60,27 @@ namespace alpha_complex { template struct Is_Epeck_D { static const bool value = false; }; template struct Is_Epeck_D> { static const bool value = true; }; +template +struct Weight; + +template +struct Weight +{ + typename Kernel::FT operator()(const typename Kernel::Weighted_point_d& p) const + { + return p.weight(); + } +}; + +template +struct Weight +{ + typename Kernel::FT operator()(const typename Kernel::Point_d& p) const + { + return 0.; + } +}; + /** * \class Alpha_complex Alpha_complex.h gudhi/Alpha_complex.h * \brief Alpha complex data structure. @@ -404,6 +425,7 @@ class Alpha_complex { // -------------------------------------------------------------------------------------------- if (!default_filtration_value) { + CGAL::NT_converter cgal_converter; // -------------------------------------------------------------------------------------------- // ### For i : d -> 0 for (int decr_dim = triangulation_->maximal_dimension(); decr_dim >= 0; decr_dim--) { @@ -420,8 +442,7 @@ class Alpha_complex { #if CGAL_VERSION_NR >= 1050000000 if(exact) CGAL::exact(sqrad); #endif - CGAL::NT_converter cv; - alpha_complex_filtration = cv(sqrad); + alpha_complex_filtration = cgal_converter(sqrad); } complex.assign_filtration(f_simplex, alpha_complex_filtration); #ifdef DEBUG_TRACES @@ -431,6 +452,12 @@ class Alpha_complex { // No need to propagate further, unweighted points all have value 0 if (decr_dim > 1) propagate_alpha_filtration(complex, f_simplex); + // For weighted points, assign point weight as filtration value + if (Weighted && decr_dim == 0) { + Vertex_handle vertex = *(complex.simplex_vertex_range(f_simplex).begin()); + FT wght = Weight()(get_point(vertex)); + complex.assign_filtration(f_simplex, cgal_converter(wght)*(-1.)); + } } } old_cache_ = std::move(cache_); -- cgit v1.2.3 From 6db3b5db0f8b6dfae2b9b6eadb8bccdfdc613fb5 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 15 Sep 2020 13:45:37 +0200 Subject: This should be correct and efficient for 0-dimension weighted alpha --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index f43cd071..b66ec20d 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -436,8 +436,8 @@ class Alpha_complex { // ### If filt(Sigma) is NaN : filt(Sigma) = alpha(Sigma) if (std::isnan(complex.filtration(f_simplex))) { Filtration_value alpha_complex_filtration = 0.0; - // No need to compute squared_radius on a single point - alpha is 0.0 - if (f_simplex_dim > 0) { + // No need to compute squared_radius on a non-weighted single point - alpha is 0.0 + if (Weighted || f_simplex_dim > 0) { auto const& sqrad = radius(complex, f_simplex); #if CGAL_VERSION_NR >= 1050000000 if(exact) CGAL::exact(sqrad); @@ -450,14 +450,8 @@ class Alpha_complex { #endif // DEBUG_TRACES } // No need to propagate further, unweighted points all have value 0 - if (decr_dim > 1) + if (decr_dim > !Weighted) propagate_alpha_filtration(complex, f_simplex); - // For weighted points, assign point weight as filtration value - if (Weighted && decr_dim == 0) { - Vertex_handle vertex = *(complex.simplex_vertex_range(f_simplex).begin()); - FT wght = Weight()(get_point(vertex)); - complex.assign_filtration(f_simplex, cgal_converter(wght)*(-1.)); - } } } old_cache_ = std::move(cache_); -- cgit v1.2.3 From 4dacc3d99bfc4a4d31088fe126090038156ab7a0 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 15 Sep 2020 16:56:17 +0200 Subject: Make Kernel available publicly for tests purpose --- src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index 622b10ee..4e5fc933 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -154,8 +154,10 @@ class Alpha_complex_3d { using Kernel = CGAL::Periodic_3_regular_triangulation_traits_3; }; + public: using Kernel = typename Kernel_3::Kernel; + private: using TdsVb = typename std::conditional, CGAL::Triangulation_ds_vertex_base_3<>>::type; -- cgit v1.2.3 From 019bc2dc28dd6db3b21a24354051fe3a4d2e1f77 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 15 Sep 2020 16:56:54 +0200 Subject: alpha complex persistence now requires cgal 5.1 --- src/Alpha_complex/utilities/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Alpha_complex/utilities/CMakeLists.txt b/src/Alpha_complex/utilities/CMakeLists.txt index f0ddfc2c..90e5734e 100644 --- a/src/Alpha_complex/utilities/CMakeLists.txt +++ b/src/Alpha_complex/utilities/CMakeLists.txt @@ -1,6 +1,6 @@ project(Alpha_complex_utilities) -if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) +if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) add_executable (alpha_complex_persistence alpha_complex_persistence.cpp) target_link_libraries(alpha_complex_persistence ${CGAL_LIBRARY} Boost::program_options) @@ -27,7 +27,7 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) endif() install(TARGETS alpha_complex_persistence DESTINATION bin) -endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) +endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) if (NOT CGAL_VERSION VERSION_LESS 4.11.0) add_executable(alpha_complex_3d_persistence alpha_complex_3d_persistence.cpp) -- cgit v1.2.3 From d6f68d20e975e0cd530cd15ca5f7f782550e6af4 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 15 Sep 2020 16:57:15 +0200 Subject: Test alpha complex dD versus 3d --- .../test/Weighted_alpha_complex_unit_test.cpp | 54 +++++++++++++++++----- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp index bf659ef7..e8372656 100644 --- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp @@ -19,6 +19,8 @@ #include // float comparison #include #include +#include +#include // for std::fabs #include #include @@ -90,7 +92,7 @@ bool cgal_3d_point_sort (Point_d a,Point_d b) { return a[2] < b[2]; } -/*BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { +BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { // Random points construction using Kernel_dD = CGAL::Epeck_d< CGAL::Dimension_tag<3> >; using Bare_point_d = typename Kernel_dD::Point_d; @@ -114,6 +116,12 @@ bool cgal_3d_point_sort (Point_d a,Point_d b) { w_points_3.emplace_back(Weighted_point_3(Bare_point_3(point[0], point[1], point[2]), weight)); } + // Structures necessary for comparison + using Points = std::vector>; + using Points_and_filtrations = std::map; + Points_and_filtrations pts_fltr_dD; + Points_and_filtrations pts_fltr_3d; + // Weighted alpha complex for dD version Gudhi::alpha_complex::Alpha_complex alpha_complex_dD_from_weighted_points(w_points_d); Gudhi::Simplex_tree<> w_simplex_d; @@ -121,17 +129,20 @@ bool cgal_3d_point_sort (Point_d a,Point_d b) { std::clog << "Iterator on weighted alpha complex dD simplices in the filtration order, with [filtration value]:" << std::endl; for (auto f_simplex : w_simplex_d.filtration_simplex_range()) { - std::clog << " ( "; - std::vector points; + Points points; for (auto vertex : w_simplex_d.simplex_vertex_range(f_simplex)) { - points.emplace_back(alpha_complex_dD_from_weighted_points.get_point(vertex).point()); + CGAL::NT_converter cgal_converter; + Bare_point_d pt = alpha_complex_dD_from_weighted_points.get_point(vertex).point(); + points.push_back({cgal_converter(pt[0]), cgal_converter(pt[1]), cgal_converter(pt[2])}); } - std::sort (points.begin(), points.end(), cgal_3d_point_sort); + std::clog << " ( "; + std::sort (points.begin(), points.end()); for (auto point : points) { std::clog << point[0] << " " << point[1] << " " << point[2] << " | "; } std::clog << ") -> " << "[" << w_simplex_d.filtration(f_simplex) << "] "; std::clog << std::endl; + pts_fltr_dD[points] = w_simplex_d.filtration(f_simplex); } // Weighted alpha complex for 3D version @@ -141,19 +152,40 @@ bool cgal_3d_point_sort (Point_d a,Point_d b) { std::clog << "Iterator on weighted alpha complex 3D simplices in the filtration order, with [filtration value]:" << std::endl; for (auto f_simplex : w_simplex_3.filtration_simplex_range()) { - std::clog << " ( "; - std::vector points; + Points points; for (auto vertex : w_simplex_3.simplex_vertex_range(f_simplex)) { - points.emplace_back(alpha_complex_3D_from_weighted_points.get_point(vertex).point()); + Bare_point_3 pt = alpha_complex_3D_from_weighted_points.get_point(vertex).point(); + CGAL::NT_converter cgal_converter; + points.push_back({cgal_converter(pt[0]), cgal_converter(pt[1]), cgal_converter(pt[2])}); } + std::clog << " ( "; std::sort (points.begin(), points.end()); for (auto point : points) { std::clog << point[0] << " " << point[1] << " " << point[2] << " | "; } std::clog << ") -> " << "[" << w_simplex_3.filtration(f_simplex) << "] "; std::clog << std::endl; + pts_fltr_3d[points] = w_simplex_d.filtration(f_simplex); } - BOOST_CHECK(w_simplex_d == w_simplex_3); - -}*/ \ No newline at end of file + // Compares structures + auto d3_itr = pts_fltr_3d.begin(); + auto dD_itr = pts_fltr_dD.begin(); + for (; d3_itr != pts_fltr_3d.end() && dD_itr != pts_fltr_dD.end(); ++d3_itr) { + if (d3_itr->first != dD_itr->first) { + for(auto point : d3_itr->first) + std::clog << point[0] << " " << point[1] << " " << point[2] << " | "; + std::clog << " versus "; + for(auto point : dD_itr->first) + std::clog << point[0] << " " << point[1] << " " << point[2] << " | "; + std::clog << std::endl; + BOOST_CHECK(false); + } + // I had to make a hard limit as it is converted from Kernel::FT + if (std::fabs(d3_itr->second - dD_itr->second) > 1e-5) { + std::clog << d3_itr->second << " versus " << dD_itr->second << " diff " << std::fabs(d3_itr->second - dD_itr->second) << std::endl; + BOOST_CHECK(false); + } + ++dD_itr; + } +} -- cgit v1.2.3 From cb68f3e4c8ce7724ccb693e5c67dd9928d12d84b Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 16 Sep 2020 12:39:00 +0200 Subject: Some documentation about weighted dD Alpha complex. Make examples 3d/dD consistents --- src/Alpha_complex/doc/Intro_alpha_complex.h | 35 +++++++++++++++++++++- .../Weighted_alpha_complex_3d_from_points.cpp | 4 +-- .../example/Weighted_alpha_complex_from_points.cpp | 16 +++++----- .../example/weightedalpha3dfrompoints_for_doc.txt | 4 +-- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/Alpha_complex/doc/Intro_alpha_complex.h b/src/Alpha_complex/doc/Intro_alpha_complex.h index 60da7169..f14adee6 100644 --- a/src/Alpha_complex/doc/Intro_alpha_complex.h +++ b/src/Alpha_complex/doc/Intro_alpha_complex.h @@ -22,6 +22,17 @@ namespace alpha_complex { * * @{ * + + * \section definition Definition * * Alpha_complex is a simplicial complex @@ -146,6 +157,28 @@ namespace alpha_complex { * `SimplicialComplexForAlpha::prune_above_filtration()`). * In the following example, the value is given by the user as argument of the program. * + * \section weightedversion Weighted specific version + * Requires: \ref eigen ≥ 3.1.0 and \ref cgal ≥ 5.1.0. + * For performances reasons, it is advised to use \ref eigen ≥ 3.5.8 and \ref cgal ≥ 5.2.0 + * A weighted version for Alpha complex is available (cf. Alpha_complex). + * + * This example builds the CGAL weighted alpha shapes from a small molecule, and initializes the alpha complex with + * it. This example is taken from CGAL 3d + * weighted alpha shapes. + * + * Then, it is asked to display information about the alpha complex. + * + * \include Alpha_complex/Weighted_alpha_complex_from_points.cpp + * + * When launching: + * + * \code $> ./Weighted_alpha_complex_example_from_points + * \endcode + * + * the program output is: + * + * \include Alpha_complex/weightedalpha3dfrompoints_for_doc.txt + * * * \section offexample Example from OFF file * @@ -166,7 +199,7 @@ namespace alpha_complex { * \include Alpha_complex/alphaoffreader_for_doc_32.txt * * - * \section weighted3dexample 3d specific example + * \section weighted3dexample 3d specific version * * A specific module for Alpha complex is available in 3d (cf. Alpha_complex_3d) and allows to construct standard, * weighted, periodic or weighted and periodic versions of alpha complexes. Alpha values computation can be diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp index c044194e..74f0cf30 100644 --- a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp +++ b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp @@ -34,10 +34,10 @@ int main(int argc, char **argv) { // ---------------------------------------------------------------------------- // Display information about the alpha complex // ---------------------------------------------------------------------------- - std::clog << "Alpha complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices() + std::clog << "Weighted alpha complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices() << " simplices - " << simplex.num_vertices() << " vertices." << std::endl; - std::clog << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; + std::clog << "Iterator on weighted alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; for (auto f_simplex : simplex.filtration_simplex_range()) { std::clog << " ( "; for (auto vertex : simplex.simplex_vertex_range(f_simplex)) { diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp index 19a04282..d49d3e93 100644 --- a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp +++ b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp @@ -8,23 +8,21 @@ #include // Explicit dimension 2 Epeck_d kernel -using Kernel = CGAL::Epeck_d< CGAL::Dimension_tag<2> >; +using Kernel = CGAL::Epeck_d< CGAL::Dimension_tag<3> >; using Bare_point = Kernel::Point_d; using Weighted_point = Kernel::Weighted_point_d; using Vector_of_points = std::vector; int main() { // ---------------------------------------------------------------------------- - // Init of a list of points + // Init of a list of points and weights from a small molecule // ---------------------------------------------------------------------------- Vector_of_points points; - points.push_back(Weighted_point(Bare_point(1.0, 1.0) , 1.)); - points.push_back(Weighted_point(Bare_point(7.0, 0.0) , 1.)); - points.push_back(Weighted_point(Bare_point(4.0, 6.0) , 1.)); - points.push_back(Weighted_point(Bare_point(9.0, 6.0) , 1.)); - points.push_back(Weighted_point(Bare_point(0.0, 14.0), 1.)); - points.push_back(Weighted_point(Bare_point(2.0, 19.0), 1.)); - points.push_back(Weighted_point(Bare_point(9.0, 17.0), 1.)); + points.push_back(Weighted_point(Bare_point(1, -1, -1), 4.)); + points.push_back(Weighted_point(Bare_point(-1, 1, -1), 4.)); + points.push_back(Weighted_point(Bare_point(-1, -1, 1), 4.)); + points.push_back(Weighted_point(Bare_point(1, 1, 1), 4.)); + points.push_back(Weighted_point(Bare_point(2, 2, 2), 1.)); // ---------------------------------------------------------------------------- // Init of an alpha complex from the list of points diff --git a/src/Alpha_complex/example/weightedalpha3dfrompoints_for_doc.txt b/src/Alpha_complex/example/weightedalpha3dfrompoints_for_doc.txt index 7a09998d..f0695f1a 100644 --- a/src/Alpha_complex/example/weightedalpha3dfrompoints_for_doc.txt +++ b/src/Alpha_complex/example/weightedalpha3dfrompoints_for_doc.txt @@ -1,5 +1,5 @@ -Alpha complex is of dimension 3 - 29 simplices - 5 vertices. -Iterator on alpha complex simplices in the filtration order, with [filtration value]: +Weighted alpha complex is of dimension 3 - 29 simplices - 5 vertices. +Iterator on weighted alpha complex simplices in the filtration order, with [filtration value]: ( 0 ) -> [-4] ( 1 ) -> [-4] ( 2 ) -> [-4] -- cgit v1.2.3 From 282934d4f51acac046c04f752534a6a900880df9 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 16 Sep 2020 12:43:35 +0200 Subject: Add weighted in toc --- src/Alpha_complex/doc/Intro_alpha_complex.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Alpha_complex/doc/Intro_alpha_complex.h b/src/Alpha_complex/doc/Intro_alpha_complex.h index f14adee6..b04562e1 100644 --- a/src/Alpha_complex/doc/Intro_alpha_complex.h +++ b/src/Alpha_complex/doc/Intro_alpha_complex.h @@ -28,6 +28,7 @@ Table of Contents
  • Definition
  • Example from points
  • Create complex algorithm
  • +
  • Weighted specific version
  • Example from OFF file
  • 3d specific version
  • @@ -214,14 +215,7 @@ Table of Contents * * \include Alpha_complex/Weighted_alpha_complex_3d_from_points.cpp * - * When launching: - * - * \code $> ./Alpha_complex_example_weighted_3d_from_points - * \endcode - * - * the program output is: - * - * \include Alpha_complex/weightedalpha3dfrompoints_for_doc.txt + * The results will be the same as in \ref weightedversion . * */ /** @} */ // end defgroup alpha_complex -- cgit v1.2.3 From 837ffddda60d3f389184fe167710f74ad8adf36b Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Thu, 17 Sep 2020 09:37:25 +0200 Subject: Some documentation for weighted version --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 7 ++++--- src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index b66ec20d..1d395bd8 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -132,17 +132,18 @@ class Alpha_complex { using Triangulation = typename std::conditional, CGAL::Delaunay_triangulation>::type; + /** \brief CGAL kernel container for computations in function of the weighted or not characteristics.*/ using A_kernel_d = Alpha_kernel_d; // Numeric type of coordinates in the kernel using FT = typename A_kernel_d::FT; - /** \brief If Weighted, the weighted point is cached (point + weight [= squared radius]), - * else a pair of point and squared radius is cached. + /** \brief Sphere is a std::pair (aka. circurmcenter and squared radius). + * If Weighted, Sphere is a Kernel::Weighted_point_d (aka. circurmcenter and the weight value is the squared radius). */ using Sphere = typename A_kernel_d::Sphere; - /** \brief A point in Euclidean space.*/ + /** \brief A point, or a weighted point in Euclidean space.*/ using Point_d = typename std::conditional::type; diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h index a4824207..e3567a6d 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h @@ -32,6 +32,14 @@ namespace Gudhi { namespace alpha_complex { +/** + * \class Alpha_kernel_d + * \brief Alpha complex kernel container. + * + * \details + * The Alpha complex kernel container stores CGAL Kernel and dispatch basics computations in function of the weighted + * or not version of the Alpha complex. + */ template < typename Kernel, bool Weighted = false > class Alpha_kernel_d { }; -- cgit v1.2.3 From 77c0275031f47bb94f94d02d63182178e46f6570 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Thu, 17 Sep 2020 10:24:30 +0200 Subject: Remove useless code --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 1d395bd8..be0a5b95 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -60,27 +60,6 @@ namespace alpha_complex { template struct Is_Epeck_D { static const bool value = false; }; template struct Is_Epeck_D> { static const bool value = true; }; -template -struct Weight; - -template -struct Weight -{ - typename Kernel::FT operator()(const typename Kernel::Weighted_point_d& p) const - { - return p.weight(); - } -}; - -template -struct Weight -{ - typename Kernel::FT operator()(const typename Kernel::Point_d& p) const - { - return 0.; - } -}; - /** * \class Alpha_complex Alpha_complex.h gudhi/Alpha_complex.h * \brief Alpha complex data structure. -- cgit v1.2.3 From 8afdbebe27effb0a9c184a153b645dd85aa0415b Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Fri, 18 Sep 2020 13:08:37 +0200 Subject: Fix #if cgal_version --- .../include/gudhi/Alpha_complex/Alpha_kernel_d.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h index e3567a6d..a6760645 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h @@ -108,18 +108,16 @@ class Alpha_kernel_d { template Sphere get_sphere(PointIterator begin, PointIterator end) const { // power_center_d_object has been renamed between CGAL 5.1 and 5.2 -#if defined CGAL_VERSION_NR >= 1050101000 && defined CGAL_VERSION_NR < 1050201000 +#if CGAL_VERSION_NR < 1050201000 return kernel_.power_center_d_object()(begin, end); -#endif -#if CGAL_VERSION_NR >= 1050201000 +#else return kernel_.construct_power_sphere_d_object()(begin, end); #endif } template FT get_squared_radius(PointIterator begin, PointIterator end) const { - Sphere sph = get_sphere(begin, end); - return sph.weight(); + return get_sphere(begin, end).weight(); } FT get_squared_radius(const Sphere& sph) const { @@ -128,10 +126,9 @@ class Alpha_kernel_d { bool is_gabriel(const Sphere& circumcenter, const Weighted_point_d& point) { // power_center_d_object has been renamed between CGAL 5.1 and 5.2 -#if defined CGAL_VERSION_NR >= 1050101000 && defined CGAL_VERSION_NR < 1050201000 +#if CGAL_VERSION_NR < 1050201000 return kernel_.power_distance_d_object()(circumcenter, point) >= 0; -#endif -#if CGAL_VERSION_NR >= 1050201000 +#else return kernel_.compute_power_product_d_object()(circumcenter, point) >= 0; #endif } -- cgit v1.2.3 From c6619e0207abf0fb5198b66a8d8f00f975c3da84 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Fri, 18 Sep 2020 16:27:49 +0200 Subject: Use CGAL 5.1 by default on dockers. Update next release --- .github/next_release.md | 6 +++--- Dockerfile_for_circleci_image | 10 +++++++++- Dockerfile_for_pip | 8 ++++---- Dockerfile_gudhi_installation | 12 ++++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.github/next_release.md b/.github/next_release.md index cd2376eb..190f8408 100644 --- a/.github/next_release.md +++ b/.github/next_release.md @@ -1,13 +1,13 @@ We are pleased to announce the release 3.4.0 of the GUDHI library. -As a major new feature, the GUDHI library now offers ... +As a major new feature, the GUDHI library now offers dD weighted alpha complex, ... We are now using GitHub to develop the GUDHI library, do not hesitate to [fork the GUDHI project on GitHub](https://github.com/GUDHI/gudhi-devel). From a user point of view, we recommend to download GUDHI user version (gudhi.3.4.0.tar.gz). Below is a list of changes made since GUDHI 3.3.0: -- [Module](link) - - ... +- [Alpha complex](https://gudhi.inria.fr/doc/latest/group__alpha__complex.html) + - the C++ weighted version for alpha complex is now available in dimension D. - [Module](link) - ... diff --git a/Dockerfile_for_circleci_image b/Dockerfile_for_circleci_image index 87f57071..ec1b8ff8 100644 --- a/Dockerfile_for_circleci_image +++ b/Dockerfile_for_circleci_image @@ -41,7 +41,6 @@ RUN apt-get install -y make \ libgmp3-dev \ libmpfr-dev \ libtbb-dev \ - libcgal-dev \ locales \ python3 \ python3-pip \ @@ -51,6 +50,15 @@ RUN apt-get install -y make \ pkg-config \ curl +RUN curl -LO "https://github.com/CGAL/cgal/releases/download/v5.1/CGAL-5.1.tar.xz" \ + && tar xf CGAL-5.1.tar.xz \ + && mkdir build \ + && cd build \ + && cmake -DCMAKE_BUILD_TYPE=Release ../CGAL-5.1/ \ + && make install \ + && cd .. \ + && rm -rf build CGAL-5.1 + ADD .github/build-requirements.txt / ADD .github/test-requirements.txt / diff --git a/Dockerfile_for_pip b/Dockerfile_for_pip index 8f60e37c..83c6d684 100644 --- a/Dockerfile_for_pip +++ b/Dockerfile_for_pip @@ -23,14 +23,14 @@ RUN git clone -b boost-1.73.0 --depth 1 https://github.com/boostorg/boost.git \ && cd .. \ && rm -rf boost -RUN wget https://github.com/CGAL/cgal/releases/download/releases%2FCGAL-5.0.2/CGAL-5.0.2.tar.xz \ - && tar xf CGAL-5.0.2.tar.xz \ +RUN wget https://github.com/CGAL/cgal/releases/download/v5.1/CGAL-5.1.tar.xz \ + && tar xf CGAL-5.1.tar.xz \ && mkdir build \ && cd build \ - && /opt/cmake/bin/cmake -DCMAKE_BUILD_TYPE=Release ../CGAL-5.0.2/ \ + && /opt/cmake/bin/cmake -DCMAKE_BUILD_TYPE=Release ../CGAL-5.1/ \ && make install \ && cd .. \ - && rm -rf build CGAL-5.0.2 + && rm -rf build CGAL-5.1 ADD .github/build-requirements.txt / diff --git a/Dockerfile_gudhi_installation b/Dockerfile_gudhi_installation index 92430fce..ebd21f8d 100644 --- a/Dockerfile_gudhi_installation +++ b/Dockerfile_gudhi_installation @@ -23,6 +23,9 @@ ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 +# Update again +RUN apt-get update + # Required for Gudhi compilation RUN apt-get install -y make \ g++ \ @@ -47,6 +50,15 @@ RUN apt-get install -y make \ pkg-config \ curl +RUN curl -LO "https://github.com/CGAL/cgal/releases/download/v5.1/CGAL-5.1.tar.xz" \ + && tar xf CGAL-5.1.tar.xz \ + && mkdir build \ + && cd build \ + && cmake -DCMAKE_BUILD_TYPE=Release ../CGAL-5.1/ \ + && make install \ + && cd .. \ + && rm -rf build CGAL-5.1 + RUN pip3 install \ numpy \ matplotlib \ -- cgit v1.2.3 From 4186971033ee43821905cac53791bf074751d3af Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 28 Sep 2020 09:15:52 +0200 Subject: code review: Let the exception propagate --- src/python/gudhi/simplex_tree.pyx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx index 5250937b..5043c621 100644 --- a/src/python/gudhi/simplex_tree.pyx +++ b/src/python/gudhi/simplex_tree.pyx @@ -295,13 +295,9 @@ cdef class SimplexTree: """ cdef pair[Simplex_tree_boundary_iterator, Simplex_tree_boundary_iterator] it = self.get_ptr().get_boundary_iterators(simplex) - try: - while it.first != it.second: - yield self.get_ptr().get_simplex_and_filtration(dereference(it.first)) - preincrement(it.first) - except RuntimeError: - print("simplex not found - cannot find boundaries") - + while it.first != it.second: + yield self.get_ptr().get_simplex_and_filtration(dereference(it.first)) + preincrement(it.first) def remove_maximal_simplex(self, simplex): """This function removes a given maximal N-simplex from the simplicial -- cgit v1.2.3 From b1b0e9afcaf0e282115dddad7b958b6ec7a94a41 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 29 Sep 2020 14:33:28 +0200 Subject: code review: inconsistency between code and comment --- src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp index 74f0cf30..a8d00272 100644 --- a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp +++ b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp @@ -9,7 +9,7 @@ // Complexity = FAST, weighted = true, periodic = false using Weighted_alpha_complex_3d = - Gudhi::alpha_complex::Alpha_complex_3d; + Gudhi::alpha_complex::Alpha_complex_3d; using Bare_point = Weighted_alpha_complex_3d::Bare_point_3; using Weighted_point = Weighted_alpha_complex_3d::Weighted_point_3; -- cgit v1.2.3 From 6f2ec5ee6572351d3aee5f559ef4cf7ad03bf914 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 29 Sep 2020 15:00:53 +0200 Subject: doc review: fix eigen version and period --- src/Alpha_complex/doc/Intro_alpha_complex.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Alpha_complex/doc/Intro_alpha_complex.h b/src/Alpha_complex/doc/Intro_alpha_complex.h index b04562e1..78486ad6 100644 --- a/src/Alpha_complex/doc/Intro_alpha_complex.h +++ b/src/Alpha_complex/doc/Intro_alpha_complex.h @@ -160,7 +160,8 @@ Table of Contents * * \section weightedversion Weighted specific version * Requires: \ref eigen ≥ 3.1.0 and \ref cgal ≥ 5.1.0. - * For performances reasons, it is advised to use \ref eigen ≥ 3.5.8 and \ref cgal ≥ 5.2.0 + * For performances reasons, it is advised to use \ref eigen ≥ 3.3.5 and \ref cgal ≥ 5.2.0. + * * A weighted version for Alpha complex is available (cf. Alpha_complex). * * This example builds the CGAL weighted alpha shapes from a small molecule, and initializes the alpha complex with -- cgit v1.2.3 From b08a52c3b625e70d1c69834df7253e115da7946e Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 29 Sep 2020 15:35:11 +0200 Subject: code review: use of std::conditional_t c++14 helper --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index be0a5b95..e8bf1f74 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -101,15 +101,16 @@ template, bool Weighte class Alpha_complex { public: /** \brief Geometric traits class that provides the geometric types and predicates needed by the triangulations.*/ - using Geom_traits = typename std::conditional, - Kernel>::type; + using Geom_traits = std::conditional_t, Kernel>; + // Add an int in TDS to save point index in the structure using TDS = CGAL::Triangulation_data_structure, CGAL::Triangulation_full_cell >; + /** \brief A (Weighted or not) Delaunay triangulation of a set of points in \f$ \mathbb{R}^D\f$.*/ - using Triangulation = typename std::conditional, - CGAL::Delaunay_triangulation>::type; + using Triangulation = std::conditional_t, + CGAL::Delaunay_triangulation>; /** \brief CGAL kernel container for computations in function of the weighted or not characteristics.*/ using A_kernel_d = Alpha_kernel_d; @@ -123,8 +124,7 @@ class Alpha_complex { using Sphere = typename A_kernel_d::Sphere; /** \brief A point, or a weighted point in Euclidean space.*/ - using Point_d = typename std::conditional::type; + using Point_d = std::conditional_t; private: // Vertex_iterator type from CGAL. -- cgit v1.2.3 From 44473bcd93892c7034fa21599509d4271f2d8bb2 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 29 Sep 2020 17:16:02 +0200 Subject: doc review: rephrase non contiguous vertices --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index e8bf1f74..38201027 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -171,7 +171,8 @@ class Alpha_complex { /** \brief Alpha_complex constructor from a list of points. * - * Duplicate points are inserted once in the Alpha_complex. This is the reason why the vertices may be not contiguous. + * The vertices may be not contiguous as some points may be discarded in the triangulation (duplicate points, + * weighted hidden point, ...). * * @param[in] points Range of points to triangulate. Points must be in Kernel::Point_d or Kernel::Weighted_point_d. * @@ -186,7 +187,8 @@ class Alpha_complex { /** \brief Alpha_complex constructor from a list of points and weights. * - * Duplicate points are inserted once in the Alpha_complex. This is the reason why the vertices may be not contiguous. + * The vertices may be not contiguous as some points may be discarded in the triangulation (duplicate points, + * weighted hidden point, ...). * * @param[in] points Range of points to triangulate. Points must be in Kernel::Point_d or Kernel::Weighted_point_d. * -- cgit v1.2.3 From dab93ead76f1435f6b74937ef0377aafb0517439 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 29 Sep 2020 17:53:34 +0200 Subject: doc review: Modify ctor with points and weights documentation --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 38201027..a692dbc6 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -176,8 +176,8 @@ class Alpha_complex { * * @param[in] points Range of points to triangulate. Points must be in Kernel::Point_d or Kernel::Weighted_point_d. * - * The type InputPointRange must be a range for which std::begin and - * std::end return input iterators on a Kernel::Point_d or Kernel::Weighted_point_d. + * The type InputPointRange must be a range for which std::begin and std::end return input iterators on a + * Kernel::Point_d or Kernel::Weighted_point_d. */ template Alpha_complex(const InputPointRange& points) @@ -190,12 +190,12 @@ class Alpha_complex { * The vertices may be not contiguous as some points may be discarded in the triangulation (duplicate points, * weighted hidden point, ...). * - * @param[in] points Range of points to triangulate. Points must be in Kernel::Point_d or Kernel::Weighted_point_d. + * @param[in] points Range of points to triangulate. Points must be in Kernel::Point_d. * * @param[in] weights Range of points weights. Weights must be in Kernel::FT. * - * The type InputPointRange must be a range for which std::begin and - * std::end return input iterators on a Kernel::Point_d. + * The type InputPointRange must be a range for which std::begin and std::end return input iterators on a + * Kernel::Point_d. */ template Alpha_complex(const InputPointRange& points, WeightRange weights) { -- cgit v1.2.3 From c1b317640f81fefff7f7a774b239957fb632fa43 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 30 Sep 2020 09:18:36 +0200 Subject: code review: emplace_back versus push_back --- .../Weighted_alpha_complex_3d_from_points.cpp | 10 +++++----- .../example/Weighted_alpha_complex_from_points.cpp | 10 +++++----- src/Alpha_complex/include/gudhi/Alpha_complex.h | 6 +++--- src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp | 20 ++++++++++---------- .../utilities/alpha_complex_persistence.cpp | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp index a8d00272..09431d6e 100644 --- a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp +++ b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp @@ -18,11 +18,11 @@ int main(int argc, char **argv) { // Init of a list of points and weights from a small molecule // ---------------------------------------------------------------------------- std::vector weighted_points; - weighted_points.push_back(Weighted_point(Bare_point(1, -1, -1), 4.)); - weighted_points.push_back(Weighted_point(Bare_point(-1, 1, -1), 4.)); - weighted_points.push_back(Weighted_point(Bare_point(-1, -1, 1), 4.)); - weighted_points.push_back(Weighted_point(Bare_point(1, 1, 1), 4.)); - weighted_points.push_back(Weighted_point(Bare_point(2, 2, 2), 1.)); + weighted_points.emplace_back(Bare_point(1, -1, -1), 4.); + weighted_points.emplace_back(Bare_point(-1, 1, -1), 4.); + weighted_points.emplace_back(Bare_point(-1, -1, 1), 4.); + weighted_points.emplace_back(Bare_point(1, 1, 1), 4.); + weighted_points.emplace_back(Bare_point(2, 2, 2), 1.); // ---------------------------------------------------------------------------- // Init of an alpha complex from the list of points diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp index d49d3e93..d1f3e436 100644 --- a/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp +++ b/src/Alpha_complex/example/Weighted_alpha_complex_from_points.cpp @@ -18,11 +18,11 @@ int main() { // Init of a list of points and weights from a small molecule // ---------------------------------------------------------------------------- Vector_of_points points; - points.push_back(Weighted_point(Bare_point(1, -1, -1), 4.)); - points.push_back(Weighted_point(Bare_point(-1, 1, -1), 4.)); - points.push_back(Weighted_point(Bare_point(-1, -1, 1), 4.)); - points.push_back(Weighted_point(Bare_point(1, 1, 1), 4.)); - points.push_back(Weighted_point(Bare_point(2, 2, 2), 1.)); + points.emplace_back(Bare_point(1, -1, -1), 4.); + points.emplace_back(Bare_point(-1, 1, -1), 4.); + points.emplace_back(Bare_point(-1, -1, 1), 4.); + points.emplace_back(Bare_point(1, 1, 1), 4.); + points.emplace_back(Bare_point(2, 2, 2), 1.); // ---------------------------------------------------------------------------- // Init of an alpha complex from the list of points diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index a692dbc6..4f8e3d54 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -310,7 +310,7 @@ class Alpha_complex { thread_local std::vector v; v.clear(); for (auto vertex : cplx.simplex_vertex_range(s)) - v.push_back(get_point_(vertex)); + v.emplace_back(get_point_(vertex)); cache_.emplace_back(kernel_.get_sphere(v.cbegin(), v.cend())); } return cache_[k]; @@ -326,7 +326,7 @@ class Alpha_complex { thread_local std::vector v; v.clear(); for (auto vertex : cplx.simplex_vertex_range(s)) - v.push_back(get_point_(vertex)); + v.emplace_back(get_point_(vertex)); return kernel_.get_squared_radius(v.cbegin(), v.cend()); } @@ -394,7 +394,7 @@ class Alpha_complex { std::clog << " " << (*vit)->data(); #endif // DEBUG_TRACES // Vector of vertex construction for simplex_tree structure - vertexVector.push_back((*vit)->data()); + vertexVector.emplace_back((*vit)->data()); } } #ifdef DEBUG_TRACES diff --git a/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp b/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp index 192834b3..6eae103d 100644 --- a/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp @@ -63,11 +63,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_sphere, TestedKernel, list_of_kerne using Point_d = typename Unweighted_kernel::Point_d; std::vector unw_pts; - unw_pts.push_back(Point_d(p0.begin(), p0.end())); - unw_pts.push_back(Point_d(p1.begin(), p1.end())); - unw_pts.push_back(Point_d(p2.begin(), p2.end())); - unw_pts.push_back(Point_d(p3.begin(), p3.end())); - unw_pts.push_back(Point_d(p4.begin(), p4.end())); + unw_pts.emplace_back(p0.begin(), p0.end()); + unw_pts.emplace_back(p1.begin(), p1.end()); + unw_pts.emplace_back(p2.begin(), p2.end()); + unw_pts.emplace_back(p3.begin(), p3.end()); + unw_pts.emplace_back(p4.begin(), p4.end()); Unweighted_kernel kernel; auto unw_sphere = kernel.get_sphere(unw_pts.cbegin(), unw_pts.cend()); @@ -79,11 +79,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_sphere, TestedKernel, list_of_kerne using Weighted_point_d = typename Weighted_kernel::Weighted_point_d; using Bare_point_d = typename Weighted_kernel::Bare_point_d; std::vector w_pts; - w_pts.push_back(Weighted_point_d(Bare_point_d(p0.begin(), p0.end()), 0.)); - w_pts.push_back(Weighted_point_d(Bare_point_d(p1.begin(), p1.end()), 0.)); - w_pts.push_back(Weighted_point_d(Bare_point_d(p2.begin(), p2.end()), 0.)); - w_pts.push_back(Weighted_point_d(Bare_point_d(p3.begin(), p3.end()), 0.)); - w_pts.push_back(Weighted_point_d(Bare_point_d(p4.begin(), p4.end()), 0.)); + w_pts.emplace_back(Bare_point_d(p0.begin(), p0.end()), 0.); + w_pts.emplace_back(Bare_point_d(p1.begin(), p1.end()), 0.); + w_pts.emplace_back(Bare_point_d(p2.begin(), p2.end()), 0.); + w_pts.emplace_back(Bare_point_d(p3.begin(), p3.end()), 0.); + w_pts.emplace_back(Bare_point_d(p4.begin(), p4.end()), 0.); Weighted_kernel w_kernel; auto w_sphere = w_kernel.get_sphere(w_pts.cbegin(), w_pts.cend()); diff --git a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp index e86b34e2..3ce7b440 100644 --- a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp @@ -50,7 +50,7 @@ std::vector read_weight_file(const std::string &weight_file) { double weight = 0.0; // Attempt read the weight in a double format, return false if it fails while (weights_ifstr >> weight) { - weights.push_back(weight); + weights.emplace_back(weight); } } else { std::cerr << "Unable to read weights file " << weight_file << std::endl; -- cgit v1.2.3 From 74143b372d3d93fc2139974fa85906047acee8a7 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 5 Oct 2020 10:33:23 +0200 Subject: code review: push_back versus emplace_back --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 6 +++--- src/Alpha_complex/utilities/alpha_complex_persistence.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 4f8e3d54..a692dbc6 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -310,7 +310,7 @@ class Alpha_complex { thread_local std::vector v; v.clear(); for (auto vertex : cplx.simplex_vertex_range(s)) - v.emplace_back(get_point_(vertex)); + v.push_back(get_point_(vertex)); cache_.emplace_back(kernel_.get_sphere(v.cbegin(), v.cend())); } return cache_[k]; @@ -326,7 +326,7 @@ class Alpha_complex { thread_local std::vector v; v.clear(); for (auto vertex : cplx.simplex_vertex_range(s)) - v.emplace_back(get_point_(vertex)); + v.push_back(get_point_(vertex)); return kernel_.get_squared_radius(v.cbegin(), v.cend()); } @@ -394,7 +394,7 @@ class Alpha_complex { std::clog << " " << (*vit)->data(); #endif // DEBUG_TRACES // Vector of vertex construction for simplex_tree structure - vertexVector.emplace_back((*vit)->data()); + vertexVector.push_back((*vit)->data()); } } #ifdef DEBUG_TRACES diff --git a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp index 3ce7b440..e86b34e2 100644 --- a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp @@ -50,7 +50,7 @@ std::vector read_weight_file(const std::string &weight_file) { double weight = 0.0; // Attempt read the weight in a double format, return false if it fails while (weights_ifstr >> weight) { - weights.emplace_back(weight); + weights.push_back(weight); } } else { std::cerr << "Unable to read weights file " << weight_file << std::endl; -- cgit v1.2.3 From 7b477e78f38324bf1473966d59aab0360bae8066 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 5 Oct 2020 10:38:31 +0200 Subject: code review: promote SAFE mode --- src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp index 09431d6e..ee12d418 100644 --- a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp +++ b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp @@ -7,9 +7,9 @@ #include #include // for numeric limits -// Complexity = FAST, weighted = true, periodic = false +// Complexity = SAFE, weighted = true, periodic = false using Weighted_alpha_complex_3d = - Gudhi::alpha_complex::Alpha_complex_3d; + Gudhi::alpha_complex::Alpha_complex_3d; using Bare_point = Weighted_alpha_complex_3d::Bare_point_3; using Weighted_point = Weighted_alpha_complex_3d::Weighted_point_3; -- cgit v1.2.3 From 3b839cae75a7e58b87216ee92356267bbe873e46 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 5 Oct 2020 11:26:24 +0200 Subject: doc review: eigen 3.3.5 and cgal 5.2.0 is advised for perf reasons not only on weighted version --- src/Alpha_complex/doc/Intro_alpha_complex.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Alpha_complex/doc/Intro_alpha_complex.h b/src/Alpha_complex/doc/Intro_alpha_complex.h index 78486ad6..fb051760 100644 --- a/src/Alpha_complex/doc/Intro_alpha_complex.h +++ b/src/Alpha_complex/doc/Intro_alpha_complex.h @@ -74,7 +74,7 @@ Table of Contents * [10^12,10^12+10^6]. Using `CGAL::Epick_d` makes the computations slightly faster, and the combinatorics are still * exact, but the computation of filtration values can exceptionally be arbitrarily bad. In all cases, we still * guarantee that the output is a valid filtration (faces have a filtration value no larger than their cofaces). - * - For performances reasons, it is advised to use `Alpha_complex` with \ref cgal ≥ 5.0.0. + * - For performances reasons, it is advised to use \ref eigen ≥ 3.3.5 and \ref cgal ≥ 5.2.0. * * \section pointsexample Example from points * @@ -160,7 +160,6 @@ Table of Contents * * \section weightedversion Weighted specific version * Requires: \ref eigen ≥ 3.1.0 and \ref cgal ≥ 5.1.0. - * For performances reasons, it is advised to use \ref eigen ≥ 3.3.5 and \ref cgal ≥ 5.2.0. * * A weighted version for Alpha complex is available (cf. Alpha_complex). * -- cgit v1.2.3 From 9bba01c0afb2c931553d2c47af0104f407d22c01 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 5 Oct 2020 13:18:59 +0200 Subject: code review: typename is useless here --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index a692dbc6..ae04e6e8 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -134,7 +134,7 @@ class Alpha_complex { using size_type = typename Triangulation::size_type; // Structure to switch from simplex tree vertex handle to CGAL vertex iterator. - using Vector_vertex_iterator = typename std::vector< CGAL_vertex_iterator >; + using Vector_vertex_iterator = std::vector< CGAL_vertex_iterator >; private: /** \brief Vertex iterator vector to switch from simplex tree vertex handle to CGAL vertex iterator. -- cgit v1.2.3 From f7faba86fced9c75c530c86665ca3c73429d8f12 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 5 Oct 2020 13:19:52 +0200 Subject: code review: include what you use --- src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h index a6760645..7c49bb14 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h @@ -11,8 +11,6 @@ #ifndef ALPHA_COMPLEX_ALPHA_KERNEL_D_H_ #define ALPHA_COMPLEX_ALPHA_KERNEL_D_H_ -#include // For EXACT or SAFE version -#include // For FAST version #include // for CGAL_VERSION_NR #include // for EIGEN_VERSION_AT_LEAST -- cgit v1.2.3 From 2d80f0e7f3e09167760338c15596b052050ddb55 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 5 Oct 2020 14:00:51 +0200 Subject: code review: roll back include epick --- src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h index 7c49bb14..d4dbd68b 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h @@ -12,6 +12,8 @@ #define ALPHA_COMPLEX_ALPHA_KERNEL_D_H_ #include // for CGAL_VERSION_NR +#include // For EXACT or SAFE version +#include // For FAST version #include // for EIGEN_VERSION_AT_LEAST -- cgit v1.2.3 From d6ca67fee4f9c2a97b64710a5b70ed66dd307372 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 5 Oct 2020 14:50:57 +0200 Subject: code review: fix include what you use and compute_squared_radius_smallest_orthogonal_sphere_d_object use --- src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h index d4dbd68b..fbb931d4 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h @@ -12,10 +12,8 @@ #define ALPHA_COMPLEX_ALPHA_KERNEL_D_H_ #include // for CGAL_VERSION_NR -#include // For EXACT or SAFE version -#include // For FAST version -#include // for EIGEN_VERSION_AT_LEAST +#include // for EIGEN_VERSION_AT_LEAST #include // for std::make_pair @@ -117,7 +115,7 @@ class Alpha_kernel_d { template FT get_squared_radius(PointIterator begin, PointIterator end) const { - return get_sphere(begin, end).weight(); + return kernel_.compute_squared_radius_smallest_orthogonal_sphere_d_object()(begin, end); } FT get_squared_radius(const Sphere& sph) const { -- cgit v1.2.3 From 298925b9c2dc3629f2d20ad9b85f5a410dee6fab Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 5 Oct 2020 15:29:25 +0200 Subject: code review: use geom_trait for Point_d type --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index ae04e6e8..1963f02b 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -124,7 +124,7 @@ class Alpha_complex { using Sphere = typename A_kernel_d::Sphere; /** \brief A point, or a weighted point in Euclidean space.*/ - using Point_d = std::conditional_t; + using Point_d = typename Geom_traits::Point_d; private: // Vertex_iterator type from CGAL. -- cgit v1.2.3 From 51f4de9a42cbdf7686a0f36106b31c0d3296ccfa Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 5 Oct 2020 16:11:46 +0200 Subject: doc review: Add some precision about regular triangulations --- src/Alpha_complex/doc/Intro_alpha_complex.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Alpha_complex/doc/Intro_alpha_complex.h b/src/Alpha_complex/doc/Intro_alpha_complex.h index fb051760..c068b268 100644 --- a/src/Alpha_complex/doc/Intro_alpha_complex.h +++ b/src/Alpha_complex/doc/Intro_alpha_complex.h @@ -161,7 +161,9 @@ Table of Contents * \section weightedversion Weighted specific version * Requires: \ref eigen ≥ 3.1.0 and \ref cgal ≥ 5.1.0. * - * A weighted version for Alpha complex is available (cf. Alpha_complex). + * A weighted version for Alpha complex is available (cf. Alpha_complex). It is like a usual Alpha complex, but based + * on a CGAL regular triangulation instead + * of Delaunay. * * This example builds the CGAL weighted alpha shapes from a small molecule, and initializes the alpha complex with * it. This example is taken from CGAL 3d -- cgit v1.2.3 From 30efe05d095051e14cbaf26d12fc2a67134e5a60 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Thu, 15 Oct 2020 16:43:54 +0200 Subject: Use unique_ptr for triangulation_ --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 1963f02b..4f7a7bd2 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -19,6 +19,7 @@ #include #include // isnan, fmax +#include // for std::unique_ptr #include #include // aka. Weighted Delaunay triangulation @@ -141,7 +142,7 @@ class Alpha_complex { * Vertex handles are inserted sequentially, starting at 0.*/ Vector_vertex_iterator vertex_handle_to_iterator_; /** \brief Pointer on the CGAL Delaunay triangulation.*/ - Triangulation* triangulation_; + std::unique_ptr triangulation_; /** \brief Kernel for triangulation_ functions access.*/ A_kernel_d kernel_; @@ -158,8 +159,7 @@ class Alpha_complex { * * @param[in] off_file_name OFF file [path and] name. */ - Alpha_complex(const std::string& off_file_name) - : triangulation_(nullptr) { + Alpha_complex(const std::string& off_file_name) { Gudhi::Points_off_reader off_reader(off_file_name); if (!off_reader.is_valid()) { std::cerr << "Alpha_complex - Unable to read file " << off_file_name << "\n"; @@ -180,8 +180,7 @@ class Alpha_complex { * Kernel::Point_d or Kernel::Weighted_point_d. */ template - Alpha_complex(const InputPointRange& points) - : triangulation_(nullptr) { + Alpha_complex(const InputPointRange& points) { init_from_range(points); } @@ -208,12 +207,6 @@ class Alpha_complex { init_from_range(weighted_points); } - /** \brief Alpha_complex destructor deletes the Delaunay triangulation. - */ - ~Alpha_complex() { - delete triangulation_; - } - // Forbid copy/move constructor/assignment operator Alpha_complex(const Alpha_complex& other) = delete; Alpha_complex& operator= (const Alpha_complex& other) = delete; @@ -249,7 +242,7 @@ class Alpha_complex { if (first != last) { // Delaunay triangulation init with point dimension. - triangulation_ = new Triangulation(kernel_.get_dimension(*first)); + triangulation_ = std::make_unique(kernel_.get_dimension(*first)); std::vector point_cloud(first, last); -- cgit v1.2.3 From afafd56fdb4a53b66ca3354fc20f787f12340fa4 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 26 Oct 2020 10:56:25 +0100 Subject: for CGAL 5.2 pre-release to work --- src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h index fbb931d4..28d6d7a9 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h @@ -106,7 +106,7 @@ class Alpha_kernel_d { template Sphere get_sphere(PointIterator begin, PointIterator end) const { // power_center_d_object has been renamed between CGAL 5.1 and 5.2 -#if CGAL_VERSION_NR < 1050201000 +#if CGAL_VERSION_NR < 1050200000 return kernel_.power_center_d_object()(begin, end); #else return kernel_.construct_power_sphere_d_object()(begin, end); @@ -124,7 +124,7 @@ class Alpha_kernel_d { bool is_gabriel(const Sphere& circumcenter, const Weighted_point_d& point) { // power_center_d_object has been renamed between CGAL 5.1 and 5.2 -#if CGAL_VERSION_NR < 1050201000 +#if CGAL_VERSION_NR < 1050200000 return kernel_.power_distance_d_object()(circumcenter, point) >= 0; #else return kernel_.compute_power_product_d_object()(circumcenter, point) >= 0; -- cgit v1.2.3 From 699a89819da922222cedcd81b4a1553ee161a633 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 26 Oct 2020 10:58:19 +0100 Subject: code review: bad copy/paste that needs rephrase --- src/Alpha_complex/include/gudhi/Alpha_complex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex.h b/src/Alpha_complex/include/gudhi/Alpha_complex.h index 4f7a7bd2..b315fa99 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex.h @@ -198,7 +198,7 @@ class Alpha_complex { */ template Alpha_complex(const InputPointRange& points, WeightRange weights) { - static_assert(Weighted, "This constructor is not available for non-weighted versions of Alpha_complex_3d"); + static_assert(Weighted, "This constructor is not available for non-weighted versions of Alpha_complex"); // FIXME: this test is only valid if we have a forward range GUDHI_CHECK(boost::size(weights) == boost::size(points), std::invalid_argument("Points number in range different from weights range number")); -- cgit v1.2.3 From 4d8c5c315b79260fbae05d359987c8d39a863d2d Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 27 Oct 2020 11:15:36 +0100 Subject: zero weighted test is guaranteed only for exact version --- src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp index e8372656..cae9dbb5 100644 --- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp @@ -29,14 +29,10 @@ // Use dynamic_dimension_tag for the user to be able to set dimension typedef CGAL::Epeck_d< CGAL::Dynamic_dimension_tag > Exact_kernel_d; -// Use static dimension_tag for the user not to be able to set dimension +// Use static dimension_tag to set dimension at 4 typedef CGAL::Epeck_d< CGAL::Dimension_tag<4> > Exact_kernel_s; -// Use dynamic_dimension_tag for the user to be able to set dimension -typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Inexact_kernel_d; -// Use static dimension_tag for the user not to be able to set dimension -typedef CGAL::Epick_d< CGAL::Dimension_tag<4> > Inexact_kernel_s; -typedef boost::mpl::list list_of_kernel_variants; +typedef boost::mpl::list list_of_kernel_variants; BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_kernel_variants) { // Random points construction @@ -53,7 +49,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_kerne // Alpha complex from points Gudhi::alpha_complex::Alpha_complex alpha_complex_from_points(points); Gudhi::Simplex_tree<> simplex; - BOOST_CHECK(alpha_complex_from_points.create_complex(simplex)); + BOOST_CHECK(alpha_complex_from_points.create_complex(simplex, std::numeric_limits::Filtration_value>::infinity(), true)); std::clog << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; for (auto f_simplex : simplex.filtration_simplex_range()) { std::clog << " ( "; @@ -68,7 +64,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_kerne std::vector weights(20, 0.); Gudhi::alpha_complex::Alpha_complex alpha_complex_from_zero_weighted_points(points, weights); Gudhi::Simplex_tree<> zw_simplex; - BOOST_CHECK(alpha_complex_from_zero_weighted_points.create_complex(zw_simplex)); + BOOST_CHECK(alpha_complex_from_zero_weighted_points.create_complex(zw_simplex, std::numeric_limits::Filtration_value>::infinity(), true)); std::clog << "Iterator on zero weighted alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; for (auto f_simplex : zw_simplex.filtration_simplex_range()) { -- cgit v1.2.3 From beaa5c2fa89ed92c84328383ac58f1e71cf510ff Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 27 Oct 2020 12:16:34 +0100 Subject: Add a test for non visible points (hidden by weights) --- .../test/Weighted_alpha_complex_unit_test.cpp | 35 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp index cae9dbb5..cc63ac1f 100644 --- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_kerne std::mt19937 rand_engine(rand_dev()); for (int idx = 0; idx < 20; idx++) { std::vector point {rd_pts(rand_engine), rd_pts(rand_engine), rd_pts(rand_engine), rd_pts(rand_engine)}; - points.emplace_back(Point_d(point.begin(), point.end())); + points.emplace_back(point.begin(), point.end()); } // Alpha complex from points @@ -108,8 +108,8 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { for (int idx = 0; idx < 20; idx++) { std::vector point {rd_pts(rand_engine), rd_pts(rand_engine), rd_pts(rand_engine)}; double weight = rd_wghts(rand_engine); - w_points_d.emplace_back(Weighted_point_d(Bare_point_d(point.begin(), point.end()), weight)); - w_points_3.emplace_back(Weighted_point_3(Bare_point_3(point[0], point[1], point[2]), weight)); + w_points_d.emplace_back(Bare_point_d(point.begin(), point.end()), weight); + w_points_3.emplace_back(Bare_point_3(point[0], point[1], point[2]), weight); } // Structures necessary for comparison @@ -185,3 +185,32 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { ++dD_itr; } } + +BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_non_visible_points) { + using Point_d = typename Exact_kernel_d::Point_d; + std::vector points; + std::vector p1 {0.}; + points.emplace_back(p1.begin(), p1.end()); + // closed enough points + std::vector p2 {0.1}; + points.emplace_back(p2.begin(), p2.end()); + std::vector weights {100., 0.01}; + + Gudhi::alpha_complex::Alpha_complex alpha_complex(points, weights); + Gudhi::Simplex_tree<> stree; + BOOST_CHECK(alpha_complex.create_complex(stree)); + + std::clog << "Iterator on weighted alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; + for (auto f_simplex : stree.filtration_simplex_range()) { + std::clog << " ( "; + for (auto vertex : stree.simplex_vertex_range(f_simplex)) { + std::clog << vertex << " "; + } + std::clog << ") -> " << "[" << stree.filtration(f_simplex) << "] "; + std::clog << std::endl; + } + + BOOST_CHECK(stree.filtration(stree.find({0})) == -100.); + BOOST_CHECK(stree.filtration(stree.find({1})) == stree.filtration(stree.find({0, 1}))); + +} \ No newline at end of file -- cgit v1.2.3 From 901fbd0ccdee2d9bb7794de8896d35aae8ede989 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 27 Oct 2020 14:45:25 +0100 Subject: Add a test about the filtration --- src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp index cc63ac1f..b84ab3de 100644 --- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp @@ -212,5 +212,6 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_non_visible_points) { BOOST_CHECK(stree.filtration(stree.find({0})) == -100.); BOOST_CHECK(stree.filtration(stree.find({1})) == stree.filtration(stree.find({0, 1}))); + BOOST_CHECK(stree.filtration(stree.find({1})) > 100000); } \ No newline at end of file -- cgit v1.2.3 From 666f3f54498f47f1bc1cddbd522e5f53b9aae63a Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 3 Nov 2020 09:27:21 +0100 Subject: Add comment in code for get_boundaries if not interested in filtration values --- src/python/gudhi/simplex_tree.pyx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx index c671da56..813dc5c2 100644 --- a/src/python/gudhi/simplex_tree.pyx +++ b/src/python/gudhi/simplex_tree.pyx @@ -287,6 +287,8 @@ cdef class SimplexTree: def get_boundaries(self, simplex): """This function returns a generator with the boundaries of a given N-simplex. + If you do not need the filtration values, the boundary can also be obtained as + :code:`itertools.combinations(simplex,len(simplex)-1)`. :param simplex: The N-simplex, represented by a list of vertex. :type simplex: list of int. -- cgit v1.2.3 From 69c70afd0442774582b7e930bdab603600a3e750 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 3 Nov 2020 11:33:39 +0100 Subject: doc review: explain briefly test aims --- .../test/Alpha_kernel_d_unit_test.cpp | 5 ++++ .../test/Weighted_alpha_complex_unit_test.cpp | 30 ++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp b/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp index 6eae103d..6da4c084 100644 --- a/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_kernel_d_unit_test.cpp @@ -37,6 +37,8 @@ typedef CGAL::Epick_d< CGAL::Dimension_tag<4> > Inexact_kernel_s; typedef boost::mpl::list list_of_kernel_variants; BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_dimension, TestedKernel, list_of_kernel_variants) { + // Test for a point (weighted or not) in 4d, that the dimension is 4. + Gudhi::alpha_complex::Alpha_kernel_d kernel; std::vector p0 {0., 1., 2., 3.}; typename TestedKernel::Point_d p0_d(p0.begin(), p0.end()); @@ -52,6 +54,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_dimension, TestedKernel, list_of_ke } BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_kernel_d_sphere, TestedKernel, list_of_kernel_variants) { + // Test with 5 points on a 3-sphere, that get_sphere returns the same center and squared radius + // for dD unweighted and for dD weighted with all weights at 0. + using Unweighted_kernel = Gudhi::alpha_complex::Alpha_kernel_d; // Sphere: (x-1)² + (y-1)² + z² + t² = 1 // At least 5 points for a 3-sphere diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp index b84ab3de..2cd66963 100644 --- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp @@ -27,14 +27,14 @@ #include #include -// Use dynamic_dimension_tag for the user to be able to set dimension -typedef CGAL::Epeck_d< CGAL::Dynamic_dimension_tag > Exact_kernel_d; -// Use static dimension_tag to set dimension at 4 -typedef CGAL::Epeck_d< CGAL::Dimension_tag<4> > Exact_kernel_s; +using list_of_exact_kernel_variants = boost::mpl::list, + CGAL::Epeck_d< CGAL::Dimension_tag<4> > + > ; -typedef boost::mpl::list list_of_kernel_variants; +BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_exact_kernel_variants) { + // Check that in exact mode for static dimension 4 the code for dD unweighted and for dD weighted with all weights + // 0 give exactly the same simplex tree (simplices and filtration values). -BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_kernel_variants) { // Random points construction using Point_d = typename Kernel::Point_d; std::vector points; @@ -89,6 +89,8 @@ bool cgal_3d_point_sort (Point_d a,Point_d b) { } BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { + // check that for random weighted 3d points in safe mode the 3D and dD codes give the same result with some tolerance + // Random points construction using Kernel_dD = CGAL::Epeck_d< CGAL::Dimension_tag<3> >; using Bare_point_d = typename Kernel_dD::Point_d; @@ -186,17 +188,25 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { } } -BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_non_visible_points) { - using Point_d = typename Exact_kernel_d::Point_d; +using list_of_1d_kernel_variants = boost::mpl::list, + CGAL::Epeck_d< CGAL::Dimension_tag<1>>, + CGAL::Epick_d< CGAL::Dynamic_dimension_tag >, + CGAL::Epick_d< CGAL::Dimension_tag<1>> + >; + +BOOST_AUTO_TEST_CASE_TEMPLATE(Weighted_alpha_complex_non_visible_points, Kernel, list_of_1d_kernel_variants) { + // check that for 2 closed weighted 1-d points, one with a high weight to hide the second one with a small weight, + // that the point with a small weight has the same high filtration value than the edge formed by the 2 points + using Point_d = typename Kernel::Point_d; std::vector points; std::vector p1 {0.}; points.emplace_back(p1.begin(), p1.end()); // closed enough points std::vector p2 {0.1}; points.emplace_back(p2.begin(), p2.end()); - std::vector weights {100., 0.01}; + std::vector weights {100., 0.01}; - Gudhi::alpha_complex::Alpha_complex alpha_complex(points, weights); + Gudhi::alpha_complex::Alpha_complex alpha_complex(points, weights); Gudhi::Simplex_tree<> stree; BOOST_CHECK(alpha_complex.create_complex(stree)); -- cgit v1.2.3 From baaf350869dbd5ff78e22cc4c3de9b8ab35b75ba Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 3 Nov 2020 11:56:52 +0100 Subject: code review: use relative error --- src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp index 2cd66963..3df76dbf 100644 --- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp @@ -179,8 +179,8 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { std::clog << std::endl; BOOST_CHECK(false); } - // I had to make a hard limit as it is converted from Kernel::FT - if (std::fabs(d3_itr->second - dD_itr->second) > 1e-5) { + // In safe mode, relative error is less than 1e-5 (can be changed with set_relative_precision_of_to_double) + if (std::fabs(d3_itr->second - dD_itr->second) / std::fabs(d3_itr->second) > 1e-5) { std::clog << d3_itr->second << " versus " << dD_itr->second << " diff " << std::fabs(d3_itr->second - dD_itr->second) << std::endl; BOOST_CHECK(false); } -- cgit v1.2.3 From 05e28e39717c4ca5871b13a350c4b142ec9a173b Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 3 Nov 2020 14:09:05 +0100 Subject: code review: use Marc's trick to test relative error --- .../test/Weighted_alpha_complex_unit_test.cpp | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp index 3df76dbf..d267276c 100644 --- a/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_alpha_complex_unit_test.cpp @@ -49,31 +49,32 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Zero_weighted_alpha_complex, Kernel, list_of_exact // Alpha complex from points Gudhi::alpha_complex::Alpha_complex alpha_complex_from_points(points); Gudhi::Simplex_tree<> simplex; - BOOST_CHECK(alpha_complex_from_points.create_complex(simplex, std::numeric_limits::Filtration_value>::infinity(), true)); - std::clog << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; + Gudhi::Simplex_tree<>::Filtration_value infty = std::numeric_limits::Filtration_value>::infinity(); + BOOST_CHECK(alpha_complex_from_points.create_complex(simplex, infty, true)); + std::clog << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" + << std::endl; for (auto f_simplex : simplex.filtration_simplex_range()) { std::clog << " ( "; for (auto vertex : simplex.simplex_vertex_range(f_simplex)) { std::clog << vertex << " "; } - std::clog << ") -> " << "[" << simplex.filtration(f_simplex) << "] "; - std::clog << std::endl; + std::clog << ") -> " << "[" << simplex.filtration(f_simplex) << "] " << std::endl; } // Alpha complex from zero weighted points std::vector weights(20, 0.); Gudhi::alpha_complex::Alpha_complex alpha_complex_from_zero_weighted_points(points, weights); Gudhi::Simplex_tree<> zw_simplex; - BOOST_CHECK(alpha_complex_from_zero_weighted_points.create_complex(zw_simplex, std::numeric_limits::Filtration_value>::infinity(), true)); + BOOST_CHECK(alpha_complex_from_zero_weighted_points.create_complex(zw_simplex, infty, true)); - std::clog << "Iterator on zero weighted alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; + std::clog << "Iterator on zero weighted alpha complex simplices in the filtration order, with [filtration value]:" + << std::endl; for (auto f_simplex : zw_simplex.filtration_simplex_range()) { std::clog << " ( "; for (auto vertex : zw_simplex.simplex_vertex_range(f_simplex)) { std::clog << vertex << " "; } - std::clog << ") -> " << "[" << zw_simplex.filtration(f_simplex) << "] "; - std::clog << std::endl; + std::clog << ") -> " << "[" << zw_simplex.filtration(f_simplex) << "] " << std::endl; } BOOST_CHECK(zw_simplex == simplex); @@ -125,7 +126,8 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { Gudhi::Simplex_tree<> w_simplex_d; BOOST_CHECK(alpha_complex_dD_from_weighted_points.create_complex(w_simplex_d)); - std::clog << "Iterator on weighted alpha complex dD simplices in the filtration order, with [filtration value]:" << std::endl; + std::clog << "Iterator on weighted alpha complex dD simplices in the filtration order, with [filtration value]:" + << std::endl; for (auto f_simplex : w_simplex_d.filtration_simplex_range()) { Points points; for (auto vertex : w_simplex_d.simplex_vertex_range(f_simplex)) { @@ -148,7 +150,8 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { Gudhi::Simplex_tree<> w_simplex_3; BOOST_CHECK(alpha_complex_3D_from_weighted_points.create_complex(w_simplex_3)); - std::clog << "Iterator on weighted alpha complex 3D simplices in the filtration order, with [filtration value]:" << std::endl; + std::clog << "Iterator on weighted alpha complex 3D simplices in the filtration order, with [filtration value]:" + << std::endl; for (auto f_simplex : w_simplex_3.filtration_simplex_range()) { Points points; for (auto vertex : w_simplex_3.simplex_vertex_range(f_simplex)) { @@ -161,8 +164,7 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { for (auto point : points) { std::clog << point[0] << " " << point[1] << " " << point[2] << " | "; } - std::clog << ") -> " << "[" << w_simplex_3.filtration(f_simplex) << "] "; - std::clog << std::endl; + std::clog << ") -> " << "[" << w_simplex_3.filtration(f_simplex) << "] " << std::endl; pts_fltr_3d[points] = w_simplex_d.filtration(f_simplex); } @@ -180,8 +182,9 @@ BOOST_AUTO_TEST_CASE(Weighted_alpha_complex_3d_comparison) { BOOST_CHECK(false); } // In safe mode, relative error is less than 1e-5 (can be changed with set_relative_precision_of_to_double) - if (std::fabs(d3_itr->second - dD_itr->second) / std::fabs(d3_itr->second) > 1e-5) { - std::clog << d3_itr->second << " versus " << dD_itr->second << " diff " << std::fabs(d3_itr->second - dD_itr->second) << std::endl; + if (std::fabs(d3_itr->second - dD_itr->second) > 1e-5 * (std::fabs(d3_itr->second) + std::fabs(dD_itr->second))) { + std::clog << d3_itr->second << " versus " << dD_itr->second << " diff " + << std::fabs(d3_itr->second - dD_itr->second) << std::endl; BOOST_CHECK(false); } ++dD_itr; @@ -210,18 +213,17 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Weighted_alpha_complex_non_visible_points, Kernel, Gudhi::Simplex_tree<> stree; BOOST_CHECK(alpha_complex.create_complex(stree)); - std::clog << "Iterator on weighted alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; + std::clog << "Iterator on weighted alpha complex simplices in the filtration order, with [filtration value]:" + << std::endl; for (auto f_simplex : stree.filtration_simplex_range()) { std::clog << " ( "; for (auto vertex : stree.simplex_vertex_range(f_simplex)) { std::clog << vertex << " "; } - std::clog << ") -> " << "[" << stree.filtration(f_simplex) << "] "; - std::clog << std::endl; + std::clog << ") -> " << "[" << stree.filtration(f_simplex) << "] " << std::endl; } BOOST_CHECK(stree.filtration(stree.find({0})) == -100.); BOOST_CHECK(stree.filtration(stree.find({1})) == stree.filtration(stree.find({0, 1}))); BOOST_CHECK(stree.filtration(stree.find({1})) > 100000); - } \ No newline at end of file -- cgit v1.2.3 From 2d4c69d698df7e40709ec0e38463b4cf30ee388d Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 3 Nov 2020 17:39:07 +0100 Subject: Fix #416 by adding full path to introduction.rst - maybe strange with conda or pip installation --- src/python/setup.py.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/setup.py.in b/src/python/setup.py.in index 98d058fc..1d6745fd 100644 --- a/src/python/setup.py.in +++ b/src/python/setup.py.in @@ -65,7 +65,7 @@ for module in pybind11_modules: )) # read the contents of introduction.rst -with open("introduction.rst", "r") as fh: +with open("@CMAKE_CURRENT_BINARY_DIR@/introduction.rst", "r") as fh: long_description = fh.read() setup( -- cgit v1.2.3 From 85c66c66e6c8dfe9ba74b3bfa0012a550e8466ec Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 3 Nov 2020 17:39:51 +0100 Subject: Fix #415 by removing all install cmake targets from examples --- src/Bitmap_cubical_complex/example/CMakeLists.txt | 2 -- src/Nerve_GIC/example/CMakeLists.txt | 3 --- src/Persistence_representations/example/CMakeLists.txt | 6 ------ src/Persistent_cohomology/example/CMakeLists.txt | 7 ------- src/Rips_complex/example/CMakeLists.txt | 5 ----- src/Skeleton_blocker/example/CMakeLists.txt | 4 ---- src/Spatial_searching/example/CMakeLists.txt | 1 - src/Subsampling/example/CMakeLists.txt | 5 ----- src/Tangential_complex/example/CMakeLists.txt | 2 -- src/Witness_complex/example/CMakeLists.txt | 7 ------- 10 files changed, 42 deletions(-) diff --git a/src/Bitmap_cubical_complex/example/CMakeLists.txt b/src/Bitmap_cubical_complex/example/CMakeLists.txt index dc659f2d..0ff290ef 100644 --- a/src/Bitmap_cubical_complex/example/CMakeLists.txt +++ b/src/Bitmap_cubical_complex/example/CMakeLists.txt @@ -6,5 +6,3 @@ if (TBB_FOUND) endif() add_test(NAME Bitmap_cubical_complex_example_random COMMAND $ "2" "100" "100") - -install(TARGETS Random_bitmap_cubical_complex DESTINATION bin) diff --git a/src/Nerve_GIC/example/CMakeLists.txt b/src/Nerve_GIC/example/CMakeLists.txt index 1667472f..4b0f4677 100644 --- a/src/Nerve_GIC/example/CMakeLists.txt +++ b/src/Nerve_GIC/example/CMakeLists.txt @@ -22,7 +22,4 @@ if (NOT CGAL_VERSION VERSION_LESS 4.11.0) "${CMAKE_CURRENT_BINARY_DIR}/lucky_cat.off" "${CMAKE_CURRENT_BINARY_DIR}/lucky_cat_PCA1") - install(TARGETS CoordGIC DESTINATION bin) - install(TARGETS FuncGIC DESTINATION bin) - endif (NOT CGAL_VERSION VERSION_LESS 4.11.0) diff --git a/src/Persistence_representations/example/CMakeLists.txt b/src/Persistence_representations/example/CMakeLists.txt index a7c6ef39..997f85dc 100644 --- a/src/Persistence_representations/example/CMakeLists.txt +++ b/src/Persistence_representations/example/CMakeLists.txt @@ -3,30 +3,24 @@ project(Persistence_representations_example) add_executable ( Persistence_representations_example_landscape_on_grid persistence_landscape_on_grid.cpp ) add_test(NAME Persistence_representations_example_landscape_on_grid COMMAND $) -install(TARGETS Persistence_representations_example_landscape_on_grid DESTINATION bin) add_executable ( Persistence_representations_example_landscape persistence_landscape.cpp ) add_test(NAME Persistence_representations_example_landscape COMMAND $) -install(TARGETS Persistence_representations_example_landscape DESTINATION bin) add_executable ( Persistence_representations_example_intervals persistence_intervals.cpp ) add_test(NAME Persistence_representations_example_intervals COMMAND $ "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers") -install(TARGETS Persistence_representations_example_intervals DESTINATION bin) add_executable ( Persistence_representations_example_vectors persistence_vectors.cpp ) add_test(NAME Persistence_representations_example_vectors COMMAND $) -install(TARGETS Persistence_representations_example_vectors DESTINATION bin) add_executable ( Persistence_representations_example_heat_maps persistence_heat_maps.cpp ) add_test(NAME Persistence_representations_example_heat_maps COMMAND $) -install(TARGETS Persistence_representations_example_heat_maps DESTINATION bin) add_executable ( Sliced_Wasserstein sliced_wasserstein.cpp ) add_test(NAME Sliced_Wasserstein COMMAND $) -install(TARGETS Sliced_Wasserstein DESTINATION bin) diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index d6a92ed6..c68c6524 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -5,7 +5,6 @@ if (TBB_FOUND) target_link_libraries(plain_homology ${TBB_LIBRARIES}) endif() add_test(NAME Persistent_cohomology_example_plain_homology COMMAND $) -install(TARGETS plain_homology DESTINATION bin) add_executable(persistence_from_simple_simplex_tree persistence_from_simple_simplex_tree.cpp) if (TBB_FOUND) @@ -13,7 +12,6 @@ if (TBB_FOUND) endif() add_test(NAME Persistent_cohomology_example_from_simple_simplex_tree COMMAND $ "1" "0") -install(TARGETS persistence_from_simple_simplex_tree DESTINATION bin) if(TARGET Boost::program_options) add_executable(rips_persistence_step_by_step rips_persistence_step_by_step.cpp) @@ -23,7 +21,6 @@ if(TARGET Boost::program_options) endif() add_test(NAME Persistent_cohomology_example_from_rips_step_by_step_on_tore_3D COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.25" "-m" "0.5" "-d" "3" "-p" "3") - install(TARGETS rips_persistence_step_by_step DESTINATION bin) endif() if(TARGET Boost::program_options) @@ -34,7 +31,6 @@ if(TARGET Boost::program_options) endif() add_test(NAME Persistent_cohomology_example_via_boundary_matrix COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/Kl.off" "-r" "0.16" "-d" "3" "-p" "3" "-m" "100") - install(TARGETS rips_persistence_via_boundary_matrix DESTINATION bin) endif() if(TARGET Boost::program_options) @@ -47,7 +43,6 @@ if(TARGET Boost::program_options) "${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/bunny_5000_complex.fsc" "-p" "2" "-m" "0") add_test(NAME Persistent_cohomology_example_from_file_3_3_100 COMMAND $ "${CMAKE_SOURCE_DIR}/data/filtered_simplicial_complex/bunny_5000_complex.fsc" "-p" "3" "-m" "100") - install(TARGETS persistence_from_file DESTINATION bin) endif() if(GMP_FOUND) @@ -61,7 +56,6 @@ if(GMP_FOUND) endif(TBB_FOUND) add_test(NAME Persistent_cohomology_example_multifield_2_71 COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.25" "-m" "0.5" "-d" "3" "-p" "2" "-q" "71") - install(TARGETS rips_multifield_persistence DESTINATION bin) endif() endif(GMPXX_FOUND) endif(GMP_FOUND) @@ -73,5 +67,4 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) target_link_libraries(custom_persistence_sort ${TBB_LIBRARIES}) endif(TBB_FOUND) add_test(NAME Persistent_cohomology_example_custom_persistence_sort COMMAND $) - install(TARGETS custom_persistence_sort DESTINATION bin) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) diff --git a/src/Rips_complex/example/CMakeLists.txt b/src/Rips_complex/example/CMakeLists.txt index 244a93ec..206f4c11 100644 --- a/src/Rips_complex/example/CMakeLists.txt +++ b/src/Rips_complex/example/CMakeLists.txt @@ -72,8 +72,3 @@ if (DIFF_PATH) endif() -install(TARGETS Rips_complex_example_from_off DESTINATION bin) -install(TARGETS Rips_complex_example_one_skeleton_from_points DESTINATION bin) -install(TARGETS Rips_complex_example_one_skeleton_from_distance_matrix DESTINATION bin) -install(TARGETS Rips_complex_example_from_csv_distance_matrix DESTINATION bin) -install(TARGETS Rips_complex_example_one_skeleton_rips_from_correlation_matrix DESTINATION bin) diff --git a/src/Skeleton_blocker/example/CMakeLists.txt b/src/Skeleton_blocker/example/CMakeLists.txt index 0e5d2f11..456612df 100644 --- a/src/Skeleton_blocker/example/CMakeLists.txt +++ b/src/Skeleton_blocker/example/CMakeLists.txt @@ -7,7 +7,3 @@ add_executable(Skeleton_blocker_example_link Skeleton_blocker_link.cpp) add_test(NAME Skeleton_blocker_example_from_simplices COMMAND $) add_test(NAME Skeleton_blocker_example_iteration COMMAND $) add_test(NAME Skeleton_blocker_example_link COMMAND $) - -install(TARGETS Skeleton_blocker_example_from_simplices DESTINATION bin) -install(TARGETS Skeleton_blocker_example_iteration DESTINATION bin) -install(TARGETS Skeleton_blocker_example_link DESTINATION bin) diff --git a/src/Spatial_searching/example/CMakeLists.txt b/src/Spatial_searching/example/CMakeLists.txt index eeb3e85f..308afa00 100644 --- a/src/Spatial_searching/example/CMakeLists.txt +++ b/src/Spatial_searching/example/CMakeLists.txt @@ -5,5 +5,4 @@ if(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) target_link_libraries(Spatial_searching_example_spatial_searching ${CGAL_LIBRARY}) add_test(NAME Spatial_searching_example_spatial_searching COMMAND $) - install(TARGETS Spatial_searching_example_spatial_searching DESTINATION bin) endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) diff --git a/src/Subsampling/example/CMakeLists.txt b/src/Subsampling/example/CMakeLists.txt index 28aab103..dfac055c 100644 --- a/src/Subsampling/example/CMakeLists.txt +++ b/src/Subsampling/example/CMakeLists.txt @@ -14,9 +14,4 @@ if(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) add_test(NAME Subsampling_example_sparsify_point_set COMMAND $) - install(TARGETS Subsampling_example_pick_n_random_points DESTINATION bin) - install(TARGETS Subsampling_example_choose_n_farthest_points DESTINATION bin) - install(TARGETS Subsampling_example_custom_kernel DESTINATION bin) - install(TARGETS Subsampling_example_sparsify_point_set DESTINATION bin) - endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) diff --git a/src/Tangential_complex/example/CMakeLists.txt b/src/Tangential_complex/example/CMakeLists.txt index cb1486a4..b66b5f39 100644 --- a/src/Tangential_complex/example/CMakeLists.txt +++ b/src/Tangential_complex/example/CMakeLists.txt @@ -15,6 +15,4 @@ if(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) add_test(NAME Tangential_complex_example_with_perturb COMMAND $) - install(TARGETS Tangential_complex_example_basic DESTINATION bin) - install(TARGETS Tangential_complex_example_with_perturb DESTINATION bin) endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) diff --git a/src/Witness_complex/example/CMakeLists.txt b/src/Witness_complex/example/CMakeLists.txt index 2659798e..5e9736ed 100644 --- a/src/Witness_complex/example/CMakeLists.txt +++ b/src/Witness_complex/example/CMakeLists.txt @@ -7,8 +7,6 @@ endif() add_test(NAME Witness_complex_example_nearest_landmark_table COMMAND $) -install(TARGETS Witness_complex_example_nearest_landmark_table DESTINATION bin) - # CGAL and Eigen3 are required for Euclidean version of Witness if(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) add_executable( Witness_complex_example_off example_witness_complex_off.cpp ) @@ -33,10 +31,5 @@ if(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) add_test(NAME Witness_complex_example_strong_off_test_torus COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "20" "1.0" "3") - - install(TARGETS Witness_complex_example_off DESTINATION bin) - install(TARGETS Witness_complex_example_sphere DESTINATION bin) - install(TARGETS Witness_complex_example_strong_off DESTINATION bin) - endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) -- cgit v1.2.3 From ef30f636af892a2e226162af9072f0741caba886 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 3 Nov 2020 22:46:50 +0100 Subject: import matplotlib only when necessary in examples, in function of args. Tests are without matplotlib, so no need to test if present --- src/python/CMakeLists.txt | 76 ++++++++++------------ ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...arcode_persistence_from_perseus_file_example.py | 2 +- ...istence_from_correlation_matrix_file_example.py | 2 +- ...ersistence_from_distance_matrix_file_example.py | 2 +- ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...complex_plain_homology_from_off_file_example.py | 2 +- 9 files changed, 42 insertions(+), 50 deletions(-) diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index c09996fe..1f101d87 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -345,29 +345,27 @@ if(PYTHONINTERP_FOUND) COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_rips_persistence_bottleneck_distance.py" -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -t 0.15 -d 3) - if(MATPLOTLIB_FOUND AND NUMPY_FOUND) - # Tangential - add_test(NAME tangential_complex_plain_homology_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/tangential_complex_plain_homology_from_off_file_example.py" - --no-diagram -i 2 -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off) + # Tangential + add_test(NAME tangential_complex_plain_homology_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/tangential_complex_plain_homology_from_off_file_example.py" + --no-diagram -i 2 -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off) add_gudhi_py_test(test_tangential_complex) - # Witness complex AND Subsampling - add_test(NAME euclidean_strong_witness_complex_diagram_persistence_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py" - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) - - add_test(NAME euclidean_witness_complex_diagram_persistence_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py" - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) - endif() + # Witness complex + add_test(NAME euclidean_strong_witness_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) + + add_test(NAME euclidean_witness_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) # Subsampling add_gudhi_py_test(test_subsampling) @@ -422,13 +420,11 @@ if(PYTHONINTERP_FOUND) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_complex_from_points_example.py") - if(MATPLOTLIB_FOUND AND NUMPY_FOUND) - add_test(NAME alpha_complex_diagram_persistence_from_off_file_example_py_test + add_test(NAME alpha_complex_diagram_persistence_from_off_file_example_py_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_complex_diagram_persistence_from_off_file_example.py" --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 0.6) - endif() add_gudhi_py_test(test_alpha_complex) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) @@ -445,30 +441,26 @@ if(PYTHONINTERP_FOUND) ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py" --no-barcode -f ${CMAKE_SOURCE_DIR}/data/bitmap/CubicalTwoSphere.txt) - if(NUMPY_FOUND) - add_test(NAME random_cubical_complex_persistence_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/random_cubical_complex_persistence_example.py" - 10 10 10) - endif() + add_test(NAME random_cubical_complex_persistence_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/random_cubical_complex_persistence_example.py" + 10 10 10) add_gudhi_py_test(test_cubical_complex) # Rips - if(MATPLOTLIB_FOUND AND NUMPY_FOUND) - add_test(NAME rips_complex_diagram_persistence_from_distance_matrix_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py" - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/distance_matrix/lower_triangular_distance_matrix.csv -e 12.0 -d 3) + add_test(NAME rips_complex_diagram_persistence_from_distance_matrix_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/distance_matrix/lower_triangular_distance_matrix.csv -e 12.0 -d 3) - add_test(NAME rips_complex_diagram_persistence_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_off_file_example.py - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -e 0.25 -d 3) - endif() + add_test(NAME rips_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_off_file_example.py + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -e 0.25 -d 3) add_test(NAME rips_complex_from_points_example_py_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py b/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py index 727af4fa..1e0273b3 100755 --- a/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py @@ -3,7 +3,6 @@ import argparse import errno import os -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -65,6 +64,7 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py b/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py index e1e572df..4e97cfe3 100755 --- a/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py @@ -3,7 +3,6 @@ import argparse import errno import os -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -82,6 +81,7 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py b/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py index 58cb2bb5..29076c74 100755 --- a/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py @@ -3,7 +3,6 @@ import argparse import errno import os -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -79,6 +78,7 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py b/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py index 499171df..ee3290c6 100755 --- a/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py +++ b/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import argparse -import matplotlib.pyplot as plot import errno import os import gudhi @@ -75,6 +74,7 @@ if is_file_perseus(args.file): print("betti_numbers()=") print(periodic_cubical_complex.betti_numbers()) if args.no_barcode == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_barcode(diag) plot.show() else: diff --git a/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py index 1acb187c..ea2eb7e1 100755 --- a/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py +++ b/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py @@ -2,7 +2,6 @@ import sys import argparse -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. @@ -84,5 +83,6 @@ invert_diag = [ ] if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(invert_diag, band=args.band) plot.show() diff --git a/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py index 79ccca96..236d085d 100755 --- a/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py +++ b/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import argparse -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. @@ -60,5 +59,6 @@ print("betti_numbers()=") print(simplex_tree.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() diff --git a/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py index 6f992508..e80233a9 100755 --- a/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py @@ -3,7 +3,6 @@ import argparse import errno import os -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -70,6 +69,7 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/tangential_complex_plain_homology_from_off_file_example.py b/src/python/example/tangential_complex_plain_homology_from_off_file_example.py index 85bade4a..a4b4e9f5 100755 --- a/src/python/example/tangential_complex_plain_homology_from_off_file_example.py +++ b/src/python/example/tangential_complex_plain_homology_from_off_file_example.py @@ -3,7 +3,6 @@ import argparse import errno import os -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -62,6 +61,7 @@ with open(args.file, "r") as f: print(st.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: -- cgit v1.2.3 From 4d26e7220bdd9a3f95beacd8a33b0fbda461ebfa Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 3 Nov 2020 22:49:56 +0100 Subject: Revert "import matplotlib only when necessary in examples, in function of args. Tests are without matplotlib, so no need to test if present" This reverts commit ef30f636af892a2e226162af9072f0741caba886. --- src/python/CMakeLists.txt | 76 ++++++++++++---------- ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...arcode_persistence_from_perseus_file_example.py | 2 +- ...istence_from_correlation_matrix_file_example.py | 2 +- ...ersistence_from_distance_matrix_file_example.py | 2 +- ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...complex_plain_homology_from_off_file_example.py | 2 +- 9 files changed, 50 insertions(+), 42 deletions(-) diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 1f101d87..c09996fe 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -345,27 +345,29 @@ if(PYTHONINTERP_FOUND) COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_rips_persistence_bottleneck_distance.py" -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -t 0.15 -d 3) - # Tangential - add_test(NAME tangential_complex_plain_homology_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/tangential_complex_plain_homology_from_off_file_example.py" - --no-diagram -i 2 -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off) + if(MATPLOTLIB_FOUND AND NUMPY_FOUND) + # Tangential + add_test(NAME tangential_complex_plain_homology_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/tangential_complex_plain_homology_from_off_file_example.py" + --no-diagram -i 2 -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off) add_gudhi_py_test(test_tangential_complex) - # Witness complex - add_test(NAME euclidean_strong_witness_complex_diagram_persistence_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py" - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) - - add_test(NAME euclidean_witness_complex_diagram_persistence_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py" - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) + # Witness complex AND Subsampling + add_test(NAME euclidean_strong_witness_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) + + add_test(NAME euclidean_witness_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) + endif() # Subsampling add_gudhi_py_test(test_subsampling) @@ -420,11 +422,13 @@ if(PYTHONINTERP_FOUND) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_complex_from_points_example.py") - add_test(NAME alpha_complex_diagram_persistence_from_off_file_example_py_test + if(MATPLOTLIB_FOUND AND NUMPY_FOUND) + add_test(NAME alpha_complex_diagram_persistence_from_off_file_example_py_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_complex_diagram_persistence_from_off_file_example.py" --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 0.6) + endif() add_gudhi_py_test(test_alpha_complex) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) @@ -441,26 +445,30 @@ if(PYTHONINTERP_FOUND) ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py" --no-barcode -f ${CMAKE_SOURCE_DIR}/data/bitmap/CubicalTwoSphere.txt) - add_test(NAME random_cubical_complex_persistence_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/random_cubical_complex_persistence_example.py" - 10 10 10) + if(NUMPY_FOUND) + add_test(NAME random_cubical_complex_persistence_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/random_cubical_complex_persistence_example.py" + 10 10 10) + endif() add_gudhi_py_test(test_cubical_complex) # Rips - add_test(NAME rips_complex_diagram_persistence_from_distance_matrix_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py" - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/distance_matrix/lower_triangular_distance_matrix.csv -e 12.0 -d 3) + if(MATPLOTLIB_FOUND AND NUMPY_FOUND) + add_test(NAME rips_complex_diagram_persistence_from_distance_matrix_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/distance_matrix/lower_triangular_distance_matrix.csv -e 12.0 -d 3) - add_test(NAME rips_complex_diagram_persistence_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_off_file_example.py - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -e 0.25 -d 3) + add_test(NAME rips_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_off_file_example.py + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -e 0.25 -d 3) + endif() add_test(NAME rips_complex_from_points_example_py_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py b/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py index 1e0273b3..727af4fa 100755 --- a/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py @@ -3,6 +3,7 @@ import argparse import errno import os +import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -64,7 +65,6 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: - import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py b/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py index 4e97cfe3..e1e572df 100755 --- a/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py @@ -3,6 +3,7 @@ import argparse import errno import os +import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -81,7 +82,6 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: - import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py b/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py index 29076c74..58cb2bb5 100755 --- a/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py @@ -3,6 +3,7 @@ import argparse import errno import os +import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -78,7 +79,6 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: - import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py b/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py index ee3290c6..499171df 100755 --- a/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py +++ b/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import argparse +import matplotlib.pyplot as plot import errno import os import gudhi @@ -74,7 +75,6 @@ if is_file_perseus(args.file): print("betti_numbers()=") print(periodic_cubical_complex.betti_numbers()) if args.no_barcode == False: - import matplotlib.pyplot as plot gudhi.plot_persistence_barcode(diag) plot.show() else: diff --git a/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py index ea2eb7e1..1acb187c 100755 --- a/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py +++ b/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py @@ -2,6 +2,7 @@ import sys import argparse +import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. @@ -83,6 +84,5 @@ invert_diag = [ ] if args.no_diagram == False: - import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(invert_diag, band=args.band) plot.show() diff --git a/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py index 236d085d..79ccca96 100755 --- a/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py +++ b/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import argparse +import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. @@ -59,6 +60,5 @@ print("betti_numbers()=") print(simplex_tree.betti_numbers()) if args.no_diagram == False: - import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() diff --git a/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py index e80233a9..6f992508 100755 --- a/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py @@ -3,6 +3,7 @@ import argparse import errno import os +import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -69,7 +70,6 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: - import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/tangential_complex_plain_homology_from_off_file_example.py b/src/python/example/tangential_complex_plain_homology_from_off_file_example.py index a4b4e9f5..85bade4a 100755 --- a/src/python/example/tangential_complex_plain_homology_from_off_file_example.py +++ b/src/python/example/tangential_complex_plain_homology_from_off_file_example.py @@ -3,6 +3,7 @@ import argparse import errno import os +import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -61,7 +62,6 @@ with open(args.file, "r") as f: print(st.betti_numbers()) if args.no_diagram == False: - import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: -- cgit v1.2.3 From a539b1a800b29ee1b67eb256b8f38558a0ee6995 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Wed, 4 Nov 2020 00:27:43 +0100 Subject: Build python first This subdirectory is built sequentially and takes a very long time. Starting it first, in a parallel build, it is still the last to end, but since it started earlier it also ends earlier. Usually I build the plugin directly with python3 setup.py build_ext --inplace -j20 But I don't think there is a natural way to do that from the makefile (except for the unlimited -j), since I doubt setuptools knows how to cooperate with make, ninja, etc to share a pool of workers. --- src/CMakeLists.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc230531..79ec42c1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,14 @@ include_directories(include) # Include module CMake subdirectories # GUDHI_SUB_DIRECTORIES is managed in CMAKE_MODULE_PATH/GUDHI_modules.cmake +if (WITH_GUDHI_PYTHON) + # specific for cython module + add_subdirectory(${GUDHI_PYTHON_PATH}) +else() + message("++ Python module will not be compiled because WITH_GUDHI_PYTHON is set to OFF") + set(GUDHI_MISSING_MODULES ${GUDHI_MISSING_MODULES} "python") +endif() + foreach(GUDHI_MODULE ${GUDHI_MODULES}) foreach(GUDHI_SUB_DIRECTORY ${GUDHI_SUB_DIRECTORIES}) if(EXISTS ${CMAKE_SOURCE_DIR}/${GUDHI_SUB_DIRECTORY}/${GUDHI_MODULE}/CMakeLists.txt) @@ -60,14 +68,6 @@ endforeach() add_subdirectory(GudhUI) -if (WITH_GUDHI_PYTHON) - # specific for cython module - add_subdirectory(${GUDHI_PYTHON_PATH}) -else() - message("++ Python module will not be compiled because WITH_GUDHI_PYTHON is set to OFF") - set(GUDHI_MISSING_MODULES ${GUDHI_MISSING_MODULES} "python") -endif() - message("++ GUDHI_MODULES list is:\"${GUDHI_MODULES}\"") message("++ GUDHI_MISSING_MODULES list is:\"${GUDHI_MISSING_MODULES}\"") -- cgit v1.2.3 From 7959734c6302e9b63e3b91780130c896127eaebe Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 4 Nov 2020 07:36:23 +0100 Subject: Revert "Fix #416 by adding full path to introduction.rst - maybe strange with conda or pip installation" This reverts commit 2d4c69d698df7e40709ec0e38463b4cf30ee388d. --- src/python/setup.py.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/setup.py.in b/src/python/setup.py.in index 1d6745fd..98d058fc 100644 --- a/src/python/setup.py.in +++ b/src/python/setup.py.in @@ -65,7 +65,7 @@ for module in pybind11_modules: )) # read the contents of introduction.rst -with open("@CMAKE_CURRENT_BINARY_DIR@/introduction.rst", "r") as fh: +with open("introduction.rst", "r") as fh: long_description = fh.read() setup( -- cgit v1.2.3 From 92361d9a117a33e0d922417cfbb2e1653f2537df Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 4 Nov 2020 07:58:01 +0100 Subject: import matplotlib only when necessary in examples, in function of args. Tests are without matplotlib, so no need to test if present --- src/python/CMakeLists.txt | 90 ++++++++++------------ ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...arcode_persistence_from_perseus_file_example.py | 2 +- ...istence_from_correlation_matrix_file_example.py | 2 +- ...ersistence_from_distance_matrix_file_example.py | 2 +- ...ex_diagram_persistence_from_off_file_example.py | 2 +- ...complex_plain_homology_from_off_file_example.py | 2 +- 9 files changed, 49 insertions(+), 57 deletions(-) diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index c09996fe..56b6876c 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -345,29 +345,27 @@ if(PYTHONINTERP_FOUND) COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_rips_persistence_bottleneck_distance.py" -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -t 0.15 -d 3) - if(MATPLOTLIB_FOUND AND NUMPY_FOUND) - # Tangential - add_test(NAME tangential_complex_plain_homology_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/tangential_complex_plain_homology_from_off_file_example.py" - --no-diagram -i 2 -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off) - - add_gudhi_py_test(test_tangential_complex) - - # Witness complex AND Subsampling - add_test(NAME euclidean_strong_witness_complex_diagram_persistence_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py" - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) - - add_test(NAME euclidean_witness_complex_diagram_persistence_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py" - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) - endif() + # Tangential + add_test(NAME tangential_complex_plain_homology_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/tangential_complex_plain_homology_from_off_file_example.py" + --no-diagram -i 2 -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off) + + add_gudhi_py_test(test_tangential_complex) + + # Witness complex + add_test(NAME euclidean_strong_witness_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) + + add_test(NAME euclidean_witness_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 1.0 -n 20 -d 2) # Subsampling add_gudhi_py_test(test_subsampling) @@ -422,13 +420,11 @@ if(PYTHONINTERP_FOUND) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_complex_from_points_example.py") - if(MATPLOTLIB_FOUND AND NUMPY_FOUND) - add_test(NAME alpha_complex_diagram_persistence_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_complex_diagram_persistence_from_off_file_example.py" - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 0.6) - endif() + add_test(NAME alpha_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/alpha_complex_diagram_persistence_from_off_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -a 0.6) add_gudhi_py_test(test_alpha_complex) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) @@ -445,30 +441,26 @@ if(PYTHONINTERP_FOUND) ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py" --no-barcode -f ${CMAKE_SOURCE_DIR}/data/bitmap/CubicalTwoSphere.txt) - if(NUMPY_FOUND) - add_test(NAME random_cubical_complex_persistence_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/random_cubical_complex_persistence_example.py" - 10 10 10) - endif() + add_test(NAME random_cubical_complex_persistence_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/random_cubical_complex_persistence_example.py" + 10 10 10) add_gudhi_py_test(test_cubical_complex) # Rips - if(MATPLOTLIB_FOUND AND NUMPY_FOUND) - add_test(NAME rips_complex_diagram_persistence_from_distance_matrix_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py" - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/distance_matrix/lower_triangular_distance_matrix.csv -e 12.0 -d 3) + add_test(NAME rips_complex_diagram_persistence_from_distance_matrix_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py" + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/distance_matrix/lower_triangular_distance_matrix.csv -e 12.0 -d 3) - add_test(NAME rips_complex_diagram_persistence_from_off_file_example_py_test - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_off_file_example.py - --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -e 0.25 -d 3) - endif() + add_test(NAME rips_complex_diagram_persistence_from_off_file_example_py_test + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example/rips_complex_diagram_persistence_from_off_file_example.py + --no-diagram -f ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off -e 0.25 -d 3) add_test(NAME rips_complex_from_points_example_py_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py b/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py index 727af4fa..1e0273b3 100755 --- a/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py @@ -3,7 +3,6 @@ import argparse import errno import os -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -65,6 +64,7 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py b/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py index e1e572df..4e97cfe3 100755 --- a/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py @@ -3,7 +3,6 @@ import argparse import errno import os -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -82,6 +81,7 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py b/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py index 58cb2bb5..29076c74 100755 --- a/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py @@ -3,7 +3,6 @@ import argparse import errno import os -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -79,6 +78,7 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py b/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py index 499171df..ee3290c6 100755 --- a/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py +++ b/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import argparse -import matplotlib.pyplot as plot import errno import os import gudhi @@ -75,6 +74,7 @@ if is_file_perseus(args.file): print("betti_numbers()=") print(periodic_cubical_complex.betti_numbers()) if args.no_barcode == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_barcode(diag) plot.show() else: diff --git a/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py index 1acb187c..ea2eb7e1 100755 --- a/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py +++ b/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py @@ -2,7 +2,6 @@ import sys import argparse -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. @@ -84,5 +83,6 @@ invert_diag = [ ] if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(invert_diag, band=args.band) plot.show() diff --git a/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py index 79ccca96..236d085d 100755 --- a/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py +++ b/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import argparse -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. @@ -60,5 +59,6 @@ print("betti_numbers()=") print(simplex_tree.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() diff --git a/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py index 6f992508..e80233a9 100755 --- a/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py +++ b/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py @@ -3,7 +3,6 @@ import argparse import errno import os -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -70,6 +69,7 @@ with open(args.file, "r") as f: print(simplex_tree.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: diff --git a/src/python/example/tangential_complex_plain_homology_from_off_file_example.py b/src/python/example/tangential_complex_plain_homology_from_off_file_example.py index 85bade4a..a4b4e9f5 100755 --- a/src/python/example/tangential_complex_plain_homology_from_off_file_example.py +++ b/src/python/example/tangential_complex_plain_homology_from_off_file_example.py @@ -3,7 +3,6 @@ import argparse import errno import os -import matplotlib.pyplot as plot import gudhi """ This file is part of the Gudhi Library - https://gudhi.inria.fr/ - @@ -62,6 +61,7 @@ with open(args.file, "r") as f: print(st.betti_numbers()) if args.no_diagram == False: + import matplotlib.pyplot as plot gudhi.plot_persistence_diagram(diag, band=args.band) plot.show() else: -- cgit v1.2.3