22 #ifndef GUDHI_KELETON_BLOCKERS_SIMPLICES_ITERATORS_H_
23 #define GUDHI_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_
28 #include "gudhi/Utils.h"
29 #include "boost/iterator/iterator_facade.hpp"
32 #include "gudhi/Skeleton_blocker_link_complex.h"
33 #include "gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h"
52 template<
typename SkeletonBlockerComplex,
typename Link>
54 public boost::iterator_facade < Simplex_around_vertex_iterator<SkeletonBlockerComplex,Link>
55 , typename SkeletonBlockerComplex::Simplex_handle
56 , boost::forward_traversal_tag
57 , typename SkeletonBlockerComplex::Simplex_handle
60 friend class boost::iterator_core_access;
61 typedef SkeletonBlockerComplex Complex;
62 typedef typename Complex::Vertex_handle Vertex_handle;
63 typedef typename Complex::Edge_handle Edge_handle;
64 typedef typename Complex::Simplex_handle Simplex_handle;
67 typedef typename Link::Vertex_handle Link_vertex_handle;
75 std::vector<std::shared_ptr<Trie> > childs;
84 Trie(Vertex_handle v_):v(v_),parent_(0){
87 Trie(Vertex_handle v_,Trie* parent):v(v_),parent_(parent){
91 bool operator==(
const Trie& other)
const{
92 return (v == other.v) ;
95 void add_child(Trie* child){
97 std::shared_ptr<Trie> ptr_to_add(child);
98 childs.push_back(ptr_to_add);
99 child->parent_ =
this;
104 friend std::ostream& operator<<(std::ostream& stream,
const Trie& trie){
105 stream<<
"T( "<< trie.v<<
" ";
106 for(
auto t : trie.childs)
113 void add_vertices_up_to_the_root(Simplex_handle& res)
const{
116 parent_->add_vertices_up_to_the_root(res);
119 Simplex_handle simplex()
const{
121 add_vertices_up_to_the_root(res);
125 bool is_leaf()
const{
126 return childs.empty();
129 bool is_root()
const{
133 const Trie* parent() {
140 parent_->childs.erase(
this);
148 Trie* go_bottom_left(){
152 return (*childs.begin())->go_bottom_left();
158 const Complex* complex;
160 std::shared_ptr<Link> link_v;
161 std::shared_ptr<Trie> trie;
162 std::list<Trie*> nodes_to_be_seen;
171 link_v(
new Link(*complex_,v_)),
173 compute_trie_and_nodes_to_be_seen();
179 complex(other.complex),
181 link_v(other.link_v),
183 nodes_to_be_seen(other.nodes_to_be_seen)
201 void compute_trie_and_nodes_to_be_seen(){
207 while(!link_v->empty()){
208 auto v0 = *(link_v->vertex_range().begin());
209 trie->add_child(build_trie(v0,trie.get()));
210 link_v->remove_vertex(v0);
212 nodes_to_be_seen.push_back(trie.get());
215 Trie* build_trie(Link_vertex_handle link_vh,Trie* parent){
216 Trie* res =
new Trie(parent_vertex(link_vh),parent);
217 for(Link_vertex_handle nv : link_v->vertex_range(link_vh)) {
219 Simplex_handle simplex_node_plus_nv(res->simplex());
220 simplex_node_plus_nv.add_vertex(parent_vertex(nv));
221 if(complex->contains(simplex_node_plus_nv)){
222 res->add_child(build_trie(nv,res));
229 bool is_node_in_complex(Trie* trie){
233 Vertex_handle parent_vertex(Link_vertex_handle link_vh)
const{
234 return complex->convert_handle_from_another_complex(*link_v,link_vh);
241 friend std::ostream& operator<<(std::ostream& stream,
const Simplex_around_vertex_iterator& savi){
242 stream<< savi.trie<< std::endl; ;
243 stream <<
"("<<savi.nodes_to_be_seen.size()<<
") nodes to see\n";
247 bool equal(
const Simplex_around_vertex_iterator& other)
const{
248 bool same_complex = (complex == other.complex);
255 bool both_empty = nodes_to_be_seen.empty() && other.nodes_to_be_seen.empty();
259 bool both_non_empty = !nodes_to_be_seen.empty() && !other.nodes_to_be_seen.empty();
261 if(!both_non_empty)
return false;
263 bool same_node = (**(nodes_to_be_seen.begin()) == **(other.nodes_to_be_seen.begin()));
269 Trie* first_node = nodes_to_be_seen.front();
271 nodes_to_be_seen.pop_front();
273 for(
auto childs : first_node->childs){
274 nodes_to_be_seen.push_back(childs.get());
279 Simplex_handle dereference()
const{
280 assert(!nodes_to_be_seen.empty());
281 Trie* first_node = nodes_to_be_seen.front();
282 return first_node->simplex();
287 nodes_to_be_seen.clear();
291 return nodes_to_be_seen.empty();
297 template<
typename SkeletonBlockerComplex>
298 class Simplex_iterator :
299 public boost::iterator_facade < Simplex_iterator<SkeletonBlockerComplex>
300 , typename SkeletonBlockerComplex::Simplex_handle
301 , boost::forward_traversal_tag
302 , typename SkeletonBlockerComplex::Simplex_handle
305 typedef Skeleton_blocker_link_superior<SkeletonBlockerComplex> Link;
307 friend class boost::iterator_core_access;
309 template<
class SkBlDS>
friend class Skeleton_blocker_complex;
312 typedef SkeletonBlockerComplex Complex;
313 typedef typename Complex::Vertex_handle Vertex_handle;
314 typedef typename Complex::Edge_handle Edge_handle;
315 typedef typename Complex::Simplex_handle Simplex_handle;
317 typedef typename Complex::CVI CVI;
320 typedef typename Link::Vertex_handle Link_vertex_handle;
324 const Complex* complex_;
327 typedef Simplex_around_vertex_iterator<SkeletonBlockerComplex,Link> SAVI;
328 SAVI current_simplex_around_current_vertex_;
329 SAVI simplices_around_current_vertex_end_;
333 Simplex_iterator():complex_(0){}
336 Simplex_iterator(
const Complex* complex):
338 current_vertex_(complex->vertex_range().begin()),
339 current_simplex_around_current_vertex_(complex,*current_vertex_),
340 simplices_around_current_vertex_end_(complex,*current_vertex_,true)
342 assert(!complex->empty());
347 Simplex_iterator(
const Complex* complex,
bool end):
355 Simplex_iterator(
const Simplex_iterator& other)
357 complex_(other.complex_),
358 current_vertex_(other.current_vertex_),
359 current_simplex_around_current_vertex_(other.current_simplex_around_current_vertex_),
360 simplices_around_current_vertex_end_(other.simplices_around_current_vertex_end_)
364 friend Simplex_iterator make_begin_iterator(
const Complex* complex){
366 return make_end_simplex_iterator(complex);
368 return Simplex_iterator(complex);
371 friend Simplex_iterator make_end_simplex_iterator(
const Complex* complex){
372 return Simplex_iterator(complex,
true);
375 bool equal(
const Simplex_iterator& other)
const{
376 if(complex_!=other.complex_)
return false;
377 if(current_vertex_!=other.current_vertex_)
return false;
378 if(is_end() && other.is_end())
return true;
379 if(current_simplex_around_current_vertex_ != other.current_simplex_around_current_vertex_)
385 if(current_simplex_around_current_vertex_!= simplices_around_current_vertex_end_){
386 current_simplex_around_current_vertex_.increment();
387 if( current_simplex_around_current_vertex_== simplices_around_current_vertex_end_)
395 void goto_next_vertex(){
396 current_vertex_.increment();
398 current_simplex_around_current_vertex_= SAVI(complex_,*current_vertex_);
399 simplices_around_current_vertex_end_ = SAVI(complex_,*current_vertex_,
true);
403 Simplex_handle dereference()
const{
404 return current_simplex_around_current_vertex_.dereference();
409 current_vertex_ = complex_->vertex_range().end();
413 return (current_vertex_ == complex_->vertex_range().end());
Simplex_around_vertex_iterator(const Complex *complex_, Vertex_handle v_, bool end)
Definition: Skeleton_blockers_simplices_iterators.h:192
Definition: Skeleton_blockers_simplices_iterators.h:53