23 #ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ 24 #define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ 26 #include <gudhi/Skeleton_blocker_link_complex.h> 27 #include <gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h> 28 #include <gudhi/Skeleton_blocker/internal/Trie.h> 29 #include <gudhi/Debug_utils.h> 31 #include <boost/iterator/iterator_facade.hpp> 39 namespace skeleton_blocker {
49 template<
typename SkeletonBlockerComplex,
typename Link>
51 public boost::iterator_facade < Simplex_around_vertex_iterator<SkeletonBlockerComplex, Link>
52 , typename SkeletonBlockerComplex::Simplex
53 , boost::forward_traversal_tag
54 , typename SkeletonBlockerComplex::Simplex
56 friend class boost::iterator_core_access;
57 typedef SkeletonBlockerComplex Complex;
58 typedef typename Complex::Vertex_handle Vertex_handle;
59 typedef typename Complex::Edge_handle Edge_handle;
60 typedef typename Complex::Simplex Simplex;
63 typedef typename Link::Vertex_handle Link_vertex_handle;
65 typedef typename Gudhi::skeleton_blocker::Trie<Simplex> Trie;
68 const Complex* complex;
70 std::shared_ptr<Link> link_v;
71 std::shared_ptr<Trie> trie;
73 std::list<Trie*> nodes_to_be_seen;
81 link_v(
new Link(*complex_, v_)),
83 compute_trie_and_nodes_to_be_seen();
89 complex(other.complex),
93 nodes_to_be_seen(other.nodes_to_be_seen) {
94 if (!other.is_end()) {
108 void compute_trie_and_nodes_to_be_seen() {
114 while (!link_v->empty()) {
115 auto v0 = *(link_v->vertex_range().begin());
116 trie->add_child(build_trie(v0, trie.get()));
117 link_v->remove_vertex(v0);
119 nodes_to_be_seen.push_back(trie.get());
122 Trie* build_trie(Link_vertex_handle link_vh, Trie* parent) {
123 Trie* res =
new Trie(parent_vertex(link_vh), parent);
124 for (Link_vertex_handle nv : link_v->vertex_range(link_vh)) {
126 Simplex simplex_node_plus_nv(res->simplex());
127 simplex_node_plus_nv.add_vertex(parent_vertex(nv));
128 if (complex->contains(simplex_node_plus_nv)) {
129 res->add_child(build_trie(nv, res));
136 bool is_node_in_complex(Trie* trie) {
140 Vertex_handle parent_vertex(Link_vertex_handle link_vh)
const {
141 return complex->convert_handle_from_another_complex(*link_v, link_vh);
146 stream << savi.trie << std::endl;
147 stream <<
"(" << savi.nodes_to_be_seen.size() <<
") nodes to see\n";
152 bool same_complex = (complex == other.complex);
159 bool both_empty = nodes_to_be_seen.empty() && other.nodes_to_be_seen.empty();
163 bool both_non_empty = !nodes_to_be_seen.empty() && !other.nodes_to_be_seen.empty();
166 if (!both_non_empty)
return false;
168 bool same_node = (**(nodes_to_be_seen.begin()) == **(other.nodes_to_be_seen.begin()));
174 Trie* first_node = nodes_to_be_seen.front();
176 nodes_to_be_seen.pop_front();
178 for (
auto childs : first_node->childs) {
179 nodes_to_be_seen.push_back(childs.get());
183 Simplex dereference()
const {
184 assert(!nodes_to_be_seen.empty());
185 Trie* first_node = nodes_to_be_seen.front();
186 return first_node->simplex();
189 Simplex get_trie_address()
const {
190 assert(!nodes_to_be_seen.empty());
191 return nodes_to_be_seen.front();
196 nodes_to_be_seen.clear();
199 bool is_end()
const {
200 return nodes_to_be_seen.empty();
204 template<
typename SkeletonBlockerComplex>
205 class Simplex_iterator :
206 public boost::iterator_facade < Simplex_iterator<SkeletonBlockerComplex>
207 , typename SkeletonBlockerComplex::Simplex
208 , boost::forward_traversal_tag
209 , typename SkeletonBlockerComplex::Simplex
213 friend class boost::iterator_core_access;
217 typedef SkeletonBlockerComplex Complex;
218 typedef typename Complex::Vertex_handle Vertex_handle;
219 typedef typename Complex::Edge_handle Edge_handle;
220 typedef typename Complex::Simplex Simplex;
221 typedef typename Complex::Complex_vertex_iterator Complex_vertex_iterator;
222 typedef typename Link::Vertex_handle Link_vertex_handle;
225 const Complex* complex_;
226 Complex_vertex_iterator current_vertex_;
229 SAVI current_simplex_around_current_vertex_;
230 SAVI simplices_around_current_vertex_end_;
233 Simplex_iterator() : complex_(0) { }
235 Simplex_iterator(
const Complex* complex) :
237 current_vertex_(complex->vertex_range().begin()),
238 current_simplex_around_current_vertex_(complex, *current_vertex_),
239 simplices_around_current_vertex_end_(complex, *current_vertex_,
true) {
241 assert(!complex->empty());
245 Simplex_iterator(
const Complex* complex,
bool end) :
251 Simplex_iterator(
const Simplex_iterator& other)
253 complex_(other.complex_),
254 current_vertex_(other.current_vertex_),
255 current_simplex_around_current_vertex_(other.current_simplex_around_current_vertex_),
256 simplices_around_current_vertex_end_(other.simplices_around_current_vertex_end_) { }
258 friend Simplex_iterator make_begin_iterator(
const Complex* complex) {
259 if (complex->empty())
260 return make_end_simplex_iterator(complex);
262 return Simplex_iterator(complex);
265 friend Simplex_iterator make_end_simplex_iterator(
const Complex* complex) {
266 return Simplex_iterator(complex,
true);
269 bool equal(
const Simplex_iterator& other)
const {
270 if (complex_ != other.complex_)
return false;
271 if (current_vertex_ != other.current_vertex_)
return false;
272 if (is_end() && other.is_end())
return true;
273 if (current_simplex_around_current_vertex_ != other.current_simplex_around_current_vertex_)
279 if (current_simplex_around_current_vertex_ != simplices_around_current_vertex_end_) {
280 current_simplex_around_current_vertex_.increment();
281 if (current_simplex_around_current_vertex_ == simplices_around_current_vertex_end_)
288 void goto_next_vertex() {
289 current_vertex_.increment();
291 current_simplex_around_current_vertex_ = SAVI(complex_, *current_vertex_);
292 simplices_around_current_vertex_end_ = SAVI(complex_, *current_vertex_,
true);
296 Simplex dereference()
const {
297 return current_simplex_around_current_vertex_.dereference();
302 current_vertex_ = complex_->vertex_range().end();
305 bool is_end()
const {
306 return (current_vertex_ == complex_->vertex_range().end());
313 template<
typename SkeletonBlockerComplex,
typename Link>
315 public boost::iterator_facade < Simplex_coboundary_iterator<SkeletonBlockerComplex, Link>
316 , typename SkeletonBlockerComplex::Simplex, boost::forward_traversal_tag, typename SkeletonBlockerComplex::Simplex> {
317 friend class boost::iterator_core_access;
318 typedef SkeletonBlockerComplex Complex;
319 typedef typename Complex::Vertex_handle Vertex_handle;
320 typedef typename Complex::Edge_handle Edge_handle;
321 typedef typename Complex::Simplex Simplex;
322 typedef typename Complex::Complex_vertex_iterator Complex_vertex_iterator;
325 typedef typename Link::Vertex_handle Link_vertex_handle;
328 const Complex* complex;
329 const Simplex& sigma;
330 std::shared_ptr<Link> link;
331 Complex_vertex_iterator current_vertex;
332 Complex_vertex_iterator link_vertex_end;
341 link(
new Link(*complex_, sigma_,
false,
true)) {
342 auto link_vertex_range = link->vertex_range();
343 current_vertex = link_vertex_range.begin();
344 link_vertex_end = link_vertex_range.end();
348 complex(other.complex),
351 current_vertex(other.current_vertex),
352 link_vertex_end(other.link_vertex_end) { }
363 Vertex_handle parent_vertex(Link_vertex_handle link_vh)
const {
364 return complex->convert_handle_from_another_complex(*link, link_vh);
374 assert(complex == other.complex && sigma == other.sigma);
375 if (is_end())
return other.is_end();
376 if (other.is_end())
return is_end();
377 return *current_vertex == *(other.current_vertex);
384 Simplex dereference()
const {
386 res.add_vertex(parent_vertex(*current_vertex));
391 bool is_end()
const {
392 return !link || current_vertex == link_vertex_end;
398 namespace skbl = skeleton_blocker;
402 #endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ Simplex_around_vertex_iterator(const Complex *complex_, Vertex_handle v_, bool end)
Definition: Skeleton_blockers_simplices_iterators.h:101
Definition: SimplicialComplexForAlpha.h:26
Class representing the link of a simplicial complex encoded by a skeleton/blockers pair...
Definition: Skeleton_blocker_link_superior.h:39
Definition: Skeleton_blockers_simplices_iterators.h:314
Definition: Skeleton_blockers_simplices_iterators.h:50
Abstract Simplicial Complex represented with a skeleton/blockers pair.
Definition: Skeleton_blocker_complex.h:63