From 516e2942d8529e03311539ad0b001b33e45721f4 Mon Sep 17 00:00:00 2001 From: fgodi Date: Tue, 19 Jun 2018 14:39:12 +0000 Subject: unitary collapses function git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@3623 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 26c1fe89a979d9e1953e7916b15faa34e41da97b --- src/Toplex_map/include/gudhi/Toplex_map.h | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/Toplex_map') diff --git a/src/Toplex_map/include/gudhi/Toplex_map.h b/src/Toplex_map/include/gudhi/Toplex_map.h index b6bb5381..7a2e5b09 100644 --- a/src/Toplex_map/include/gudhi/Toplex_map.h +++ b/src/Toplex_map/include/gudhi/Toplex_map.h @@ -2,6 +2,7 @@ #define TOPLEX_MAP_H #include +#include #include #include #include @@ -69,7 +70,7 @@ public: * The edge has to verify the link condition if you want to preserve topology. * Returns the remaining vertex. * \ingroup toplex_map */ - Toplex_map::Vertex contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y, bool force=false); + Toplex_map::Vertex contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y); /** Adds the given simplex to the complex. * The simplex must not have neither maximal face nor coface in the complex. @@ -89,6 +90,8 @@ public: * \ingroup toplex_map */ std::size_t num_simplices() const; + std::set unitary_collapse(const Toplex_map::Vertex k, const Toplex_map::Vertex d); + protected: /** \internal Gives an index in order to look for a simplex quickly. * \ingroup toplex_map */ @@ -196,18 +199,17 @@ Toplex_map::Simplex_ptr_set Toplex_map::maximal_cofaces(const Input_vertex_range return cofaces; } -Toplex_map::Vertex Toplex_map::contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y, bool force){ +Toplex_map::Vertex Toplex_map::contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y){ if(!t0.count(x)) return y; if(!t0.count(y)) return x; int k, d; - if(force || (t0.at(x).size() > t0.at(y).size())) + if(t0.at(x).size() > t0.at(y).size()) k=x, d=y; else k=y, d=x; for(const Toplex_map::Simplex_ptr& sptr : Simplex_ptr_set(t0.at(d))){ //Copy constructor needed because the set is modified Simplex sigma(*sptr); - Simplex s; s.insert(2); erase_maximal(sptr); sigma.erase(d); sigma.insert(k); @@ -216,12 +218,27 @@ Toplex_map::Vertex Toplex_map::contraction(const Toplex_map::Vertex x, const Top return k; } +std::set Toplex_map::unitary_collapse(const Toplex_map::Vertex k, const Toplex_map::Vertex d){ + std::set r; + for(const Toplex_map::Simplex_ptr& sptr : Simplex_ptr_set(t0.at(d))){ + //Copy constructor needed because the set is modified + Simplex sigma(*sptr); + erase_maximal(sptr); + sigma.erase(d); + for(const Toplex_map::Vertex v : sigma) + r.insert(v); + sigma.insert(k); + insert_simplex(sigma); + } + return r; +} + template void Toplex_map::insert_independent_simplex(const Input_vertex_range &vertex_range){ + auto key = get_key(vertex_range); for(const Toplex_map::Vertex& v : vertex_range){ if(!t0.count(v)) t0.emplace(v, Simplex_ptr_set()); - auto k = get_key(vertex_range); - t0.at(v).emplace(k); + t0.at(v).emplace(key); } } -- cgit v1.2.3