Alpha_kernel_d.h
1 /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2  * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3  * Author(s): Vincent Rouvreau
4  *
5  * Copyright (C) 2020 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef ALPHA_COMPLEX_ALPHA_KERNEL_D_H_
12 #define ALPHA_COMPLEX_ALPHA_KERNEL_D_H_
13 
14 #include <CGAL/version.h> // for CGAL_VERSION_NR
15 
16 #include <Eigen/Core> // for EIGEN_VERSION_AT_LEAST
17 
18 #include <utility> // for std::make_pair
19 
20 // Make compilation fail - required for external projects - https://github.com/GUDHI/gudhi-devel/issues/10
21 #if CGAL_VERSION_NR < 1041101000
22 # error Alpha_complex is only available for CGAL >= 4.11
23 #endif
24 
25 #if !EIGEN_VERSION_AT_LEAST(3,1,0)
26 # error Alpha_complex is only available for Eigen3 >= 3.1.0 installed with CGAL
27 #endif
28 
29 namespace Gudhi {
30 
31 namespace alpha_complex {
32 
41 template < typename Kernel, bool Weighted = false >
43 };
44 
45 // Unweighted Kernel_d version
46 template < typename Kernel >
47 class Alpha_kernel_d<Kernel, false> {
48  private:
49  // Kernel for functions access.
50  Kernel kernel_;
51  public:
52  // Fake type for compilation to succeed (cf. std::conditional in Alpha_complex.h)
53  using Weighted_point_d = void;
54  using Point_d = typename Kernel::Point_d;
55  // Numeric type of coordinates in the kernel
56  using FT = typename Kernel::FT;
57  // Sphere is a pair of point and squared radius.
58  using Sphere = typename std::pair<Point_d, FT>;
59 
60  int get_dimension(const Point_d& p0) const {
61  return kernel_.point_dimension_d_object()(p0);
62  }
63 
64  template<class PointIterator>
65  Sphere get_sphere(PointIterator begin, PointIterator end) const {
66  Point_d c = kernel_.construct_circumcenter_d_object()(begin, end);
67  FT r = kernel_.squared_distance_d_object()(c, *begin);
68  return std::make_pair(std::move(c), std::move(r));
69  }
70 
71  template<class PointIterator>
72  FT get_squared_radius(PointIterator begin, PointIterator end) const {
73  return kernel_.compute_squared_radius_d_object()(begin, end);
74  }
75 
76  FT get_squared_radius(const Sphere& sph) const {
77  return sph.second;
78  }
79 
80  bool is_gabriel(const Sphere& circumcenter, const Point_d& point) {
81  return kernel_.squared_distance_d_object()(circumcenter.first, point) >= circumcenter.second;
82  }
83 };
84 
85 // Weighted Kernel_d version
86 template < typename Kernel >
87 class Alpha_kernel_d<Kernel, true> {
88  private:
89  // Kernel for functions access.
90  Kernel kernel_;
91 
92  public:
93  // Fake type for compilation to succeed (cf. std::conditional in Alpha_complex.h)
94  using Point_d = void;
95  using Weighted_point_d = typename Kernel::Weighted_point_d;
96  using Bare_point_d = typename Kernel::Point_d;
97  // Numeric type of coordinates in the kernel
98  using FT = typename Kernel::FT;
99  // Sphere is a weighted point (point + weight [= squared radius]).
100  using Sphere = Weighted_point_d;
101 
102  int get_dimension(const Weighted_point_d& p0) const {
103  return kernel_.point_dimension_d_object()(p0.point());
104  }
105 
106  template<class PointIterator>
107  Sphere get_sphere(PointIterator begin, PointIterator end) const {
108  // power_center_d_object has been renamed between CGAL 5.1 and 5.2
109 #if CGAL_VERSION_NR < 1050200000
110  return kernel_.power_center_d_object()(begin, end);
111 #else
112  return kernel_.construct_power_sphere_d_object()(begin, end);
113 #endif
114  }
115 
116  template<class PointIterator>
117  FT get_squared_radius(PointIterator begin, PointIterator end) const {
118  return kernel_.compute_squared_radius_smallest_orthogonal_sphere_d_object()(begin, end);
119  }
120 
121  FT get_squared_radius(const Sphere& sph) const {
122  return sph.weight();
123  }
124 
125  bool is_gabriel(const Sphere& circumcenter, const Weighted_point_d& point) {
126  // power_center_d_object has been renamed between CGAL 5.1 and 5.2
127 #if CGAL_VERSION_NR < 1050200000
128  return kernel_.power_distance_d_object()(circumcenter, point) >= 0;
129 #else
130  return kernel_.compute_power_product_d_object()(circumcenter, point) >= 0;
131 #endif
132  }
133 };
134 
135 } // namespace alpha_complex
136 
137 namespace alphacomplex = alpha_complex;
138 
139 } // namespace Gudhi
140 
141 #endif // ALPHA_COMPLEX_ALPHA_KERNEL_D_H_
Definition: SimplicialComplexForAlpha.h:14
Alpha complex kernel container.
Definition: Alpha_kernel_d.h:42
GUDHI  Version 3.4.1  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Fri Jan 22 2021 09:41:15 for GUDHI by Doxygen 1.8.13