11 #ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ 12 #define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ 14 #include <gudhi/Skeleton_blocker_link_complex.h> 15 #include <gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h> 16 #include <gudhi/Skeleton_blocker/internal/Trie.h> 17 #include <gudhi/Debug_utils.h> 19 #include <boost/iterator/iterator_facade.hpp> 27 namespace skeleton_blocker {
37 template<
typename SkeletonBlockerComplex,
typename Link>
39 public 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;
69 link_v(
new Link(*complex_, v_)),
71 compute_trie_and_nodes_to_be_seen();
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);
134 stream << savi.trie << std::endl;
135 stream <<
"(" << savi.nodes_to_be_seen.size() <<
") nodes to see\n";
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 childs : first_node->childs) {
167 nodes_to_be_seen.push_back(childs.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();
192 template<
typename SkeletonBlockerComplex>
193 class Simplex_iterator :
194 public boost::iterator_facade < Simplex_iterator<SkeletonBlockerComplex>
195 , typename SkeletonBlockerComplex::Simplex
196 , boost::forward_traversal_tag
197 , typename SkeletonBlockerComplex::Simplex
201 friend class boost::iterator_core_access;
205 typedef SkeletonBlockerComplex Complex;
206 typedef typename Complex::Vertex_handle Vertex_handle;
207 typedef typename Complex::Edge_handle Edge_handle;
208 typedef typename Complex::Simplex Simplex;
209 typedef typename Complex::Complex_vertex_iterator Complex_vertex_iterator;
210 typedef typename Link::Vertex_handle Link_vertex_handle;
213 const Complex* complex_;
214 Complex_vertex_iterator current_vertex_;
217 SAVI current_simplex_around_current_vertex_;
218 SAVI simplices_around_current_vertex_end_;
221 Simplex_iterator() : complex_(0) { }
223 Simplex_iterator(
const Complex* complex) :
225 current_vertex_(complex->vertex_range().begin()),
226 current_simplex_around_current_vertex_(complex, *current_vertex_),
227 simplices_around_current_vertex_end_(complex, *current_vertex_,
true) {
229 assert(!complex->empty());
233 Simplex_iterator(
const Complex* complex,
bool end) :
239 Simplex_iterator(
const Simplex_iterator& other)
241 complex_(other.complex_),
242 current_vertex_(other.current_vertex_),
243 current_simplex_around_current_vertex_(other.current_simplex_around_current_vertex_),
244 simplices_around_current_vertex_end_(other.simplices_around_current_vertex_end_) { }
246 friend Simplex_iterator make_begin_iterator(
const Complex* complex) {
247 if (complex->empty())
248 return make_end_simplex_iterator(complex);
250 return Simplex_iterator(complex);
253 friend Simplex_iterator make_end_simplex_iterator(
const Complex* complex) {
254 return Simplex_iterator(complex,
true);
257 bool equal(
const Simplex_iterator& other)
const {
258 if (complex_ != other.complex_)
return false;
259 if (current_vertex_ != other.current_vertex_)
return false;
260 if (is_end() && other.is_end())
return true;
261 if (current_simplex_around_current_vertex_ != other.current_simplex_around_current_vertex_)
267 if (current_simplex_around_current_vertex_ != simplices_around_current_vertex_end_) {
268 current_simplex_around_current_vertex_.increment();
269 if (current_simplex_around_current_vertex_ == simplices_around_current_vertex_end_)
276 void goto_next_vertex() {
277 current_vertex_.increment();
279 current_simplex_around_current_vertex_ = SAVI(complex_, *current_vertex_);
280 simplices_around_current_vertex_end_ = SAVI(complex_, *current_vertex_,
true);
284 Simplex dereference()
const {
285 return current_simplex_around_current_vertex_.dereference();
290 current_vertex_ = complex_->vertex_range().end();
293 bool is_end()
const {
294 return (current_vertex_ == complex_->vertex_range().end());
301 template<
typename SkeletonBlockerComplex,
typename Link>
303 public 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;
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();
336 complex(other.complex),
339 current_vertex(other.current_vertex),
340 link_vertex_end(other.link_vertex_end) { }
351 Vertex_handle parent_vertex(Link_vertex_handle link_vh)
const {
352 return complex->convert_handle_from_another_complex(*link, link_vh);
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;
386 namespace skbl = skeleton_blocker;
390 #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:89
Definition: SimplicialComplexForAlpha.h:14
Class representing the link of a simplicial complex encoded by a skeleton/blockers pair...
Definition: Skeleton_blocker_link_superior.h:27
Definition: Skeleton_blockers_simplices_iterators.h:302
Definition: Skeleton_blockers_simplices_iterators.h:38
Abstract Simplicial Complex represented with a skeleton/blockers pair.
Definition: Skeleton_blocker_complex.h:51