-- cgit v1.2.3 From e7162cf121d5e1619ca4b7b54b9cef4d9ff1c9f7 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 16 May 2017 14:25:19 +0000 Subject: 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 --- src/common/include/gudhi/reader_utils.h | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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 > read_persistence_diagram_from_file(std::string const& filename) { + + std::vector< std::pair > 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_ -- cgit v1.2.3 From 884d91ed81876af1a3d986843253acaaff443834 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 16 May 2017 14:26:11 +0000 Subject: Use read_persistence_diagram_from_file in this example git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2440 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: cb5cbba3f968c6cd16025250076bbe1df4f2e11a --- .../example/bottleneck_read_file_example.cpp | 31 +++------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index bde05825..e50a243d 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -21,8 +21,10 @@ */ #define CGAL_HAS_THREADS +#define DEBUG_TRACES #include +#include #include #include #include // for pair @@ -30,39 +32,14 @@ #include #include -std::vector< std::pair > read_diagram_from_file(const char* filename) { - std::ifstream in; - in.open(filename); - std::vector< std::pair > result; - if (!in.is_open()) { - std::cerr << "File : " << filename << " do not exist. The program will now terminate \n"; - throw "File do not exist \n"; - } - - std::string line; - while (!in.eof()) { - getline(in, line); - if (line.length() != 0) { - std::stringstream lineSS; - lineSS << line; - double beginn, endd; - lineSS >> beginn; - lineSS >> endd; - result.push_back(std::make_pair(beginn, endd)); - } - } - in.close(); - return result; -} // read_diagram_from_file - int main(int argc, char** argv) { if (argc < 3) { std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file " << "should contain a birth-death pair per line. Third, optional parameter is an error bound on a bottleneck" << " distance (set by default to zero). The program will now terminate \n"; } - std::vector< std::pair< double, double > > diag1 = read_diagram_from_file(argv[1]); - std::vector< std::pair< double, double > > diag2 = read_diagram_from_file(argv[2]); + std::vector< std::pair< double, double > > diag1 = read_persistence_diagram_from_file(argv[1]); + std::vector< std::pair< double, double > > diag2 = read_persistence_diagram_from_file(argv[2]); double tolerance = 0.; if (argc == 4) { tolerance = atof(argv[3]); -- cgit v1.2.3 From f8992aa852dc1a5ef1392837581f55650cccaebf Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 19 May 2017 08:52:58 +0000 Subject: Remove DEBUG_TRACES git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2446 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2290435a73db6bea9297fa79e10f7e36be10a43e --- src/Bottleneck_distance/example/bottleneck_read_file_example.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index e50a243d..67bd27db 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -21,7 +21,6 @@ */ #define CGAL_HAS_THREADS -#define DEBUG_TRACES #include #include -- cgit v1.2.3 From 269fa842c2eaeb7ddf8040abfd6c18d23ac767e9 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 23 May 2017 09:10:41 +0000 Subject: read_persistence_diagram_from_file now uses an output iterator git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2455 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3969666dcde3581a75789c5a4b62817dea553f9f --- .../example/bottleneck_read_file_example.cpp | 15 +++++++++++++-- src/common/include/gudhi/reader_utils.h | 17 ++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index 67bd27db..74c8d1ab 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -31,14 +31,25 @@ #include #include +struct Persistence_interval + : std::pair +{ + Persistence_interval(std::tuple data) + : std::pair(std::make_pair(std::get<1>(data), std::get<2>(data))) + {} +}; + int main(int argc, char** argv) { if (argc < 3) { std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file " << "should contain a birth-death pair per line. Third, optional parameter is an error bound on a bottleneck" << " distance (set by default to zero). The program will now terminate \n"; } - std::vector< std::pair< double, double > > diag1 = read_persistence_diagram_from_file(argv[1]); - std::vector< std::pair< double, double > > diag2 = read_persistence_diagram_from_file(argv[2]); + std::vector diag1; + std::vector diag2; + read_persistence_diagram_from_file(argv[1], std::back_inserter(diag1)); + read_persistence_diagram_from_file(argv[2], std::back_inserter(diag2)); + double tolerance = 0.; if (argc == 4) { tolerance = atof(argv[3]); diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index ceee8daf..019a3db2 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -298,11 +298,11 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from /** Reads a file containing persistance intervals. Each line might contain 2, 3 or 4 values: [field] [dimension] birth death +The output iterator `out` is used this way: `*out++ = std::make_tuple(dim, birth, death);` +where `dim` is an `int`, `birth` a `double`, and `death` a `double`. **/ - -std::vector< std::pair > read_persistence_diagram_from_file(std::string const& filename) { - - std::vector< std::pair > result; +template +void read_persistence_diagram_from_file(std::string const& filename, OutputIterator out) { std::ifstream in; in.open(filename); @@ -310,7 +310,6 @@ std::vector< std::pair > read_persistence_diagram_from_file(std: #ifdef DEBUG_TRACES std::cerr << "File \"" << filename << "\" does not exist.\n"; #endif // DEBUG_TRACES - return result; } std::string line; @@ -319,7 +318,9 @@ std::vector< std::pair > read_persistence_diagram_from_file(std: 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])); + //int field = (n == 4 ? static_cast(numbers[0]) : -1); + int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); + *out++ = std::make_tuple(dim, numbers[n - 2], numbers[n - 1]); #ifdef DEBUG_TRACES std::cerr << numbers[n - 2] << " - " << numbers[n - 1] << "\n"; #endif // DEBUG_TRACES @@ -327,8 +328,6 @@ std::vector< std::pair > read_persistence_diagram_from_file(std: } in.close(); - return result; -} // read_diagram_from_file - +} // read_persistence_diagram_from_file #endif // READER_UTILS_H_ -- cgit v1.2.3 From 71527e6ff81a7ac657f8a797a050bbcf7a131cb9 Mon Sep 17 00:00:00 2001 From: cjamin Date: Mon, 29 May 2017 16:22:49 +0000 Subject: Add 2 new variants of read_persistence_diagram_from_file git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2463 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: bd0dd2c981856c8e1a51b2b97ac10d9edd59f694 --- .../example/bottleneck_read_file_example.cpp | 6 +- src/common/include/gudhi/reader_utils.h | 85 ++++++++++++++++++++-- 2 files changed, 82 insertions(+), 9 deletions(-) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index 74c8d1ab..e26edd26 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -45,10 +45,8 @@ int main(int argc, char** argv) { "should contain a birth-death pair per line. Third, optional parameter is an error bound on a bottleneck" << " distance (set by default to zero). The program will now terminate \n"; } - std::vector diag1; - std::vector diag2; - read_persistence_diagram_from_file(argv[1], std::back_inserter(diag1)); - read_persistence_diagram_from_file(argv[2], std::back_inserter(diag2)); + std::vector> diag1 = read_persistence_diagram_from_file(argv[1], -1); + std::vector> diag2 = read_persistence_diagram_from_file(argv[2], -1); double tolerance = 0.; if (argc == 4) { diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 019a3db2..7b371afc 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -310,24 +310,99 @@ void read_persistence_diagram_from_file(std::string const& filename, OutputItera #ifdef DEBUG_TRACES std::cerr << "File \"" << filename << "\" does not exist.\n"; #endif // DEBUG_TRACES + return; } - std::string line; while (!in.eof()) { + std::string line; 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]); - //int field = (n == 4 ? static_cast(numbers[0]) : -1); - int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); - *out++ = std::make_tuple(dim, numbers[n - 2], numbers[n - 1]); + if (n >= 2) { + //int field = (n == 4 ? static_cast(numbers[0]) : -1); + int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); + *out++ = std::make_tuple(dim, numbers[n - 2], numbers[n - 1]); + } + } + } + + in.close(); +} // read_persistence_diagram_from_file + +/** +Reads a file containing persistance intervals. +Each line might contain 2, 3 or 4 values: [field] [dimension] birth death +The return value is an `std::map[dim, std::vector[std::pair[birth, death]]]` +where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +**/ +std::map>> read_persistence_diagram_from_file(std::string const& filename) { + + std::map>> ret; + + std::ifstream in; + in.open(filename); + if (!in.is_open()) { #ifdef DEBUG_TRACES - std::cerr << numbers[n - 2] << " - " << numbers[n - 1] << "\n"; + std::cerr << "File \"" << filename << "\" does not exist.\n"; #endif // DEBUG_TRACES + return ret; + } + + while (!in.eof()) { + std::string line; + 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]); + if (n >= 2) { + int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); + ret[dim].push_back(std::make_pair(numbers[n - 2], numbers[n - 1])); + } + } + } + + in.close(); + return ret; +} // read_persistence_diagram_from_file + + +/** +Reads a file containing persistance intervals. +Each line might contain 2, 3 or 4 values: [field] [dimension] birth death +If `only_this_dim` = -1, dimension is ignored and all lines are returned. +If `only_this_dim` is >= 0, only the lines where dimension = `only_this_dim` +(or where dimension is not specified) are returned. +The return value is an `std::vector[std::pair[birth, death]]` +where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +**/ +std::vector> read_persistence_diagram_from_file(std::string const& filename, int only_this_dim) { + + std::vector> ret; + + 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 ret; + } + + while (!in.eof()) { + std::string line; + 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]); + int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); + if (n >= 2 && (only_this_dim == -1 || dim == only_this_dim)) + ret.push_back(std::make_pair(numbers[n - 2], numbers[n - 1])); } } in.close(); + return ret; } // read_persistence_diagram_from_file #endif // READER_UTILS_H_ -- cgit v1.2.3 From 006516d2df5eaa6e38765158f72fa29fea8fb610 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 30 May 2017 12:50:12 +0000 Subject: Remove debug code git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2473 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 458dcfcf18b36f8dd0023dfe5af0d6083d1c7684 --- src/Bottleneck_distance/example/bottleneck_read_file_example.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index e26edd26..f6fd6501 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -20,8 +20,6 @@ * along with this program. If not, see . */ -#define CGAL_HAS_THREADS - #include #include #include -- cgit v1.2.3 From 6d4b5ec65b863abb5b183635a0e64341c19e7b4b Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 30 May 2017 13:00:15 +0000 Subject: Clean-up git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2474 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9586b4987dad745fa60bca1a433349a2f78fa9bd --- src/Bottleneck_distance/example/bottleneck_read_file_example.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index f6fd6501..de8c7f9d 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -29,14 +29,6 @@ #include #include -struct Persistence_interval - : std::pair -{ - Persistence_interval(std::tuple data) - : std::pair(std::make_pair(std::get<1>(data), std::get<2>(data))) - {} -}; - int main(int argc, char** argv) { if (argc < 3) { std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file " << -- cgit v1.2.3 From 53abf1ac75eefcecc1391d140183a49588f0d2d2 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 31 May 2017 11:30:58 +0000 Subject: Fix doc and shorten code git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2485 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 97dcd51c0dc9cef00a655e5e0ad078de752eabe8 --- src/common/include/gudhi/reader_utils.h | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 7b371afc..df10d5a5 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -297,15 +297,14 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from /** Reads a file containing persistance intervals. -Each line might contain 2, 3 or 4 values: [field] [dimension] birth death +Each line might contain 2, 3 or 4 values: [[field] dimension] birth death The output iterator `out` is used this way: `*out++ = std::make_tuple(dim, birth, death);` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. **/ template void read_persistence_diagram_from_file(std::string const& filename, OutputIterator out) { - std::ifstream in; - in.open(filename); + std::ifstream in(filename); if (!in.is_open()) { #ifdef DEBUG_TRACES std::cerr << "File \"" << filename << "\" does not exist.\n"; @@ -326,13 +325,11 @@ void read_persistence_diagram_from_file(std::string const& filename, OutputItera } } } - - in.close(); } // read_persistence_diagram_from_file /** Reads a file containing persistance intervals. -Each line might contain 2, 3 or 4 values: [field] [dimension] birth death +Each line might contain 2, 3 or 4 values: [[field] dimension] birth death The return value is an `std::map[dim, std::vector[std::pair[birth, death]]]` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. **/ @@ -340,8 +337,7 @@ std::map>> read_persistence_diagram_f std::map>> ret; - std::ifstream in; - in.open(filename); + std::ifstream in(filename); if (!in.is_open()) { #ifdef DEBUG_TRACES std::cerr << "File \"" << filename << "\" does not exist.\n"; @@ -362,14 +358,13 @@ std::map>> read_persistence_diagram_f } } - in.close(); return ret; } // read_persistence_diagram_from_file /** Reads a file containing persistance intervals. -Each line might contain 2, 3 or 4 values: [field] [dimension] birth death +Each line might contain 2, 3 or 4 values: [[field] dimension] birth death If `only_this_dim` = -1, dimension is ignored and all lines are returned. If `only_this_dim` is >= 0, only the lines where dimension = `only_this_dim` (or where dimension is not specified) are returned. @@ -380,8 +375,7 @@ std::vector> read_persistence_diagram_from_file(std::s std::vector> ret; - std::ifstream in; - in.open(filename); + std::ifstream in(filename); if (!in.is_open()) { #ifdef DEBUG_TRACES std::cerr << "File \"" << filename << "\" does not exist.\n"; @@ -401,7 +395,6 @@ std::vector> read_persistence_diagram_from_file(std::s } } - in.close(); return ret; } // read_persistence_diagram_from_file -- cgit v1.2.3 From 8457da40a4af813d6368cd85d1f60d2b2de52191 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 31 May 2017 11:36:20 +0000 Subject: Typo git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2486 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: dcc6134d95dea816a3c54a2a796535f384ccfc54 --- src/common/include/gudhi/reader_utils.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index df10d5a5..55a1e875 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -296,7 +296,7 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from } // read_lower_triangular_matrix_from_csv_file /** -Reads a file containing persistance intervals. +Reads a file containing persistence intervals. Each line might contain 2, 3 or 4 values: [[field] dimension] birth death The output iterator `out` is used this way: `*out++ = std::make_tuple(dim, birth, death);` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. @@ -328,7 +328,7 @@ void read_persistence_diagram_from_file(std::string const& filename, OutputItera } // read_persistence_diagram_from_file /** -Reads a file containing persistance intervals. +Reads a file containing persistence intervals. Each line might contain 2, 3 or 4 values: [[field] dimension] birth death The return value is an `std::map[dim, std::vector[std::pair[birth, death]]]` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. @@ -363,7 +363,7 @@ std::map>> read_persistence_diagram_f /** -Reads a file containing persistance intervals. +Reads a file containing persistence intervals. Each line might contain 2, 3 or 4 values: [[field] dimension] birth death If `only_this_dim` = -1, dimension is ignored and all lines are returned. If `only_this_dim` is >= 0, only the lines where dimension = `only_this_dim` -- cgit v1.2.3 From cbcf098dbc2af8f385216d74d6ffbbe08deaff66 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 31 May 2017 11:44:16 +0000 Subject: Fix doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2487 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7be9a5da2a64835ff7558373e7a754647bc5b663 --- src/common/include/gudhi/reader_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 55a1e875..bb744b1c 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -330,7 +330,7 @@ void read_persistence_diagram_from_file(std::string const& filename, OutputItera /** Reads a file containing persistence intervals. Each line might contain 2, 3 or 4 values: [[field] dimension] birth death -The return value is an `std::map[dim, std::vector[std::pair[birth, death]]]` +The return value is an `std::map>>` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. **/ std::map>> read_persistence_diagram_from_file(std::string const& filename) { @@ -368,7 +368,7 @@ Each line might contain 2, 3 or 4 values: [[field] dimension] birth death If `only_this_dim` = -1, dimension is ignored and all lines are returned. If `only_this_dim` is >= 0, only the lines where dimension = `only_this_dim` (or where dimension is not specified) are returned. -The return value is an `std::vector[std::pair[birth, death]]` +The return value is an `std::vector>` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. **/ std::vector> read_persistence_diagram_from_file(std::string const& filename, int only_this_dim) { -- cgit v1.2.3 From 66873d7ee6dd369dd3d8c1909d6376ed2bce4cc7 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 31 May 2017 11:54:55 +0000 Subject: Check if birth <= death git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2488 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fc7aeca7ca7cd1ec2e9a9263849ec34d4dfa8414 --- src/common/include/gudhi/reader_utils.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index bb744b1c..6a89ce90 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -24,6 +24,7 @@ #define READER_UTILS_H_ #include +#include #include @@ -321,6 +322,7 @@ void read_persistence_diagram_from_file(std::string const& filename, OutputItera if (n >= 2) { //int field = (n == 4 ? static_cast(numbers[0]) : -1); int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); + GUDHI_CHECK(numbers[n - 2] <= numbers[n - 1], "Error: birth > death."); *out++ = std::make_tuple(dim, numbers[n - 2], numbers[n - 1]); } } @@ -353,6 +355,7 @@ std::map>> read_persistence_diagram_f int n = sscanf(line.c_str(), "%lf %lf %lf %lf", &numbers[0], &numbers[1], &numbers[2], &numbers[3]); if (n >= 2) { int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); + GUDHI_CHECK(numbers[n - 2] <= numbers[n - 1], "Error: birth > death."); ret[dim].push_back(std::make_pair(numbers[n - 2], numbers[n - 1])); } } @@ -391,7 +394,10 @@ std::vector> read_persistence_diagram_from_file(std::s int n = sscanf(line.c_str(), "%lf %lf %lf %lf", &numbers[0], &numbers[1], &numbers[2], &numbers[3]); int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); if (n >= 2 && (only_this_dim == -1 || dim == only_this_dim)) + { + GUDHI_CHECK(numbers[n - 2] <= numbers[n - 1], "Error: birth > death."); ret.push_back(std::make_pair(numbers[n - 2], numbers[n - 1])); + } } } -- cgit v1.2.3 From df15aa4e16c00a7dc3bca01e01db8608b50dd4b9 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 31 May 2017 11:58:05 +0000 Subject: Add persistence diagram samples git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2489 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: bcad955589cbfccdb5f887e409df17a07288c9e4 --- data/persistence_diagram/first.pers | 5 +++++ data/persistence_diagram/second.pers | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 data/persistence_diagram/first.pers create mode 100644 data/persistence_diagram/second.pers diff --git a/data/persistence_diagram/first.pers b/data/persistence_diagram/first.pers new file mode 100644 index 00000000..193c60ba --- /dev/null +++ b/data/persistence_diagram/first.pers @@ -0,0 +1,5 @@ +# Simple persistence diagram +2.7 3.7 +9.6 14. +34.2 34.974 +3. inf \ No newline at end of file diff --git a/data/persistence_diagram/second.pers b/data/persistence_diagram/second.pers new file mode 100644 index 00000000..6292fde6 --- /dev/null +++ b/data/persistence_diagram/second.pers @@ -0,0 +1,3 @@ +2.8 4.45 +9.5 14.1 +3.2 inf \ No newline at end of file -- cgit v1.2.3 From 267f55ba68cd3c7beee9cd8c7bd9e13d90217848 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 31 May 2017 12:03:13 +0000 Subject: Test bottleneck_read_file_example git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2490 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: dbbce2ac4862dfdd3c01a619bf68120112ab44d5 --- src/Bottleneck_distance/example/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Bottleneck_distance/example/CMakeLists.txt b/src/Bottleneck_distance/example/CMakeLists.txt index 0534a2c4..508e57bf 100644 --- a/src/Bottleneck_distance/example/CMakeLists.txt +++ b/src/Bottleneck_distance/example/CMakeLists.txt @@ -19,6 +19,10 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.15" "-m" "0.12" "-d" "3" "-p" "3") + add_test(NAME Bottleneck_read_file_example + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers" "${CMAKE_SOURCE_DIR}/data/persistence_diagram/second.pers") + install(TARGETS bottleneck_read_file_example DESTINATION bin) install(TARGETS bottleneck_basic_example DESTINATION bin) install(TARGETS alpha_rips_persistence_bottleneck_distance DESTINATION bin) -- cgit v1.2.3 From 8493f7a38001930329ec6204e6b3e8dff1c67df1 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 1 Jun 2017 10:26:05 +0000 Subject: Use make_function_output_iterator to avoid code duplication git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2498 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7d9a9d3f72ef4af17f4a9b8263526df69498090c --- src/common/include/gudhi/reader_utils.h | 54 +++++---------------------------- 1 file changed, 7 insertions(+), 47 deletions(-) diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 6a89ce90..f0903acc 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -25,6 +25,7 @@ #include #include +#include #include @@ -338,29 +339,9 @@ where `dim` is an `int`, `birth` a `double`, and `death` a `double`. std::map>> read_persistence_diagram_from_file(std::string const& filename) { std::map>> ret; - - std::ifstream in(filename); - if (!in.is_open()) { -#ifdef DEBUG_TRACES - std::cerr << "File \"" << filename << "\" does not exist.\n"; -#endif // DEBUG_TRACES - return ret; - } - - while (!in.eof()) { - std::string line; - 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]); - if (n >= 2) { - int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); - GUDHI_CHECK(numbers[n - 2] <= numbers[n - 1], "Error: birth > death."); - ret[dim].push_back(std::make_pair(numbers[n - 2], numbers[n - 1])); - } - } - } - + read_persistence_diagram_from_file( + filename, + boost::make_function_output_iterator([&ret](auto t) { ret[get<0>(t)].push_back(std::make_pair(get<1>(t), get<2>(t))); })); return ret; } // read_persistence_diagram_from_file @@ -377,30 +358,9 @@ where `dim` is an `int`, `birth` a `double`, and `death` a `double`. std::vector> read_persistence_diagram_from_file(std::string const& filename, int only_this_dim) { std::vector> ret; - - std::ifstream in(filename); - if (!in.is_open()) { -#ifdef DEBUG_TRACES - std::cerr << "File \"" << filename << "\" does not exist.\n"; -#endif // DEBUG_TRACES - return ret; - } - - while (!in.eof()) { - std::string line; - 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]); - int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); - if (n >= 2 && (only_this_dim == -1 || dim == only_this_dim)) - { - GUDHI_CHECK(numbers[n - 2] <= numbers[n - 1], "Error: birth > death."); - ret.push_back(std::make_pair(numbers[n - 2], numbers[n - 1])); - } - } - } - + read_persistence_diagram_from_file( + filename, + boost::make_function_output_iterator([&ret](auto t) { ret.emplace_back(get<1>(t), get<2>(t)); })); return ret; } // read_persistence_diagram_from_file -- cgit v1.2.3 From 03f7d661f8b5d34320a075a826c0bfeafa16633f Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 1 Jun 2017 14:55:10 +0000 Subject: Doc for "pers" file format git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2500 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 2da948fefffcb1961961e3111c89f400f23b65d3 --- src/common/doc/main_page.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index bd4615f5..fba0a858 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -152,6 +152,27 @@ \section Toolbox Toolbox + \subsection FileFormats File Formats + \subsubsection FileFormatsPers Persistence Diagram + + Such a file, whose extension is usually `.pers`, contains a list of persistence intervals.
+ Lines starting with `#` are ignored (comments).
+ Other lines might contain 2, 3 or 4 values (the number of values on each line must be the same for all lines): + \code{.unparsed} + [[field] dimension] birth death + \endcode + + Here is a simple sample file: + \code{.unparsed} + # Beautiful persistence diagram + 2 2.7 3.7 + 2 9.6 14. + 3 34.2 34.974 + 4 3. inf + \endcode + + Other sample files can be found in the `data/persistence_diagram`. + \subsection BottleneckDistanceToolbox Bottleneck distance \image html "perturb_pd.png" "Bottleneck distance is the length of the longest edge" -- cgit v1.2.3 From 3a7ffc0bfec712cb586d5c7ea154a4fd20be1a39 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 9 Jun 2017 10:32:48 +0000 Subject: Change names and adapt example git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2531 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 833a51dd03ddccca38c6011834bb58667d63ccbf --- .../example/bottleneck_read_file_example.cpp | 4 ++-- src/common/include/gudhi/reader_utils.h | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index de8c7f9d..94d9a148 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -35,8 +35,8 @@ int main(int argc, char** argv) { "should contain a birth-death pair per line. Third, optional parameter is an error bound on a bottleneck" << " distance (set by default to zero). The program will now terminate \n"; } - std::vector> diag1 = read_persistence_diagram_from_file(argv[1], -1); - std::vector> diag2 = read_persistence_diagram_from_file(argv[2], -1); + std::vector> diag1 = read_persistence_intervals_in_dimension(argv[1]); + std::vector> diag2 = read_persistence_intervals_in_dimension(argv[2]); double tolerance = 0.; if (argc == 4) { diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index f0903acc..62b479ac 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -304,7 +304,7 @@ The output iterator `out` is used this way: `*out++ = std::make_tuple(dim, birth where `dim` is an `int`, `birth` a `double`, and `death` a `double`. **/ template -void read_persistence_diagram_from_file(std::string const& filename, OutputIterator out) { +void read_persistence_intervals_and_dimension(std::string const& filename, OutputIterator out) { std::ifstream in(filename); if (!in.is_open()) { @@ -336,10 +336,10 @@ Each line might contain 2, 3 or 4 values: [[field] dimension] birth death The return value is an `std::map>>` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. **/ -std::map>> read_persistence_diagram_from_file(std::string const& filename) { +std::map>> read_persistence_intervals_grouped_by_dimension(std::string const& filename) { std::map>> ret; - read_persistence_diagram_from_file( + read_persistence_intervals_and_dimension( filename, boost::make_function_output_iterator([&ret](auto t) { ret[get<0>(t)].push_back(std::make_pair(get<1>(t), get<2>(t))); })); return ret; @@ -355,10 +355,10 @@ If `only_this_dim` is >= 0, only the lines where dimension = `only_this_dim` The return value is an `std::vector>` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. **/ -std::vector> read_persistence_diagram_from_file(std::string const& filename, int only_this_dim) { +std::vector> read_persistence_intervals_in_dimension(std::string const& filename, int only_this_dim = -1) { std::vector> ret; - read_persistence_diagram_from_file( + read_persistence_intervals_and_dimension( filename, boost::make_function_output_iterator([&ret](auto t) { ret.emplace_back(get<1>(t), get<2>(t)); })); return ret; -- cgit v1.2.3 From 2ceede5cd9f226e66bb1ecbe1798330c349c2aa0 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 9 Jun 2017 10:39:31 +0000 Subject: Missing "return" git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2532 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8905e0d3406cbe26615b83ab7056e7fd5bd8ed0e --- src/Bottleneck_distance/example/bottleneck_read_file_example.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index 94d9a148..6cfbeafa 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -34,6 +34,7 @@ int main(int argc, char** argv) { std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file " << "should contain a birth-death pair per line. Third, optional parameter is an error bound on a bottleneck" << " distance (set by default to zero). The program will now terminate \n"; + //return -1; } std::vector> diag1 = read_persistence_intervals_in_dimension(argv[1]); std::vector> diag2 = read_persistence_intervals_in_dimension(argv[2]); @@ -44,4 +45,6 @@ int main(int argc, char** argv) { } double b = Gudhi::persistence_diagram::bottleneck_distance(diag1, diag2, tolerance); std::cout << "The distance between the diagrams is : " << b << ". The tolerance is : " << tolerance << std::endl; + + return 0; } -- cgit v1.2.3 From 4918b9c752a2d269678791dc4772ae9276539051 Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 9 Jun 2017 10:42:12 +0000 Subject: Throw exceptions if file not found git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2533 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b412f432aeac6aef07ac2d9d65d50dc8f508c2e6 --- src/common/include/gudhi/reader_utils.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 62b479ac..35af09bd 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -94,7 +94,10 @@ template< typename Graph_t, typename Filtration_value, typename Vertex_handle > Graph_t read_graph(std::string file_name) { std::ifstream in_(file_name.c_str(), std::ios::in); if (!in_.is_open()) { - std::cerr << "Unable to open file " << file_name << std::endl; + std::string error_str("read_graph - Unable to open file "); + error_str.append(file_name); + std::cerr << error_str << std::endl; + throw std::invalid_argument(error_str); } typedef std::pair< Vertex_handle, Vertex_handle > Edge_t; @@ -308,10 +311,10 @@ void read_persistence_intervals_and_dimension(std::string const& filename, Outpu std::ifstream in(filename); if (!in.is_open()) { -#ifdef DEBUG_TRACES - std::cerr << "File \"" << filename << "\" does not exist.\n"; -#endif // DEBUG_TRACES - return; + std::string error_str("read_persistence_intervals_and_dimension - Unable to open file "); + error_str.append(filename); + std::cerr << error_str << std::endl; + throw std::invalid_argument(error_str); } while (!in.eof()) { -- cgit v1.2.3 From 93c97a9a93b930a2f3c1c119d9e4d2567c54dacc Mon Sep 17 00:00:00 2001 From: cjamin Date: Fri, 9 Jun 2017 11:20:13 +0000 Subject: Create a new page for file formats git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2534 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: dc0d836b9df68a3f339dcbc6b8ff51577faf3d7b --- src/common/doc/file_formats.h | 25 +++++++++++++++++++++++++ src/common/doc/main_page.h | 23 ++--------------------- 2 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 src/common/doc/file_formats.h diff --git a/src/common/doc/file_formats.h b/src/common/doc/file_formats.h new file mode 100644 index 00000000..1f7ba201 --- /dev/null +++ b/src/common/doc/file_formats.h @@ -0,0 +1,25 @@ +/*! \page fileformats File formats + + \tableofcontents + + \section FileFormatsPers Persistence Diagram + + Such a file, whose extension is usually `.pers`, contains a list of persistence intervals.
+ Lines starting with `#` are ignored (comments).
+ Other lines might contain 2, 3 or 4 values (the number of values on each line must be the same for all lines): + \code{.unparsed} + [[field] dimension] birth death + \endcode + + Here is a simple sample file: + \code{.unparsed} + # Beautiful persistence diagram + 2 2.7 3.7 + 2 9.6 14. + 3 34.2 34.974 + 4 3. inf + \endcode + + Other sample files can be found in the `data/persistence_diagram` folder. + +*/ \ No newline at end of file diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index fba0a858..b7f93ed2 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -152,27 +152,7 @@
\section Toolbox Toolbox - \subsection FileFormats File Formats - \subsubsection FileFormatsPers Persistence Diagram - - Such a file, whose extension is usually `.pers`, contains a list of persistence intervals.
- Lines starting with `#` are ignored (comments).
- Other lines might contain 2, 3 or 4 values (the number of values on each line must be the same for all lines): - \code{.unparsed} - [[field] dimension] birth death - \endcode - - Here is a simple sample file: - \code{.unparsed} - # Beautiful persistence diagram - 2 2.7 3.7 - 2 9.6 14. - 3 34.2 34.974 - 4 3. inf - \endcode - - Other sample files can be found in the `data/persistence_diagram`. - + \subsection BottleneckDistanceToolbox Bottleneck distance \image html "perturb_pd.png" "Bottleneck distance is the length of the longest edge" @@ -489,3 +469,4 @@ make doxygen * @example Witness_complex/example_witness_complex_sphere.cpp */ +#include "file_formats.h" \ No newline at end of file -- cgit v1.2.3 From 8b8689e9dc0c9970eee7c75cb8ea08433ce28196 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 13 Jun 2017 13:37:48 +0000 Subject: Add header and namespace + remove unnecessary include git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2537 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fc2da43c18649c606ac4760a923684f9eef0c95e --- src/common/doc/file_formats.h | 33 +++++++++++++++++++++++++++++++-- src/common/doc/main_page.h | 3 +-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/common/doc/file_formats.h b/src/common/doc/file_formats.h index 1f7ba201..c145b271 100644 --- a/src/common/doc/file_formats.h +++ b/src/common/doc/file_formats.h @@ -1,3 +1,30 @@ +/* This file is part of the Gudhi Library. The Gudhi library +* (Geometric Understanding in Higher Dimensions) is a generic C++ +* library for computational topology. +* +* Author(s): Clément Jamin +* +* Copyright (C) 2017 INRIA +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef DOC_COMMON_FILE_FORMAT_H_ +#define DOC_COMMON_FILE_FORMAT_H_ + +namespace Gudhi { + /*! \page fileformats File formats \tableofcontents @@ -21,5 +48,7 @@ \endcode Other sample files can be found in the `data/persistence_diagram` folder. - -*/ \ No newline at end of file +*/ +} // namespace Gudhi + +#endif // DOC_COMMON_FILE_FORMAT_H_ diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index b7f93ed2..12012ecb 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -468,5 +468,4 @@ make doxygen * @example Witness_complex/example_witness_complex_persistence.cpp * @example Witness_complex/example_witness_complex_sphere.cpp */ - -#include "file_formats.h" \ No newline at end of file + \ No newline at end of file -- cgit v1.2.3 From e6b1730fd0832fad2a9103863428465155f70986 Mon Sep 17 00:00:00 2001 From: cjamin Date: Tue, 13 Jun 2017 15:29:35 +0000 Subject: This should never have been commented out git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2540 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5e5fc971986908e5b9383130704536686e1b66ea --- src/Bottleneck_distance/example/bottleneck_read_file_example.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp index 6cfbeafa..238d99ad 100644 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp @@ -34,7 +34,7 @@ int main(int argc, char** argv) { std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file " << "should contain a birth-death pair per line. Third, optional parameter is an error bound on a bottleneck" << " distance (set by default to zero). The program will now terminate \n"; - //return -1; + return -1; } std::vector> diag1 = read_persistence_intervals_in_dimension(argv[1]); std::vector> diag2 = read_persistence_intervals_in_dimension(argv[2]); -- cgit v1.2.3 From a6b6f91bfd5a86ee88297b27f18c2bc7d38f6db4 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 14 Jun 2017 07:45:09 +0000 Subject: Remove birth<=death check (should be done by the caller if necessary) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2544 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ce50159f4bf779a2a42d357cf1c2aa290feaf9b9 --- src/common/include/gudhi/reader_utils.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 35af09bd..8df20dcc 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -305,6 +305,7 @@ Reads a file containing persistence intervals. Each line might contain 2, 3 or 4 values: [[field] dimension] birth death The output iterator `out` is used this way: `*out++ = std::make_tuple(dim, birth, death);` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +Note: the function does not check that birth <= death. **/ template void read_persistence_intervals_and_dimension(std::string const& filename, OutputIterator out) { @@ -326,7 +327,6 @@ void read_persistence_intervals_and_dimension(std::string const& filename, Outpu if (n >= 2) { //int field = (n == 4 ? static_cast(numbers[0]) : -1); int dim = (n >= 3 ? static_cast(numbers[n - 3]) : -1); - GUDHI_CHECK(numbers[n - 2] <= numbers[n - 1], "Error: birth > death."); *out++ = std::make_tuple(dim, numbers[n - 2], numbers[n - 1]); } } @@ -338,6 +338,7 @@ Reads a file containing persistence intervals. Each line might contain 2, 3 or 4 values: [[field] dimension] birth death The return value is an `std::map>>` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +Note: the function does not check that birth <= death. **/ std::map>> read_persistence_intervals_grouped_by_dimension(std::string const& filename) { @@ -357,6 +358,7 @@ If `only_this_dim` is >= 0, only the lines where dimension = `only_this_dim` (or where dimension is not specified) are returned. The return value is an `std::vector>` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. +Note: the function does not check that birth <= death. **/ std::vector> read_persistence_intervals_in_dimension(std::string const& filename, int only_this_dim = -1) { -- cgit v1.2.3 From cdb39c39a60fe06009168c1ecb1d4ce5de0bed8c Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 16 Jun 2017 09:31:43 +0000 Subject: Fix auto lambda (requires C++14) compilation issue git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/read_persistence_from_file@2550 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: df64cfdde77500b06f00432a1d1532518cd4dd37 --- src/common/include/gudhi/reader_utils.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index 8df20dcc..f1684d78 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -25,8 +25,8 @@ #include #include -#include +#include #include #include @@ -340,12 +340,12 @@ The return value is an `std::map>>` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. Note: the function does not check that birth <= death. **/ -std::map>> read_persistence_intervals_grouped_by_dimension(std::string const& filename) { +inline std::map>> read_persistence_intervals_grouped_by_dimension(std::string const& filename) { std::map>> ret; read_persistence_intervals_and_dimension( filename, - boost::make_function_output_iterator([&ret](auto t) { ret[get<0>(t)].push_back(std::make_pair(get<1>(t), get<2>(t))); })); + boost::make_function_output_iterator([&ret](std::tuple t) { ret[get<0>(t)].push_back(std::make_pair(get<1>(t), get<2>(t))); })); return ret; } // read_persistence_diagram_from_file @@ -360,12 +360,12 @@ The return value is an `std::vector>` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. Note: the function does not check that birth <= death. **/ -std::vector> read_persistence_intervals_in_dimension(std::string const& filename, int only_this_dim = -1) { +inline std::vector> read_persistence_intervals_in_dimension(std::string const& filename, int only_this_dim = -1) { std::vector> ret; read_persistence_intervals_and_dimension( filename, - boost::make_function_output_iterator([&ret](auto t) { ret.emplace_back(get<1>(t), get<2>(t)); })); + boost::make_function_output_iterator([&ret](std::tuple t) { ret.emplace_back(get<1>(t), get<2>(t)); })); return ret; } // read_persistence_diagram_from_file -- cgit v1.2.3