11 #ifndef SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_
12 #define SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_
14 #include <gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h>
22 namespace skeleton_blocker {
32 template<
typename SkeletonBlockerDS>
34 assert(this->contains_blocker(*sigma));
36 build_link_of_blocker(*
this, *sigma, link_blocker_sigma);
43 template<
typename SkeletonBlockerDS>
45 std::list<Vertex_handle> vertex_to_check;
46 for (
auto v : this->vertex_range())
47 vertex_to_check.push_front(v);
49 while (!vertex_to_check.empty()) {
51 vertex_to_check.pop_front();
53 bool blocker_popable_found =
true;
54 while (blocker_popable_found) {
55 blocker_popable_found =
false;
56 for (
auto block : this->blocker_range(v)) {
57 if (this->is_popable_blocker(block)) {
59 if (nv != v) vertex_to_check.push_back(nv);
60 this->delete_blocker(block);
61 blocker_popable_found =
true;
72 template<
typename SkeletonBlockerDS>
74 bool blocker_popable_found =
true;
75 while (blocker_popable_found) {
76 blocker_popable_found =
false;
77 for (
auto block : this->blocker_range(v)) {
78 if (is_popable_blocker(block)) {
79 this->delete_blocker(block);
80 blocker_popable_found =
true;
91 template<
typename SkeletonBlockerDS>
93 std::list<Vertex_handle> vertex_to_check;
94 vertex_to_check.push_front(v);
96 while (!vertex_to_check.empty()) {
98 vertex_to_check.pop_front();
100 bool blocker_popable_found =
true;
101 while (blocker_popable_found) {
102 blocker_popable_found =
false;
103 for (
auto block : this->blocker_range(v)) {
104 if (this->is_popable_blocker(block)) {
106 if (nv != v) vertex_to_check.push_back(nv);
107 this->delete_blocker(block);
108 blocker_popable_found =
true;
119 template<
typename SkeletonBlockerDS>
122 update_blockers_after_remove_star_of_vertex_or_edge(
Simplex(v));
123 while (this->degree(v) > 0) {
124 Vertex_handle w(* (adjacent_vertices(v.vertex, this->skeleton).first));
125 this->remove_edge(v, w);
127 this->remove_vertex(v);
135 template<
typename SkeletonBlockerDS>
137 std::list <Blocker_handle> blockers_to_update;
138 if (simplex_to_be_removed.empty())
return;
141 for (
auto blocker : this->blocker_range(v0)) {
142 if (blocker->contains(simplex_to_be_removed))
143 blockers_to_update.push_back(blocker);
146 for (
auto blocker_to_update : blockers_to_update) {
147 Simplex sub_blocker_to_be_added;
148 bool sub_blocker_need_to_be_added =
149 (blocker_to_update->dimension() - simplex_to_be_removed.dimension()) >= 2;
150 if (sub_blocker_need_to_be_added) {
151 sub_blocker_to_be_added = *blocker_to_update;
152 sub_blocker_to_be_added.difference(simplex_to_be_removed);
154 this->delete_blocker(blocker_to_update);
155 if (sub_blocker_need_to_be_added)
156 this->add_blocker(sub_blocker_to_be_added);
163 template<
typename SkeletonBlockerDS>
165 update_blockers_after_remove_star_of_vertex_or_edge(
Simplex(a, b));
167 this->remove_edge(a, b);
173 template<
typename SkeletonBlockerDS>
175 return remove_star(this->first_vertex(e), this->second_vertex(e));
181 template<
typename SkeletonBlockerDS>
183 assert(this->contains(sigma));
189 remove_blocker_containing_simplex(sigma);
190 this->add_blocker(sigma);
194 template<
typename SkeletonBlockerDS>
198 assert(!this->contains(sigma));
200 if (!contains_vertices(sigma)) {
201 std::cerr <<
"add_simplex: Some vertices were not present in the complex, adding them" << std::endl;
202 size_t num_vertices_to_add = sigma.
last_vertex() - this->num_vertices() + 1;
203 for (
size_t i = 0; i < num_vertices_to_add; ++i)
206 assert(contains_vertices(sigma));
207 if (!contains_edges(sigma))
209 remove_blocker_include_in_simplex(sigma);
210 add_blockers_after_simplex_insertion(sigma);
213 template<
typename SkeletonBlockerDS>
215 if (sigma.dimension() < 1)
return;
217 for (
auto s : coboundary_range(sigma)) {
218 this->add_blocker(s);
225 template<
typename SkeletonBlockerDS>
226 void Skeleton_blocker_complex<SkeletonBlockerDS>::remove_blocker_containing_simplex(
const Simplex& sigma) {
227 std::vector <Blocker_handle> blockers_to_remove;
228 for (
auto blocker : this->blocker_range(sigma.first_vertex())) {
229 if (blocker->contains(sigma))
230 blockers_to_remove.push_back(blocker);
232 for (
auto blocker_to_update : blockers_to_remove)
233 this->delete_blocker(blocker_to_update);
239 template<
typename SkeletonBlockerDS>
240 void Skeleton_blocker_complex<SkeletonBlockerDS>::remove_blocker_include_in_simplex(
const Simplex& sigma) {
243 std::set <Blocker_handle> blockers_to_remove;
244 for (
auto s : sigma) {
245 for (
auto blocker : this->blocker_range(s)) {
246 if (sigma.contains(*blocker))
247 blockers_to_remove.insert(blocker);
250 for (
auto blocker_to_update : blockers_to_remove) {
251 auto s = *blocker_to_update;
252 this->delete_blocker(blocker_to_update);
256 for (
const auto& b : coboundary_range(s))
257 if (!sigma.contains(b))
258 this->add_blocker(b);
267 template<
typename SkeletonBlockerDS>
269 std::vector<Simplex> & buffer)
const {
270 for (
auto const blocker : this->const_blocker_range(a)) {
271 Simplex beta = (*blocker);
272 beta.remove_vertex(a);
273 buffer.push_back(beta);
277 this->add_neighbours(b, n);
278 this->remove_neighbours(a, n);
285 buffer.push_back(beta);
297 template<
typename SkeletonBlockerDS>
300 this->add_edge_without_blockers(a, x);
301 if (this->visitor) this->visitor->on_swaped_edge(a, b, x);
302 this->remove_edge(b, x);
305 template<
typename SkeletonBlockerDS>
307 Skeleton_blocker_complex<SkeletonBlockerDS>::delete_blockers_around_vertex(
Vertex_handle v) {
308 std::list <Blocker_handle> blockers_to_delete;
309 for (
auto blocker : this->blocker_range(v)) {
310 blockers_to_delete.push_back(blocker);
312 while (!blockers_to_delete.empty()) {
313 this->remove_blocker(blockers_to_delete.back());
314 blockers_to_delete.pop_back();
321 template<
typename SkeletonBlockerDS>
324 std::list<Blocker_handle> blocker_to_delete;
325 for (
auto blocker : this->blocker_range(a))
326 if (blocker->contains(b)) blocker_to_delete.push_back(blocker);
327 while (!blocker_to_delete.empty()) {
328 this->delete_blocker(blocker_to_delete.back());
329 blocker_to_delete.pop_back();
338 template<
typename SkeletonBlockerDS>
341 assert(this->contains_vertex(a));
342 assert(this->contains_vertex(b));
344 if (this->contains_edge(a, b))
345 this->add_edge_without_blockers(a, b);
348 if (!link_condition(a, b))
349 delete_blockers_around_edge(a, b);
351 std::set<Simplex> blockers_to_add;
353 get_blockers_to_be_added_after_contraction(a, b, blockers_to_add);
355 delete_blockers_around_vertices(a, b);
357 update_edges_after_contraction(a, b);
359 this->remove_vertex(b);
361 notify_changed_edges(a);
363 for (
auto block : blockers_to_add)
364 this->add_blocker(block);
366 assert(this->contains_vertex(a));
367 assert(!this->contains_vertex(b));
370 template<
typename SkeletonBlockerDS>
373 std::set<Simplex>& blockers_to_add) {
374 blockers_to_add.
clear();
378 LinkComplexType link_a(*
this, a);
379 LinkComplexType link_b(*
this, b);
381 std::vector<Simplex> vector_alpha, vector_beta;
383 tip_blockers(a, b, vector_alpha);
384 tip_blockers(b, a, vector_beta);
386 for (
auto alpha = vector_alpha.begin(); alpha != vector_alpha.end(); ++alpha) {
387 for (
auto beta = vector_beta.begin(); beta != vector_beta.end(); ++beta) {
388 Simplex sigma = *alpha;
389 sigma.union_vertices(*beta);
390 Root_simplex_handle sigma_id = this->get_id(sigma);
391 if (this->contains(sigma) &&
395 blockers_to_add.insert(sigma);
404 template<
typename SkeletonBlockerDS>
407 std::vector<Blocker_handle> blocker_to_delete;
408 for (
auto bl : this->blocker_range(a))
409 blocker_to_delete.push_back(bl);
410 for (
auto bl : this->blocker_range(b))
411 blocker_to_delete.push_back(bl);
412 while (!blocker_to_delete.empty()) {
413 this->delete_blocker(blocker_to_delete.back());
414 blocker_to_delete.pop_back();
418 template<
typename SkeletonBlockerDS>
422 this->remove_edge(a, b);
426 while (this->degree(b) > 0) {
427 Vertex_handle x(*(adjacent_vertices(b.vertex, this->skeleton).first));
428 if (!this->contains_edge(a, x))
430 this->swap_edge(a, b, x);
432 this->remove_edge(b, x);
436 template<
typename SkeletonBlockerDS>
438 Skeleton_blocker_complex<SkeletonBlockerDS>::notify_changed_edges(
Vertex_handle a) {
440 boost_adjacency_iterator v, v_end;
442 for (tie(v, v_end) = adjacent_vertices(a.vertex, this->skeleton); v != v_end; ++v)
443 if (this->visitor) this->visitor->on_changed_edge(a,
Vertex_handle(*v));
449 namespace skbl = skeleton_blocker;
Abstract Simplicial Complex represented with a skeleton/blockers pair.
Definition: Skeleton_blocker_complex.h:51
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_complex.h:1162
Vertex_handle first_vertex(Edge_handle edge_handle) const
returns the first vertex of an edge
Definition: Skeleton_blocker_complex.h:512
void contract_edge(Edge_handle edge)
Definition: Skeleton_blocker_complex.h:1244
void add_simplex(const Simplex &sigma)
add a simplex and all its faces.
Definition: Skeleton_blocker_simplifiable_complex.h:195
void remove_all_popable_blockers(Vertex_handle v)
Removes all the popable blockers of the complex passing through v and delete them....
Definition: Skeleton_blocker_simplifiable_complex.h:92
void remove_popable_blockers()
Definition: Skeleton_blocker_simplifiable_complex.h:44
virtual void clear()
Definition: Skeleton_blocker_complex.h:311
void remove_star(Vertex_handle v)
Definition: Skeleton_blocker_simplifiable_complex.h:120
bool is_popable_blocker(Blocker_handle sigma) const
Definition: Skeleton_blocker_simplifiable_complex.h:33
boost::graph_traits< Graph >::edge_descriptor Edge_handle
Handle to an edge of the complex.
Definition: Skeleton_blocker_complex.h:114
Class representing the link of a simplicial complex encoded by a skeleton/blockers pair....
Definition: Skeleton_blocker_link_complex.h:31
Abstract simplex used in Skeleton blockers data-structure.
Definition: Skeleton_blocker_simplex.h:38
T first_vertex() const
Definition: Skeleton_blocker_simplex.h:210
T last_vertex() const
Definition: Skeleton_blocker_simplex.h:220
int dimension() const
Definition: Skeleton_blocker_simplex.h:197
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Definition: SkeletonBlockerDS.h:56
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15