23 #ifndef GUDHI_HASSE_DIAGRAM_H
24 #define GUDHI_HASSE_DIAGRAM_H
27 #include <boost/iterator/counting_iterator.hpp>
31 template <
class HasseCpx >
35 template<
class Complex_ds >
36 Hasse_simplex ( Complex_ds & cpx
37 ,
typename Complex_ds::Simplex_handle sh )
39 , filtration_(cpx.filtration(sh))
42 boundary_.reserve(cpx.dimension(sh)+1);
43 for(
auto b_sh : cpx.boundary_simplex_range(sh) )
44 { boundary_.push_back( cpx.key(b_sh) ); }
47 Hasse_simplex (
typename HasseCpx::Simplex_key key
48 ,
typename HasseCpx::Filtration_value fil
49 , std::vector<typename HasseCpx::Simplex_handle> boundary)
52 , boundary_(boundary) {}
54 typename HasseCpx::Simplex_key key_;
55 typename HasseCpx::Filtration_value filtration_;
56 std::vector<typename HasseCpx::Simplex_handle> boundary_;
76 typedef Hasse_simplex<Hasse_complex> Hasse_simp;
79 typedef int Simplex_handle;
81 typedef boost::counting_iterator< Simplex_handle > Filtration_simplex_iterator;
82 typedef boost::iterator_range<Filtration_simplex_iterator> Filtration_simplex_range;
84 typedef typename std::vector< Simplex_handle >::iterator Boundary_simplex_iterator;
85 typedef boost::iterator_range<Boundary_simplex_iterator> Boundary_simplex_range;
87 typedef typename std::vector< Simplex_handle >::iterator Skeleton_simplex_iterator;
88 typedef boost::iterator_range< Skeleton_simplex_iterator > Skeleton_simplex_range;
92 Skeleton_simplex_range skeleton_simplex_range(
int dim = 0 ) {
93 if(dim != 0) { std::cerr <<
"Dimension must be 0 \n"; }
94 return Skeleton_simplex_range(vertices_.begin(),vertices_.end());
97 template <
class Complex_ds >
101 , threshold_(cpx.filtration())
103 , dim_max_(cpx.dimension())
105 complex_.reserve(cpx.num_simplices());
107 for(
auto cpx_sh : cpx.filtration_simplex_range())
109 complex_.push_back(Hasse_simp(cpx,cpx_sh));
110 if(dimension(idx) == 0) { vertices_.push_back(idx); }
122 size_t num_simplices() {
return complex_.size(); }
124 Filtration_simplex_range filtration_simplex_range()
125 {
return Filtration_simplex_range( Filtration_simplex_iterator(0)
126 , Filtration_simplex_iterator(complex_.size()) ); }
128 Simplex_key key( Simplex_handle sh ) {
return complex_[sh].key_; }
134 if(key == null_key())
return null_simplex();
138 Simplex_handle null_simplex() {
return -1; }
141 if( sh == null_simplex() ) {
return filtration(); }
142 return complex_[sh].filtration_;
147 int dimension ( Simplex_handle sh ) {
148 if(complex_[sh].boundary_.empty())
return 0;
149 return complex_[sh].boundary_.size()-1;
151 int dimension () {
return dim_max_; }
153 std::pair<Simplex_handle,Simplex_handle> endpoints( Simplex_handle sh )
154 {
return std::pair<Simplex_handle,Simplex_handle>( complex_[sh].boundary_[0]
155 , complex_[sh].boundary_[1] ) ;}
157 void assign_key( Simplex_handle sh,
Simplex_key key) { complex_[sh].key_ = key; }
159 Boundary_simplex_range boundary_simplex_range ( Simplex_handle sh )
160 {
return Boundary_simplex_range( complex_[sh].boundary_.begin()
161 , complex_[sh].boundary_.end() ); }
163 void display_simplex(Simplex_handle sh)
165 std::cout << dimension(sh) <<
" ";
166 for(
auto sh_b : boundary_simplex_range(sh)) std::cout << sh_b <<
" ";
167 std::cout <<
" " << filtration(sh) <<
" key=" << key(sh);
170 void initialize_filtration()
173 for(
auto & h_simp : complex_) { h_simp.key_ = key; ++key; }
176 std::vector< Hasse_simp > complex_;
177 std::vector<Simplex_handle> vertices_;
179 size_t num_vertices_;
183 template<
typename T1,
typename T2,
typename T3 >
184 std::istream& operator>> ( std::istream & is
187 assert(hcpx.num_simplices() == 0);
191 hcpx.complex_.reserve(num_simp);
193 std::vector< typename Hasse_complex<T1,T2,T3>::Simplex_key > boundary;
198 while(read_hasse_simplex( is, boundary, fil ))
203 if(max_dim < hcpx.dimension(key)) { max_dim = hcpx.dimension(key); }
204 if(hcpx.dimension(key) == 0) { hcpx.vertices_.push_back(key); }
205 if(max_fil < fil) { max_fil = fil; }
211 hcpx.dim_max_ = max_dim;
212 hcpx.threshold_ = max_fil;
219 #endif // GUDHI_HASSE_DIAGRAM_H
Key type used as simplex identifier.
Definition: SimplexKey.h:27
Data structure representing a Hasse diagram, i.e. a complex where all codimension 1 incidence relatio...
Definition: Hasse_complex.h:72
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:32
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:26