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(const std::vector<std::vector<double>>& points) {
49  Dynamic_kernel k;
50  unsigned intrisic_dim = 0;
51  if (points.size() > 0)
52  intrisic_dim = points[0].size() - 1;
53 
54  tangential_complex_ = new TC(points, intrisic_dim, k);
55  tangential_complex_->compute_tangential_complex();
56  num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices();
57  }
58 
59  Tangential_complex_interface(const std::string& off_file_name, bool from_file = true) {
60  Gudhi::Points_off_reader<Point_d> off_reader(off_file_name);
61  Dynamic_kernel k;
62  unsigned intrisic_dim = 0;
63  std::vector<Point_d> points = off_reader.get_point_cloud();
64  if (points.size() > 0)
65  intrisic_dim = points[0].size() - 1;
66 
67  tangential_complex_ = new TC(points, intrisic_dim, k);
68  tangential_complex_->compute_tangential_complex();
69  num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices();
70  }
71 
72  ~Tangential_complex_interface() {
73  delete tangential_complex_;
74  }
75 
76  std::vector<double> get_point(unsigned vh) {
77  std::vector<double> vd;
78  if (vh < tangential_complex_->number_of_vertices()) {
79  Point_d ph = tangential_complex_->get_point(vh);
80  for (auto coord = ph.cartesian_begin(); coord < ph.cartesian_end(); coord++)
81  vd.push_back(*coord);
82  }
83  return vd;
84  }
85 
86  unsigned number_of_vertices() {
87  return tangential_complex_->number_of_vertices();
88  }
89 
90  unsigned number_of_simplices() {
91  return num_inconsistencies_.num_simplices;
92  }
93 
94  unsigned number_of_inconsistent_simplices() {
95  return num_inconsistencies_.num_inconsistent_simplices;
96  }
97 
98  unsigned number_of_inconsistent_stars() {
99  return num_inconsistencies_.num_inconsistent_stars;
100  }
101 
102  void fix_inconsistencies_using_perturbation(double max_perturb, double time_limit) {
103  tangential_complex_->fix_inconsistencies_using_perturbation(max_perturb, time_limit);
104  num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices();
105  }
106 
107  void create_simplex_tree(Simplex_tree<>* simplex_tree) {
108  tangential_complex_->create_complex<Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_full_featured>>(*simplex_tree);
109  simplex_tree->initialize_filtration();
110  }
111 
112  private:
113  TC* tangential_complex_;
114  TC::Num_inconsistencies num_inconsistencies_;
115 };
116 
117 } // namespace tangential_complex
118 
119 } // namespace Gudhi
120 
121 #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:796
GUDHI  Version 2.1.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Thu Jun 14 2018 18:07:51 for GUDHI by Doxygen 1.8.13