Tangential_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_TANGENTIAL_COMPLEX_INTERFACE_H_
24 #define INCLUDE_TANGENTIAL_COMPLEX_INTERFACE_H_
25 
26 #include <gudhi/Simplex_tree.h>
27 #include <gudhi/Tangential_complex.h>
28 #include <gudhi/Points_off_io.h>
29 #include <CGAL/Epick_d.h>
30 
31 #include "Simplex_tree_interface.h"
32 
33 #include <vector>
34 #include <utility> // std::pair
35 #include <iostream>
36 #include <string>
37 
38 namespace Gudhi {
39 
40 namespace tangential_complex {
41 
42 class Tangential_complex_interface {
43  using Dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >;
44  using Point_d = Dynamic_kernel::Point_d;
45  using TC = Tangential_complex<Dynamic_kernel, CGAL::Dynamic_dimension_tag, CGAL::Parallel_tag>;
46 
47  public:
48  Tangential_complex_interface(int intrisic_dim, const std::vector<std::vector<double>>& points) {
49  Dynamic_kernel k;
50 
51  tangential_complex_ = new TC(points, intrisic_dim, k);
52  tangential_complex_->compute_tangential_complex();
53  num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices();
54  }
55 
56  Tangential_complex_interface(int intrisic_dim, const std::string& off_file_name, bool from_file = true) {
57  Dynamic_kernel k;
58 
59  Gudhi::Points_off_reader<Point_d> off_reader(off_file_name);
60  std::vector<Point_d> points = off_reader.get_point_cloud();
61 
62  tangential_complex_ = new TC(points, intrisic_dim, k);
63  tangential_complex_->compute_tangential_complex();
64  num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices();
65  }
66 
67  ~Tangential_complex_interface() {
68  delete tangential_complex_;
69  }
70 
71  std::vector<double> get_point(unsigned vh) {
72  std::vector<double> vd;
73  if (vh < tangential_complex_->number_of_vertices()) {
74  Point_d ph = tangential_complex_->get_point(vh);
75  for (auto coord = ph.cartesian_begin(); coord < ph.cartesian_end(); coord++)
76  vd.push_back(*coord);
77  }
78  return vd;
79  }
80 
81  unsigned number_of_vertices() {
82  return tangential_complex_->number_of_vertices();
83  }
84 
85  unsigned number_of_simplices() {
86  return num_inconsistencies_.num_simplices;
87  }
88 
89  unsigned number_of_inconsistent_simplices() {
90  return num_inconsistencies_.num_inconsistent_simplices;
91  }
92 
93  unsigned number_of_inconsistent_stars() {
94  return num_inconsistencies_.num_inconsistent_stars;
95  }
96 
97  void fix_inconsistencies_using_perturbation(double max_perturb, double time_limit) {
98  tangential_complex_->fix_inconsistencies_using_perturbation(max_perturb, time_limit);
99  num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices();
100  }
101 
102  void create_simplex_tree(Simplex_tree<>* simplex_tree) {
103  tangential_complex_->create_complex<Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_full_featured>>(*simplex_tree);
104  simplex_tree->initialize_filtration();
105  }
106 
107  private:
108  TC* tangential_complex_;
109  TC::Num_inconsistencies num_inconsistencies_;
110 };
111 
112 } // namespace tangential_complex
113 
114 } // namespace Gudhi
115 
116 #endif // INCLUDE_TANGENTIAL_COMPLEX_INTERFACE_H_
Simplex Tree data structure for representing simplicial complexes.
Definition: Simplex_tree.h:72
OFF file reader implementation in order to read points from an OFF file.
Definition: Points_off_io.h:134
Definition: SimplicialComplexForAlpha.h:26
void initialize_filtration()
Initializes the filtrations, i.e. sort the simplices according to their order in the filtration and i...
Definition: Simplex_tree.h:800
GUDHI  Version 2.3.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Fri Oct 5 2018 15:05:03 for GUDHI by Doxygen 1.8.13