From 10ca6a70ba7ffea5c65d9c045b624da3d4200a63 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 15 Jun 2020 07:52:15 +0200 Subject: Factory to build python alpha complex. 3d version of alpha complex. Needs change in doc as alphacomplexdoc.off is a fake 3d off data file --- src/python/include/Alpha_complex_factory.h | 144 +++++++++++++++++++++++++++ src/python/include/Alpha_complex_interface.h | 74 ++++---------- 2 files changed, 163 insertions(+), 55 deletions(-) create mode 100644 src/python/include/Alpha_complex_factory.h (limited to 'src/python/include') diff --git a/src/python/include/Alpha_complex_factory.h b/src/python/include/Alpha_complex_factory.h new file mode 100644 index 00000000..7cab73bd --- /dev/null +++ b/src/python/include/Alpha_complex_factory.h @@ -0,0 +1,144 @@ +/* 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 INCLUDE_ALPHA_COMPLEX_FACTORY_H_ +#define INCLUDE_ALPHA_COMPLEX_FACTORY_H_ + +#include +#include +#include +#include +#include +#include + +#include + +#include "Simplex_tree_interface.h" + +#include +#include +#include +#include // for std::unique_ptr + +namespace Gudhi { + +namespace alpha_complex { + +template +std::vector pt_cgal_to_cython(CgalPointType& point) { + std::vector vd; + for (auto coord = point.cartesian_begin(); coord != point.cartesian_end(); coord++) + vd.push_back(CGAL::to_double(*coord)); + return vd; +} + +template +static CgalPointType pt_cython_to_cgal(std::vector const& vec) { + return CgalPointType(vec.size(), vec.begin(), vec.end()); +} + +class Abstract_alpha_complex { + public: + virtual std::vector get_point(int vh) = 0; + virtual void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + bool default_filtration_value) = 0; +}; + +class Exact_Alphacomplex_dD : public Abstract_alpha_complex { + private: + using Exact_kernel = CGAL::Epeck_d; + using Point_exact_kernel = typename Exact_kernel::Point_d; + + public: + Exact_Alphacomplex_dD(const std::vector>& points, bool exact_version) + : exact_version_(exact_version) { + ac_exact_ptr_ = std::make_unique>( + boost::adaptors::transform(points, pt_cython_to_cgal)); + } + + std::vector get_point(int vh) { + Point_exact_kernel const& point = ac_exact_ptr_->get_point(vh); + return pt_cgal_to_cython(point); + } + + void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + bool default_filtration_value){ + ac_exact_ptr_->create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); + } + + private: + bool exact_version_; + std::unique_ptr> ac_exact_ptr_; +}; + +class Inexact_Alphacomplex_dD : public Abstract_alpha_complex { + private: + using Inexact_kernel = CGAL::Epick_d; + using Point_inexact_kernel = typename Inexact_kernel::Point_d; + + public: + Inexact_Alphacomplex_dD(const std::vector>& points, bool exact_version) + : exact_version_(exact_version) { + ac_inexact_ptr_ = std::make_unique>( + boost::adaptors::transform(points, pt_cython_to_cgal)); + } + + std::vector get_point(int vh) { + Point_inexact_kernel const& point = ac_inexact_ptr_->get_point(vh); + return pt_cgal_to_cython(point); + } + void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + bool default_filtration_value){ + ac_inexact_ptr_->create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); + } + + private: + bool exact_version_; + std::unique_ptr> ac_inexact_ptr_; +}; + +template +class Alphacomplex_3D : public Abstract_alpha_complex { + private: + using Point_3 = typename Alpha_complex_3d::Bare_point_3; + + static Point_3 pt_cython_to_cgal_3(std::vector const& vec) { + return Point_3(vec[0], vec[1], vec[2]); + } + + public: + Alphacomplex_3D(const std::vector>& points) { + alpha3d_ptr_ = std::make_unique>( + boost::adaptors::transform(points, pt_cython_to_cgal_3)); + } + + std::vector get_point(int vh) { + Point_3 const& point = alpha3d_ptr_->get_point(vh); + return pt_cgal_to_cython(point); + } + + void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + bool default_filtration_value){ + alpha3d_ptr_->create_complex(*simplex_tree, max_alpha_square); + if (default_filtration_value) { + // TODO + } + } + + private: + std::unique_ptr> alpha3d_ptr_; +}; + + +} // namespace alpha_complex + +} // namespace Gudhi + +#endif // INCLUDE_ALPHA_COMPLEX_FACTORY_H_ diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h index 3ac5db1f..c4b9df4b 100644 --- a/src/python/include/Alpha_complex_interface.h +++ b/src/python/include/Alpha_complex_interface.h @@ -11,12 +11,8 @@ #ifndef INCLUDE_ALPHA_COMPLEX_INTERFACE_H_ #define INCLUDE_ALPHA_COMPLEX_INTERFACE_H_ -#include -#include -#include -#include - -#include +#include "Alpha_complex_factory.h" +#include #include "Simplex_tree_interface.h" @@ -30,67 +26,35 @@ namespace Gudhi { namespace alpha_complex { class Alpha_complex_interface { - private: - using Exact_kernel = CGAL::Epeck_d; - using Inexact_kernel = CGAL::Epick_d; - using Point_exact_kernel = typename Exact_kernel::Point_d; - using Point_inexact_kernel = typename Inexact_kernel::Point_d; - - template - std::vector pt_cgal_to_cython(CgalPointType& point) { - std::vector vd; - for (auto coord = point.cartesian_begin(); coord != point.cartesian_end(); coord++) - vd.push_back(CGAL::to_double(*coord)); - return vd; - } - - template - static CgalPointType pt_cython_to_cgal(std::vector const& vec) { - return CgalPointType(vec.size(), vec.begin(), vec.end()); - } - public: - Alpha_complex_interface(const std::vector>& points, bool fast_version) - : fast_version_(fast_version) { - if (fast_version_) { - ac_inexact_ptr_ = std::make_unique>( - boost::adaptors::transform(points, pt_cython_to_cgal)); + Alpha_complex_interface(const std::vector>& points, bool fast_version, bool exact_version) { + if (points[0].size() == 3) { + if (fast_version) + alpha_ptr_ = std::make_unique>(points); + else if (exact_version) + alpha_ptr_ = std::make_unique>(points); + else + alpha_ptr_ = std::make_unique>(points); } else { - ac_exact_ptr_ = std::make_unique>( - boost::adaptors::transform(points, pt_cython_to_cgal)); + if (fast_version) { + alpha_ptr_ = std::make_unique(points, exact_version); + } else { + alpha_ptr_ = std::make_unique(points, exact_version); + } } } - Alpha_complex_interface(const std::string& off_file_name, bool fast_version, bool from_file = true) - : fast_version_(fast_version) { - if (fast_version_) - ac_inexact_ptr_ = std::make_unique>(off_file_name); - else - ac_exact_ptr_ = std::make_unique>(off_file_name); - } - std::vector get_point(int vh) { - if (fast_version_) { - Point_inexact_kernel const& point = ac_inexact_ptr_->get_point(vh); - return pt_cgal_to_cython(point); - } else { - Point_exact_kernel const& point = ac_exact_ptr_->get_point(vh); - return pt_cgal_to_cython(point); - } + return alpha_ptr_->get_point(vh); } - void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool exact_version, + void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool default_filtration_value) { - if (fast_version_) - ac_inexact_ptr_->create_complex(*simplex_tree, max_alpha_square, exact_version, default_filtration_value); - else - ac_exact_ptr_->create_complex(*simplex_tree, max_alpha_square, exact_version, default_filtration_value); + alpha_ptr_->create_simplex_tree(simplex_tree, max_alpha_square, default_filtration_value); } private: - bool fast_version_; - std::unique_ptr> ac_exact_ptr_; - std::unique_ptr> ac_inexact_ptr_; + std::unique_ptr alpha_ptr_; }; } // namespace alpha_complex -- cgit v1.2.3 From eceabc8d9d682cb1c93db8d52594c4bbf243c71e Mon Sep 17 00:00:00 2001 From: Vincent Rouvreau <10407034+VincentRouvreau@users.noreply.github.com> Date: Tue, 16 Jun 2020 01:52:53 -0700 Subject: Update src/python/include/Alpha_complex_factory.h Co-authored-by: Marc Glisse --- src/python/include/Alpha_complex_factory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/python/include') diff --git a/src/python/include/Alpha_complex_factory.h b/src/python/include/Alpha_complex_factory.h index 7cab73bd..d7bf3617 100644 --- a/src/python/include/Alpha_complex_factory.h +++ b/src/python/include/Alpha_complex_factory.h @@ -32,7 +32,7 @@ namespace Gudhi { namespace alpha_complex { template -std::vector pt_cgal_to_cython(CgalPointType& point) { +std::vector pt_cgal_to_cython(CgalPointType const& point) { std::vector vd; for (auto coord = point.cartesian_begin(); coord != point.cartesian_end(); coord++) vd.push_back(CGAL::to_double(*coord)); -- cgit v1.2.3 From 8014dac407f1cce2ce4082902adb1409e4987013 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 16 Jun 2020 11:22:30 +0200 Subject: Code review: check point is not empty. vector reserve. Kernel and Point type for all classes --- src/python/include/Alpha_complex_factory.h | 48 +++++++++++++--------------- src/python/include/Alpha_complex_interface.h | 2 +- 2 files changed, 24 insertions(+), 26 deletions(-) (limited to 'src/python/include') diff --git a/src/python/include/Alpha_complex_factory.h b/src/python/include/Alpha_complex_factory.h index d7bf3617..69b584c5 100644 --- a/src/python/include/Alpha_complex_factory.h +++ b/src/python/include/Alpha_complex_factory.h @@ -34,6 +34,7 @@ namespace alpha_complex { template std::vector pt_cgal_to_cython(CgalPointType const& point) { std::vector vd; + vd.reserve(point.dimension()); for (auto coord = point.cartesian_begin(); coord != point.cartesian_end(); coord++) vd.push_back(CGAL::to_double(*coord)); return vd; @@ -53,87 +54,84 @@ class Abstract_alpha_complex { class Exact_Alphacomplex_dD : public Abstract_alpha_complex { private: - using Exact_kernel = CGAL::Epeck_d; - using Point_exact_kernel = typename Exact_kernel::Point_d; + using Kernel = CGAL::Epeck_d; + using Point = typename Kernel::Point_d; public: Exact_Alphacomplex_dD(const std::vector>& points, bool exact_version) - : exact_version_(exact_version) { - ac_exact_ptr_ = std::make_unique>( - boost::adaptors::transform(points, pt_cython_to_cgal)); + : exact_version_(exact_version), + alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal)) { } std::vector get_point(int vh) { - Point_exact_kernel const& point = ac_exact_ptr_->get_point(vh); + Point const& point = alpha_complex_.get_point(vh); return pt_cgal_to_cython(point); } void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool default_filtration_value){ - ac_exact_ptr_->create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); + alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); } private: bool exact_version_; - std::unique_ptr> ac_exact_ptr_; + Alpha_complex alpha_complex_; }; class Inexact_Alphacomplex_dD : public Abstract_alpha_complex { private: - using Inexact_kernel = CGAL::Epick_d; - using Point_inexact_kernel = typename Inexact_kernel::Point_d; + using Kernel = CGAL::Epick_d; + using Point = typename Kernel::Point_d; public: Inexact_Alphacomplex_dD(const std::vector>& points, bool exact_version) - : exact_version_(exact_version) { - ac_inexact_ptr_ = std::make_unique>( - boost::adaptors::transform(points, pt_cython_to_cgal)); + : exact_version_(exact_version), + alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal)) { } std::vector get_point(int vh) { - Point_inexact_kernel const& point = ac_inexact_ptr_->get_point(vh); + Point const& point = alpha_complex_.get_point(vh); return pt_cgal_to_cython(point); } void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool default_filtration_value){ - ac_inexact_ptr_->create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); + alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); } private: bool exact_version_; - std::unique_ptr> ac_inexact_ptr_; + Alpha_complex alpha_complex_; }; template class Alphacomplex_3D : public Abstract_alpha_complex { private: - using Point_3 = typename Alpha_complex_3d::Bare_point_3; + using Point = typename Alpha_complex_3d::Bare_point_3; - static Point_3 pt_cython_to_cgal_3(std::vector const& vec) { - return Point_3(vec[0], vec[1], vec[2]); + static Point pt_cython_to_cgal_3(std::vector const& vec) { + return Point(vec[0], vec[1], vec[2]); } public: - Alphacomplex_3D(const std::vector>& points) { - alpha3d_ptr_ = std::make_unique>( - boost::adaptors::transform(points, pt_cython_to_cgal_3)); + Alphacomplex_3D(const std::vector>& points) + : alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal_3)) { } std::vector get_point(int vh) { - Point_3 const& point = alpha3d_ptr_->get_point(vh); + Point const& point = alpha_complex_.get_point(vh); return pt_cgal_to_cython(point); } void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool default_filtration_value){ - alpha3d_ptr_->create_complex(*simplex_tree, max_alpha_square); + alpha_complex_.create_complex(*simplex_tree, max_alpha_square); if (default_filtration_value) { // TODO } } private: - std::unique_ptr> alpha3d_ptr_; + Alpha_complex_3d alpha_complex_; }; diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h index c4b9df4b..0b946f8e 100644 --- a/src/python/include/Alpha_complex_interface.h +++ b/src/python/include/Alpha_complex_interface.h @@ -28,7 +28,7 @@ namespace alpha_complex { class Alpha_complex_interface { public: Alpha_complex_interface(const std::vector>& points, bool fast_version, bool exact_version) { - if (points[0].size() == 3) { + if (points.size() > 0 && points[0].size() == 3) { if (fast_version) alpha_ptr_ = std::make_unique>(points); else if (exact_version) -- cgit v1.2.3 From dc9fc58500cc9f1be70e0d34a24cb634d4fc6c34 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Fri, 19 Jun 2020 20:29:46 +0200 Subject: When 3d points are on a 2d plane case - Fixes also default_filtration_value=True in 3d --- src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 4 ++ src/python/include/Alpha_complex_factory.h | 17 ++++---- src/python/include/Alpha_complex_interface.h | 47 ++++++++++++++-------- 3 files changed, 42 insertions(+), 26 deletions(-) (limited to 'src/python/include') diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index c19ebb79..c29905f4 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -471,6 +471,10 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ #ifdef DEBUG_TRACES std::clog << "filtration_with_alpha_values returns : " << objects.size() << " objects" << std::endl; #endif // DEBUG_TRACES + if (objects.size() == 0) { + std::cerr << "Alpha_complex_3d create_complex - no triangulation as points are on a 2d plane\n"; + return false; // ----- >> + } using Alpha_value_iterator = typename std::vector::const_iterator; Alpha_value_iterator alpha_value_iterator = alpha_values.begin(); diff --git a/src/python/include/Alpha_complex_factory.h b/src/python/include/Alpha_complex_factory.h index 69b584c5..7d98f454 100644 --- a/src/python/include/Alpha_complex_factory.h +++ b/src/python/include/Alpha_complex_factory.h @@ -48,7 +48,7 @@ static CgalPointType pt_cython_to_cgal(std::vector const& vec) { class Abstract_alpha_complex { public: virtual std::vector get_point(int vh) = 0; - virtual void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool default_filtration_value) = 0; }; @@ -68,9 +68,9 @@ class Exact_Alphacomplex_dD : public Abstract_alpha_complex { return pt_cgal_to_cython(point); } - void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool default_filtration_value){ - alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); + return alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); } private: @@ -93,9 +93,9 @@ class Inexact_Alphacomplex_dD : public Abstract_alpha_complex { Point const& point = alpha_complex_.get_point(vh); return pt_cgal_to_cython(point); } - void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool default_filtration_value){ - alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); + return alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); } private: @@ -122,12 +122,9 @@ class Alphacomplex_3D : public Abstract_alpha_complex { return pt_cgal_to_cython(point); } - void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool default_filtration_value){ - alpha_complex_.create_complex(*simplex_tree, max_alpha_square); - if (default_filtration_value) { - // TODO - } + return alpha_complex_.create_complex(*simplex_tree, max_alpha_square); } private: diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h index 0b946f8e..604ff85e 100644 --- a/src/python/include/Alpha_complex_interface.h +++ b/src/python/include/Alpha_complex_interface.h @@ -27,21 +27,10 @@ namespace alpha_complex { class Alpha_complex_interface { public: - Alpha_complex_interface(const std::vector>& points, bool fast_version, bool exact_version) { - if (points.size() > 0 && points[0].size() == 3) { - if (fast_version) - alpha_ptr_ = std::make_unique>(points); - else if (exact_version) - alpha_ptr_ = std::make_unique>(points); - else - alpha_ptr_ = std::make_unique>(points); - } else { - if (fast_version) { - alpha_ptr_ = std::make_unique(points, exact_version); - } else { - alpha_ptr_ = std::make_unique(points, exact_version); - } - } + Alpha_complex_interface(const std::vector>& points, bool fast_version, bool exact_version) + : points_(points.begin(), points.end()), + fast_version_(fast_version), + exact_version_(exact_version) { } std::vector get_point(int vh) { @@ -50,11 +39,37 @@ class Alpha_complex_interface { void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool default_filtration_value) { - alpha_ptr_->create_simplex_tree(simplex_tree, max_alpha_square, default_filtration_value); + if (points_.size() > 0) { + std::size_t dimension = points_[0].size(); + if (dimension == 3 && !default_filtration_value) { + if (fast_version_) + alpha_ptr_ = std::make_unique>(points_); + else if (exact_version_) + alpha_ptr_ = std::make_unique>(points_); + else + alpha_ptr_ = std::make_unique>(points_); + if (!alpha_ptr_->create_simplex_tree(simplex_tree, max_alpha_square, default_filtration_value)) { + // create_simplex_tree will fail if all points are on a 2d plane - Retry with dimension 2 + dimension--; + } + } + // Not ** else ** because we have to take into account if 3d fails + if (dimension != 3 || default_filtration_value) { + if (fast_version_) { + alpha_ptr_ = std::make_unique(points_, exact_version_); + } else { + alpha_ptr_ = std::make_unique(points_, exact_version_); + } + alpha_ptr_->create_simplex_tree(simplex_tree, max_alpha_square, default_filtration_value); + } + } } private: std::unique_ptr alpha_ptr_; + std::vector> points_; + bool fast_version_; + bool exact_version_; }; } // namespace alpha_complex -- cgit v1.2.3 From 0b27bb3fe7e6d876a9db60223ab7d4b61c15c3f5 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Sun, 21 Jun 2020 08:40:25 +0200 Subject: Add tests for 3d points on a plane --- src/python/include/Alpha_complex_interface.h | 3 +- src/python/test/test_alpha_complex.py | 48 +++++++++++++++++----------- 2 files changed, 31 insertions(+), 20 deletions(-) (limited to 'src/python/include') diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h index 604ff85e..38533a08 100644 --- a/src/python/include/Alpha_complex_interface.h +++ b/src/python/include/Alpha_complex_interface.h @@ -49,8 +49,9 @@ class Alpha_complex_interface { else alpha_ptr_ = std::make_unique>(points_); if (!alpha_ptr_->create_simplex_tree(simplex_tree, max_alpha_square, default_filtration_value)) { - // create_simplex_tree will fail if all points are on a 2d plane - Retry with dimension 2 + // create_simplex_tree will fail if all points are on a plane - Retry with dD by setting dimension to 2 dimension--; + alpha_ptr_.reset(); } } // Not ** else ** because we have to take into account if 3d fails diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py index 943ad2c4..1aca23fc 100755 --- a/src/python/test/test_alpha_complex.py +++ b/src/python/test/test_alpha_complex.py @@ -8,7 +8,7 @@ - YYYY/MM Author: Description of the modification """ -from gudhi import AlphaComplex, SimplexTree +import gudhi import math import numpy as np import pytest @@ -25,17 +25,16 @@ __license__ = "MIT" def _empty_alpha(precision): - alpha_complex = AlphaComplex(points=[[0, 0]], precision = precision) + alpha_complex = gudhi.AlphaComplex(points=[[0, 0]], precision = precision) assert alpha_complex.__is_defined() == True def test_empty_alpha(): - _empty_alpha('fast') - _empty_alpha('safe') - _empty_alpha('exact') + for precision in ['fast', 'safe', 'exact']: + _empty_alpha(precision) def _infinite_alpha(precision): point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - alpha_complex = AlphaComplex(points=point_list, precision = precision) + alpha_complex = gudhi.AlphaComplex(points=point_list, precision = precision) assert alpha_complex.__is_defined() == True simplex_tree = alpha_complex.create_simplex_tree() @@ -84,13 +83,12 @@ def _infinite_alpha(precision): assert False def test_infinite_alpha(): - _infinite_alpha('fast') - _infinite_alpha('safe') - _infinite_alpha('exact') + for precision in ['fast', 'safe', 'exact']: + _infinite_alpha(precision) def _filtered_alpha(precision): point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - filtered_alpha = AlphaComplex(points=point_list, precision = precision) + filtered_alpha = gudhi.AlphaComplex(points=point_list, precision = precision) simplex_tree = filtered_alpha.create_simplex_tree(max_alpha_square=0.25) @@ -128,9 +126,8 @@ def _filtered_alpha(precision): assert simplex_tree.get_cofaces([0], 1) == [([0, 1], 0.25), ([0, 2], 0.25)] def test_filtered_alpha(): - _filtered_alpha('fast') - _filtered_alpha('safe') - _filtered_alpha('exact') + for precision in ['fast', 'safe', 'exact']: + _filtered_alpha(precision) def _safe_alpha_persistence_comparison(precision): #generate periodic signal @@ -144,10 +141,10 @@ def _safe_alpha_persistence_comparison(precision): embedding2 = [[signal[i], delayed[i]] for i in range(len(time))] #build alpha complex and simplex tree - alpha_complex1 = AlphaComplex(points=embedding1, precision = precision) + alpha_complex1 = gudhi.AlphaComplex(points=embedding1, precision = precision) simplex_tree1 = alpha_complex1.create_simplex_tree() - alpha_complex2 = AlphaComplex(points=embedding2, precision = precision) + alpha_complex2 = gudhi.AlphaComplex(points=embedding2, precision = precision) simplex_tree2 = alpha_complex2.create_simplex_tree() diag1 = simplex_tree1.persistence() @@ -165,7 +162,7 @@ def test_safe_alpha_persistence_comparison(): def _delaunay_complex(precision): point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - filtered_alpha = AlphaComplex(points=point_list, precision = precision) + filtered_alpha = gudhi.AlphaComplex(points=point_list, precision = precision) simplex_tree = filtered_alpha.create_simplex_tree(default_filtration_value = True) @@ -197,6 +194,19 @@ def _delaunay_complex(precision): assert math.isnan(filtered_value[1]) def test_delaunay_complex(): - _delaunay_complex('fast') - _delaunay_complex('safe') - _delaunay_complex('exact') + for precision in ['fast', 'safe', 'exact']: + _delaunay_complex(precision) + +def _3d_points_on_a_plane(precision, default_filtration_value): + alpha = gudhi.AlphaComplex(off_file=gudhi.__root_source_dir__ + '/data/points/alphacomplexdoc.off', + precision = precision) + + simplex_tree = alpha.create_simplex_tree(default_filtration_value = default_filtration_value) + assert simplex_tree.dimension() == 2 + assert simplex_tree.num_vertices() == 7 + assert simplex_tree.num_simplices() == 25 + +def test_3d_points_on_a_plane(): + for default_filtration_value in [True, False]: + for precision in ['fast', 'safe', 'exact']: + _3d_points_on_a_plane(precision, default_filtration_value) \ No newline at end of file -- cgit v1.2.3 From 627dfd9116890ae4cb1fc181ad37952607ea08d6 Mon Sep 17 00:00:00 2001 From: Vincent Rouvreau <10407034+VincentRouvreau@users.noreply.github.com> Date: Mon, 29 Jun 2020 08:30:38 -0700 Subject: Code review: points ctor Co-authored-by: Marc Glisse --- src/python/include/Alpha_complex_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/python/include') diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h index 38533a08..23be194d 100644 --- a/src/python/include/Alpha_complex_interface.h +++ b/src/python/include/Alpha_complex_interface.h @@ -28,7 +28,7 @@ namespace alpha_complex { class Alpha_complex_interface { public: Alpha_complex_interface(const std::vector>& points, bool fast_version, bool exact_version) - : points_(points.begin(), points.end()), + : points_(points), fast_version_(fast_version), exact_version_(exact_version) { } -- cgit v1.2.3 From 7ed01ff1d89256038e0cfb0e2d86815437e55545 Mon Sep 17 00:00:00 2001 From: Vincent Rouvreau <10407034+VincentRouvreau@users.noreply.github.com> Date: Mon, 29 Jun 2020 08:35:22 -0700 Subject: Code review: override is a good practice Co-authored-by: Marc Glisse --- src/python/include/Alpha_complex_factory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/python/include') diff --git a/src/python/include/Alpha_complex_factory.h b/src/python/include/Alpha_complex_factory.h index 7d98f454..b0e9dc93 100644 --- a/src/python/include/Alpha_complex_factory.h +++ b/src/python/include/Alpha_complex_factory.h @@ -63,7 +63,7 @@ class Exact_Alphacomplex_dD : public Abstract_alpha_complex { alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal)) { } - std::vector get_point(int vh) { + std::vector get_point(int vh) override { Point const& point = alpha_complex_.get_point(vh); return pt_cgal_to_cython(point); } -- cgit v1.2.3 From 54309849264b5f5ab61e11031044d135c0bb9aa5 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 1 Jul 2020 22:33:35 +0200 Subject: Code review: let's use override as a good practice --- src/python/include/Alpha_complex_factory.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/python/include') diff --git a/src/python/include/Alpha_complex_factory.h b/src/python/include/Alpha_complex_factory.h index b0e9dc93..d699ad9b 100644 --- a/src/python/include/Alpha_complex_factory.h +++ b/src/python/include/Alpha_complex_factory.h @@ -63,13 +63,13 @@ class Exact_Alphacomplex_dD : public Abstract_alpha_complex { alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal)) { } - std::vector get_point(int vh) override { + virtual std::vector get_point(int vh) override { Point const& point = alpha_complex_.get_point(vh); return pt_cgal_to_cython(point); } - bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, - bool default_filtration_value){ + virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + bool default_filtration_value) override { return alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); } @@ -89,12 +89,12 @@ class Inexact_Alphacomplex_dD : public Abstract_alpha_complex { alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal)) { } - std::vector get_point(int vh) { + virtual std::vector get_point(int vh) override { Point const& point = alpha_complex_.get_point(vh); return pt_cgal_to_cython(point); } - bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, - bool default_filtration_value){ + virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + bool default_filtration_value) override { return alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value); } @@ -117,13 +117,13 @@ class Alphacomplex_3D : public Abstract_alpha_complex { : alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal_3)) { } - std::vector get_point(int vh) { + virtual std::vector get_point(int vh) override { Point const& point = alpha_complex_.get_point(vh); return pt_cgal_to_cython(point); } - bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, - bool default_filtration_value){ + virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, + bool default_filtration_value) override { return alpha_complex_.create_complex(*simplex_tree, max_alpha_square); } -- cgit v1.2.3