Rips_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_RIPS_COMPLEX_INTERFACE_H_
24 #define INCLUDE_RIPS_COMPLEX_INTERFACE_H_
25 
26 #include <gudhi/Simplex_tree.h>
27 #include <gudhi/Rips_complex.h>
28 #include <gudhi/Points_off_io.h>
30 #include <gudhi/reader_utils.h>
31 
32 #include "Simplex_tree_interface.h"
33 
34 #include <iostream>
35 #include <vector>
36 #include <utility> // std::pair
37 #include <string>
38 
39 namespace Gudhi {
40 
41 namespace rips_complex {
42 
43 class Rips_complex_interface {
44  using Point_d = std::vector<double>;
45  using Distance_matrix = std::vector<std::vector<Simplex_tree_interface<>::Filtration_value>>;
46 
47  public:
48  Rips_complex_interface(const std::vector<std::vector<double>>& values, double threshold, bool euclidean) {
49  if (euclidean) {
50  // Rips construction where values is a vector of points
51  rips_complex_ = new Rips_complex<Simplex_tree_interface<>::Filtration_value>(values, threshold,
53  } else {
54  // Rips construction where values is a distance matrix
55  rips_complex_ = new Rips_complex<Simplex_tree_interface<>::Filtration_value>(values, threshold);
56  }
57  }
58 
59  Rips_complex_interface(const std::string& file_name, double threshold, bool euclidean, bool from_file = true) {
60  if (euclidean) {
61  // Rips construction where file_name is an OFF file
62  Gudhi::Points_off_reader<Point_d> off_reader(file_name);
63  rips_complex_ = new Rips_complex<Simplex_tree_interface<>::Filtration_value>(off_reader.get_point_cloud(),
64  threshold,
66  } else {
67  // Rips construction where values is a distance matrix
68  Distance_matrix distances =
69  Gudhi::read_lower_triangular_matrix_from_csv_file<Simplex_tree_interface<>::Filtration_value>(file_name);
70  rips_complex_ = new Rips_complex<Simplex_tree_interface<>::Filtration_value>(distances, threshold);
71  }
72  }
73 
74  ~Rips_complex_interface() {
75  delete rips_complex_;
76  }
77 
78  void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, int dim_max) {
79  rips_complex_->create_complex(*simplex_tree, dim_max);
80  simplex_tree->initialize_filtration();
81  }
82 
83  private:
85 };
86 
87 } // namespace rips_complex
88 
89 } // namespace Gudhi
90 
91 #endif // INCLUDE_RIPS_COMPLEX_INTERFACE_H_
void create_complex(SimplicialComplexForRips &complex, int dim_max)
Initializes the simplicial complex from the Rips graph and expands it until a given maximal dimension...
Definition: Rips_complex.h:113
OFF file reader implementation in order to read points from an OFF file.
Definition: Points_off_io.h:134
Compute the Euclidean distance between two Points given by a range of coordinates. The points are assumed to have the same dimension.
Definition: distance_functions.h:43
Definition: SimplicialComplexForAlpha.h:26
Rips complex data structure.
Definition: Rips_complex.h:57
Global distance functions.
This file includes common file reader for GUDHI.
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