summaryrefslogtreecommitdiff
path: root/src/Toplex_map
diff options
context:
space:
mode:
authorfgodi <fgodi@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-12-07 15:46:43 +0000
committerfgodi <fgodi@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-12-07 15:46:43 +0000
commit20034acbc1a6aa83a0a9fd2ee660bcda4dec6ebf (patch)
tree1e9e57e83114cbfbe7b043dff8a99d3955c71351 /src/Toplex_map
parent5430f6a24b6909f1d63cd2028e88ef2d69fb8a0d (diff)
small modifications
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/toplex_map@3053 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7eeee9f036954c20f1f64369fc74dd64c98000bc
Diffstat (limited to 'src/Toplex_map')
-rw-r--r--src/Toplex_map/include/gudhi/Fake_simplex_tree.h38
-rw-r--r--src/Toplex_map/include/gudhi/Filtered_toplex_map.h4
-rw-r--r--src/Toplex_map/include/gudhi/Toplex_map.h100
3 files changed, 71 insertions, 71 deletions
diff --git a/src/Toplex_map/include/gudhi/Fake_simplex_tree.h b/src/Toplex_map/include/gudhi/Fake_simplex_tree.h
index 104f1742..ea5ac618 100644
--- a/src/Toplex_map/include/gudhi/Fake_simplex_tree.h
+++ b/src/Toplex_map/include/gudhi/Fake_simplex_tree.h
@@ -49,11 +49,11 @@ public:
/** Handle type to a vertex contained in the simplicial complex.
* \ingroup toplex_map */
- typedef Vertex Vertex_handle;
+ typedef Toplex_map::Vertex Vertex_handle;
/** Handle type to a simplex contained in the simplicial complex.
* \ingroup toplex_map */
- typedef Simplex Simplex_handle;
+ typedef Toplex_map::Simplex Simplex_handle;
typedef void Insertion_result_type;
@@ -85,19 +85,19 @@ public:
/** Returns a range over the vertices of a simplex.
* \ingroup toplex_map */
- Simplex simplex_vertex_range(const Simplex& s) const;
+ 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<Simplex> max_simplices() const;
+ std::vector<Toplex_map::Simplex> max_simplices() const;
/** Returns all the simplices, of max dimension d if a parameter d is given.
* \ingroup toplex_map */
- std::vector<Simplex> filtration_simplex_range(int d=std::numeric_limits<int>::max()) const;
+ std::vector<Toplex_map::Simplex> filtration_simplex_range(int d=std::numeric_limits<int>::max()) const;
/** Returns all the simplices of max dimension d
* \ingroup toplex_map */
- std::vector<Simplex> skeleton_simplex_range(int d) const;
+ std::vector<Toplex_map::Simplex> skeleton_simplex_range(int d) const;
protected:
@@ -148,31 +148,31 @@ std::size_t Fake_simplex_tree::num_simplices() const {
}
std::size_t Fake_simplex_tree::num_vertices() const {
- std::unordered_set<Vertex> vertices;
- for(const Simplex& s : max_simplices())
- for (Vertex v : s)
+ std::unordered_set<Toplex_map::Vertex> vertices;
+ for(const Toplex_map::Simplex& s : max_simplices())
+ for (Toplex_map::Vertex v : s)
vertices.emplace(v);
return vertices.size();
}
-Simplex Fake_simplex_tree::simplex_vertex_range(const Simplex& s) const {
+Toplex_map::Simplex Fake_simplex_tree::simplex_vertex_range(const Simplex& s) const {
return s;
}
-std::vector<Simplex> Fake_simplex_tree::max_simplices() const{
- std::vector<Simplex> max_s;
+std::vector<Toplex_map::Simplex> Fake_simplex_tree::max_simplices() const{
+ std::vector<Toplex_map::Simplex> max_s;
for(auto kv : toplex_maps)
- for(const 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;
}
-std::vector<Simplex> Fake_simplex_tree::filtration_simplex_range(int d) const{
- std::vector<Simplex> m = max_simplices();
- std::vector<Simplex> range;
- Simplex_ptr_set seen;
+std::vector<Toplex_map::Simplex> Fake_simplex_tree::filtration_simplex_range(int d) const{
+ std::vector<Toplex_map::Simplex> m = max_simplices();
+ std::vector<Toplex_map::Simplex> range;
+ Toplex_map::Simplex_ptr_set seen;
while(m.begin()!=m.end()){
- Simplex s(m.back());
+ Toplex_map::Simplex s(m.back());
m.pop_back();
if(seen.find(get_key(s))==seen.end()){
if((int) s.size()-1 <=d)
@@ -186,7 +186,7 @@ std::vector<Simplex> Fake_simplex_tree::filtration_simplex_range(int d) const{
return range;
}
-std::vector<Simplex> Fake_simplex_tree::skeleton_simplex_range(int d) const{
+std::vector<Toplex_map::Simplex> Fake_simplex_tree::skeleton_simplex_range(int d) const{
return filtration_simplex_range(d);
}
diff --git a/src/Toplex_map/include/gudhi/Filtered_toplex_map.h b/src/Toplex_map/include/gudhi/Filtered_toplex_map.h
index 28814d15..379c65dd 100644
--- a/src/Toplex_map/include/gudhi/Filtered_toplex_map.h
+++ b/src/Toplex_map/include/gudhi/Filtered_toplex_map.h
@@ -1,4 +1,4 @@
-#ifndef FILTERED_TOPLEX_MAP_H
+ #ifndef FILTERED_TOPLEX_MAP_H
#define FILTERED_TOPLEX_MAP_H
#include <gudhi/Toplex_map.h>
@@ -54,7 +54,7 @@ protected:
};
template <typename Input_vertex_range>
-std::pair<Simplex, bool> Filtered_toplex_map::insert_simplex_and_subfaces(const Input_vertex_range &vertex_range, Filtration_value f){
+std::pair<Toplex_map::Simplex, bool> 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());
diff --git a/src/Toplex_map/include/gudhi/Toplex_map.h b/src/Toplex_map/include/gudhi/Toplex_map.h
index b433f3de..00127baf 100644
--- a/src/Toplex_map/include/gudhi/Toplex_map.h
+++ b/src/Toplex_map/include/gudhi/Toplex_map.h
@@ -7,7 +7,7 @@
#include <memory>
#include <limits>
-#define vertex_upper_bound std::numeric_limits<Vertex>::max()
+#define vertex_upper_bound std::numeric_limits<Toplex_map::Vertex>::max()
namespace Gudhi {
@@ -24,17 +24,17 @@ public:
/** Simplex is the type of simplices.
* \ingroup toplex_map */
- typedef std::unordered_set<Vertex> Simplex;
+ typedef std::unordered_set<Toplex_map::Vertex> Simplex;
/** The type of the pointers to maximal simplices.
* \ingroup toplex_map */
- typedef std::shared_ptr<Simplex> Simplex_ptr;
+ typedef std::shared_ptr<Toplex_map::Simplex> Simplex_ptr;
- struct Sptr_hash{ std::size_t operator()(const Simplex_ptr& s) const; };
- struct Sptr_equal{ std::size_t operator()(const Simplex_ptr& a, const Simplex_ptr& b) const; };
- /** The type of the sets of Simplex_ptr.
+ struct Sptr_hash{ std::size_t operator()(const Toplex_map::Simplex_ptr& s) const; };
+ struct Sptr_equal{ std::size_t operator()(const Toplex_map::Simplex_ptr& a, const Toplex_map::Simplex_ptr& b) const; };
+ /** The type of the sets of Toplex_map::Simplex_ptr.
* \ingroup toplex_map */
- typedef std::unordered_set<Simplex_ptr, Sptr_hash, Sptr_equal> Simplex_ptr_set;
+ typedef std::unordered_set<Toplex_map::Simplex_ptr, Sptr_hash, Sptr_equal> Simplex_ptr_set;
/** \brief Adds the given simplex to the complex.
* Nothing happens if the simplex has a coface in the complex.
@@ -63,13 +63,13 @@ public:
* Gives not more than max_number maximal cofaces if max_number is strictly positive.
* \ingroup toplex_map */
template <typename Input_vertex_range>
- Simplex_ptr_set maximal_cofaces(const Input_vertex_range &vertex_range, const std::size_t max_number = 0) const;
+ Toplex_map::Simplex_ptr_set maximal_cofaces(const Input_vertex_range &vertex_range, const std::size_t max_number = 0) const;
/** Contracts one edge in the complex.
* The edge has to verify the link condition if you want to preserve topology.
* Returns the remaining vertex.
* \ingroup toplex_map */
- Vertex contraction(const Vertex x, const Vertex y);
+ 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.
@@ -79,11 +79,11 @@ public:
/** \internal Removes a toplex without adding facets after.
* \ingroup toplex_map */
- void erase_maximal(const Simplex_ptr& sptr);
+ void erase_maximal(const Toplex_map::Simplex_ptr& sptr);
/** Removes a vertex from any simplex containing it.
* \ingroup toplex_map */
- void remove_vertex(const Vertex x);
+ void remove_vertex(const Toplex_map::Vertex x);
/** \brief Number of maximal simplices.
* \ingroup toplex_map */
@@ -93,16 +93,16 @@ protected:
/** \internal Gives an index in order to look for a simplex quickly.
* \ingroup toplex_map */
template <typename Input_vertex_range>
- Vertex best_index(const Input_vertex_range &vertex_range) const;
+ Toplex_map::Vertex best_index(const Input_vertex_range &vertex_range) const;
/** \internal The map from vertices to toplices
* \ingroup toplex_map */
- std::unordered_map<Vertex, Simplex_ptr_set> t0;
+ std::unordered_map<Toplex_map::Vertex, Toplex_map::Simplex_ptr_set> t0;
};
// Pointers are also used as key in the hash sets.
template <typename Input_vertex_range>
-Simplex_ptr get_key(const Input_vertex_range &vertex_range);
+Toplex_map::Simplex_ptr get_key(const Input_vertex_range &vertex_range);
// Is the first simplex a face of the second ?
template <typename Input_vertex_range1, typename Input_vertex_range2>
@@ -110,24 +110,24 @@ bool included(const Input_vertex_range1 &vertex_range1, const Input_vertex_range
// All the facets of the given simplex.
template <typename Input_vertex_range>
-std::vector<Simplex> facets(const Input_vertex_range &vertex_range);
+std::vector<Toplex_map::Simplex> facets(const Input_vertex_range &vertex_range);
template <typename Input_vertex_range>
void Toplex_map::insert_simplex(const Input_vertex_range &vertex_range){
if(membership(vertex_range)) return;
bool replace_facets = true;
- for(const Simplex& facet : facets(vertex_range))
+ for(const Toplex_map::Simplex& facet : facets(vertex_range))
if(!maximality(facet))
{
replace_facets=false;
break;
}
if(replace_facets)
- for(const Simplex& facet : facets(vertex_range))
+ for(const Toplex_map::Simplex& facet : facets(vertex_range))
erase_maximal(get_key(facet));
else
- for(const Vertex& v : vertex_range)
- if(t0.count(v)) for(const Simplex_ptr& fptr : Simplex_ptr_set(t0.at(v)))
+ for(const Toplex_map::Vertex& v : vertex_range)
+ if(t0.count(v)) for(const Toplex_map::Simplex_ptr& fptr : Simplex_ptr_set(t0.at(v)))
//Copy constructor needed because the set is modified
if(included(*fptr,vertex_range)) erase_maximal(fptr);
// We erase all the maximal faces of the simplex
@@ -140,12 +140,12 @@ void Toplex_map::remove_simplex(const Input_vertex_range &vertex_range){
t0.clear();
// Removal of the empty simplex means cleaning everything
else {
- const Vertex& v = best_index(vertex_range);
- if(t0.count(v)) for(const Simplex_ptr& sptr : Simplex_ptr_set(t0.at(v)))
+ const Toplex_map::Vertex& v = best_index(vertex_range);
+ if(t0.count(v)) for(const Toplex_map::Simplex_ptr& sptr : Simplex_ptr_set(t0.at(v)))
//Copy constructor needed because the set is modified
if(included(vertex_range, *sptr)){
erase_maximal(sptr);
- for(const Simplex& f : facets(vertex_range))
+ for(const Toplex_map::Simplex& f : facets(vertex_range))
if(!membership(f)) insert_independent_simplex(f);
// We add the facets which are new maximal simplices
}
@@ -155,10 +155,10 @@ void Toplex_map::remove_simplex(const Input_vertex_range &vertex_range){
template <typename Input_vertex_range>
bool Toplex_map::membership(const Input_vertex_range &vertex_range) const{
if(t0.size()==0) return false;
- const Vertex& v = best_index(vertex_range);
+ const Toplex_map::Vertex& v = best_index(vertex_range);
if(!t0.count(v)) return false;
if(maximality(vertex_range)) return true;
- for(const Simplex_ptr& sptr : t0.at(v))
+ for(const Toplex_map::Simplex_ptr& sptr : t0.at(v))
if(included(vertex_range, *sptr))
return true;
return false;
@@ -166,27 +166,27 @@ bool Toplex_map::membership(const Input_vertex_range &vertex_range) const{
template <typename Input_vertex_range>
bool Toplex_map::maximality(const Input_vertex_range &vertex_range) const{
- const Vertex& v = best_index(vertex_range);
+ const Toplex_map::Vertex& v = best_index(vertex_range);
if(!t0.count(v)) return false;
return t0.at(v).count(get_key(vertex_range));
}
template <typename Input_vertex_range>
-Simplex_ptr_set Toplex_map::maximal_cofaces(const Input_vertex_range &vertex_range, const std::size_t max_number) const{
+Toplex_map::Simplex_ptr_set Toplex_map::maximal_cofaces(const Input_vertex_range &vertex_range, const std::size_t max_number) const{
Simplex_ptr_set cofaces;
if(maximality(vertex_range))
cofaces.emplace(get_key(vertex_range));
else if(vertex_range.begin()==vertex_range.end())
for(const auto& kv : t0)
- for(const Simplex_ptr& sptr : kv.second){
+ for(const Toplex_map::Simplex_ptr& sptr : kv.second){
//kv.second is a Simplex_ptr_set
cofaces.emplace(sptr);
if(cofaces.size()==max_number)
return cofaces;
}
else {
- const Vertex& v = best_index(vertex_range);
- if(t0.count(v)) for(const Simplex_ptr& sptr : t0.at(v))
+ const Toplex_map::Vertex& v = best_index(vertex_range);
+ if(t0.count(v)) for(const Toplex_map::Simplex_ptr& sptr : t0.at(v))
if(included(vertex_range, *sptr)){
cofaces.emplace(sptr);
if(cofaces.size()==max_number)
@@ -196,7 +196,7 @@ Simplex_ptr_set Toplex_map::maximal_cofaces(const Input_vertex_range &vertex_ran
return cofaces;
}
-Vertex Toplex_map::contraction(const Vertex x, const Vertex y){
+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;
@@ -204,7 +204,7 @@ Vertex Toplex_map::contraction(const Vertex x, const Vertex y){
k=x, d=y;
else
k=y, d=x;
- for(const Simplex_ptr& sptr : Simplex_ptr_set(t0.at(d))){
+ 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);
@@ -217,14 +217,14 @@ Vertex Toplex_map::contraction(const Vertex x, const Vertex y){
template <typename Input_vertex_range>
void Toplex_map::insert_independent_simplex(const Input_vertex_range &vertex_range){
- for(const Vertex& v : vertex_range){
+ for(const Toplex_map::Vertex& v : vertex_range){
if(!t0.count(v)) t0.emplace(v, Simplex_ptr_set());
t0.at(v).emplace(get_key(vertex_range));
}
}
-void Toplex_map::remove_vertex(const Vertex x){
- for(const Simplex_ptr& sptr : Simplex_ptr_set(t0.at(x))){
+void Toplex_map::remove_vertex(const Toplex_map::Vertex x){
+ for(const Toplex_map::Simplex_ptr& sptr : Simplex_ptr_set(t0.at(x))){
Simplex sigma(*sptr);
erase_maximal(sptr);
sigma.erase(x);
@@ -236,61 +236,61 @@ std::size_t Toplex_map::num_simplices() const{
return maximal_cofaces(Simplex()).size();
}
-inline void Toplex_map::erase_maximal(const Simplex_ptr& sptr){
+inline void Toplex_map::erase_maximal(const Toplex_map::Simplex_ptr& sptr){
Simplex sigma(*sptr);
if (sptr->size()==0)
sigma.insert(vertex_upper_bound);
- for(const Vertex& v : sigma){
+ for(const Toplex_map::Vertex& v : sigma){
t0.at(v).erase(sptr);
if(t0.at(v).size()==0) t0.erase(v);
}
}
template <typename Input_vertex_range>
-Vertex Toplex_map::best_index(const Input_vertex_range &vertex_range) const{
+Toplex_map::Vertex Toplex_map::best_index(const Input_vertex_range &vertex_range) const{
std::size_t min = std::numeric_limits<size_t>::max();
Vertex arg_min = vertex_upper_bound;
- for(const Vertex& v : vertex_range)
+ for(const Toplex_map::Vertex& v : vertex_range)
if(!t0.count(v)) return v;
else if(t0.at(v).size() < min)
min = t0.at(v).size(), arg_min = v;
return arg_min;
}
-std::size_t Sptr_equal::operator()(const Simplex_ptr& s1, const Simplex_ptr& s2) const {
+std::size_t Toplex_map::Sptr_equal::operator()(const Toplex_map::Simplex_ptr& s1, const Toplex_map::Simplex_ptr& s2) const {
if (s1->size() != s2->size()) return false;
return included(*s1,*s2);
// inclusion tests equality for same size simplices
}
-std::size_t Sptr_hash::operator()(const Simplex_ptr& s) const {
+std::size_t Toplex_map::Sptr_hash::operator()(const Toplex_map::Simplex_ptr& s) const {
std::hash<double> h_f;
//double hash works better than int hash
size_t h = 0;
- for(const Vertex& v : *s)
+ for(const Toplex_map::Vertex& v : *s)
h += h_f(static_cast<double>(v));
return h;
}
template <typename Input_vertex_range>
-Simplex_ptr get_key(const Input_vertex_range &vertex_range){
- Simplex s(vertex_range.begin(), vertex_range.end());
- return std::make_shared<Simplex>(s);
+Toplex_map::Simplex_ptr get_key(const Input_vertex_range &vertex_range){
+ Toplex_map::Simplex s(vertex_range.begin(), vertex_range.end());
+ return std::make_shared<Toplex_map::Simplex>(s);
}
template <typename Input_vertex_range1, typename Input_vertex_range2>
bool included(const Input_vertex_range1 &vertex_range1, const Input_vertex_range2 &vertex_range2){
- Simplex s2(vertex_range2.begin(), vertex_range2.end());
- for(const Vertex& v : vertex_range1)
+ Toplex_map::Simplex s2(vertex_range2.begin(), vertex_range2.end());
+ for(const Toplex_map::Vertex& v : vertex_range1)
if(!s2.count(v)) return false;
return true;
}
template <typename Input_vertex_range>
-std::vector<Simplex> facets(const Input_vertex_range &vertex_range){
- std::vector<Simplex> facets;
- Simplex f(vertex_range.begin(), vertex_range.end());
- for(const Vertex& v : vertex_range){
+std::vector<Toplex_map::Simplex> facets(const Input_vertex_range &vertex_range){
+ std::vector<Toplex_map::Simplex> facets;
+ Toplex_map::Simplex f(vertex_range.begin(), vertex_range.end());
+ for(const Toplex_map::Vertex& v : vertex_range){
f.erase(v);
facets.emplace_back(f);
f.insert(v);