16#ifndef SIMPLEX_TREE_H_
17#define SIMPLEX_TREE_H_
19#include <gudhi/Simplex_tree/simplex_tree_options.h>
20#include <gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h>
21#include <gudhi/Simplex_tree/Simplex_tree_siblings.h>
22#include <gudhi/Simplex_tree/Simplex_tree_iterators.h>
23#include <gudhi/Simplex_tree/Simplex_tree_star_simplex_iterators.h>
24#include <gudhi/Simplex_tree/serialization_utils.h>
25#include <gudhi/Simplex_tree/hooks_simplex_base.h>
29#include <gudhi/Debug_utils.h>
31#include <boost/container/map.hpp>
32#include <boost/container/flat_map.hpp>
33#include <boost/iterator/transform_iterator.hpp>
34#include <boost/graph/adjacency_list.hpp>
35#include <boost/range/adaptor/reversed.hpp>
36#include <boost/range/adaptor/transformed.hpp>
37#include <boost/range/size.hpp>
38#include <boost/container/static_vector.hpp>
39#include <boost/range/adaptors.hpp>
41#include <boost/intrusive/list.hpp>
42#include <boost/intrusive/parent_from_member.hpp>
46#include <tbb/parallel_sort.h>
54#include <initializer_list>
58#include <unordered_map>
94template<
typename SimplexTreeOptions = Simplex_tree_options_default>
118 typedef typename boost::container::flat_map<Vertex_handle, Node> flat_map;
121 typedef typename boost::container::map<Vertex_handle, Node> map;
124 flat_map>::type Dictionary;
131 struct Key_simplex_base_real {
132 Key_simplex_base_real() : key_(-1) {}
138 struct Key_simplex_base_dummy {
139 Key_simplex_base_dummy() {}
141 void assign_key(Simplex_key);
142 Simplex_key key()
const;
144 struct Extended_filtration_data {
147 Extended_filtration_data(){}
150 typedef typename std::conditional<Options::store_key, Key_simplex_base_real, Key_simplex_base_dummy>::type
153 struct Filtration_simplex_base_real {
154 Filtration_simplex_base_real() : filt_(0) {}
160 struct Filtration_simplex_base_dummy {
161 Filtration_simplex_base_dummy() {}
162 void assign_filtration(
Filtration_value GUDHI_CHECK_code(f)) { GUDHI_CHECK(f == 0,
"filtration value specified for a complex that does not store them"); }
166 Filtration_simplex_base_dummy>::type Filtration_simplex_base;
178 typedef typename Dictionary::iterator Dictionary_it;
179 typedef typename Dictionary_it::value_type Dit_value_t;
181 struct return_first {
196 using Optimized_star_simplex_range = boost::iterator_range<Optimized_star_simplex_iterator>;
198 class Fast_cofaces_predicate {
203 Fast_cofaces_predicate(
Simplex_tree* st,
int codim,
int dim)
204 : st_(st), codim_(codim), dim_(codim + dim) {}
205 bool operator()(
const Simplex_handle iter )
const {
210 return dim_ == st_->dimension(iter);
216 using Optimized_cofaces_simplex_filtered_range = boost::filtered_range<Fast_cofaces_predicate,
217 Optimized_star_simplex_range>;
222 static constexpr int max_dimension() {
return 40; }
246 Optimized_cofaces_simplex_filtered_range,
252 using Static_vertex_vector = boost::container::static_vector<
Vertex_handle, max_dimension()>;
295 boost::make_transform_iterator(root_.members_.begin(), return_first()),
296 boost::make_transform_iterator(root_.members_.end(), return_first()));
340 return filtration_vect_;
369 template<
class SimplexHandle>
386 template<
class SimplexHandle>
2563template<
typename...T>
2565 for (
auto sh : st.filtration_simplex_range()) {
2566 os << st.dimension(sh) <<
" ";
2567 for (
auto v : st.simplex_vertex_range(sh)) {
2575template<
typename...T>
2578 std::vector<typename ST::Vertex_handle> simplex;
2584 int dim =
static_cast<int> (simplex.size() - 1);
2585 if (max_dim < dim) {
Extended simplex type data structure for representing the type of simplices in an extended filtration...
Iterator over the simplices of the boundary of a simplex and their opposite vertices.
Definition Simplex_tree_iterators.h:194
Iterator over the simplices of the boundary of a simplex.
Definition Simplex_tree_iterators.h:82
Iterator over the simplices of a simplicial complex.
Definition Simplex_tree_iterators.h:309
Iterator over the simplices of the star of a simplex.
Definition Simplex_tree_star_simplex_iterators.h:162
Data structure to store a set of nodes in a SimplexTree sharing the same parent node.
Definition Simplex_tree_siblings.h:31
Iterator over the vertices of a simplex in a SimplexTree.
Definition Simplex_tree_iterators.h:37
Iterator over the simplices of the skeleton of a given dimension of the simplicial complex.
Definition Simplex_tree_iterators.h:383
Simplex Tree data structure for representing simplicial complexes.
Definition Simplex_tree.h:95
static Siblings * self_siblings(SimplexHandle sh)
Definition Simplex_tree.h:1023
Simplex_tree(Simplex_tree &&complex_source)
User-defined move constructor relocates the whole tree structure.
Definition Simplex_tree.h:414
void insert_edge_as_flag(Vertex_handle u, Vertex_handle v, Filtration_value fil, int dim_max, std::vector< Simplex_handle > &added_simplices)
Adds a new vertex or a new edge in a flag complex, as well as all simplices of its star,...
Definition Simplex_tree.h:1407
Options::Filtration_value Filtration_value
Type for the value of the filtration function.
Definition Simplex_tree.h:102
Cofaces_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension)
Compute the cofaces of a n simplex.
Definition Simplex_tree.h:1172
Simplex_tree_boundary_opposite_vertex_simplex_iterator< Simplex_tree > Boundary_opposite_vertex_simplex_iterator
Iterator over the simplices of the boundary of a simplex and their opposite vertices.
Definition Simplex_tree.h:263
void reset_filtration(Filtration_value filt_value, int min_dim=0)
This function resets the filtration value of all the simplices of dimension at least min_dim....
Definition Simplex_tree.h:2383
void assign_filtration(Simplex_handle sh, Filtration_value fv)
Sets the filtration value of a simplex.
Definition Simplex_tree.h:625
std::conditional< Options::link_nodes_by_label, Optimized_cofaces_simplex_filtered_range, std::vector< Simplex_handle > >::type Cofaces_simplex_range
Range over the cofaces of a simplex.
Definition Simplex_tree.h:247
bool make_filtration_non_decreasing()
This function ensures that each simplex has a higher filtration value than its faces by increasing th...
Definition Simplex_tree.h:1895
Dictionary::iterator Simplex_handle
Handle type to a simplex contained in the simplicial complex represented by the simplex tree.
Definition Simplex_tree.h:175
Vertex_handle vertex_with_same_filtration(Simplex_handle sh)
Returns a vertex of sh that has the same filtration value as sh if it exists, and null_vertex() other...
Definition Simplex_tree.h:2213
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:338
bool prune_above_dimension(int dimension)
Remove all simplices of dimension greater than a given value.
Definition Simplex_tree.h:2006
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:913
bool operator!=(Simplex_tree< OtherSimplexTreeOptions > &st2)
Checks if two simplex trees are different.
Definition Simplex_tree.h:556
Vertex_handle null_vertex() const
Returns a Vertex_handle different from all Vertex_handles associated to the vertices of the simplicia...
Definition Simplex_tree.h:646
boost::iterator_range< Boundary_simplex_iterator > Boundary_simplex_range
Range over the simplices of the boundary of a simplex.
Definition Simplex_tree.h:259
Simplex_vertex_range simplex_vertex_range(Simplex_handle sh) const
Returns a range over the vertices of a simplex.
Definition Simplex_tree.h:349
void for_each_simplex(Fun &&fun)
Definition Simplex_tree.h:1859
void clear_filtration()
Clears the filtration cache produced by initialize_filtration().
Definition Simplex_tree.h:1092
Simplex_tree_simplex_vertex_iterator< Simplex_tree > Simplex_vertex_iterator
Iterator over the vertices of a simplex.
Definition Simplex_tree.h:241
void clear()
Remove all the simplices, leaving an empty complex.
Definition Simplex_tree.h:1925
static Simplex_key key(Simplex_handle sh)
Returns the key associated to a simplex.
Definition Simplex_tree.h:597
static Filtration_value filtration(Simplex_handle sh)
Returns the filtration value of a simplex.
Definition Simplex_tree.h:614
bool operator==(Simplex_tree< OtherSimplexTreeOptions > &st2)
Checks if two simplex trees are equal.
Definition Simplex_tree.h:547
bool has_children(SimplexHandle sh) const
Returns true if the node in the simplex tree pointed by the given simplex handle has children.
Definition Simplex_tree.h:742
Cofaces_simplex_range star_simplex_range(const Simplex_handle simplex)
Compute the star of a n simplex.
Definition Simplex_tree.h:1158
void expansion_with_blockers(int max_dim, Blocker block_simplex)
Expands a simplex tree containing only a graph. Simplices corresponding to cliques in the graph are a...
Definition Simplex_tree.h:1732
boost::iterator_range< Simplex_vertex_iterator > Simplex_vertex_range
Range over the vertices of a simplex.
Definition Simplex_tree.h:243
void initialize_filtration(bool ignore_infinite_values=false)
Initializes the filtration cache, i.e. sorts the simplices according to their order in the filtration...
Definition Simplex_tree.h:1055
void remove_maximal_simplex(Simplex_handle sh)
Remove a maximal simplex.
Definition Simplex_tree.h:2087
std::pair< Simplex_handle, Simplex_handle > endpoints(Simplex_handle sh)
Definition Simplex_tree.h:1016
void assign_key(Simplex_handle sh, Simplex_key key)
Assign a value 'key' to the key of the simplex represented by the Simplex_handle 'sh'.
Definition Simplex_tree.h:1009
Options::Simplex_key Simplex_key
Key associated to each simplex.
Definition Simplex_tree.h:106
Simplex_tree()
Constructs an empty simplex tree.
Definition Simplex_tree.h:397
void maybe_initialize_filtration()
Initializes the filtration cache if it isn't initialized yet.
Definition Simplex_tree.h:1083
boost::iterator_range< Complex_simplex_iterator > Complex_simplex_range
Range over the simplices of the simplicial complex.
Definition Simplex_tree.h:271
Simplex_tree_boundary_simplex_iterator< Simplex_tree > Boundary_simplex_iterator
Iterator over the simplices of the boundary of a simplex.
Definition Simplex_tree.h:257
Simplex_tree_siblings< Simplex_tree, Dictionary > Siblings
Set of nodes sharing a same parent in the simplex tree.
Definition Simplex_tree.h:127
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:767
Boundary_opposite_vertex_simplex_range boundary_opposite_vertex_simplex_range(SimplexHandle sh)
Given a simplex, returns a range over the simplices of its boundary and their opposite vertices.
Definition Simplex_tree.h:387
bool is_empty() const
Returns whether the complex is empty.
Definition Simplex_tree.h:656
Simplex_handle edge_with_same_filtration(Simplex_handle sh)
Returns an edge of sh that has the same filtration value as sh if it exists, and null_simplex() other...
Definition Simplex_tree.h:2227
Simplex_tree_complex_simplex_iterator< Simplex_tree > Complex_simplex_iterator
Iterator over the simplices of the simplicial complex.
Definition Simplex_tree.h:269
Simplex_handle simplex(Simplex_key idx) const
Returns the simplex that has index idx in the filtration.
Definition Simplex_tree.h:605
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:318
std::vector< size_t > num_simplices_by_dimension()
Returns the number of simplices of each dimension in the simplex tree.
Definition Simplex_tree.h:699
boost::transform_iterator< return_first, Dictionary_it > Complex_vertex_iterator
Iterator over the vertices of the simplicial complex.
Definition Simplex_tree.h:235
void insert_batch_vertices(VertexRange const &vertices, Filtration_value filt=0)
Inserts several vertices.
Definition Simplex_tree.h:1335
std::vector< Simplex_handle > Filtration_simplex_range
Range over the simplices of the simplicial complex, ordered by the filtration.
Definition Simplex_tree.h:281
Filtration_simplex_range::const_iterator Filtration_simplex_iterator
Iterator over the simplices of the simplicial complex, ordered by the filtration.
Definition Simplex_tree.h:285
Extended_filtration_data extend_filtration()
Extend filtration for computing extended persistence. This function only uses the filtration values a...
Definition Simplex_tree.h:2153
Simplex_handle minimal_simplex_with_same_filtration(Simplex_handle sh)
Returns a minimal face of sh that has the same filtration value as sh.
Definition Simplex_tree.h:2260
Options::Vertex_handle Vertex_handle
Type for the vertex handle.
Definition Simplex_tree.h:110
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:2126
size_t num_vertices() const
Returns the number of vertices in the complex.
Definition Simplex_tree.h:651
void expansion(int max_dim)
Expands the Simplex_tree containing only its one skeleton until dimension max_dim.
Definition Simplex_tree.h:1360
Simplex_tree(const Simplex_tree &complex_source)
User-defined copy constructor reproduces the whole tree structure.
Definition Simplex_tree.h:404
boost::iterator_range< Complex_vertex_iterator > Complex_vertex_range
Range over the vertices of the simplicial complex.
Definition Simplex_tree.h:237
static Simplex_key null_key()
Returns a fixed number not in the interval [0, num_simplices()).
Definition Simplex_tree.h:640
Boundary_simplex_range boundary_simplex_range(SimplexHandle sh)
Returns a range over the simplices of the boundary of a simplex.
Definition Simplex_tree.h:370
int dimension(Simplex_handle sh)
Returns the dimension of a simplex.
Definition Simplex_tree.h:720
bool prune_above_filtration(Filtration_value filtration)
Prune above filtration value given as parameter.
Definition Simplex_tree.h:1941
int upper_bound_dimension() const
Returns an upper bound on the dimension of the simplicial complex.
Definition Simplex_tree.h:725
Siblings * root()
Definition Simplex_tree.h:1032
int dimension()
Returns the dimension of the simplicial complex.
Definition Simplex_tree.h:733
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:942
size_t num_simplices()
Returns the number of simplices in the simplex_tree.
Definition Simplex_tree.h:664
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:276
Simplex_tree & operator=(Simplex_tree &&complex_source)
User-defined move assignment relocates the whole tree structure.
Definition Simplex_tree.h:448
boost::iterator_range< Boundary_opposite_vertex_simplex_iterator > Boundary_opposite_vertex_simplex_range
Range over the simplices of the boundary of a simplex and their opposite vertices.
Definition Simplex_tree.h:265
Simplex_tree & operator=(const Simplex_tree &complex_source)
User-defined copy assignment reproduces the whole tree structure.
Definition Simplex_tree.h:431
void insert_graph(const OneSkeletonGraph &skel_graph)
Inserts a 1-skeleton in an empty Simplex_tree.
Definition Simplex_tree.h:1272
boost::iterator_range< Skeleton_simplex_iterator > Skeleton_simplex_range
Range over the simplices of the skeleton of the simplicial complex, for a given dimension.
Definition Simplex_tree.h:279
void print_hasse(std::ostream &os)
Write the hasse diagram of the simplicial complex in os.
Definition Simplex_tree.h:1838
~Simplex_tree()
Destructor; deallocates the whole tree structure.
Definition Simplex_tree.h:426
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:635
Complex_simplex_range complex_simplex_range()
Returns a range over the simplices of the simplicial complex.
Definition Simplex_tree.h:304
Complex_vertex_range complex_vertex_range()
Returns a range over the vertices of the simplicial complex. The order is increasing according to < o...
Definition Simplex_tree.h:293
void set_dimension(int dimension, bool exact=true)
Set a dimension for the simplicial complex.
Definition Simplex_tree.h:1042
Graph simplicial complex methods.
std::ostream & operator<<(std::ostream &os, const Permutahedral_representation< Vertex, OrderedSetPartition > &simplex)
Print a permutahedral representation to a stream.
Definition Permutahedral_representation.h:173
This file includes common file reader for GUDHI.
bool read_simplex(std::istream &in_, std::vector< Vertex_handle > &simplex, Filtration_value &fil)
Read a face from a file.
Definition reader_utils.h:158
Value type for a filtration function on a cell complex.
Definition FiltrationValue.h:20
No hook when SimplexTreeOptions::link_nodes_by_label is false.
Definition hooks_simplex_base.h:20
Data structure to put all simplex tree nodes with same label into a list.
Definition hooks_simplex_base.h:29
Node of a simplex tree with filtration value and simplex key.
Definition Simplex_tree_node_explicit_storage.h:38
Concept describing an indexing scheme (see FilteredComplex) for applying continuous maps to a cell co...
Definition IndexingTag.h:18
Key type used as simplex identifier.
Definition SimplexKey.h:15
Concept of the template parameter for the class Gudhi::Simplex_tree<SimplexTreeOptions>.
Definition SimplexTreeOptions.h:17
static const bool store_filtration
If true, each simplex has extra storage for one Filtration_value, and this value is propagated by ope...
Definition SimplexTreeOptions.h:32
static const bool link_nodes_by_label
If true, the lists of Node with same label are stored to enhance cofaces and stars access.
Definition SimplexTreeOptions.h:37
static const bool stable_simplex_handles
If true, Simplex_handle will not be invalidated after insertions or removals.
Definition SimplexTreeOptions.h:39
static constexpr bool contiguous_vertices
If true, the list of vertices present in the complex must always be 0, ..., num_vertices-1,...
Definition SimplexTreeOptions.h:35
Handle type for the vertices of a cell complex.
Definition VertexHandle.h:15