Simplex_tree_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_SIMPLEX_TREE_INTERFACE_H_
24 #define INCLUDE_SIMPLEX_TREE_INTERFACE_H_
25 
26 #include <gudhi/graph_simplicial_complex.h>
28 #include <gudhi/Simplex_tree.h>
29 #include <gudhi/Points_off_io.h>
30 
31 #include "Persistent_cohomology_interface.h"
32 
33 #include <iostream>
34 #include <vector>
35 #include <utility> // std::pair
36 
37 namespace Gudhi {
38 
39 template<typename SimplexTreeOptions = Simplex_tree_options_full_featured>
40 class Simplex_tree_interface : public Simplex_tree<SimplexTreeOptions> {
41  public:
44  using Vertex_handle = typename Base::Vertex_handle;
45  using Simplex_handle = typename Base::Simplex_handle;
46  using Insertion_result = typename std::pair<Simplex_handle, bool>;
47  using Simplex = std::vector<Vertex_handle>;
48  using Complex = std::vector<std::pair<Simplex, Filtration_value>>;
49 
50  public:
51  bool find_simplex(const Simplex& vh) {
52  return (Base::find(vh) != Base::null_simplex());
53  }
54 
55  void assign_simplex_filtration(const Simplex& vh, Filtration_value filtration) {
56  Base::assign_filtration(Base::find(vh), filtration);
57  }
58 
59  bool insert(const Simplex& simplex, Filtration_value filtration = 0) {
60  Insertion_result result = Base::insert_simplex_and_subfaces(simplex, filtration);
61  return (result.second);
62  }
63 
64  // Do not interface this function, only used in alpha complex interface for complex creation
65  bool insert_simplex(const Simplex& simplex, Filtration_value filtration = 0) {
66  Insertion_result result = Base::insert_simplex(simplex, filtration);
67  return (result.second);
68  }
69 
70  // Do not interface this function, only used in interface for complex creation
71  bool insert_simplex_and_subfaces(const Simplex& simplex, Filtration_value filtration = 0) {
72  Insertion_result result = Base::insert_simplex_and_subfaces(simplex, filtration);
73  return (result.second);
74  }
75 
76  // Do not interface this function, only used in strong witness interface for complex creation
77  bool insert_simplex(const std::vector<std::size_t>& simplex, Filtration_value filtration = 0) {
78  Insertion_result result = Base::insert_simplex(simplex, filtration);
79  return (result.second);
80  }
81 
82  // Do not interface this function, only used in strong witness interface for complex creation
83  bool insert_simplex_and_subfaces(const std::vector<std::size_t>& simplex, Filtration_value filtration = 0) {
84  Insertion_result result = Base::insert_simplex_and_subfaces(simplex, filtration);
85  return (result.second);
86  }
87 
88  Filtration_value simplex_filtration(const Simplex& simplex) {
89  return Base::filtration(Base::find(simplex));
90  }
91 
92  void remove_maximal_simplex(const Simplex& simplex) {
95  }
96 
97  Complex get_filtration() {
99  Complex filtrations;
100  for (auto f_simplex : Base::filtration_simplex_range()) {
101  Simplex simplex;
102  for (auto vertex : Base::simplex_vertex_range(f_simplex)) {
103  simplex.insert(simplex.begin(), vertex);
104  }
105  filtrations.push_back(std::make_pair(simplex, Base::filtration(f_simplex)));
106  }
107  return filtrations;
108  }
109 
110  Complex get_skeleton(int dimension) {
111  Complex skeletons;
112  for (auto f_simplex : Base::skeleton_simplex_range(dimension)) {
113  Simplex simplex;
114  for (auto vertex : Base::simplex_vertex_range(f_simplex)) {
115  simplex.insert(simplex.begin(), vertex);
116  }
117  skeletons.push_back(std::make_pair(simplex, Base::filtration(f_simplex)));
118  }
119  return skeletons;
120  }
121 
122  Complex get_star(const Simplex& simplex) {
123  Complex star;
124  for (auto f_simplex : Base::star_simplex_range(Base::find(simplex))) {
125  Simplex simplex_star;
126  for (auto vertex : Base::simplex_vertex_range(f_simplex)) {
127  std::cout << vertex << " ";
128  simplex_star.insert(simplex_star.begin(), vertex);
129  }
130  std::cout << std::endl;
131  star.push_back(std::make_pair(simplex_star, Base::filtration(f_simplex)));
132  }
133  return star;
134  }
135 
136  Complex get_cofaces(const Simplex& simplex, int dimension) {
137  Complex cofaces;
138  for (auto f_simplex : Base::cofaces_simplex_range(Base::find(simplex), dimension)) {
139  Simplex simplex_coface;
140  for (auto vertex : Base::simplex_vertex_range(f_simplex)) {
141  std::cout << vertex << " ";
142  simplex_coface.insert(simplex_coface.begin(), vertex);
143  }
144  std::cout << std::endl;
145  cofaces.push_back(std::make_pair(simplex_coface, Base::filtration(f_simplex)));
146  }
147  return cofaces;
148  }
149 
150  void create_persistence(Gudhi::Persistent_cohomology_interface<Base>* pcoh) {
152  pcoh = new Gudhi::Persistent_cohomology_interface<Base>(*this);
153  }
154 };
155 
156 } // namespace Gudhi
157 
158 #endif // INCLUDE_SIMPLEX_TREE_INTERFACE_H_
Dictionary::iterator Simplex_handle
Handle type to a simplex contained in the simplicial complex represented by the simplex tree...
Definition: Simplex_tree.h:135
Simplex Tree data structure for representing simplicial complexes.
Definition: Simplex_tree.h:72
std::pair< Simplex_handle, bool > insert_simplex_and_subfaces(const InputVertexRange &Nsimplex, Filtration_value filtration=0)
Insert a N-simplex and all his subfaces, from a N-simplex represented by a range of Vertex_handles...
Definition: Simplex_tree.h:683
static Simplex_handle null_simplex()
Returns a Simplex_handle different from all Simplex_handles associated to the simplices in the simpli...
Definition: Simplex_tree.h:431
Definition: SimplicialComplexForAlpha.h:26
Filtration_simplex_range const & filtration_simplex_range(Indexing_tag=Indexing_tag())
Returns a range over the simplices of the simplicial complex, in the order of the filtration...
Definition: Simplex_tree.h:248
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
Simplex_handle find(const InputVertexRange &s)
Given a range of Vertex_handles, returns the Simplex_handle of the simplex in the simplicial complex ...
Definition: Simplex_tree.h:517
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:32
Cofaces_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension)
Compute the cofaces of a n simplex.
Definition: Simplex_tree.h:892
void assign_filtration(Simplex_handle sh, Filtration_value fv)
Sets the filtration value of a simplex.
Definition: Simplex_tree.h:421
Simplex_vertex_range simplex_vertex_range(Simplex_handle sh)
Returns a range over the vertices of a simplex.
Definition: Simplex_tree.h:261
Global distance functions.
Options::Vertex_handle Vertex_handle
Type for the vertex handle.
Definition: Simplex_tree.h:87
Skeleton_simplex_range skeleton_simplex_range(int dim)
Returns a range over the simplices of the dim-skeleton of the simplicial complex. ...
Definition: Simplex_tree.h:228
Cofaces_simplex_range star_simplex_range(const Simplex_handle simplex)
Compute the star of a n simplex.
Definition: Simplex_tree.h:881
static Filtration_value filtration(Simplex_handle sh)
Returns the filtration value of a simplex.
Definition: Simplex_tree.h:410
void remove_maximal_simplex(Simplex_handle sh)
Remove a maximal simplex.
Definition: Simplex_tree.h:1378
Options::Filtration_value Filtration_value
Type for the value of the filtration function.
Definition: Simplex_tree.h:79
std::pair< Simplex_handle, bool > insert_simplex(const InputVertexRange &simplex, Filtration_value filtration=0)
Insert a simplex, represented by a range of Vertex_handles, in the simplicial complex.
Definition: Simplex_tree.h:654
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Tue Aug 14 2018 11:45:43 for GUDHI by Doxygen 1.8.13