12#ifndef SIMPLEX_TREE_H_
13#define SIMPLEX_TREE_H_
15#include <gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h>
16#include <gudhi/Simplex_tree/Simplex_tree_siblings.h>
17#include <gudhi/Simplex_tree/Simplex_tree_iterators.h>
18#include <gudhi/Simplex_tree/indexing_tag.h>
19#include <gudhi/Simplex_tree/serialization_utils.h>
23#include <gudhi/Debug_utils.h>
25#include <boost/container/flat_map.hpp>
26#include <boost/iterator/transform_iterator.hpp>
27#include <boost/graph/adjacency_list.hpp>
28#include <boost/range/adaptor/reversed.hpp>
29#include <boost/range/adaptor/transformed.hpp>
30#include <boost/range/size.hpp>
31#include <boost/container/static_vector.hpp>
34#include <tbb/parallel_sort.h>
42#include <initializer_list>
67struct Simplex_tree_options_full_featured;
82template<
typename SimplexTreeOptions = Simplex_tree_options_full_featured>
106 typedef typename boost::container::flat_map<Vertex_handle, Node> Dictionary;
113 struct Key_simplex_base_real {
114 Key_simplex_base_real() : key_(-1) {}
120 struct Key_simplex_base_dummy {
121 Key_simplex_base_dummy() {}
123 void assign_key(Simplex_key);
124 Simplex_key key()
const;
126 struct Extended_filtration_data {
129 Extended_filtration_data(){}
132 typedef typename std::conditional<Options::store_key, Key_simplex_base_real, Key_simplex_base_dummy>::type
135 struct Filtration_simplex_base_real {
136 Filtration_simplex_base_real() : filt_(0) {}
142 struct Filtration_simplex_base_dummy {
143 Filtration_simplex_base_dummy() {}
144 void assign_filtration(
Filtration_value GUDHI_CHECK_code(f)) { GUDHI_CHECK(f == 0,
"filtration value specified for a complex that does not store them"); }
148 Filtration_simplex_base_dummy>::type Filtration_simplex_base;
159 typedef typename Dictionary::iterator Dictionary_it;
160 typedef typename Dictionary_it::value_type Dit_value_t;
162 struct return_first {
232 boost::make_transform_iterator(root_.members_.begin(), return_first()),
233 boost::make_transform_iterator(root_.members_.end(), return_first()));
277 return filtration_vect_;
306 template<
class SimplexHandle>
323 template<
class SimplexHandle>
1958template<
typename...T>
1960 for (
auto sh : st.filtration_simplex_range()) {
1962 for (
auto v : st.simplex_vertex_range(sh)) {
1970template<
typename...T>
1973 std::vector<typename ST::Vertex_handle> simplex;
1979 int dim =
static_cast<int> (simplex.size() - 1);
1980 if (max_dim < dim) {
1998 typedef int Vertex_handle;
1999 typedef double Filtration_value;
2000 typedef std::uint32_t Simplex_key;
2001 static const bool store_key =
true;
2002 static const bool store_filtration =
true;
2003 static const bool contiguous_vertices =
false;
2014 typedef int Vertex_handle;
2015 typedef float Filtration_value;
2016 typedef std::uint32_t Simplex_key;
2017 static const bool store_key =
true;
2018 static const bool store_filtration =
true;
2019 static const bool contiguous_vertices =
true;
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:190
Iterator over the simplices of the boundary of a simplex.
Definition Simplex_tree_iterators.h:83
Iterator over the simplices of a simplicial complex.
Definition Simplex_tree_iterators.h:300
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:38
Iterator over the simplices of the skeleton of a given dimension of the simplicial complex.
Definition Simplex_tree_iterators.h:374
Simplex Tree data structure for representing simplicial complexes.
Definition Simplex_tree.h:83
static Siblings * self_siblings(SimplexHandle sh)
Definition Simplex_tree.h:893
Simplex_tree(Simplex_tree &&complex_source)
User-defined move constructor relocates the whole tree structure.
Definition Simplex_tree.h:351
bool operator==(Simplex_tree &st2)
Checks if two simplex trees are equal.
Definition Simplex_tree.h:476
Options::Filtration_value Filtration_value
Type for the value of the filtration function.
Definition Simplex_tree.h:90
Cofaces_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension)
Compute the cofaces of a n simplex.
Definition Simplex_tree.h:1032
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:200
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:1779
void assign_filtration(Simplex_handle sh, Filtration_value fv)
Sets the filtration value of a simplex.
Definition Simplex_tree.h:550
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:1410
Dictionary::iterator Simplex_handle
Handle type to a simplex contained in the simplicial complex represented by the simplex tree.
Definition Simplex_tree.h:156
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:1714
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:275
bool prune_above_dimension(int dimension)
Remove all simplices of dimension greater than a given value.
Definition Simplex_tree.h:1505
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:789
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:571
boost::iterator_range< Boundary_simplex_iterator > Boundary_simplex_range
Range over the simplices of the boundary of a simplex.
Definition Simplex_tree.h:196
Simplex_vertex_range simplex_vertex_range(Simplex_handle sh) const
Returns a range over the vertices of a simplex.
Definition Simplex_tree.h:286
void clear_filtration()
Clears the filtration cache produced by initialize_filtration().
Definition Simplex_tree.h:958
Simplex_tree_simplex_vertex_iterator< Simplex_tree > Simplex_vertex_iterator
Iterator over the vertices of a simplex.
Definition Simplex_tree.h:186
static Simplex_key key(Simplex_handle sh)
Returns the key associated to a simplex.
Definition Simplex_tree.h:522
static Filtration_value filtration(Simplex_handle sh)
Returns the filtration value of a simplex.
Definition Simplex_tree.h:539
bool operator!=(Simplex_tree &st2)
Checks if two simplex trees are different.
Definition Simplex_tree.h:484
bool has_children(SimplexHandle sh) const
Returns true if the node in the simplex tree pointed by sh has children.
Definition Simplex_tree.h:637
Cofaces_simplex_range star_simplex_range(const Simplex_handle simplex)
Compute the star of a n simplex.
Definition Simplex_tree.h:1021
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:1291
boost::iterator_range< Simplex_vertex_iterator > Simplex_vertex_range
Range over the vertices of a simplex.
Definition Simplex_tree.h:188
void remove_maximal_simplex(Simplex_handle sh)
Remove a maximal simplex.
Definition Simplex_tree.h:1586
std::pair< Simplex_handle, Simplex_handle > endpoints(Simplex_handle sh)
Definition Simplex_tree.h:886
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:879
Options::Simplex_key Simplex_key
Key associated to each simplex.
Definition Simplex_tree.h:94
Simplex_tree()
Constructs an empty simplex tree.
Definition Simplex_tree.h:334
void maybe_initialize_filtration()
Initializes the filtration cache if it isn't initialized yet.
Definition Simplex_tree.h:949
boost::iterator_range< Complex_simplex_iterator > Complex_simplex_range
Range over the simplices of the simplicial complex.
Definition Simplex_tree.h:208
Simplex_tree_boundary_simplex_iterator< Simplex_tree > Boundary_simplex_iterator
Iterator over the simplices of the boundary of a simplex.
Definition Simplex_tree.h:194
Simplex_tree_siblings< Simplex_tree, Dictionary > Siblings
Set of nodes sharing a same parent in the simplex tree.
Definition Simplex_tree.h:109
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:650
std::vector< Simplex_handle > Cofaces_simplex_range
Range over the cofaces of a simplex.
Definition Simplex_tree.h:190
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:324
bool is_empty() const
Returns whether the complex is empty.
Definition Simplex_tree.h:581
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:1728
Simplex_tree_complex_simplex_iterator< Simplex_tree > Complex_simplex_iterator
Iterator over the simplices of the simplicial complex.
Definition Simplex_tree.h:206
Simplex_handle simplex(Simplex_key idx) const
Returns the simplex that has index idx in the filtration.
Definition Simplex_tree.h:530
void initialize_filtration()
Initializes the filtration cache, i.e. sorts the simplices according to their order in the filtration...
Definition Simplex_tree.h:925
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:255
boost::transform_iterator< return_first, Dictionary_it > Complex_vertex_iterator
Iterator over the vertices of the simplicial complex.
Definition Simplex_tree.h:180
void insert_batch_vertices(VertexRange const &vertices, Filtration_value filt=0)
Inserts several vertices.
Definition Simplex_tree.h:1176
std::vector< Simplex_handle > Filtration_simplex_range
Range over the simplices of the simplicial complex, ordered by the filtration.
Definition Simplex_tree.h:218
Filtration_simplex_range::const_iterator Filtration_simplex_iterator
Iterator over the simplices of the simplicial complex, ordered by the filtration.
Definition Simplex_tree.h:222
Extended_filtration_data extend_filtration()
Extend filtration for computing extended persistence. This function only uses the filtration values a...
Definition Simplex_tree.h:1652
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:1761
Options::Vertex_handle Vertex_handle
Type for the vertex handle.
Definition Simplex_tree.h:98
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:1623
size_t num_vertices() const
Returns the number of vertices in the complex.
Definition Simplex_tree.h:576
void expansion(int max_dim)
Expands the Simplex_tree containing only its one skeleton until dimension max_dim.
Definition Simplex_tree.h:1194
Simplex_tree(const Simplex_tree &complex_source)
User-defined copy constructor reproduces the whole tree structure.
Definition Simplex_tree.h:341
boost::iterator_range< Complex_vertex_iterator > Complex_vertex_range
Range over the vertices of the simplicial complex.
Definition Simplex_tree.h:182
static Simplex_key null_key()
Returns a fixed number not in the interval [0, num_simplices()).
Definition Simplex_tree.h:565
Boundary_simplex_range boundary_simplex_range(SimplexHandle sh)
Returns a range over the simplices of the boundary of a simplex.
Definition Simplex_tree.h:307
int dimension(Simplex_handle sh)
Returns the dimension of a simplex.
Definition Simplex_tree.h:609
bool prune_above_filtration(Filtration_value filtration)
Prune above filtration value given as parameter.
Definition Simplex_tree.h:1464
int upper_bound_dimension() const
Returns an upper bound on the dimension of the simplicial complex.
Definition Simplex_tree.h:620
Siblings * root()
Definition Simplex_tree.h:902
int dimension()
Returns the dimension of the simplicial complex.
Definition Simplex_tree.h:628
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:818
size_t num_simplices()
returns the number of simplices in the simplex_tree.
Definition Simplex_tree.h:587
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:213
Simplex_tree & operator=(Simplex_tree &&complex_source)
User-defined move assignment relocates the whole tree structure.
Definition Simplex_tree.h:385
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:202
Simplex_tree & operator=(const Simplex_tree &complex_source)
User-defined copy assignment reproduces the whole tree structure.
Definition Simplex_tree.h:368
void insert_graph(const OneSkeletonGraph &skel_graph)
Inserts a 1-skeleton in an empty Simplex_tree.
Definition Simplex_tree.h:1119
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:216
void print_hasse(std::ostream &os)
Write the hasse diagram of the simplicial complex in os.
Definition Simplex_tree.h:1392
~Simplex_tree()
Destructor; deallocates the whole tree structure.
Definition Simplex_tree.h:363
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:560
Complex_simplex_range complex_simplex_range()
Returns a range over the simplices of the simplicial complex.
Definition Simplex_tree.h:241
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:230
void set_dimension(int dimension, bool exact=true)
Set a dimension for the simplicial complex.
Definition Simplex_tree.h:912
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
Node of a simplex tree with filtration value and simplex key.
Definition Simplex_tree_node_explicit_storage.h:29
Definition Simplex_tree.h:2012
Definition Simplex_tree.h:1996
Tag for a linear ordering of simplices.
Definition indexing_tag.h:20
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:15
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:27
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:29
Handle type for the vertices of a cell complex.
Definition VertexHandle.h:15