From 1c2d52705af9ae38cba9401bff66d9e8095d0c9e Mon Sep 17 00:00:00 2001 From: fgodi Date: Thu, 29 Mar 2018 09:41:34 +0000 Subject: names git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@3313 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a2d37ef72c86e5050408496fe1620a69c6c55242 --- src/Toplex_map/include/gudhi/ftm_to_st_wrapper.h | 189 +++++++++++++++++++++ src/Toplex_map/include/gudhi/sb_to_st_wrapper.h | 109 ++++++++++++ .../include/gudhi/wrappers/Fake_simplex_tree.h | 189 --------------------- src/Toplex_map/include/gudhi/wrappers/Sb_wrapper.h | 109 ------------ 4 files changed, 298 insertions(+), 298 deletions(-) create mode 100644 src/Toplex_map/include/gudhi/ftm_to_st_wrapper.h create mode 100644 src/Toplex_map/include/gudhi/sb_to_st_wrapper.h delete mode 100644 src/Toplex_map/include/gudhi/wrappers/Fake_simplex_tree.h delete mode 100644 src/Toplex_map/include/gudhi/wrappers/Sb_wrapper.h (limited to 'src/Toplex_map') diff --git a/src/Toplex_map/include/gudhi/ftm_to_st_wrapper.h b/src/Toplex_map/include/gudhi/ftm_to_st_wrapper.h new file mode 100644 index 00000000..55955e7b --- /dev/null +++ b/src/Toplex_map/include/gudhi/ftm_to_st_wrapper.h @@ -0,0 +1,189 @@ +#ifndef FAKE_SIMPLEX_TREE_H +#define FAKE_SIMPLEX_TREE_H + +#include + +#include +#include + +#include +#include + +namespace Gudhi { + +struct Visitor { + Toplex_map* tm; + + Visitor(Toplex_map* tm) + :tm(tm) + {} + + template + void clique(const Clique& c, const Graph& g) + { + tm->insert_simplex(c); + } +}; + +/** Fake_simplex_tree is a wrapper for Filtered_toplex_map which has the interface of the Simplex_tree. + * Mostly for retro-compatibility purpose. If you use a function that output non maximal simplices, it will be non efficient. + * \ingroup toplex_map */ +class Fake_simplex_tree : public Filtered_toplex_map { + +public: + + /** Handle type to a vertex contained in the simplicial complex. + * \ingroup toplex_map */ + typedef Toplex_map::Vertex Vertex_handle; + + /** Handle type to a simplex contained in the simplicial complex. + * \ingroup toplex_map */ + typedef Toplex_map::Simplex Simplex_handle; + + typedef void Insertion_result_type; + + /** Inserts the flag complex of a given range `Gudhi::rips_complex::Rips_complex::OneSkeletonGraph` + * in the simplicial complex. + * \ingroup toplex_map */ + template + void insert_graph(const OneSkeletonGraph& skel_graph); + + /** Do actually nothing. + * \ingroup toplex_map */ + void expansion(int max_dim); + + /** Returns the number of vertices stored i.e. the number of max simplices + * \ingroup toplex_map */ + std::size_t num_vertices() const; + + /** Returns the dimension of the complex. + * \ingroup toplex_map */ + std::size_t dimension() const; + + /** Returns the dimension of a given simplex in the complex. + * \ingroup toplex_map */ + std::size_t dimension(Simplex_ptr& sptr) const; + + /** Returns the number of simplices stored i.e. the number of maximal simplices. + * \ingroup toplex_map */ + std::size_t num_simplices() const; + + /** Returns a range over the vertices of a simplex. + * \ingroup toplex_map */ + Toplex_map::Simplex simplex_vertex_range(const Simplex& s) const; + + /** Returns a set of all maximal (critical if there is filtration values) simplices. + * \ingroup toplex_map */ + std::vector max_simplices() const; + + /** Returns all the simplices, of max dimension d if a parameter d is given. + * \ingroup toplex_map */ + std::vector filtration_simplex_range(int d=std::numeric_limits::max()) const; + + /** Returns all the simplices of max dimension d + * \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: + + /** \internal Does all the facets of the given simplex belong to the complex ? + * \ingroup toplex_map */ + template + bool all_facets_inside(const Input_vertex_range &vertex_range) const; + +}; + +template +void Fake_simplex_tree::insert_graph(const OneSkeletonGraph& skel_graph){ + 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("")))); +} + +void Fake_simplex_tree::expansion(int max_dim){} + +template +bool Fake_simplex_tree::all_facets_inside(const Input_vertex_range &vertex_range) const{ + Simplex sigma(vertex_range); + for(const Simplex& s : facets(sigma)) + if(!membership(s)) return false; + return true; +} + +std::size_t Fake_simplex_tree::dimension() const { + std::size_t max = 0; + for(const Simplex& s : max_simplices()) + max = std::max(max, s.size()); + return max-1; +} + +std::size_t Fake_simplex_tree::dimension(Simplex_ptr& sptr) const{ + return sptr->size(); +} + +std::size_t Fake_simplex_tree::num_simplices() const { + //return filtration_simplex_range().size(); + return max_simplices().size(); +} + +std::size_t Fake_simplex_tree::num_vertices() const { + std::unordered_set vertices; + for(const Toplex_map::Simplex& s : max_simplices()) + for (Toplex_map::Vertex v : s) + vertices.emplace(v); + return vertices.size(); +} + +Toplex_map::Simplex Fake_simplex_tree::simplex_vertex_range(const Simplex& s) const { + return s; +} + +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())) + max_s.emplace_back(*sptr); + return max_s; +} + +std::vector Fake_simplex_tree::filtration_simplex_range(int d) const{ + std::vector m = max_simplices(); + std::vector range; + Toplex_map::Simplex_ptr_set seen; + while(m.begin()!=m.end()){ + Toplex_map::Simplex s(m.back()); + m.pop_back(); + if(seen.find(get_key(s))==seen.end()){ + if((int) s.size()-1 <=d) + range.emplace_back(s); + seen.emplace(get_key(s)); + if(s.size()>0) + for(Simplex& sigma : facets(s)) + m.emplace_back(sigma); + } + } + return range; +} + +std::vector Fake_simplex_tree::skeleton_simplex_range(int d) const{ + 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/sb_to_st_wrapper.h b/src/Toplex_map/include/gudhi/sb_to_st_wrapper.h new file mode 100644 index 00000000..0bdf7b9c --- /dev/null +++ b/src/Toplex_map/include/gudhi/sb_to_st_wrapper.h @@ -0,0 +1,109 @@ +#include + +#ifndef SKELETON_BLOCKER_WRAPPER_H_ +#define SKELETON_BLOCKER_WRAPPER_H_ + +namespace Gudhi { + +class Sb_wrapper{ + +public: + + typedef Gudhi::skeleton_blocker::Skeleton_blocker_simple_traits Traits; + typedef Gudhi::skeleton_blocker::Skeleton_blocker_complex Complex; + + typedef Complex::Vertex_handle Vertex_handle; + + typedef Complex::Simplex Simplex; + + typedef Toplex_map::Vertex Vertex; + + typedef Toplex_map::Simplex_ptr Simplex_ptr; + + typedef Toplex_map::Simplex_ptr_set Simplex_ptr_set; + + typedef double Filtration_value; + + template + std::pair insert_simplex_and_subfaces(const Input_vertex_range &vertex_range, double); + + template + bool membership(const Input_vertex_range &vertex_range) const; + + typedef Toplex_map::Simplex Simplex_handle; + + typedef void Insertion_result_type; + + /** Inserts the flag complex of a given range `Gudhi::rips_complex::Rips_complex::OneSkeletonGraph` + * in the simplicial complex. */ + template + void insert_graph(const OneSkeletonGraph& skel_graph); + + /** Do actually nothing. */ + void expansion(int max_dim); + + /** Returns the number of vertices stored i.e. the number of max simplices */ + std::size_t num_vertices() const; + + /** Returns the dimension of the complex. */ + std::size_t dimension() const; + + /** Returns the dimension of a given simplex in the complex. */ + std::size_t dimension(Simplex_ptr& sptr) const; + + /** Returns the number of simplices stored i.e. the number of maximal simplices. */ + std::size_t num_simplices() const; + + /** Returns a range over the vertices of a simplex. */ + Toplex_map::Simplex simplex_vertex_range(const Simplex& s) const; + + /** Returns a set of all maximal (critical if there is filtration values) simplices. */ + std::vector max_simplices() const; + + /** Returns all the simplices, of max dimension d if a parameter d is given. */ + std::vector filtration_simplex_range(int d=std::numeric_limits::max()) const; + + /** Returns all the simplices of max dimension d */ + std::vector skeleton_simplex_range(int d) const; + +private: + + Complex sb; + +}; + + +template +void Sb_wrapper::insert_graph(const OneSkeletonGraph& skel_graph){ + 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) + // insert_vertex(*vi); + //edges +} + +void Sb_wrapper::expansion(int max_dim){} + +template +std::pair Sb_wrapper::insert_simplex_and_subfaces(const Input_vertex_range &vertex_range, double){ + Complex::Simplex s; + for (auto v : vertex_range) + s.add_vertex(Vertex_handle(v)); + if(sb.contains(s)) + return std::make_pair(false,false); + sb.add_simplex(s); + return std::make_pair(true,true); +} + +std::size_t Sb_wrapper::num_vertices() const{ + std::size_t num_vertices = 0; + for(auto v : sb.vertex_range()) + ++num_vertices; + return num_vertices; +} + + + +} + +#endif diff --git a/src/Toplex_map/include/gudhi/wrappers/Fake_simplex_tree.h b/src/Toplex_map/include/gudhi/wrappers/Fake_simplex_tree.h deleted file mode 100644 index 55955e7b..00000000 --- a/src/Toplex_map/include/gudhi/wrappers/Fake_simplex_tree.h +++ /dev/null @@ -1,189 +0,0 @@ -#ifndef FAKE_SIMPLEX_TREE_H -#define FAKE_SIMPLEX_TREE_H - -#include - -#include -#include - -#include -#include - -namespace Gudhi { - -struct Visitor { - Toplex_map* tm; - - Visitor(Toplex_map* tm) - :tm(tm) - {} - - template - void clique(const Clique& c, const Graph& g) - { - tm->insert_simplex(c); - } -}; - -/** Fake_simplex_tree is a wrapper for Filtered_toplex_map which has the interface of the Simplex_tree. - * Mostly for retro-compatibility purpose. If you use a function that output non maximal simplices, it will be non efficient. - * \ingroup toplex_map */ -class Fake_simplex_tree : public Filtered_toplex_map { - -public: - - /** Handle type to a vertex contained in the simplicial complex. - * \ingroup toplex_map */ - typedef Toplex_map::Vertex Vertex_handle; - - /** Handle type to a simplex contained in the simplicial complex. - * \ingroup toplex_map */ - typedef Toplex_map::Simplex Simplex_handle; - - typedef void Insertion_result_type; - - /** Inserts the flag complex of a given range `Gudhi::rips_complex::Rips_complex::OneSkeletonGraph` - * in the simplicial complex. - * \ingroup toplex_map */ - template - void insert_graph(const OneSkeletonGraph& skel_graph); - - /** Do actually nothing. - * \ingroup toplex_map */ - void expansion(int max_dim); - - /** Returns the number of vertices stored i.e. the number of max simplices - * \ingroup toplex_map */ - std::size_t num_vertices() const; - - /** Returns the dimension of the complex. - * \ingroup toplex_map */ - std::size_t dimension() const; - - /** Returns the dimension of a given simplex in the complex. - * \ingroup toplex_map */ - std::size_t dimension(Simplex_ptr& sptr) const; - - /** Returns the number of simplices stored i.e. the number of maximal simplices. - * \ingroup toplex_map */ - std::size_t num_simplices() const; - - /** Returns a range over the vertices of a simplex. - * \ingroup toplex_map */ - Toplex_map::Simplex simplex_vertex_range(const Simplex& s) const; - - /** Returns a set of all maximal (critical if there is filtration values) simplices. - * \ingroup toplex_map */ - std::vector max_simplices() const; - - /** Returns all the simplices, of max dimension d if a parameter d is given. - * \ingroup toplex_map */ - std::vector filtration_simplex_range(int d=std::numeric_limits::max()) const; - - /** Returns all the simplices of max dimension d - * \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: - - /** \internal Does all the facets of the given simplex belong to the complex ? - * \ingroup toplex_map */ - template - bool all_facets_inside(const Input_vertex_range &vertex_range) const; - -}; - -template -void Fake_simplex_tree::insert_graph(const OneSkeletonGraph& skel_graph){ - 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("")))); -} - -void Fake_simplex_tree::expansion(int max_dim){} - -template -bool Fake_simplex_tree::all_facets_inside(const Input_vertex_range &vertex_range) const{ - Simplex sigma(vertex_range); - for(const Simplex& s : facets(sigma)) - if(!membership(s)) return false; - return true; -} - -std::size_t Fake_simplex_tree::dimension() const { - std::size_t max = 0; - for(const Simplex& s : max_simplices()) - max = std::max(max, s.size()); - return max-1; -} - -std::size_t Fake_simplex_tree::dimension(Simplex_ptr& sptr) const{ - return sptr->size(); -} - -std::size_t Fake_simplex_tree::num_simplices() const { - //return filtration_simplex_range().size(); - return max_simplices().size(); -} - -std::size_t Fake_simplex_tree::num_vertices() const { - std::unordered_set vertices; - for(const Toplex_map::Simplex& s : max_simplices()) - for (Toplex_map::Vertex v : s) - vertices.emplace(v); - return vertices.size(); -} - -Toplex_map::Simplex Fake_simplex_tree::simplex_vertex_range(const Simplex& s) const { - return s; -} - -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())) - max_s.emplace_back(*sptr); - return max_s; -} - -std::vector Fake_simplex_tree::filtration_simplex_range(int d) const{ - std::vector m = max_simplices(); - std::vector range; - Toplex_map::Simplex_ptr_set seen; - while(m.begin()!=m.end()){ - Toplex_map::Simplex s(m.back()); - m.pop_back(); - if(seen.find(get_key(s))==seen.end()){ - if((int) s.size()-1 <=d) - range.emplace_back(s); - seen.emplace(get_key(s)); - if(s.size()>0) - for(Simplex& sigma : facets(s)) - m.emplace_back(sigma); - } - } - return range; -} - -std::vector Fake_simplex_tree::skeleton_simplex_range(int d) const{ - 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/wrappers/Sb_wrapper.h b/src/Toplex_map/include/gudhi/wrappers/Sb_wrapper.h deleted file mode 100644 index 0bdf7b9c..00000000 --- a/src/Toplex_map/include/gudhi/wrappers/Sb_wrapper.h +++ /dev/null @@ -1,109 +0,0 @@ -#include - -#ifndef SKELETON_BLOCKER_WRAPPER_H_ -#define SKELETON_BLOCKER_WRAPPER_H_ - -namespace Gudhi { - -class Sb_wrapper{ - -public: - - typedef Gudhi::skeleton_blocker::Skeleton_blocker_simple_traits Traits; - typedef Gudhi::skeleton_blocker::Skeleton_blocker_complex Complex; - - typedef Complex::Vertex_handle Vertex_handle; - - typedef Complex::Simplex Simplex; - - typedef Toplex_map::Vertex Vertex; - - typedef Toplex_map::Simplex_ptr Simplex_ptr; - - typedef Toplex_map::Simplex_ptr_set Simplex_ptr_set; - - typedef double Filtration_value; - - template - std::pair insert_simplex_and_subfaces(const Input_vertex_range &vertex_range, double); - - template - bool membership(const Input_vertex_range &vertex_range) const; - - typedef Toplex_map::Simplex Simplex_handle; - - typedef void Insertion_result_type; - - /** Inserts the flag complex of a given range `Gudhi::rips_complex::Rips_complex::OneSkeletonGraph` - * in the simplicial complex. */ - template - void insert_graph(const OneSkeletonGraph& skel_graph); - - /** Do actually nothing. */ - void expansion(int max_dim); - - /** Returns the number of vertices stored i.e. the number of max simplices */ - std::size_t num_vertices() const; - - /** Returns the dimension of the complex. */ - std::size_t dimension() const; - - /** Returns the dimension of a given simplex in the complex. */ - std::size_t dimension(Simplex_ptr& sptr) const; - - /** Returns the number of simplices stored i.e. the number of maximal simplices. */ - std::size_t num_simplices() const; - - /** Returns a range over the vertices of a simplex. */ - Toplex_map::Simplex simplex_vertex_range(const Simplex& s) const; - - /** Returns a set of all maximal (critical if there is filtration values) simplices. */ - std::vector max_simplices() const; - - /** Returns all the simplices, of max dimension d if a parameter d is given. */ - std::vector filtration_simplex_range(int d=std::numeric_limits::max()) const; - - /** Returns all the simplices of max dimension d */ - std::vector skeleton_simplex_range(int d) const; - -private: - - Complex sb; - -}; - - -template -void Sb_wrapper::insert_graph(const OneSkeletonGraph& skel_graph){ - 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) - // insert_vertex(*vi); - //edges -} - -void Sb_wrapper::expansion(int max_dim){} - -template -std::pair Sb_wrapper::insert_simplex_and_subfaces(const Input_vertex_range &vertex_range, double){ - Complex::Simplex s; - for (auto v : vertex_range) - s.add_vertex(Vertex_handle(v)); - if(sb.contains(s)) - return std::make_pair(false,false); - sb.add_simplex(s); - return std::make_pair(true,true); -} - -std::size_t Sb_wrapper::num_vertices() const{ - std::size_t num_vertices = 0; - for(auto v : sb.vertex_range()) - ++num_vertices; - return num_vertices; -} - - - -} - -#endif -- cgit v1.2.3