38class Simplex_around_vertex_iterator :
39public boost::iterator_facade < Simplex_around_vertex_iterator<SkeletonBlockerComplex, Link>
40, typename SkeletonBlockerComplex::Simplex
41, boost::forward_traversal_tag
42, typename SkeletonBlockerComplex::Simplex
44 friend class boost::iterator_core_access;
45 typedef SkeletonBlockerComplex Complex;
46 typedef typename Complex::Vertex_handle Vertex_handle;
47 typedef typename Complex::Edge_handle Edge_handle;
48 typedef typename Complex::Simplex Simplex;
51 typedef typename Link::Vertex_handle Link_vertex_handle;
53 typedef typename Gudhi::skeleton_blocker::Trie<Simplex> Trie;
56 const Complex* complex;
58 std::shared_ptr<Link> link_v;
59 std::shared_ptr<Trie> trie;
61 std::list<Trie*> nodes_to_be_seen;
64 Simplex_around_vertex_iterator() : complex(0) { }
66 Simplex_around_vertex_iterator(
const Complex* complex_, Vertex_handle v_) :
69 link_v(
new Link(*complex_, v_)),
71 compute_trie_and_nodes_to_be_seen();
76 Simplex_around_vertex_iterator(
const Simplex_around_vertex_iterator& other) :
77 complex(other.complex),
81 nodes_to_be_seen(other.nodes_to_be_seen) {
82 if (!other.is_end()) {
96 void compute_trie_and_nodes_to_be_seen() {
102 while (!link_v->empty()) {
103 auto v0 = *(link_v->vertex_range().begin());
104 trie->add_child(build_trie(v0, trie.get()));
105 link_v->remove_vertex(v0);
107 nodes_to_be_seen.push_back(trie.get());
110 Trie* build_trie(Link_vertex_handle link_vh, Trie* parent) {
111 Trie* res =
new Trie(parent_vertex(link_vh), parent);
112 for (Link_vertex_handle nv : link_v->vertex_range(link_vh)) {
114 Simplex simplex_node_plus_nv(res->simplex());
115 simplex_node_plus_nv.add_vertex(parent_vertex(nv));
116 if (complex->contains(simplex_node_plus_nv)) {
117 res->add_child(build_trie(nv, res));
124 bool is_node_in_complex(Trie* trie) {
128 Vertex_handle parent_vertex(Link_vertex_handle link_vh)
const {
129 return complex->convert_handle_from_another_complex(*link_v, link_vh);
133 friend std::ostream& operator<<(std::ostream& stream,
const Simplex_around_vertex_iterator& savi) {
134 stream << savi.trie << std::endl;
135 stream <<
"(" << savi.nodes_to_be_seen.size() <<
") nodes to see\n";
139 bool equal(
const Simplex_around_vertex_iterator& other)
const {
140 bool same_complex = (complex == other.complex);
147 bool both_empty = nodes_to_be_seen.empty() && other.nodes_to_be_seen.empty();
151 bool both_non_empty = !nodes_to_be_seen.empty() && !other.nodes_to_be_seen.empty();
154 if (!both_non_empty)
return false;
156 bool same_node = (**(nodes_to_be_seen.begin()) == **(other.nodes_to_be_seen.begin()));
162 Trie* first_node = nodes_to_be_seen.front();
164 nodes_to_be_seen.pop_front();
166 for (
auto child : first_node->children) {
167 nodes_to_be_seen.push_back(child.get());
171 Simplex dereference()
const {
172 assert(!nodes_to_be_seen.empty());
173 Trie* first_node = nodes_to_be_seen.front();
174 return first_node->simplex();
177 Simplex get_trie_address()
const {
178 assert(!nodes_to_be_seen.empty());
179 return nodes_to_be_seen.front();
184 nodes_to_be_seen.clear();
187 bool is_end()
const {
188 return nodes_to_be_seen.empty();
302class Simplex_coboundary_iterator :
303public boost::iterator_facade < Simplex_coboundary_iterator<SkeletonBlockerComplex, Link>
304, typename SkeletonBlockerComplex::Simplex, boost::forward_traversal_tag, typename SkeletonBlockerComplex::Simplex> {
305 friend class boost::iterator_core_access;
306 typedef SkeletonBlockerComplex Complex;
307 typedef typename Complex::Vertex_handle Vertex_handle;
308 typedef typename Complex::Edge_handle Edge_handle;
309 typedef typename Complex::Simplex Simplex;
310 typedef typename Complex::Complex_vertex_iterator Complex_vertex_iterator;
313 typedef typename Link::Vertex_handle Link_vertex_handle;
316 const Complex* complex;
317 const Simplex& sigma;
318 std::shared_ptr<Link> link;
319 Complex_vertex_iterator current_vertex;
320 Complex_vertex_iterator link_vertex_end;
323 Simplex_coboundary_iterator() : complex(0) { }
325 Simplex_coboundary_iterator(
const Complex* complex_,
const Simplex& sigma_) :
329 link(
new Link(*complex_, sigma_,
false,
true)) {
330 auto link_vertex_range = link->vertex_range();
331 current_vertex = link_vertex_range.begin();
332 link_vertex_end = link_vertex_range.end();
335 Simplex_coboundary_iterator(
const Simplex_coboundary_iterator& other) :
336 complex(other.complex),
339 current_vertex(other.current_vertex),
340 link_vertex_end(other.link_vertex_end) { }
343 Simplex_coboundary_iterator(
const Complex* complex_,
const Simplex& sigma_,
bool end) :
351 Vertex_handle parent_vertex(Link_vertex_handle link_vh)
const {
352 return complex->convert_handle_from_another_complex(*link, link_vh);
356 friend std::ostream& operator<<(std::ostream& stream,
const Simplex_coboundary_iterator& sci) {
361 bool equal(
const Simplex_coboundary_iterator& other)
const {
362 assert(complex == other.complex && sigma == other.sigma);
363 if (is_end())
return other.is_end();
364 if (other.is_end())
return is_end();
365 return *current_vertex == *(other.current_vertex);
372 Simplex dereference()
const {
374 res.
add_vertex(parent_vertex(*current_vertex));
379 bool is_end()
const {
380 return !link || current_vertex == link_vertex_end;