From c7b82f49f01075519189f1fdb56cc485e4ad9f46 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Thu, 21 May 2020 11:08:25 +0200 Subject: Use unique_pointer and template alpha complex interface for python interface --- .../utilities/alpha_complex_persistence.cpp | 1 + src/python/gudhi/alpha_complex.pyx | 2 +- src/python/include/Alpha_complex_interface.h | 18 +++++++++--------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp index 7c898dfd..e17831d9 100644 --- a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include diff --git a/src/python/gudhi/alpha_complex.pyx b/src/python/gudhi/alpha_complex.pyx index d75e374a..2b7ce00d 100644 --- a/src/python/gudhi/alpha_complex.pyx +++ b/src/python/gudhi/alpha_complex.pyx @@ -26,7 +26,7 @@ __copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Alpha_complex_interface.h" namespace "Gudhi": - cdef cppclass Alpha_complex_interface "Gudhi::alpha_complex::Alpha_complex_interface": + cdef cppclass Alpha_complex_interface "Gudhi::alpha_complex::Alpha_complex_interface": Alpha_complex_interface(vector[vector[double]] points) nogil except + # bool from_file is a workaround for cython to find the correct signature Alpha_complex_interface(string off_file, bool from_file) nogil except + diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h index 40de88f3..5fb694cd 100644 --- a/src/python/include/Alpha_complex_interface.h +++ b/src/python/include/Alpha_complex_interface.h @@ -23,29 +23,29 @@ #include #include #include +#include // for std::unique_ptr namespace Gudhi { namespace alpha_complex { +using Exact_kernel = CGAL::Epeck_d< CGAL::Dynamic_dimension_tag >; +using Inexact_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; + +template class Alpha_complex_interface { - using Dynamic_kernel = CGAL::Epeck_d< CGAL::Dynamic_dimension_tag >; - using Point_d = Dynamic_kernel::Point_d; + using Point_d = typename Kernel::Point_d; public: Alpha_complex_interface(const std::vector>& points) { auto mkpt = [](std::vector const& vec){ return Point_d(vec.size(), vec.begin(), vec.end()); }; - alpha_complex_ = new Alpha_complex(boost::adaptors::transform(points, mkpt)); + alpha_complex_ = std::make_unique>(boost::adaptors::transform(points, mkpt)); } Alpha_complex_interface(const std::string& off_file_name, bool from_file = true) { - alpha_complex_ = new Alpha_complex(off_file_name); - } - - ~Alpha_complex_interface() { - delete alpha_complex_; + alpha_complex_ = std::make_unique>(off_file_name); } std::vector get_point(int vh) { @@ -61,7 +61,7 @@ class Alpha_complex_interface { } private: - Alpha_complex* alpha_complex_; + std::unique_ptr> alpha_complex_; }; } // namespace alpha_complex -- cgit v1.2.3