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') 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