summaryrefslogtreecommitdiff
path: root/src/Nerve_GIC
diff options
context:
space:
mode:
authormcarrier <mcarrier@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-04-20 14:22:38 +0000
committermcarrier <mcarrier@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2017-04-20 14:22:38 +0000
commita972e9c190e86b0bb0fd4947bceedbcfc50a6266 (patch)
treec3d8f07ac58b52f4a0b1d84c7bd207af8ce4e057 /src/Nerve_GIC
parente4decddc3f2bb2e9644d8412833e316b68201880 (diff)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/Nerve_GIC@2372 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 98ac2704dddfb45235380f4507de2e934e4a6075
Diffstat (limited to 'src/Nerve_GIC')
-rw-r--r--src/Nerve_GIC/example/simple_GIC.cpp6
-rw-r--r--src/Nerve_GIC/include/gudhi/GIC.h42
2 files changed, 39 insertions, 9 deletions
diff --git a/src/Nerve_GIC/example/simple_GIC.cpp b/src/Nerve_GIC/example/simple_GIC.cpp
index e3d19cc8..ec183a5d 100644
--- a/src/Nerve_GIC/example/simple_GIC.cpp
+++ b/src/Nerve_GIC/example/simple_GIC.cpp
@@ -12,7 +12,7 @@ int main(int argc, char **argv) {
std::string off_file_name(argv[1]);
double threshold = atof(argv[2]);
- std::string function_file_name(argv[3]);
+ int coord = atoi(argv[3]);
double resolution = atof(argv[4]);
double gain = atof(argv[5]);
@@ -26,8 +26,10 @@ int main(int argc, char **argv) {
// ----------------------------------------------------------------------------
Gudhi::graph_induced_complex::Graph_induced_complex GIC;
+
GIC.set_graph_from_rips(threshold, off_file_name);
- GIC.set_cover_from_function(function_file_name,resolution,gain,0);
+ GIC.set_function_from_coordinate(coord, off_file_name);
+ GIC.set_cover_from_function(resolution,gain,0);
//GIC.find_GIC_simplices();
GIC.find_GIC_simplices_with_functional_minimal_cover(resolution,gain);
Simplex_tree stree; GIC.create_complex(stree);
diff --git a/src/Nerve_GIC/include/gudhi/GIC.h b/src/Nerve_GIC/include/gudhi/GIC.h
index 5d9ca174..4a3a1af9 100644
--- a/src/Nerve_GIC/include/gudhi/GIC.h
+++ b/src/Nerve_GIC/include/gudhi/GIC.h
@@ -126,6 +126,26 @@ class Graph_induced_complex {
}
}
+ public:
+ void set_graph_from_OFF(const std::string& off_file_name){
+ int numpts, numedges, numfaces, i; std::vector<int> edge(2); double x; int num; std::vector<int> simplex;
+ std::ifstream input(off_file_name); std::string line; getline(input, line);
+ input >> numpts; input >> numedges; input >> numfaces;
+ i = 0; while(i < numpts){input >> x; input >> x; input >> x; i++;}
+ i = 0; while(i < numfaces){
+ simplex.clear(); input >> num;
+ for(int j = 0; j < num; j++){int k; input >> k; simplex.push_back(k);}
+ for(int j = 0; j < num; j++){
+ for(int k = j+1; k < num; k++){
+ edge[0] = simplex[j]; edge[1] = simplex[k];
+ st.insert_simplex_and_subfaces(edge);
+ }
+ }
+ i++;
+ }
+
+ }
+
public: // Set graph from Rips complex.
void set_graph_from_rips(const double& threshold, const std::string& off_file_name){
Points_off_reader<Point> off_reader(off_file_name);
@@ -147,6 +167,14 @@ class Graph_induced_complex {
}
}
+ public: // Set function from kth coordinate
+ void set_function_from_coordinate(const int& k, const std::string& off_file_name){
+ Points_off_reader<Point> off_reader(off_file_name);
+ //std::vector<Point> cloud = off_reader.get_point_cloud();
+ int numpts = off_reader.get_point_cloud().size(); //cloud.size();
+ for(int i = 0; i < numpts; i++) func.insert(std::pair<int,double>(i,off_reader.get_point_cloud()[i][k])); //std::cout << cloud[i][k] << std::endl;
+ }
+
public: // Set function from vector.
void set_function_from_vector(const std::vector<double>& function){
for(int i = 0; i < function.size(); i++) func.insert(std::pair<int,double>(i, function[i]));
@@ -174,9 +202,9 @@ class Graph_induced_complex {
void set_cover_from_function(const double& resolution, const double& gain, const bool& token){
// Read function values and compute min and max
- std::map<int, double>::iterator it; std::vector<double> range; double maxf, minf; minf = std::numeric_limits<float>::max(); maxf = std::numeric_limits<float>::min();
- for(it = func.begin(); it != func.end(); it++){range.push_back(it->second); minf = std::min(minf, it->second); maxf = std::max(maxf, it->second);}
- int num_pts = func.size();
+ std::map<int, double>::iterator it; /*std::vector<double> range;*/ double maxf, minf; minf = std::numeric_limits<float>::max(); maxf = std::numeric_limits<float>::min();
+ for(it = func.begin(); it != func.end(); it++){/*range.push_back(it->second);*/ minf = std::min(minf, it->second); maxf = std::max(maxf, it->second);}
+ int num_pts = func.size(); //std::cout << minf << " " << maxf << std::endl;
// Compute cover of im(f)
std::vector<std::pair<double,double> > intervals; int res;
@@ -265,7 +293,7 @@ class Graph_induced_complex {
for(std::map<int, std::vector<int> >::iterator it = prop.begin(); it != prop.end(); it++){
if ( !(visit[it->first]) ){
std::vector<int> cc; cc.clear();
- dfs(prop,it->first,cc,visit); int cci = cc.size();
+ dfs(prop,it->first,cc,visit); int cci = cc.size(); std::cout << cci << std::endl;
for(int i = 0; i < cci; i++) cover[cc[i]].push_back(id);
id++;
}
@@ -324,7 +352,7 @@ class Graph_induced_complex {
for(int i = 0; i < num_nodes; i++)
for(int j = 0; j < cover_elts[i].size(); j++)
simplex.push_back(cover_elts[i][j]);
- std::sort(simplex.begin(),simplex.end()); it = std::unique(simplex.begin(),simplex.end());
+ std::sort(simplex.begin(),simplex.end()); std::vector<Cover_t>::iterator it = std::unique(simplex.begin(),simplex.end());
simplex.resize(std::distance(simplex.begin(),it));
simplices.push_back(simplex);
}
@@ -371,9 +399,9 @@ class Graph_induced_complex {
simplices.clear();
for (auto simplex : st.complex_simplex_range()) {
if(!st.has_children(simplex)){
- std::vector<std::vector<Cover_t> > cover_elts; std::vector<Cover_t> sim;
+ std::vector<std::vector<Cover_t> > cover_elts; //std::vector<Cover_t> sim;
for (auto vertex : st.simplex_vertex_range(simplex)) cover_elts.push_back(cover[vertex]);
- find_all_simplices(cover_elts,0,sim);
+ find_all_simplices(cover_elts/*,0,sim*/);
}
}
std::vector<std::vector<Cover_t> >::iterator it;