11 #ifndef INCLUDE_SIMPLEX_TREE_INTERFACE_H_
12 #define INCLUDE_SIMPLEX_TREE_INTERFACE_H_
16 #include <gudhi/Simplex_tree.h>
17 #include <gudhi/Points_off_io.h>
18 #ifdef GUDHI_USE_EIGEN3
19 #include <gudhi/Flag_complex_edge_collapser.h>
30 template<
typename SimplexTreeOptions = Simplex_tree_options_full_featured>
31 class Simplex_tree_interface :
public Simplex_tree<SimplexTreeOptions> {
37 using Insertion_result =
typename std::pair<Simplex_handle, bool>;
38 using Simplex = std::vector<Vertex_handle>;
39 using Simplex_and_filtration = std::pair<Simplex, Filtration_value>;
40 using Filtered_simplices = std::vector<Simplex_and_filtration>;
43 using Extended_filtration_data =
typename Base::Extended_filtration_data;
48 Extended_filtration_data efd;
50 bool find_simplex(
const Simplex& simplex) {
63 return (result.second);
69 return (result.second);
75 return (result.second);
81 return (result.second);
87 return (result.second);
99 Simplex_and_filtration get_simplex_and_filtration(Simplex_handle f_simplex) {
102 simplex.insert(simplex.begin(), vertex);
107 Filtered_simplices get_star(
const Simplex& simplex) {
108 Filtered_simplices star;
112 simplex_star.insert(simplex_star.begin(), vertex);
119 Filtered_simplices get_cofaces(
const Simplex& simplex,
int dimension) {
120 Filtered_simplices cofaces;
124 simplex_coface.insert(simplex_coface.begin(), vertex);
126 cofaces.push_back(std::make_pair(simplex_coface,
Base::filtration(f_simplex)));
131 void compute_extended_filtration() {
136 std::vector<std::vector<std::pair<int, std::pair<Filtration_value, Filtration_value>>>> compute_extended_persistence_subdiagrams(
const std::vector<std::pair<
int, std::pair<Filtration_value, Filtration_value>>>& dgm,
Filtration_value min_persistence){
137 std::vector<std::vector<std::pair<int, std::pair<Filtration_value, Filtration_value>>>> new_dgm(4);
138 for (
unsigned int i = 0; i < dgm.size(); i++){
141 std::pair<int, std::pair<Filtration_value, Filtration_value>> pd_point = std::make_pair(dgm[i].first, std::make_pair(px.first, py.first));
142 if(std::abs(px.first - py.first) > min_persistence){
144 if (px.second == Extended_simplex_type::UP && py.second == Extended_simplex_type::UP){
145 new_dgm[0].push_back(pd_point);
148 else if (px.second == Extended_simplex_type::DOWN && py.second == Extended_simplex_type::DOWN){
149 new_dgm[1].push_back(pd_point);
153 if (px.first < py.first){
154 new_dgm[2].push_back(pd_point);
158 new_dgm[3].push_back(pd_point);
166 Simplex_tree_interface* collapse_edges(
int nb_collapse_iteration) {
167 #ifdef GUDHI_USE_EIGEN3
168 using Filtered_edge = std::tuple<Vertex_handle, Vertex_handle, Filtration_value>;
169 std::vector<Filtered_edge> edges;
173 auto vit = rg.begin();
180 for (
int iteration = 0; iteration < nb_collapse_iteration; iteration++) {
183 Simplex_tree_interface* collapsed_stree_ptr =
new Simplex_tree_interface();
189 for (
auto remaining_edge : edges) {
190 collapsed_stree_ptr->insert({std::get<0>(remaining_edge), std::get<1>(remaining_edge)}, std::get<2>(remaining_edge));
192 return collapsed_stree_ptr;
194 throw std::runtime_error(
"Unable to collapse edges as it requires Eigen3 >= 3.1.0.");
199 Complex_simplex_iterator get_simplices_iterator_begin() {
204 Complex_simplex_iterator get_simplices_iterator_end() {
209 typename std::vector<Simplex_handle>::const_iterator get_filtration_iterator_begin() {
215 typename std::vector<Simplex_handle>::const_iterator get_filtration_iterator_end() {
220 Skeleton_simplex_iterator get_skeleton_iterator_begin(
int dimension) {
225 Skeleton_simplex_iterator get_skeleton_iterator_end(
int dimension) {
230 std::pair<Boundary_simplex_iterator, Boundary_simplex_iterator> get_boundary_iterators(
const Simplex& simplex) {
233 throw std::runtime_error(
"simplex not found - cannot find boundaries");
236 return std::make_pair(boundary_srange.begin(), boundary_srange.end());
Options::Filtration_value Filtration_value
Type for the value of the filtration function.
Definition: Simplex_tree.h:82
Cofaces_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension)
Compute the cofaces of a n simplex.
Definition: Simplex_tree.h:993
void assign_filtration(Simplex_handle sh, Filtration_value fv)
Sets the filtration value of a simplex.
Definition: Simplex_tree.h:520
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:781
Dictionary::iterator Simplex_handle
Handle type to a simplex contained in the simplicial complex represented by the simplex tree.
Definition: Simplex_tree.h:149
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:262
Simplex_vertex_range simplex_vertex_range(Simplex_handle sh) const
Returns a range over the vertices of a simplex.
Definition: Simplex_tree.h:273
void clear_filtration()
Clears the filtration cache produced by initialize_filtration().
Definition: Simplex_tree.h:919
static Filtration_value filtration(Simplex_handle sh)
Returns the filtration value of a simplex.
Definition: Simplex_tree.h:509
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:752
Cofaces_simplex_range star_simplex_range(const Simplex_handle simplex)
Compute the star of a n simplex.
Definition: Simplex_tree.h:982
boost::iterator_range< Simplex_vertex_iterator > Simplex_vertex_range
Range over the vertices of a simplex.
Definition: Simplex_tree.h:181
void remove_maximal_simplex(Simplex_handle sh)
Remove a maximal simplex.
Definition: Simplex_tree.h:1489
Simplex_tree_boundary_simplex_iterator< Simplex_tree > Boundary_simplex_iterator
Iterator over the simplices of the boundary of a simplex.
Definition: Simplex_tree.h:187
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:615
Simplex_tree_complex_simplex_iterator< Simplex_tree > Complex_simplex_iterator
Iterator over the simplices of the simplicial complex.
Definition: Simplex_tree.h:193
std::pair< Filtration_value, Extended_simplex_type > decode_extended_filtration(Filtration_value f, const Extended_filtration_data &efd)
Retrieve the original filtration value for a given simplex in the Simplex_tree. Since the computation...
Definition: Simplex_tree.h:1526
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:242
Extended_filtration_data extend_filtration()
Extend filtration for computing extended persistence. This function only uses the filtration values a...
Definition: Simplex_tree.h:1555
Options::Vertex_handle Vertex_handle
Type for the vertex handle.
Definition: Simplex_tree.h:90
Boundary_simplex_range boundary_simplex_range(SimplexHandle sh)
Returns a range over the simplices of the boundary of a simplex.
Definition: Simplex_tree.h:294
int dimension()
Returns the dimension of the simplicial complex.
Definition: Simplex_tree.h:593
Simplex_tree_skeleton_simplex_iterator< Simplex_tree > Skeleton_simplex_iterator
Iterator over the simplices of the skeleton of the simplicial complex, for a given dimension.
Definition: Simplex_tree.h:200
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:530
Complex_simplex_range complex_simplex_range()
Returns a range over the simplices of the simplicial complex.
Definition: Simplex_tree.h:228
Abstract simplex used in Skeleton blockers data-structure.
Definition: Skeleton_blocker_simplex.h:38
Global distance functions.
Graph simplicial complex methods.
auto flag_complex_collapse_edges(const FilteredEdgeRange &edges)
Implicitly constructs a flag complex from edges as an input, collapses edges while preserving the per...
Definition: Flag_complex_edge_collapser.h:363
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:20
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15