Alpha_complex_factory.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 INCLUDE_ALPHA_COMPLEX_FACTORY_H_
12 #define INCLUDE_ALPHA_COMPLEX_FACTORY_H_
13 
14 #include <gudhi/Simplex_tree.h>
15 #include <gudhi/Alpha_complex.h>
16 #include <gudhi/Alpha_complex_3d.h>
17 #include <gudhi/Alpha_complex_options.h>
18 #include <CGAL/Epeck_d.h>
19 #include <CGAL/Epick_d.h>
20 
21 #include <boost/range/adaptor/transformed.hpp>
22 
23 #include "Simplex_tree_interface.h"
24 
25 #include <iostream>
26 #include <vector>
27 #include <string>
28 #include <memory> // for std::unique_ptr
29 
30 namespace Gudhi {
31 
32 namespace alpha_complex {
33 
34 template <typename CgalPointType>
35 std::vector<double> pt_cgal_to_cython(CgalPointType const& point) {
36  std::vector<double> vd;
37  vd.reserve(point.dimension());
38  for (auto coord = point.cartesian_begin(); coord != point.cartesian_end(); coord++)
39  vd.push_back(CGAL::to_double(*coord));
40  return vd;
41 }
42 
43 template <typename CgalPointType>
44 static CgalPointType pt_cython_to_cgal(std::vector<double> const& vec) {
45  return CgalPointType(vec.size(), vec.begin(), vec.end());
46 }
47 
48 class Abstract_alpha_complex {
49  public:
50  virtual std::vector<double> get_point(int vh) = 0;
51 
52  virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
53  bool default_filtration_value) = 0;
54 
55  virtual ~Abstract_alpha_complex() = default;
56 };
57 
58 class Exact_Alphacomplex_dD final : public Abstract_alpha_complex {
59  private:
60  using Kernel = CGAL::Epeck_d<CGAL::Dynamic_dimension_tag>;
61  using Point = typename Kernel::Point_d;
62 
63  public:
64  Exact_Alphacomplex_dD(const std::vector<std::vector<double>>& points, bool exact_version)
65  : exact_version_(exact_version),
66  alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal<Point>)) {
67  }
68 
69  virtual std::vector<double> get_point(int vh) override {
70  Point const& point = alpha_complex_.get_point(vh);
71  return pt_cgal_to_cython(point);
72  }
73 
74  virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
75  bool default_filtration_value) override {
76  return alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value);
77  }
78 
79  private:
80  bool exact_version_;
81  Alpha_complex<Kernel> alpha_complex_;
82 };
83 
84 class Inexact_Alphacomplex_dD final : public Abstract_alpha_complex {
85  private:
86  using Kernel = CGAL::Epick_d<CGAL::Dynamic_dimension_tag>;
87  using Point = typename Kernel::Point_d;
88 
89  public:
90  Inexact_Alphacomplex_dD(const std::vector<std::vector<double>>& points, bool exact_version)
91  : exact_version_(exact_version),
92  alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal<Point>)) {
93  }
94 
95  virtual std::vector<double> get_point(int vh) override {
96  Point const& point = alpha_complex_.get_point(vh);
97  return pt_cgal_to_cython(point);
98  }
99  virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
100  bool default_filtration_value) override {
101  return alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value);
102  }
103 
104  private:
105  bool exact_version_;
106  Alpha_complex<Kernel> alpha_complex_;
107 };
108 
109 template <complexity Complexity>
110 class Alphacomplex_3D final : public Abstract_alpha_complex {
111  private:
113 
114  static Point pt_cython_to_cgal_3(std::vector<double> const& vec) {
115  return Point(vec[0], vec[1], vec[2]);
116  }
117 
118  public:
119  Alphacomplex_3D(const std::vector<std::vector<double>>& points)
120  : alpha_complex_(boost::adaptors::transform(points, pt_cython_to_cgal_3)) {
121  }
122 
123  virtual std::vector<double> get_point(int vh) override {
124  Point const& point = alpha_complex_.get_point(vh);
125  return pt_cgal_to_cython(point);
126  }
127 
128  virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
129  bool default_filtration_value) override {
130  return alpha_complex_.create_complex(*simplex_tree, max_alpha_square);
131  }
132 
133  private:
135 };
136 
137 
138 } // namespace alpha_complex
139 
140 } // namespace Gudhi
141 
142 #endif // INCLUDE_ALPHA_COMPLEX_FACTORY_H_
Alpha complex data structure for 3d specific case.
Definition: Alpha_complex_3d.h:121
GUDHIdev  Version 3.5.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Fri Jan 14 2022 18:28:42 for GUDHIdev by Doxygen 1.9.1