diff options
author | ROUVREAU Vincent <vincent.rouvreau@inria.fr> | 2021-04-07 16:47:34 +0200 |
---|---|---|
committer | ROUVREAU Vincent <vincent.rouvreau@inria.fr> | 2021-04-07 16:47:34 +0200 |
commit | d79ef2f79c33d8e8b8fd88e16f30e16433ab6644 (patch) | |
tree | 3f7642c750a71883361bdef85975d5c43c5f882d | |
parent | e4381a3e2ad79d3150cd03704bef3fc006e7c54b (diff) |
alpha complex python module requires cgal 5.1 for weighted version. Alpha complex factory does not require a weighted specific version for alpha complex dD
-rw-r--r-- | src/python/CMakeLists.txt | 12 | ||||
-rw-r--r-- | src/python/include/Alpha_complex_factory.h | 102 | ||||
-rw-r--r-- | src/python/include/Alpha_complex_interface.h | 13 |
3 files changed, 46 insertions, 81 deletions
diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 307181b7..0739d7b5 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -156,13 +156,15 @@ if(PYTHONINTERP_FOUND) set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'nerve_gic', ") endif () if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) - set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'alpha_complex', ") set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'alpha_complex_3d', ") set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'subsampling', ") set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'tangential_complex', ") set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'euclidean_witness_complex', ") set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'euclidean_strong_witness_complex', ") endif () + if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) + set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'alpha_complex', ") + endif () if(CGAL_FOUND) # Add CGAL compilation args @@ -345,13 +347,15 @@ if(PYTHONINTERP_FOUND) # Test examples - if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) + if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) # Bottleneck and Alpha add_test(NAME alpha_rips_persistence_bottleneck_distance_py_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E env "${GUDHI_PYTHON_PATH_ENV}" ${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) + endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) + if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) # Tangential add_test(NAME tangential_complex_plain_homology_from_off_file_example_py_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} @@ -421,7 +425,7 @@ if(PYTHONINTERP_FOUND) add_gudhi_py_test(test_cover_complex) endif (NOT CGAL_VERSION VERSION_LESS 4.11.0) - if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) + if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 5.1.0) # Alpha add_test(NAME alpha_complex_from_points_example_py_test WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} @@ -433,7 +437,7 @@ if(PYTHONINTERP_FOUND) ${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) add_gudhi_py_test(test_alpha_complex) - 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_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) # Euclidean witness diff --git a/src/python/include/Alpha_complex_factory.h b/src/python/include/Alpha_complex_factory.h index 5d3bfb65..7d45af7c 100644 --- a/src/python/include/Alpha_complex_factory.h +++ b/src/python/include/Alpha_complex_factory.h @@ -31,9 +31,11 @@ namespace Gudhi { namespace alpha_complex { +// template Functor that transforms a CGAL point to a vector of double as expected by cython template<typename CgalPointType, bool Weighted> struct Point_cgal_to_cython; +// Specialized Unweighted Functor template<typename CgalPointType> struct Point_cgal_to_cython<CgalPointType, false> { std::vector<double> operator()(CgalPointType const& point) const @@ -46,6 +48,7 @@ struct Point_cgal_to_cython<CgalPointType, false> { } }; +// Specialized Weighted Functor template<typename CgalPointType> struct Point_cgal_to_cython<CgalPointType, true> { std::vector<double> operator()(CgalPointType const& weighted_point) const @@ -59,15 +62,7 @@ struct Point_cgal_to_cython<CgalPointType, true> { } }; -template <typename CgalPointType> -std::vector<double> pt_cgal_to_cython(CgalPointType const& point) { - std::vector<double> 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; -} - +// Function that transforms a cython point (aka. a vector of double) to a CGAL point template <typename CgalPointType> static CgalPointType pt_cython_to_cgal(std::vector<double> const& vec) { return CgalPointType(vec.size(), vec.begin(), vec.end()); @@ -83,20 +78,29 @@ class Abstract_alpha_complex { virtual ~Abstract_alpha_complex() = default; }; +template <bool Weighted = false> class Exact_alpha_complex_dD final : public Abstract_alpha_complex { private: using Kernel = CGAL::Epeck_d<CGAL::Dynamic_dimension_tag>; - using Point = typename Kernel::Point_d; + using Bare_point = typename Kernel::Point_d; + using Point = std::conditional_t<Weighted, typename Kernel::Weighted_point_d, + typename Kernel::Point_d>; public: Exact_alpha_complex_dD(const std::vector<std::vector<double>>& points, bool exact_version) : exact_version_(exact_version), - alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal<Point>)) { + alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal<Bare_point>)) { + } + + Exact_alpha_complex_dD(const std::vector<std::vector<double>>& points, + const std::vector<double>& weights, bool exact_version) + : exact_version_(exact_version), + alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal<Bare_point>), weights) { } virtual std::vector<double> get_point(int vh) override { - Point const& point = alpha_complex_.get_point(vh); - return pt_cgal_to_cython(point); + // Can be a Weighted or a Bare point in function of Weighted + return Point_cgal_to_cython<Point, Weighted>()(alpha_complex_.get_point(vh)); } virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, @@ -106,76 +110,32 @@ class Exact_alpha_complex_dD final : public Abstract_alpha_complex { private: bool exact_version_; - Alpha_complex<Kernel> alpha_complex_; + Alpha_complex<Kernel, Weighted> alpha_complex_; }; +template <bool Weighted = false> class Inexact_alpha_complex_dD final : public Abstract_alpha_complex { private: using Kernel = CGAL::Epick_d<CGAL::Dynamic_dimension_tag>; - using Point = typename Kernel::Point_d; + using Bare_point = typename Kernel::Point_d; + using Point = std::conditional_t<Weighted, typename Kernel::Weighted_point_d, + typename Kernel::Point_d>; public: Inexact_alpha_complex_dD(const std::vector<std::vector<double>>& points, bool exact_version) : exact_version_(exact_version), - alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal<Point>)) { - } - - virtual std::vector<double> get_point(int vh) override { - Point const& point = alpha_complex_.get_point(vh); - return pt_cgal_to_cython(point); - } - 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); - } - - private: - bool exact_version_; - Alpha_complex<Kernel> alpha_complex_; -}; - -class Exact_weighted_alpha_complex_dD final : public Abstract_alpha_complex { - private: - using Kernel = CGAL::Epeck_d<CGAL::Dynamic_dimension_tag>; - using Point = typename Kernel::Point_d; - - public: - Exact_weighted_alpha_complex_dD(const std::vector<std::vector<double>>& points, - const std::vector<double>& weights, bool exact_version) - : exact_version_(exact_version), - alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal<Point>), weights) { - } - - virtual std::vector<double> get_point(int vh) override { - Point const& point = alpha_complex_.get_point(vh).point(); - return pt_cgal_to_cython(point); - } - - 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); + alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal<Bare_point>)) { } - private: - bool exact_version_; - Alpha_complex<Kernel, true> alpha_complex_; -}; - -class Inexact_weighted_alpha_complex_dD final : public Abstract_alpha_complex { - private: - using Kernel = CGAL::Epick_d<CGAL::Dynamic_dimension_tag>; - using Point = typename Kernel::Point_d; - - public: - Inexact_weighted_alpha_complex_dD(const std::vector<std::vector<double>>& points, - const std::vector<double>& weights, bool exact_version) + Inexact_alpha_complex_dD(const std::vector<std::vector<double>>& points, + const std::vector<double>& weights, bool exact_version) : exact_version_(exact_version), - alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal<Point>), weights) { + alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal<Bare_point>), weights) { } virtual std::vector<double> get_point(int vh) override { - Point const& point = alpha_complex_.get_point(vh).point(); - return pt_cgal_to_cython(point); + // Can be a Weighted or a Bare point in function of Weighted + return Point_cgal_to_cython<Point, Weighted>()(alpha_complex_.get_point(vh)); } virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, bool default_filtration_value) override { @@ -184,7 +144,7 @@ class Inexact_weighted_alpha_complex_dD final : public Abstract_alpha_complex { private: bool exact_version_; - Alpha_complex<Kernel, true> alpha_complex_; + Alpha_complex<Kernel, Weighted> alpha_complex_; }; template <complexity Complexity, bool Weighted = false> @@ -207,8 +167,8 @@ class Alpha_complex_3D final : public Abstract_alpha_complex { } virtual std::vector<double> get_point(int vh) override { - Point const& point = alpha_complex_.get_point(vh); - return Point_cgal_to_cython<Point, Weighted>()(point); + // Can be a Weighted or a Bare point in function of Weighted + return Point_cgal_to_cython<Point, Weighted>()(alpha_complex_.get_point(vh)); } virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h index 31a8147b..ed243f19 100644 --- a/src/python/include/Alpha_complex_interface.h +++ b/src/python/include/Alpha_complex_interface.h @@ -31,17 +31,18 @@ class Alpha_complex_interface { const std::vector<double>& weights, bool fast_version, bool exact_version) : empty_point_set_(points.size() == 0) { + const bool weighted = (weights.size() > 0); if (fast_version) { - if (weights.size() == 0) { - alpha_ptr_ = std::make_unique<Inexact_alpha_complex_dD>(points, exact_version); + if (weighted) { + alpha_ptr_ = std::make_unique<Inexact_alpha_complex_dD<true>>(points, weights, exact_version); } else { - alpha_ptr_ = std::make_unique<Inexact_weighted_alpha_complex_dD>(points, weights, exact_version); + alpha_ptr_ = std::make_unique<Inexact_alpha_complex_dD<false>>(points, exact_version); } } else { - if (weights.size() == 0) { - alpha_ptr_ = std::make_unique<Exact_alpha_complex_dD>(points, exact_version); + if (weighted) { + alpha_ptr_ = std::make_unique<Exact_alpha_complex_dD<true>>(points, weights, exact_version); } else { - alpha_ptr_ = std::make_unique<Exact_weighted_alpha_complex_dD>(points, weights, exact_version); + alpha_ptr_ = std::make_unique<Exact_alpha_complex_dD<false>>(points, exact_version); } } } |