Rips_complex_interface.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) 2016 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef INCLUDE_RIPS_COMPLEX_INTERFACE_H_
12 #define INCLUDE_RIPS_COMPLEX_INTERFACE_H_
13 
14 #include <gudhi/Simplex_tree.h>
15 #include <gudhi/Rips_complex.h>
16 #include <gudhi/Sparse_rips_complex.h>
18 
19 #include <boost/optional.hpp>
20 
21 #include "Simplex_tree_interface.h"
22 
23 #include <iostream>
24 #include <vector>
25 #include <utility> // std::pair
26 #include <string>
27 
28 namespace Gudhi {
29 
30 namespace rips_complex {
31 
32 class Rips_complex_interface {
33  using Point_d = std::vector<double>;
34  using Distance_matrix = std::vector<std::vector<Simplex_tree_interface<>::Filtration_value>>;
35 
36  public:
37  void init_points(const std::vector<std::vector<double>>& points, double threshold) {
38  rips_complex_.emplace(points, threshold, Gudhi::Euclidean_distance());
39  }
40  void init_matrix(const std::vector<std::vector<double>>& matrix, double threshold) {
41  rips_complex_.emplace(matrix, threshold);
42  }
43 
44  void init_points_sparse(const std::vector<std::vector<double>>& points, double threshold, double epsilon) {
45  sparse_rips_complex_.emplace(points, Gudhi::Euclidean_distance(), epsilon, -std::numeric_limits<double>::infinity(), threshold);
46  }
47  void init_matrix_sparse(const std::vector<std::vector<double>>& matrix, double threshold, double epsilon) {
48  sparse_rips_complex_.emplace(matrix, epsilon, -std::numeric_limits<double>::infinity(), threshold);
49  }
50 
51  void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, int dim_max) {
52  if (rips_complex_)
53  rips_complex_->create_complex(*simplex_tree, dim_max);
54  else
55  sparse_rips_complex_->create_complex(*simplex_tree, dim_max);
56  }
57 
58  private:
59  // std::variant would work, but we don't require C++17 yet, and boost::variant is not super convenient.
60  // Anyway, storing a graph would make more sense. Or changing the interface completely so there is no such storage.
61  boost::optional<Rips_complex<Simplex_tree_interface<>::Filtration_value>> rips_complex_;
62  boost::optional<Sparse_rips_complex<Simplex_tree_interface<>::Filtration_value>> sparse_rips_complex_;
63 };
64 
65 } // namespace rips_complex
66 
67 } // namespace Gudhi
68 
69 #endif // INCLUDE_RIPS_COMPLEX_INTERFACE_H_
Compute the Euclidean distance between two Points given by a range of coordinates....
Definition: distance_functions.h:34
Global distance functions.
GUDHIdev  Version 3.5.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Wed Apr 6 2022 19:26:28 for GUDHIdev by Doxygen 1.9.1