23 #ifndef GUDHI_READER_UTILS_H
24 #define GUDHI_READER_UTILS_H
28 #include <boost/graph/adjacency_list.hpp>
29 #include "gudhi/graph_simplicial_complex.h"
41 read_points ( std::string file_name
42 , std::vector< std::vector< double > > & points)
44 std::ifstream in_file (file_name.c_str(),std::ios::in);
45 if(!in_file.is_open()) {
46 std::cerr <<
"Unable to open file " << file_name << std::endl;
51 while( getline ( in_file , line ) )
53 std::vector< double > point;
54 std::istringstream iss( line );
55 while(iss >> x) { point.push_back(x); }
56 points.push_back(point);
74 read_graph ( std::string file_name )
76 std::ifstream in_ (file_name.c_str(),std::ios::in);
77 if(!in_.is_open()) { std::cerr <<
"Unable to open file " << file_name << std::endl; }
79 std::vector< Edge_t > edges;
80 std::vector< Filtration_value > edges_fil;
81 std::map< Vertex_handle, Filtration_value > vertices;
85 Vertex_handle u,v,max_h = -1;
87 while( getline ( in_ , line ) )
89 std::istringstream iss( line );
95 if(max_h < u) { max_h = u; }
99 iss >> u; iss >> v; iss >> fil;
100 edges.push_back(Edge_t(u,v));
101 edges_fil.push_back(fil);
110 if((
size_t)(max_h+1) != vertices.size())
111 { std::cerr <<
"Error: vertices must be labeled from 0 to n-1 \n"; }
113 Graph_t skel_graph(edges.begin(),edges.end(),edges_fil.begin(),vertices.size());
114 auto vertex_prop = boost::get(vertex_filtration_t(),skel_graph);
116 boost::graph_traits<Graph_t>::vertex_iterator vi, vi_end;
117 auto v_it = vertices.begin();
118 for (tie(vi, vi_end) = boost::vertices(skel_graph); vi != vi_end; ++vi,++v_it)
119 { boost::put(vertex_prop, *vi, v_it->second); }
136 template<
typename Vertex_handle
137 ,
typename Filtration_value >
138 bool read_simplex ( std::istream & in_
139 , std::vector< Vertex_handle > & simplex
140 , Filtration_value & fil )
143 if(!(in_ >> dim))
return false;
145 for(
int i=0; i<dim+1; ++i)
146 { in_ >> v; simplex.push_back(v); }
148 in_.ignore((std::numeric_limits<std::streamsize>::max)(),
'\n');
165 template<
typename Simplex_key
166 ,
typename Filtration_value >
167 bool read_hasse_simplex ( std::istream & in_
168 , std::vector< Simplex_key > & boundary
169 , Filtration_value & fil )
172 if(!(in_ >> dim))
return false;
173 if(dim == 0) {in_ >> fil;
return true;}
175 for(
int i=0; i<dim+1; ++i)
176 { in_ >> key; boundary.push_back(key); }
181 #endif // GUDHI_READER_UTILS_H