11#ifndef READER_UTILS_H_ 
   12#define READER_UTILS_H_ 
   15#include <gudhi/Debug_utils.h> 
   17# include <boost/iterator/function_output_iterator.hpp> 
   18#include <boost/graph/adjacency_list.hpp> 
   46inline void read_points(std::string file_name, std::vector<std::vector<double>>& points) {
 
   47  std::ifstream in_file(file_name.c_str(), std::ios::in);
 
   48  if (!in_file.is_open()) {
 
   49    std::cerr << 
"Unable to open file " << file_name << std::endl;
 
   55  while (getline(in_file, line)) {
 
   56    std::vector<double> point;
 
   57    std::istringstream iss(line);
 
   62    if (!point.empty()) points.push_back(point);
 
   83template <
typename Graph_t, 
typename Filtration_value, 
typename Vertex_handle>
 
   85  std::ifstream in_(file_name.c_str(), std::ios::in);
 
   87    std::string error_str(
"read_graph - Unable to open file ");
 
   88    error_str.append(file_name);
 
   89    std::cerr << error_str << std::endl;
 
   90    throw std::invalid_argument(error_str);
 
   93  typedef std::pair<Vertex_handle, Vertex_handle> Edge_t;
 
   94  std::vector<Edge_t> edges;
 
   95  std::vector<Filtration_value> edges_fil;
 
   96  std::map<Vertex_handle, Filtration_value> vertices;
 
  102  while (getline(in_, line)) {
 
  103    std::istringstream iss(line);
 
  119          edges.push_back(Edge_t(u, v));
 
  120          edges_fil.push_back(fil);
 
  129  if ((
size_t)(max_h + 1) != vertices.size()) {
 
  130    std::cerr << 
"Error: vertices must be labeled from 0 to n-1 \n";
 
  133  Graph_t skel_graph(edges.begin(), edges.end(), edges_fil.begin(), vertices.size());
 
  134  auto vertex_prop = 
boost::get(vertex_filtration_t(), skel_graph);
 
  136  typename boost::graph_traits<Graph_t>::vertex_iterator vi, vi_end;
 
  137  auto v_it = vertices.begin();
 
  138  for (std::tie(vi, vi_end) = boost::vertices(skel_graph); vi != vi_end; ++vi, ++v_it) {
 
  139    boost::put(vertex_prop, *vi, v_it->second);
 
  157template <
typename Vertex_handle, 
typename Filtration_value>
 
  160  if (!(in_ >> dim)) 
return false;
 
  162  for (
int i = 0; i < dim + 1; ++i) {
 
  163    if (!(in_ >> v)) 
return false;
 
  164    simplex.push_back(v);
 
  166  if (!(in_ >> fil)) 
return false;
 
  167  in_.ignore((std::numeric_limits<std::streamsize>::max)(), 
'\n');  
 
  182template <
typename Simplex_key, 
typename Filtration_value>
 
  185  if (!(in_ >> dim)) 
return false;
 
  191  for (
int i = 0; i < dim + 1; ++i) {
 
  193    boundary.push_back(key);
 
  219template <
typename Filtration_value>
 
  221                                                                                      const char separator = 
';') {
 
  223  std::clog << 
"Using procedure read_lower_triangular_matrix_from_csv_file \n";
 
  225  std::vector<std::vector<Filtration_value>> result;
 
  227  in.open(filename.c_str());
 
  235  std::getline(in, line);
 
  236  std::vector<Filtration_value> values_in_this_line;
 
  237  result.push_back(values_in_this_line);
 
  239  int number_of_line = 0;
 
  242  while (std::getline(in, line)) {
 
  244    if (line.size() == 0) 
break;
 
  247    if (line[line.size() - 1] == separator) {
 
  253    std::replace(line.begin(), line.end(), separator, 
' ');
 
  256    std::istringstream iss(line);
 
  259    int number_of_entry = 0;
 
  260    std::vector<Filtration_value> values_in_this_line;
 
  264      if (number_of_entry <= number_of_line) {
 
  265        values_in_this_line.push_back(entry);
 
  269    if (!values_in_this_line.empty()) result.push_back(values_in_this_line);
 
  275  std::clog << 
"Here is the matrix we read : \n";
 
  276  for (
size_t i = 0; i != result.size(); ++i) {
 
  277    for (
size_t j = 0; j != result[i].size(); ++j) {
 
  278      std::clog << result[i][j] << 
" ";
 
  280    std::clog << std::endl;
 
  294template <
typename OutputIterator>
 
  297  std::clog << 
"read_persistence_intervals_and_dimension - " << filename << std::endl;
 
  299  std::ifstream in(filename);
 
  301    std::string error_str(
"read_persistence_intervals_and_dimension - Unable to open file ");
 
  302    error_str.append(filename);
 
  303    std::cerr << error_str << std::endl;
 
  304    throw std::invalid_argument(error_str);
 
  310    if (line.length() != 0 && line[0] != 
'#') {
 
  312      int n = sscanf(line.c_str(), 
"%lf %lf %lf %lf", &numbers[0], &numbers[1], &numbers[2], &numbers[3]);
 
  314      std::clog << 
"[" << n << 
"] = ";
 
  315      for (
int i = 0; i < n; i++) {
 
  316        std::clog << numbers[i] << 
",";
 
  318      std::clog << std::endl;
 
  321        int dim = (n >= 3 ? 
static_cast<int>(numbers[n - 3]) : -1);
 
  322        *out++ = std::make_tuple(dim, numbers[n - 2], numbers[n - 1]);
 
  336    std::string 
const& filename) {
 
  337  std::map<int, std::vector<std::pair<double, double>>> ret;
 
  339      filename, boost::make_function_output_iterator([&ret](std::tuple<int, double, double> t) {
 
  340        ret[get<0>(t)].push_back(std::make_pair(get<1>(t), get<2>(t)));
 
  356                                                                                      int only_this_dim = -1) {
 
  357  std::vector<std::pair<double, double>> ret;
 
  359      filename, boost::make_function_output_iterator([only_this_dim, &ret](std::tuple<int, double, double> t) {
 
  360        if (only_this_dim == get<0>(t) || only_this_dim == -1) ret.emplace_back(get<1>(t), get<2>(t));
 
Graph simplicial complex methods.
 
constexpr auto & get(Gudhi::persistence_matrix::Persistence_interval< Dimension, Event_value > &i) noexcept
Partial specialization of get for Gudhi::persistence_matrix::Persistence_interval.
Definition: persistence_interval.h:199
 
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
 
bool read_hasse_simplex(std::istream &in_, std::vector< Simplex_key > &boundary, Filtration_value &fil)
Read a hasse simplex from a file.
Definition: reader_utils.h:183
 
Graph_t read_graph(std::string file_name)
Read a graph from a file.
Definition: reader_utils.h:84
 
std::vector< std::pair< double, double > > read_persistence_intervals_in_dimension(std::string const &filename, int only_this_dim=-1)
Definition: reader_utils.h:355
 
void read_persistence_intervals_and_dimension(std::string const &filename, OutputIterator out)
Definition: reader_utils.h:295
 
bool read_simplex(std::istream &in_, std::vector< Vertex_handle > &simplex, Filtration_value &fil)
Read a face from a file.
Definition: reader_utils.h:158
 
std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from_csv_file(const std::string &filename, const char separator=';')
Read a lower triangular distance matrix from a csv file. We assume that the .csv store the whole (squ...
Definition: reader_utils.h:220
 
void read_points(std::string file_name, std::vector< std::vector< double > > &points)
Read a set of points to turn it into a vector< vector<double> > by filling points.
Definition: reader_utils.h:46
 
std::map< int, std::vector< std::pair< double, double > > > read_persistence_intervals_grouped_by_dimension(std::string const &filename)
Definition: reader_utils.h:335
 
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:20
 
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15