22 #ifndef GUDHI_SKELETON_BLOCKERS_SIMPLIFIABLE_COMPLEX_H_
23 #define GUDHI_SKELETON_BLOCKERS_SIMPLIFIABLE_COMPLEX_H_
25 #include "gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h"
37 template<
typename SkeletonBlockerDS>
48 typedef typename SkeletonBlockerComplex::boost_adjacency_iterator boost_adjacency_iterator;
50 typedef typename SkeletonBlockerComplex::boost_vertex_handle boost_vertex_handle;
58 typedef typename SkeletonBlockerComplex::Root_simplex_iterator Root_simplex_iterator;
59 typedef typename SkeletonBlockerComplex::Simplex_handle_iterator Simplex_handle_iterator;
60 typedef typename SkeletonBlockerComplex::BlockerMap BlockerMap;
61 typedef typename SkeletonBlockerComplex::BlockerPair BlockerPair;
62 typedef typename SkeletonBlockerComplex::BlockerMapIterator BlockerMapIterator;
63 typedef typename SkeletonBlockerComplex::BlockerMapConstIterator BlockerMapConstIterator;
103 build_link_of_blocker(*
this,*sigma,link_blocker_sigma);
105 bool res = link_blocker_sigma.is_contractible()==CONTRACTIBLE;
118 std::list<Blocker_handle> get_blockers(){
119 std::list<Blocker_handle> res;
121 res.push_back(blocker);
135 std::list<Vertex_handle> vertex_to_check;
137 vertex_to_check.push_front(v);
139 while(!vertex_to_check.empty()){
141 vertex_to_check.pop_front();
143 bool blocker_popable_found=
true;
144 while (blocker_popable_found){
145 blocker_popable_found =
false;
149 if(nv!=v) vertex_to_check.push_back(nv);
151 blocker_popable_found =
true;
164 bool blocker_popable_found=
true;
165 while (blocker_popable_found){
166 blocker_popable_found =
false;
170 blocker_popable_found =
true;
183 update_blockers_after_remove_star_of_vertex_or_edge(v);
185 while (this->
degree(v) > 0)
187 Vertex_handle w( * (adjacent_vertices(v.vertex, this->skeleton).first));
199 void update_blockers_after_remove_star_of_vertex_or_edge(
const Simplex_handle& simplex_to_be_removed){
200 std::list <Blocker_handle> blockers_to_update;
201 if(simplex_to_be_removed.empty())
return;
203 auto v0 = simplex_to_be_removed.first_vertex();
205 if(blocker->contains(simplex_to_be_removed))
206 blockers_to_update.push_back(blocker);
209 for(
auto blocker_to_update : blockers_to_update){
210 Simplex_handle sub_blocker_to_be_added;
211 bool sub_blocker_need_to_be_added =
212 (blocker_to_update->dimension()-simplex_to_be_removed.dimension()) >= 2;
213 if(sub_blocker_need_to_be_added){
214 sub_blocker_to_be_added = *blocker_to_update;
215 sub_blocker_to_be_added.difference(simplex_to_be_removed);
218 if(sub_blocker_need_to_be_added)
231 update_blockers_after_remove_star_of_vertex_or_edge(
Simplex_handle(a,b));
255 remove_blocker_containing_simplex(sigma);
267 remove_blocker_include_in_simplex(sigma);
274 void remove_blocker_containing_simplex(
const Simplex_handle& sigma){
275 std::vector <Blocker_handle> blockers_to_remove;
276 for (
auto blocker : this->
blocker_range(sigma.first_vertex())){
277 if(blocker->contains(sigma))
278 blockers_to_remove.push_back(blocker);
280 for(
auto blocker_to_update : blockers_to_remove)
287 void remove_blocker_include_in_simplex(
const Simplex_handle& sigma){
288 std::vector <Blocker_handle> blockers_to_remove;
289 for (
auto blocker : this->
blocker_range(sigma.first_vertex())){
290 if(sigma.contains(*blocker))
291 blockers_to_remove.push_back(blocker);
293 for(
auto blocker_to_update : blockers_to_remove)
300 enum simplifiable_status{ NOT_HOMOTOPY_EQ,MAYBE_HOMOTOPY_EQ,HOMOTOPY_EQ};
301 simplifiable_status is_remove_star_homotopy_preserving(
const Simplex_handle& simplex){
302 return MAYBE_HOMOTOPY_EQ;
307 enum contractible_status{ NOT_CONTRACTIBLE,MAYBE_CONTRACTIBLE,CONTRACTIBLE};
318 if (this->
is_cone())
return CONTRACTIBLE;
319 else return MAYBE_CONTRACTIBLE;
339 if ( blocker->contains(b) ){
371 void tip_blockers(Vertex_handle a, Vertex_handle b, std::vector<Simplex_handle> & buffer)
const{
374 Simplex_handle beta = (*blocker);
375 beta.remove_vertex(a);
376 buffer.push_back(beta);
380 this->add_neighbours(b,n);
381 this->remove_neighbours(a,n);
385 for (Vertex_handle y : n)
388 beta.add_vertex( y );
389 buffer.push_back(beta);
404 void swap_edge(Vertex_handle a,Vertex_handle b,Vertex_handle x){
406 if (this->visitor) this->visitor->on_swaped_edge(a,b,x);
415 void delete_blockers_around_vertex(Vertex_handle v){
416 std::list <Blocker_handle> blockers_to_delete;
418 blockers_to_delete.push_back(blocker);
420 while (!blockers_to_delete.empty()){
422 blockers_to_delete.pop_back();
429 void delete_blockers_around_edge(Vertex_handle a, Vertex_handle b){
430 std::list<Blocker_handle> blocker_to_delete;
432 if (blocker->contains(b)) blocker_to_delete.push_back(blocker);
433 while (!blocker_to_delete.empty())
436 blocker_to_delete.pop_back();
458 assert(this->contains_vertex(a));
459 assert(this->contains_vertex(b));
464 delete_blockers_around_edge(a,b);
466 std::set<Simplex_handle> blockers_to_add;
468 get_blockers_to_be_added_after_contraction(a,b,blockers_to_add);
470 delete_blockers_around_vertices(a,b);
472 update_edges_after_contraction(a,b);
476 notify_changed_edges(a);
478 for(
auto block : blockers_to_add)
481 assert(this->contains_vertex(a));
482 assert(!this->contains_vertex(b));
488 void get_blockers_to_be_added_after_contraction(Vertex_handle a,Vertex_handle b,std::set<Simplex_handle>& blockers_to_add){
489 blockers_to_add.clear();
493 LinkComplexType link_a(*
this,a);
494 LinkComplexType link_b(*
this,b);
496 std::vector<Simplex_handle> vector_alpha, vector_beta;
498 tip_blockers(a,b,vector_alpha);
499 tip_blockers(b,a,vector_beta);
501 for (
auto alpha = vector_alpha.begin(); alpha != vector_alpha.end(); ++alpha){
502 for (
auto beta = vector_beta.begin(); beta != vector_beta.end(); ++beta)
504 Simplex_handle sigma = *alpha; sigma.union_vertices(*beta);
505 Root_simplex_handle sigma_id = this->
get_id(sigma);
507 proper_faces_in_union<SkeletonBlockerComplex>(sigma_id,link_a,link_b))
511 blockers_to_add.insert(sigma);
521 void delete_blockers_around_vertices(Vertex_handle a,Vertex_handle b){
522 std::vector<Blocker_handle> blocker_to_delete;
524 blocker_to_delete.push_back(bl);
526 blocker_to_delete.push_back(bl);
527 while (!blocker_to_delete.empty())
530 blocker_to_delete.pop_back();
535 void update_edges_after_contraction(Vertex_handle a,Vertex_handle b){
541 while (this->
degree(b)> 0)
543 Vertex_handle x(*(adjacent_vertices(b.vertex, this->skeleton).first));
546 this->swap_edge(a,b,x);
552 void notify_changed_edges(Vertex_handle a){
554 boost_adjacency_iterator v, v_end;
556 for (tie(v, v_end) = adjacent_vertices(a.vertex, this->skeleton); v != v_end; ++v)
557 if (this->visitor) this->visitor->on_changed_edge(a,Vertex_handle(*v));
Const_complex_blocker_range const_blocker_range() const
Returns a range of the blockers of the complex.
Definition: Skeleton_blocker_complex.h:1332
void remove_blocker(const Blocker_handle sigma)
Removes the simplex from the set of blockers.
Definition: Skeleton_blocker_complex.h:789
bool contains_blocker(const Blocker_handle s) const
Definition: Skeleton_blocker_complex.h:844
virtual bool is_popable_blocker(Blocker_handle sigma) const
Definition: Skeleton_blocker_simplifiable_complex.h:100
Blocker_handle add_blocker(const Simplex_handle &blocker)
Adds the simplex to the set of blockers and returns a Blocker_handle toward it if was not present bef...
Definition: Skeleton_blocker_complex.h:719
Class that allows simplification operation on a simplicial complex represented by a skeleton/blockers...
Definition: Skeleton_blocker_simplifiable_complex.h:38
Class representing the link of a simplicial complex encoded by a skeleton/blockers pair...
Definition: Skeleton_blocker_link_complex.h:42
Complex_blocker_range blocker_range()
Returns a range of the blockers of the complex.
Definition: Skeleton_blocker_complex.h:1322
bool link_condition(Vertex_handle a, Vertex_handle b, bool ignore_popable_blockers=false) const
Definition: Skeleton_blocker_simplifiable_complex.h:337
Vertex_handle second_vertex(Edge_handle edge_handle) const
returns the first vertex of an edge
Definition: Skeleton_blocker_complex.h:589
void remove_star(Edge_handle e)
Definition: Skeleton_blocker_simplifiable_complex.h:240
void remove_star(const Simplex_handle &sigma)
Definition: Skeleton_blocker_simplifiable_complex.h:247
void delete_blocker(Blocker_handle sigma)
Definition: Skeleton_blocker_complex.h:834
boost::graph_traits< Graph >::edge_descriptor Edge_handle
Handle to an edge of the complex.
Definition: Skeleton_blocker_complex.h:139
void contract_edge(Edge_handle edge)
Definition: Skeleton_blocker_simplifiable_complex.h:447
void remove_star(Vertex_handle a, Vertex_handle b)
Definition: Skeleton_blocker_simplifiable_complex.h:230
Skeleton_blocker_simplifiable_complex(std::list< Simplex_handle > &simplices, Visitor *visitor_=NULL)
Constructor with a list of simplices.
Definition: Skeleton_blocker_simplifiable_complex.h:81
Vertex_handle first_vertex(Edge_handle edge_handle) const
returns the first vertex of an edge
Definition: Skeleton_blocker_complex.h:581
The type of edges that are stored the boost graph. An Edge must be Default Constructible and Equality...
Definition: SkeletonBlockerDS.h:97
void remove_star(Vertex_handle v)
Definition: Skeleton_blocker_simplifiable_complex.h:180
virtual boost::optional< Vertex_handle > get_address(Root_vertex_handle id) const
Given an Id return the address of the vertex having this Id in the complex.
Definition: Skeleton_blocker_complex.h:500
Root_vertex_handle first() const
Returns the first vertex of the edge.
int degree(Vertex_handle local) const
return the graph degree of a vertex.
Definition: Skeleton_blocker_complex.h:537
virtual contractible_status is_contractible() const
Test if the complex is reducible using a strategy defined in the class (by default it tests if the co...
Definition: Skeleton_blocker_simplifiable_complex.h:317
Abstract Simplicial Complex represented with a skeleton/blockers pair.
Definition: Skeleton_blocker_complex.h:63
T last_vertex() const
Definition: Skeleton_blocker_simplex.h:245
T first_vertex() const
Definition: Skeleton_blocker_simplex.h:235
void remove_popable_blockers(Vertex_handle v)
Definition: Skeleton_blocker_simplifiable_complex.h:163
bool link_condition(Edge_handle &e, bool ignore_popable_blockers=false) const
Definition: Skeleton_blocker_simplifiable_complex.h:354
Edge_handle add_edge(Vertex_handle a, Vertex_handle b)
Adds an edge between vertices a and b and all its cofaces.
Definition: Skeleton_blocker_complex.h:606
Simplicial subcomplex of a complex represented by a skeleton/blockers pair.
Definition: Skeleton_blocker_link_superior.h:31
Concept for the template class passed for Skeleton_blocker_complex. Most importantly, it contains the nodes for vertices and edges (Graph_vertex and Graph_edge) that are stored in the simplicial complex. The user can redefine these classes to attach additional information to vertices and edges.
Definition: SkeletonBlockerDS.h:25
Complex_vertex_range vertex_range() const
Returns a Complex_vertex_range over all vertices of the complex.
Definition: Skeleton_blocker_complex.h:1089
void add_simplex(const Simplex_handle &sigma)
add a maximal simplex plus all its cofaces.
Definition: Skeleton_blocker_simplifiable_complex.h:264
Root_vertex_handle get_id(Vertex_handle local) const
Definition: Skeleton_blocker_complex.h:511
void remove_vertex(Vertex_handle address)
Remove a vertex from the simplicial complex.
Definition: Skeleton_blocker_complex.h:461
virtual Edge_handle remove_edge(Vertex_handle a, Vertex_handle b)
Removes an edge from the simplicial complex and all its cofaces.
Definition: Skeleton_blocker_complex.h:639
bool contains_edge(Vertex_handle a, Vertex_handle b) const
Definition: Skeleton_blocker_complex.h:686
Abstract simplex used in Skeleton blockers data-structure.
Definition: Skeleton_blocker_simplex.h:48
Root_vertex_handle second() const
Returns the second vertex of the edge.
bool is_cone() const
Test if the complex is a cone.
Definition: Skeleton_blocker_complex.h:1055
Interface for a visitor of a simplicial complex.
Definition: Skeleton_blocker_complex_visitor.h:38
int dimension() const
Definition: Skeleton_blocker_simplex.h:222
Definition: SkeletonBlockerDS.h:60
void contract_edge(Vertex_handle a, Vertex_handle b)
Definition: Skeleton_blocker_simplifiable_complex.h:457
void remove_popable_blockers()
Definition: Skeleton_blocker_simplifiable_complex.h:134
Root_vertex_handle and Vertex_handle are similar to global and local vertex descriptor used in boost ...
Definition: SkeletonBlockerDS.h:50
virtual bool contains(const Simplex_handle &s) const
returns true iff the simplex s belongs to the simplicial complex.
Definition: Skeleton_blocker_complex.h:994