diff options
author | cjamin <cjamin@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2017-05-16 14:25:19 +0000 |
---|---|---|
committer | cjamin <cjamin@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2017-05-16 14:25:19 +0000 |
commit | e7162cf121d5e1619ca4b7b54b9cef4d9ff1c9f7 (patch) | |
tree | a290384c991c8604d70afdaa1b77e8cd28ac0188 /src/common/include/gudhi | |
parent | 31ec7b36f20f127850b5cd7a1b1858cc5a2b8c49 (diff) |
Add read_persistence_diagram_from_file
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2439 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 026fbb0528343a15a46935ded3aaf13297afeff5
Diffstat (limited to 'src/common/include/gudhi')
-rw-r--r-- | src/common/include/gudhi/reader_utils.h | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 97a87edd..ceee8daf 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -2,7 +2,7 @@ * (Geometric Understanding in Higher Dimensions) is a generic C++ * library for computational topology. * - * Author(s): Clement Maria, Pawel Dlotko + * Author(s): Clement Maria, Pawel Dlotko, Clement Jamin * * Copyright (C) 2014 INRIA * @@ -295,4 +295,40 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from return result; } // read_lower_triangular_matrix_from_csv_file +/** +Reads a file containing persistance intervals. +Each line might contain 2, 3 or 4 values: [field] [dimension] birth death +**/ + +std::vector< std::pair<double, double> > read_persistence_diagram_from_file(std::string const& filename) { + + std::vector< std::pair<double, double> > result; + + std::ifstream in; + in.open(filename); + if (!in.is_open()) { +#ifdef DEBUG_TRACES + std::cerr << "File \"" << filename << "\" does not exist.\n"; +#endif // DEBUG_TRACES + return result; + } + + std::string line; + while (!in.eof()) { + getline(in, line); + if (line.length() != 0 && line[0] != '#') { + double numbers[4]; + int n = sscanf(line.c_str(), "%lf %lf %lf %lf", &numbers[0], &numbers[1], &numbers[2], &numbers[3]); + result.push_back(std::make_pair(numbers[n - 2], numbers[n - 1])); +#ifdef DEBUG_TRACES + std::cerr << numbers[n - 2] << " - " << numbers[n - 1] << "\n"; +#endif // DEBUG_TRACES + } + } + + in.close(); + return result; +} // read_diagram_from_file + + #endif // READER_UTILS_H_ |