Alpha_complex_interface.h
1 /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): Vincent Rouvreau
6  *
7  * Copyright (C) 2016 Inria
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef INCLUDE_ALPHA_COMPLEX_INTERFACE_H_
24 #define INCLUDE_ALPHA_COMPLEX_INTERFACE_H_
25 
26 #include <gudhi/Simplex_tree.h>
27 #include <gudhi/Alpha_complex.h>
28 #include <CGAL/Epick_d.h>
29 
30 #include "Simplex_tree_interface.h"
31 
32 #include <iostream>
33 #include <vector>
34 #include <string>
35 
36 namespace Gudhi {
37 
38 namespace alpha_complex {
39 
40 class Alpha_complex_interface {
41  using Dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >;
42  using Point_d = Dynamic_kernel::Point_d;
43 
44  public:
45  Alpha_complex_interface(const std::vector<std::vector<double>>& points) {
46  alpha_complex_ = new Alpha_complex<Dynamic_kernel>(points);
47  }
48 
49  Alpha_complex_interface(const std::string& off_file_name, bool from_file = true) {
50  alpha_complex_ = new Alpha_complex<Dynamic_kernel>(off_file_name);
51  }
52 
53  ~Alpha_complex_interface() {
54  delete alpha_complex_;
55  }
56 
57  std::vector<double> get_point(int vh) {
58  std::vector<double> vd;
59  try {
60  Point_d ph = alpha_complex_->get_point(vh);
61  for (auto coord = ph.cartesian_begin(); coord < ph.cartesian_end(); coord++)
62  vd.push_back(*coord);
63  } catch (std::out_of_range outofrange) {
64  // std::out_of_range is thrown in case not found. Other exceptions must be re-thrown
65  }
66  return vd;
67  }
68 
69  void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square) {
70  alpha_complex_->create_complex(*simplex_tree, max_alpha_square);
71  simplex_tree->initialize_filtration();
72  }
73 
74  private:
75  Alpha_complex<Dynamic_kernel>* alpha_complex_;
76 };
77 
78 } // namespace alpha_complex
79 
80 } // namespace Gudhi
81 
82 #endif // INCLUDE_ALPHA_COMPLEX_INTERFACE_H_
Definition: SimplicialComplexForAlpha.h:26
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Tue Jul 17 2018 12:56:28 for GUDHI by Doxygen 1.8.13