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
29namespace Gudhi {
30
31namespace alpha_complex {
32
41template < typename Kernel, bool Weighted = false >
43};
44
45// Unweighted Kernel_d version
46template < typename Kernel >
47class Alpha_kernel_d<Kernel, false> {
48 private:
49 // Kernel for functions access.
50 Kernel kernel_;
51
52 public:
53 // Fake type for compilation to succeed (cf. std::conditional in Alpha_complex.h)
54 using Weighted_point_d = void;
55 using Point_d = typename Kernel::Point_d;
56 // Numeric type of coordinates in the kernel
57 using FT = typename Kernel::FT;
58 // Sphere is a pair of point and squared radius.
59 using Sphere = typename std::pair<Point_d, FT>;
60
61 int get_dimension(const Point_d& p0) const {
62 return kernel_.point_dimension_d_object()(p0);
63 }
64
65 template<class PointIterator>
66 Sphere get_sphere(PointIterator begin, PointIterator end) const {
67 Point_d c = kernel_.construct_circumcenter_d_object()(begin, end);
68 FT r = kernel_.squared_distance_d_object()(c, *begin);
69 return std::make_pair(std::move(c), std::move(r));
70 }
71
72 template<class PointIterator>
73 FT get_squared_radius(PointIterator begin, PointIterator end) const {
74 return kernel_.compute_squared_radius_d_object()(begin, end);
75 }
76
77 FT get_squared_radius(const Sphere& sph) const {
78 return sph.second;
79 }
80
81 bool is_gabriel(const Sphere& circumcenter, const Point_d& point) {
82 return kernel_.squared_distance_d_object()(circumcenter.first, point) >= circumcenter.second;
83 }
84};
85
86// Weighted Kernel_d version
87template < typename Kernel >
88class Alpha_kernel_d<Kernel, true> {
89 private:
90 // Kernel for functions access.
91 Kernel kernel_;
92
93 public:
94 // Fake type for compilation to succeed (cf. std::conditional in Alpha_complex.h)
95 using Point_d = void;
96 using Weighted_point_d = typename Kernel::Weighted_point_d;
97 using Bare_point_d = typename Kernel::Point_d;
98 // Numeric type of coordinates in the kernel
99 using FT = typename Kernel::FT;
100 // Sphere is a weighted point (point + weight [= squared radius]).
101 using Sphere = Weighted_point_d;
102
103 int get_dimension(const Weighted_point_d& p0) const {
104 return kernel_.point_dimension_d_object()(p0.point());
105 }
106
107 template<class PointIterator>
108 Sphere get_sphere(PointIterator begin, PointIterator end) const {
109 // power_center_d_object has been renamed between CGAL 5.1 and 5.2
110#if CGAL_VERSION_NR < 1050200000
111 return kernel_.power_center_d_object()(begin, end);
112#else
113 return kernel_.construct_power_sphere_d_object()(begin, end);
114#endif
115 }
116
117 template<class PointIterator>
118 FT get_squared_radius(PointIterator begin, PointIterator end) const {
119 return kernel_.compute_squared_radius_smallest_orthogonal_sphere_d_object()(begin, end);
120 }
121
122 FT get_squared_radius(const Sphere& sph) const {
123 return sph.weight();
124 }
125
126 bool is_gabriel(const Sphere& circumcenter, const Weighted_point_d& point) {
127 // power_center_d_object has been renamed between CGAL 5.1 and 5.2
128#if CGAL_VERSION_NR < 1050200000
129 return kernel_.power_distance_d_object()(circumcenter, point) >= 0;
130#else
131 return kernel_.compute_power_product_d_object()(circumcenter, point) >= 0;
132#endif
133 }
134};
135
136} // namespace alpha_complex
137
138namespace alphacomplex = alpha_complex;
139
140} // namespace Gudhi
141
142#endif // ALPHA_COMPLEX_ALPHA_KERNEL_D_H_
Alpha complex kernel container.
Definition: Alpha_kernel_d.h:42
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14