From 7f3ea79d26c78c8b2107a6a85feba933bd5512ac Mon Sep 17 00:00:00 2001 From: fgodi Date: Tue, 27 Mar 2018 18:46:18 +0000 Subject: sb_wrapper working git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@3308 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c7400a11583b8b67483974664e410f4c77232fb1 --- src/Toplex_map/include/gudhi/Fake_simplex_tree.h | 17 +++++++++++------ src/Toplex_map/include/gudhi/Filtered_toplex_map.h | 10 +++++----- src/Toplex_map/include/gudhi/Toplex_map.h | 7 ++++--- src/Toplex_map/test/toplex_map_unit_test.cpp | 2 ++ 4 files changed, 22 insertions(+), 14 deletions(-) (limited to 'src/Toplex_map') diff --git a/src/Toplex_map/include/gudhi/Fake_simplex_tree.h b/src/Toplex_map/include/gudhi/Fake_simplex_tree.h index abd815f9..55955e7b 100644 --- a/src/Toplex_map/include/gudhi/Fake_simplex_tree.h +++ b/src/Toplex_map/include/gudhi/Fake_simplex_tree.h @@ -31,9 +31,6 @@ struct Visitor { class Fake_simplex_tree : public Filtered_toplex_map { public: - /** The type of the sets of Simplex_ptr. - * \ingroup toplex_map */ - typedef Toplex_map::Simplex_ptr_set Simplex_ptr_set; /** Handle type to a vertex contained in the simplicial complex. * \ingroup toplex_map */ @@ -87,6 +84,8 @@ public: * \ingroup toplex_map */ std::vector skeleton_simplex_range(int d) const; + Toplex_map::Vertex contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y); + protected: @@ -99,14 +98,14 @@ protected: template void Fake_simplex_tree::insert_graph(const OneSkeletonGraph& skel_graph){ - toplex_maps.emplace(nan(""),Toplex_map()); + toplex_maps.emplace(nan(""), new Toplex_map()); using vertex_iterator = typename boost::graph_traits::vertex_iterator; vertex_iterator vi, vi_end; for (std::tie(vi, vi_end) = boost::vertices(skel_graph); vi != vi_end; ++vi) { Simplex s; s.insert(*vi); insert_simplex_and_subfaces(s); } - bron_kerbosch_all_cliques(skel_graph, Visitor(&(this->toplex_maps.at(nan(""))))); + bron_kerbosch_all_cliques(skel_graph, Visitor(this->toplex_maps.at(nan("")))); } void Fake_simplex_tree::expansion(int max_dim){} @@ -150,7 +149,7 @@ Toplex_map::Simplex Fake_simplex_tree::simplex_vertex_range(const Simplex& s) co std::vector Fake_simplex_tree::max_simplices() const{ std::vector max_s; for(auto kv : toplex_maps) - for(const Toplex_map::Simplex_ptr& sptr : kv.second.maximal_cofaces(Simplex())) + for(const Toplex_map::Simplex_ptr& sptr : kv.second->maximal_cofaces(Simplex())) max_s.emplace_back(*sptr); return max_s; } @@ -178,6 +177,12 @@ std::vector Fake_simplex_tree::skeleton_simplex_range(int d return filtration_simplex_range(d); } +Toplex_map::Vertex Fake_simplex_tree::contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y){ + for(auto kv : toplex_maps) + kv.second->contraction(x,y,true); + return y; +} + } //namespace Gudhi #endif /* FAKE_SIMPLEX_TREE_H */ diff --git a/src/Toplex_map/include/gudhi/Filtered_toplex_map.h b/src/Toplex_map/include/gudhi/Filtered_toplex_map.h index 379c65dd..a3653acd 100644 --- a/src/Toplex_map/include/gudhi/Filtered_toplex_map.h +++ b/src/Toplex_map/include/gudhi/Filtered_toplex_map.h @@ -50,15 +50,15 @@ public: bool membership(const Input_vertex_range &vertex_range) const; protected: - std::map toplex_maps; + std::map toplex_maps; }; template std::pair Filtered_toplex_map::insert_simplex_and_subfaces(const Input_vertex_range &vertex_range, Filtration_value f){ Simplex s(vertex_range.begin(),vertex_range.end()); if(membership(s)) return make_pair(s,false); - if(!toplex_maps.count(f)) toplex_maps.emplace(f,Toplex_map()); - toplex_maps.at(f).insert_simplex(vertex_range); + if(!toplex_maps.count(f)) toplex_maps.emplace(f,new Toplex_map()); + toplex_maps.at(f)->insert_simplex(vertex_range); return make_pair(s,true); } @@ -66,7 +66,7 @@ std::pair Filtered_toplex_map::insert_simplex_and_sub template Filtered_toplex_map::Filtration_value Filtered_toplex_map::filtration(const Input_vertex_range &vertex_range) const{ for(auto kv : toplex_maps) - if(kv.second.membership(vertex_range)) + if(kv.second->membership(vertex_range)) return kv.first; //min only because a map is ordered return nan(""); } @@ -74,7 +74,7 @@ Filtered_toplex_map::Filtration_value Filtered_toplex_map::filtration(const Inpu template bool Filtered_toplex_map::membership(const Input_vertex_range &vertex_range) const{ for(auto kv : toplex_maps) - if(kv.second.membership(vertex_range)) + if(kv.second->membership(vertex_range)) return true; return false; } diff --git a/src/Toplex_map/include/gudhi/Toplex_map.h b/src/Toplex_map/include/gudhi/Toplex_map.h index 00127baf..ccea34d5 100644 --- a/src/Toplex_map/include/gudhi/Toplex_map.h +++ b/src/Toplex_map/include/gudhi/Toplex_map.h @@ -69,7 +69,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); + Toplex_map::Vertex contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y, bool force=false); /** Adds the given simplex to the complex. * The simplex must not have neither maximal face nor coface in the complex. @@ -196,17 +196,18 @@ 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){ +Toplex_map::Vertex Toplex_map::contraction(const Toplex_map::Vertex x, const Toplex_map::Vertex y, bool force){ if(!t0.count(x)) return y; if(!t0.count(y)) return x; int k, d; - if(t0.at(x).size() > t0.at(y).size()) + if(force || (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); diff --git a/src/Toplex_map/test/toplex_map_unit_test.cpp b/src/Toplex_map/test/toplex_map_unit_test.cpp index b7a9251c..b714cd2a 100644 --- a/src/Toplex_map/test/toplex_map_unit_test.cpp +++ b/src/Toplex_map/test/toplex_map_unit_test.cpp @@ -1,6 +1,8 @@ #include #include #include +#include + #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE "toplex map" -- cgit v1.2.3