summaryrefslogtreecommitdiff
path: root/src/Alpha_complex/include/gudhi/Alpha_complex/Alpha_kernel_d.h
blob: a4824207f22663d34679af95b06fbb0df68a71b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*    This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
 *    See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
 *    Author(s):       Vincent Rouvreau
 *
 *    Copyright (C) 2020 Inria
 *
 *    Modification(s):
 *      - YYYY/MM Author: Description of the modification
 */

#ifndef ALPHA_COMPLEX_ALPHA_KERNEL_D_H_
#define ALPHA_COMPLEX_ALPHA_KERNEL_D_H_

#include <CGAL/Epeck_d.h>  // For EXACT or SAFE version
#include <CGAL/Epick_d.h>  // For FAST version
#include <CGAL/version.h>  // for CGAL_VERSION_NR

#include <Eigen/src/Core/util/Macros.h>  // for EIGEN_VERSION_AT_LEAST

#include <utility>  // for std::make_pair

// Make compilation fail - required for external projects - https://github.com/GUDHI/gudhi-devel/issues/10
#if CGAL_VERSION_NR < 1041101000
# error Alpha_complex is only available for CGAL >= 4.11
#endif

#if !EIGEN_VERSION_AT_LEAST(3,1,0)
# error Alpha_complex is only available for Eigen3 >= 3.1.0 installed with CGAL
#endif

namespace Gudhi {

namespace alpha_complex {

template < typename Kernel, bool Weighted = false >
class Alpha_kernel_d {
};

// Unweighted Kernel_d version
template < typename Kernel >
class Alpha_kernel_d<Kernel, false> {
 private:
  // Kernel for functions access.
  Kernel kernel_;
 public:
  // Fake type for compilation to succeed (cf. std::conditional in Alpha_complex.h)
  using Weighted_point_d = void;
  using Point_d = typename Kernel::Point_d;
  // Numeric type of coordinates in the kernel
  using FT = typename Kernel::FT;
  // Sphere is a pair of point and squared radius.
  using Sphere = typename std::pair<Point_d, FT>;

  int get_dimension(const Point_d& p0) const {
    return kernel_.point_dimension_d_object()(p0);
  }

  template<class PointIterator>
  Sphere get_sphere(PointIterator begin, PointIterator end) const {
    Point_d c = kernel_.construct_circumcenter_d_object()(begin, end);
    FT r = kernel_.squared_distance_d_object()(c, *begin);
    return std::make_pair(std::move(c), std::move(r));
  }

  template<class PointIterator>
  FT get_squared_radius(PointIterator begin, PointIterator end) const {
    return kernel_.compute_squared_radius_d_object()(begin, end);
  }

  FT get_squared_radius(const Sphere& sph) const {
    return sph.second;
  }

  bool is_gabriel(const Sphere& circumcenter, const Point_d& point) {
    return kernel_.squared_distance_d_object()(circumcenter.first, point) >= circumcenter.second;
  }
};

// Weighted Kernel_d version
template < typename Kernel >
class Alpha_kernel_d<Kernel, true> {
 private:
  // Kernel for functions access.
  Kernel kernel_;

 public:
  // Fake type for compilation to succeed (cf. std::conditional in Alpha_complex.h)
  using Point_d = void;
  using Weighted_point_d = typename Kernel::Weighted_point_d;
  using Bare_point_d = typename Kernel::Point_d;
  // Numeric type of coordinates in the kernel
  using FT = typename Kernel::FT;
  // Sphere is a weighted point (point + weight [= squared radius]).
  using Sphere = Weighted_point_d;

  int get_dimension(const Weighted_point_d& p0) const {
    return kernel_.point_dimension_d_object()(p0.point());
  }

  template<class PointIterator>
  Sphere get_sphere(PointIterator begin, PointIterator end) const {
    // power_center_d_object has been renamed between CGAL 5.1 and 5.2
#if defined CGAL_VERSION_NR >= 1050101000 && defined CGAL_VERSION_NR < 1050201000
    return kernel_.power_center_d_object()(begin, end);
#endif
#if CGAL_VERSION_NR >= 1050201000
    return kernel_.construct_power_sphere_d_object()(begin, end);
#endif
  }

  template<class PointIterator>
  FT get_squared_radius(PointIterator begin, PointIterator end) const {
    Sphere sph = get_sphere(begin, end);
    return sph.weight();
  }

  FT get_squared_radius(const Sphere& sph) const {
    return sph.weight();
  }

  bool is_gabriel(const Sphere& circumcenter, const Weighted_point_d& point) {
    // power_center_d_object has been renamed between CGAL 5.1 and 5.2
#if defined CGAL_VERSION_NR >= 1050101000 && defined CGAL_VERSION_NR < 1050201000
    return kernel_.power_distance_d_object()(circumcenter, point) >= 0;
#endif
#if CGAL_VERSION_NR >= 1050201000
    return kernel_.compute_power_product_d_object()(circumcenter, point) >= 0;
#endif
  }
};

}  // namespace alpha_complex

namespace alphacomplex = alpha_complex;

}  // namespace Gudhi

#endif  // ALPHA_COMPLEX_ALPHA_KERNEL_D_H_