22 #ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_
23 #define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_
25 #include <gudhi/Skeleton_blocker_link_complex.h>
26 #include <gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h>
27 #include <gudhi/Skeleton_blocker/internal/Trie.h>
28 #include <gudhi/Utils.h>
30 #include <boost/iterator/iterator_facade.hpp>
48 template<
typename SkeletonBlockerComplex,
typename Link>
50 public boost::iterator_facade < Simplex_around_vertex_iterator<SkeletonBlockerComplex, Link>
51 , typename SkeletonBlockerComplex::Simplex_handle
52 , boost::forward_traversal_tag
53 , typename SkeletonBlockerComplex::Simplex_handle
55 friend class boost::iterator_core_access;
56 typedef SkeletonBlockerComplex Complex;
58 typedef typename Complex::Edge_handle Edge_handle;
62 typedef typename Link::Vertex_handle Link_vertex_handle;
64 typedef typename Gudhi::skbl::Trie<Simplex_handle> Trie;
67 const Complex* complex;
69 std::shared_ptr<Link> link_v;
70 std::shared_ptr<Trie> trie;
71 std::list<Trie*> nodes_to_be_seen;
79 link_v(
new Link(*complex_, v_)),
81 compute_trie_and_nodes_to_be_seen();
87 complex(other.complex),
91 nodes_to_be_seen(other.nodes_to_be_seen) {
92 if (!other.is_end()) {}
105 void compute_trie_and_nodes_to_be_seen() {
111 while (!link_v->empty()) {
112 auto v0 = *(link_v->vertex_range().begin());
113 trie->add_child(build_trie(v0, trie.get()));
114 link_v->remove_vertex(v0);
116 nodes_to_be_seen.push_back(trie.get());
119 Trie* build_trie(Link_vertex_handle link_vh, Trie* parent) {
120 Trie* res =
new Trie(parent_vertex(link_vh), parent);
121 for (Link_vertex_handle nv : link_v->vertex_range(link_vh)) {
124 simplex_node_plus_nv.
add_vertex(parent_vertex(nv));
125 if (complex->contains(simplex_node_plus_nv)) {
126 res->add_child(build_trie(nv, res));
133 bool is_node_in_complex(Trie* trie) {
137 Vertex_handle parent_vertex(Link_vertex_handle link_vh)
const {
138 return complex->convert_handle_from_another_complex(*link_v, link_vh);
142 friend std::ostream& operator<<(std::ostream& stream,
const Simplex_around_vertex_iterator& savi) {
143 stream << savi.trie << std::endl;
144 stream <<
"(" << savi.nodes_to_be_seen.size() <<
") nodes to see\n";
148 bool equal(
const Simplex_around_vertex_iterator& other)
const {
149 bool same_complex = (complex == other.complex);
156 bool both_empty = nodes_to_be_seen.empty() && other.nodes_to_be_seen.empty();
160 bool both_non_empty = !nodes_to_be_seen.empty() && !other.nodes_to_be_seen.empty();
162 if (!both_non_empty)
return false;
164 bool same_node = (**(nodes_to_be_seen.begin()) == **(other.nodes_to_be_seen.begin()));
170 Trie* first_node = nodes_to_be_seen.front();
172 nodes_to_be_seen.pop_front();
174 for (
auto childs : first_node->childs) {
175 nodes_to_be_seen.push_back(childs.get());
180 assert(!nodes_to_be_seen.empty());
181 Trie* first_node = nodes_to_be_seen.front();
182 return first_node->simplex();
186 assert(!nodes_to_be_seen.empty());
187 return nodes_to_be_seen.front();
192 nodes_to_be_seen.clear();
195 bool is_end()
const {
196 return nodes_to_be_seen.empty();
200 template<
typename SkeletonBlockerComplex>
201 class Simplex_iterator :
202 public boost::iterator_facade < Simplex_iterator<SkeletonBlockerComplex>
203 , typename SkeletonBlockerComplex::Simplex_handle
204 , boost::forward_traversal_tag
205 , typename SkeletonBlockerComplex::Simplex_handle
207 typedef Skeleton_blocker_link_superior<SkeletonBlockerComplex> Link;
209 friend class boost::iterator_core_access;
211 template<
class SkBlDS>
friend class Skeleton_blocker_complex;
213 typedef SkeletonBlockerComplex
Complex;
215 typedef typename Complex::Edge_handle Edge_handle;
218 typedef typename Link::Vertex_handle Link_vertex_handle;
222 Complex_vertex_iterator current_vertex_;
224 typedef Simplex_around_vertex_iterator<SkeletonBlockerComplex, Link> SAVI;
225 SAVI current_simplex_around_current_vertex_;
226 SAVI simplices_around_current_vertex_end_;
229 Simplex_iterator() : complex_(0) { }
231 Simplex_iterator(
const Complex* complex) :
233 current_vertex_(complex->vertex_range().begin()),
234 current_simplex_around_current_vertex_(complex, *current_vertex_),
235 simplices_around_current_vertex_end_(complex, *current_vertex_, true) {
237 assert(!complex->empty());
242 Simplex_iterator(
const Complex* complex,
bool end) :
248 Simplex_iterator(
const Simplex_iterator& other)
250 complex_(other.complex_),
251 current_vertex_(other.current_vertex_),
252 current_simplex_around_current_vertex_(other.current_simplex_around_current_vertex_),
253 simplices_around_current_vertex_end_(other.simplices_around_current_vertex_end_) { }
255 friend Simplex_iterator make_begin_iterator(
const Complex* complex) {
256 if (complex->empty())
257 return make_end_simplex_iterator(complex);
259 return Simplex_iterator(complex);
262 friend Simplex_iterator make_end_simplex_iterator(
const Complex* complex) {
263 return Simplex_iterator(complex,
true);
266 bool equal(
const Simplex_iterator& other)
const {
267 if (complex_ != other.complex_)
return false;
268 if (current_vertex_ != other.current_vertex_)
return false;
269 if (is_end() && other.is_end())
return true;
270 if (current_simplex_around_current_vertex_ != other.current_simplex_around_current_vertex_)
276 if (current_simplex_around_current_vertex_ != simplices_around_current_vertex_end_) {
277 current_simplex_around_current_vertex_.increment();
278 if (current_simplex_around_current_vertex_ == simplices_around_current_vertex_end_)
285 void goto_next_vertex() {
286 current_vertex_.increment();
288 current_simplex_around_current_vertex_ = SAVI(complex_, *current_vertex_);
289 simplices_around_current_vertex_end_ = SAVI(complex_, *current_vertex_,
true);
294 return current_simplex_around_current_vertex_.dereference();
299 current_vertex_ = complex_->vertex_range().end();
302 bool is_end()
const {
303 return (current_vertex_ == complex_->vertex_range().end());
311 #endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_
void add_vertex(T v)
Definition: Skeleton_blocker_simplex.h:124
Simplex_around_vertex_iterator(const Complex *complex_, Vertex_handle v_, bool end)
Definition: Skeleton_blockers_simplices_iterators.h:98
Abstract simplex used in Skeleton blockers data-structure.
Definition: Skeleton_blocker_simplex.h:50
Definition: Skeleton_blockers_simplices_iterators.h:49
Definition: SkeletonBlockerDS.h:60
Iterator on the vertices of a simplicial complex.
Definition: Skeleton_blockers_vertices_iterators.h:39