From a972e9c190e86b0bb0fd4947bceedbcfc50a6266 Mon Sep 17 00:00:00 2001 From: mcarrier Date: Thu, 20 Apr 2017 14:22:38 +0000 Subject: git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/Nerve_GIC@2372 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 98ac2704dddfb45235380f4507de2e934e4a6075 --- src/Nerve_GIC/example/simple_GIC.cpp | 6 ++++-- src/Nerve_GIC/include/gudhi/GIC.h | 42 ++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 9 deletions(-) (limited to 'src') 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 edge(2); double x; int num; std::vector 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 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 off_reader(off_file_name); + //std::vector 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(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& function){ for(int i = 0; i < function.size(); i++) func.insert(std::pair(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::iterator it; std::vector range; double maxf, minf; minf = std::numeric_limits::max(); maxf = std::numeric_limits::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::iterator it; /*std::vector range;*/ double maxf, minf; minf = std::numeric_limits::max(); maxf = std::numeric_limits::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 > intervals; int res; @@ -265,7 +293,7 @@ class Graph_induced_complex { for(std::map >::iterator it = prop.begin(); it != prop.end(); it++){ if ( !(visit[it->first]) ){ std::vector 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::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 > cover_elts; std::vector sim; + std::vector > cover_elts; //std::vector 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 >::iterator it; -- cgit v1.2.3