summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/doc/file_formats.h59
-rw-r--r--src/common/doc/main_page.h20
-rw-r--r--src/common/example/CMakeLists.txt13
-rw-r--r--src/common/include/gudhi/Clock.h20
-rw-r--r--src/common/include/gudhi/reader_utils.h145
-rw-r--r--src/common/test/CMakeLists.txt11
-rw-r--r--src/common/test/README2
-rw-r--r--src/common/test/persistence_intervals_with_dimension.pers5
-rw-r--r--src/common/test/persistence_intervals_with_field.pers4
-rw-r--r--src/common/test/persistence_intervals_without_dimension.pers7
-rw-r--r--src/common/test/test_distance_matrix_reader.cpp4
-rw-r--r--src/common/test/test_persistence_intervals_reader.cpp322
-rw-r--r--src/common/utilities/CMakeLists.txt1
-rw-r--r--src/common/utilities/off_file_from_shape_generator.cpp2
14 files changed, 553 insertions, 62 deletions
diff --git a/src/common/doc/file_formats.h b/src/common/doc/file_formats.h
new file mode 100644
index 00000000..d715aa4d
--- /dev/null
+++ b/src/common/doc/file_formats.h
@@ -0,0 +1,59 @@
+/* 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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef DOC_COMMON_FILE_FORMAT_H_
+#define DOC_COMMON_FILE_FORMAT_H_
+
+namespace Gudhi {
+
+/*! \page fileformats File formats
+
+ \tableofcontents
+
+ \section FileFormatsPers Persistence Diagram
+
+ Such a file, whose extension is usually `.pers`, contains a list of persistence intervals.<br>
+ Lines starting with `#` are ignored (comments).<br>
+ Other lines might contain 2, 3 or 4 values (the number of values on each line must be the same for all lines):
+ \verbatim
+ [[field] dimension] birth death
+ \endverbatim
+
+ Here is a simple sample file:
+ \verbatim
+ # Persistence diagram example
+ 2 2.7 3.7
+ 2 9.6 14.
+ # Some comments
+ 3 34.2 34.974
+ 4 3. inf
+ \endverbatim
+
+ Other sample files can be found in the `data/persistence_diagram` folder.
+
+ Such files can be generated with `Gudhi::persistent_cohomology::Persistent_cohomology::output_diagram()` and read with
+ `Gudhi::read_persistence_intervals_and_dimension()`, `Gudhi::read_persistence_intervals_grouped_by_dimension()` or
+ `Gudhi::read_persistence_intervals_in_dimension()`.
+*/
+} // 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 6ff3f94d..cee0c28b 100644
--- a/src/common/doc/main_page.h
+++ b/src/common/doc/main_page.h
@@ -160,7 +160,7 @@
<b>Author:</b> Fran&ccedil;ois Godi<br>
<b>Introduced in:</b> GUDHI 2.0.0<br>
<b>Copyright:</b> GPL v3<br>
- <b>Requires:</b> \ref cgal &ge; 4.8.1 and \ref eigen3
+ <b>Requires:</b> \ref cgal &ge; 4.8.1
</td>
<td width="75%">
Bottleneck distance measures the similarity between two persistence diagrams.
@@ -329,13 +329,29 @@ make doxygen
* Alpha_complex/Alpha_complex_from_off.cpp</a>
* \li <a href="_alpha_complex_2_alpha_complex_from_points_8cpp-example.html">
* Alpha_complex/Alpha_complex_from_points.cpp</a>
+ * \li <a href="_bottleneck_distance_2alpha_rips_persistence_bottleneck_distance_8cpp-example.html">
+ * Bottleneck_distance/alpha_rips_persistence_bottleneck_distance.cpp.cpp</a>
* \li <a href="_persistent_cohomology_2alpha_complex_persistence_8cpp-example.html">
* Persistent_cohomology/alpha_complex_persistence.cpp</a>
* \li <a href="_persistent_cohomology_2periodic_alpha_complex_3d_persistence_8cpp-example.html">
* Persistent_cohomology/periodic_alpha_complex_3d_persistence.cpp</a>
* \li <a href="_persistent_cohomology_2custom_persistence_sort_8cpp-example.html">
* Persistent_cohomology/custom_persistence_sort.cpp</a>
- *
+ * \li <a href="_spatial_searching_2example_spatial_searching_8cpp-example.html">
+ * Spatial_searching/example_spatial_searching.cpp</a>
+ * \li <a href="_subsampling_2example_choose_n_farthest_points_8cpp-example.html">
+ * Subsampling/example_choose_n_farthest_points.cpp</a>
+ * \li <a href="_subsampling_2example_custom_kernel_8cpp-example.html">
+ * Subsampling/example_custom_kernel.cpp</a>
+ * \li <a href="_subsampling_2example_pick_n_random_points_8cpp-example.html">
+ * Subsampling/example_pick_n_random_points.cpp</a>
+ * \li <a href="_subsampling_2example_sparsify_point_set_8cpp-example.html">
+ * Subsampling/example_sparsify_point_set.cpp</a>
+ * \li <a href="_tangential_complex_2example_basic_8cpp-example.html">
+ * Tangential_complex/example_basic.cpp</a>
+ * \li <a href="_tangential_complex_2example_with_perturb_8cpp-example.html">
+ * Tangential_complex/example_with_perturb.cpp</a>
+ *
* \subsection tbb Threading Building Blocks
* <a target="_blank" href="https://www.threadingbuildingblocks.org/">Intel&reg; TBB</a> lets you easily write parallel
* C++ programs that take full advantage of multicore performance, that are portable and composable, and that have
diff --git a/src/common/example/CMakeLists.txt b/src/common/example/CMakeLists.txt
index af3c2c9d..afe865d4 100644
--- a/src/common/example/CMakeLists.txt
+++ b/src/common/example/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6)
project(Common_examples)
add_executable ( vector_double_off_reader example_vector_double_points_off_reader.cpp )
-target_link_libraries(vector_double_off_reader ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
+target_link_libraries(vector_double_off_reader ${CGAL_LIBRARY})
add_test(NAME Common_example_vector_double_off_reader COMMAND $<TARGET_FILE:vector_double_off_reader>
"${CMAKE_SOURCE_DIR}/data/points/SO3_10000.off")
@@ -10,18 +10,19 @@ install(TARGETS vector_double_off_reader DESTINATION bin)
if(CGAL_FOUND)
add_executable ( cgal_3D_off_reader example_CGAL_3D_points_off_reader.cpp )
- target_link_libraries(cgal_3D_off_reader ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
+ target_link_libraries(cgal_3D_off_reader ${CGAL_LIBRARY})
add_test(NAME Common_example_vector_cgal_3D_off_reader COMMAND $<TARGET_FILE:cgal_3D_off_reader>
"${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off")
- # need CGAL 4.7and Eigen3
+ install(TARGETS cgal_3D_off_reader DESTINATION bin)
+
+ # need CGAL 4.7 and Eigen3
if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0)
add_executable ( cgal_off_reader example_CGAL_points_off_reader.cpp )
- target_link_libraries(cgal_off_reader ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
+ target_link_libraries(cgal_off_reader ${CGAL_LIBRARY})
add_test(NAME Common_example_vector_cgal_off_reader COMMAND $<TARGET_FILE:cgal_off_reader>
"${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off")
+ install(TARGETS cgal_off_reader DESTINATION bin)
endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0)
- install(TARGETS cgal_3D_off_reader DESTINATION bin)
- install(TARGETS cgal_off_reader DESTINATION bin)
endif()
diff --git a/src/common/include/gudhi/Clock.h b/src/common/include/gudhi/Clock.h
index 77f196ca..b83de2f5 100644
--- a/src/common/include/gudhi/Clock.h
+++ b/src/common/include/gudhi/Clock.h
@@ -23,9 +23,9 @@
#ifndef CLOCK_H_
#define CLOCK_H_
-#include <boost/date_time/posix_time/posix_time.hpp>
-
+#include <iostream>
#include <string>
+#include <chrono>
namespace Gudhi {
@@ -33,20 +33,20 @@ class Clock {
public:
// Construct and start the timer
Clock(const std::string& msg_ = std::string())
- : startTime(boost::posix_time::microsec_clock::local_time()),
+ : startTime(std::chrono::system_clock::now()),
end_called(false),
msg(msg_) { }
// Restart the timer
void begin() const {
end_called = false;
- startTime = boost::posix_time::microsec_clock::local_time();
+ startTime = std::chrono::system_clock::now();
}
// Stop the timer
void end() const {
end_called = true;
- endTime = boost::posix_time::microsec_clock::local_time();
+ endTime = std::chrono::system_clock::now();
}
std::string message() const {
@@ -62,7 +62,7 @@ class Clock {
if (!clock.msg.empty())
stream << clock.msg << ": ";
- stream << clock.num_seconds() << "s";
+ stream << clock.num_seconds() << "s\n";
return stream;
}
@@ -71,15 +71,15 @@ class Clock {
// - or now otherwise. In this case, the timer is not stopped.
double num_seconds() const {
if (!end_called) {
- auto end = boost::posix_time::microsec_clock::local_time();
- return (end - startTime).total_milliseconds() / 1000.;
+ auto end = std::chrono::system_clock::now();
+ return std::chrono::duration_cast<std::chrono::milliseconds>(end-startTime).count() / 1000.;
} else {
- return (endTime - startTime).total_milliseconds() / 1000.;
+ return std::chrono::duration_cast<std::chrono::milliseconds>(endTime-startTime).count() / 1000.;
}
}
private:
- mutable boost::posix_time::ptime startTime, endTime;
+ mutable std::chrono::time_point<std::chrono::system_clock> startTime, endTime;
mutable bool end_called;
std::string msg;
};
diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h
index 97a87edd..90be4fc7 100644
--- a/src/common/include/gudhi/reader_utils.h
+++ b/src/common/include/gudhi/reader_utils.h
@@ -1,8 +1,8 @@
-/* This file is part of the Gudhi Library. The Gudhi library
- * (Geometric Understanding in Higher Dimensions) is a generic C++
+/* 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): Clement Maria, Pawel Dlotko
+ * Author(s): Clement Maria, Pawel Dlotko, Clement Jamin
*
* Copyright (C) 2014 INRIA
*
@@ -24,7 +24,9 @@
#define READER_UTILS_H_
#include <gudhi/graph_simplicial_complex.h>
+#include <gudhi/Debug_utils.h>
+#include <boost/function_output_iterator.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <iostream>
@@ -34,6 +36,9 @@
#include <string>
#include <vector>
#include <utility> // for pair
+#include <tuple> // for std::make_tuple
+
+namespace Gudhi {
// Keep this file tag for Doxygen to parse the code, otherwise, functions are not documented.
// It is required for global functions and variables.
@@ -50,7 +55,7 @@
* X21 X22 ... X2d<br>
* etc<br>
*/
-inline void read_points(std::string file_name, std::vector< std::vector< double > > & points) {
+inline void read_points(std::string file_name, std::vector<std::vector<double>>& points) {
std::ifstream in_file(file_name.c_str(), std::ios::in);
if (!in_file.is_open()) {
std::cerr << "Unable to open file " << file_name << std::endl;
@@ -60,14 +65,13 @@ inline void read_points(std::string file_name, std::vector< std::vector< double
std::string line;
double x;
while (getline(in_file, line)) {
- std::vector< double > point;
+ std::vector<double> point;
std::istringstream iss(line);
while (iss >> x) {
point.push_back(x);
}
// Check for empty lines
- if (!point.empty())
- points.push_back(point);
+ if (!point.empty()) points.push_back(point);
}
in_file.close();
}
@@ -88,17 +92,20 @@ inline void read_points(std::string file_name, std::vector< std::vector< double
* Every simplex must appear exactly once.
* Simplices of dimension more than 1 are ignored.
*/
-template< typename Graph_t, typename Filtration_value, typename Vertex_handle >
+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;
- std::vector< Edge_t > edges;
- std::vector< Filtration_value > edges_fil;
- std::map< Vertex_handle, Filtration_value > vertices;
+ typedef std::pair<Vertex_handle, Vertex_handle> Edge_t;
+ std::vector<Edge_t> edges;
+ std::vector<Filtration_value> edges_fil;
+ std::map<Vertex_handle, Filtration_value> vertices;
std::string line;
int dim;
@@ -108,8 +115,7 @@ Graph_t read_graph(std::string file_name) {
std::istringstream iss(line);
while (iss >> dim) {
switch (dim) {
- case 0:
- {
+ case 0: {
iss >> u;
iss >> fil;
vertices[u] = fil;
@@ -118,8 +124,7 @@ Graph_t read_graph(std::string file_name) {
}
break;
}
- case 1:
- {
+ case 1: {
iss >> u;
iss >> v;
iss >> fil;
@@ -127,16 +132,13 @@ Graph_t read_graph(std::string file_name) {
edges_fil.push_back(fil);
break;
}
- default:
- {
- break;
- }
+ default: { break; }
}
}
}
in_.close();
- if ((size_t) (max_h + 1) != vertices.size()) {
+ if ((size_t)(max_h + 1) != vertices.size()) {
std::cerr << "Error: vertices must be labeled from 0 to n-1 \n";
}
@@ -164,8 +166,8 @@ Graph_t read_graph(std::string file_name) {
* Every simplex must appear exactly once.
* Simplices of dimension more than 1 are ignored.
*/
-template< typename Vertex_handle, typename Filtration_value >
-bool read_simplex(std::istream & in_, std::vector< Vertex_handle > & simplex, Filtration_value & fil) {
+template <typename Vertex_handle, typename Filtration_value>
+bool read_simplex(std::istream& in_, std::vector<Vertex_handle>& simplex, Filtration_value& fil) {
int dim = 0;
if (!(in_ >> dim)) return false;
Vertex_handle v;
@@ -189,8 +191,8 @@ bool read_simplex(std::istream & in_, std::vector< Vertex_handle > & simplex, Fi
* The key of a simplex is its position in the filtration order and also the number of its row in the file.
* Dimi ki1 ki2 ... kiDimi Fili means that the ith simplex in the filtration has dimension Dimi, filtration value
* fil1 and simplices with key ki1 ... kiDimi in its boundary.*/
-template< typename Simplex_key, typename Filtration_value >
-bool read_hasse_simplex(std::istream & in_, std::vector< Simplex_key > & boundary, Filtration_value & fil) {
+template <typename Simplex_key, typename Filtration_value>
+bool read_hasse_simplex(std::istream& in_, std::vector<Simplex_key>& boundary, Filtration_value& fil) {
int dim;
if (!(in_ >> dim)) return false;
if (dim == 0) {
@@ -209,7 +211,7 @@ bool read_hasse_simplex(std::istream & in_, std::vector< Simplex_key > & boundar
/**
* @brief Read a lower triangular distance matrix from a csv file. We assume that the .csv store the whole
* (square) matrix.
- *
+ *
* @author Pawel Dlotko
*
* Square matrix file format:<br>
@@ -226,13 +228,13 @@ bool read_hasse_simplex(std::istream & in_, std::vector< Simplex_key > & boundar
* Dj1;Dj2;...;Dj(j-1);<br>
*
**/
-template< typename Filtration_value >
-std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from_csv_file(const std::string& filename,
- const char separator = ';') {
+template <typename Filtration_value>
+std::vector<std::vector<Filtration_value>> read_lower_triangular_matrix_from_csv_file(const std::string& filename,
+ const char separator = ';') {
#ifdef DEBUG_TRACES
std::cout << "Using procedure read_lower_triangular_matrix_from_csv_file \n";
#endif // DEBUG_TRACES
- std::vector< std::vector< Filtration_value > > result;
+ std::vector<std::vector<Filtration_value>> result;
std::ifstream in;
in.open(filename.c_str());
if (!in.is_open()) {
@@ -243,7 +245,7 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from
// the first line is emtpy, so we ignore it:
std::getline(in, line);
- std::vector< Filtration_value > values_in_this_line;
+ std::vector<Filtration_value> values_in_this_line;
result.push_back(values_in_this_line);
int number_of_line = 0;
@@ -251,11 +253,10 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from
// first, read the file line by line to a string:
while (std::getline(in, line)) {
// if line is empty, break
- if (line.size() == 0)
- break;
+ if (line.size() == 0) break;
// if the last element of a string is comma:
- if (line[ line.size() - 1 ] == separator) {
+ if (line[line.size() - 1] == separator) {
// then shrink the string by one
line.pop_back();
}
@@ -268,7 +269,7 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from
// and now read the doubles.
int number_of_entry = 0;
- std::vector< Filtration_value > values_in_this_line;
+ std::vector<Filtration_value> values_in_this_line;
while (iss.good()) {
double entry;
iss >> entry;
@@ -277,7 +278,7 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from
}
++number_of_entry;
}
- if (!values_in_this_line.empty())result.push_back(values_in_this_line);
+ if (!values_in_this_line.empty()) result.push_back(values_in_this_line);
++number_of_line;
}
in.close();
@@ -295,4 +296,74 @@ std::vector< std::vector< Filtration_value > > read_lower_triangular_matrix_from
return result;
} // read_lower_triangular_matrix_from_csv_file
+/**
+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 <typename OutputIterator>
+void read_persistence_intervals_and_dimension(std::string const& filename, OutputIterator out) {
+ std::ifstream in(filename);
+ if (!in.is_open()) {
+ 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()) {
+ 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<int>(numbers[n - 3]) : -1);
+ *out++ = std::make_tuple(dim, numbers[n - 2], numbers[n - 1]);
+ }
+ }
+ }
+}
+
+/**
+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`.
+Note: the function does not check that birth <= death.
+**/
+inline std::map<int, std::vector<std::pair<double, double>>> read_persistence_intervals_grouped_by_dimension(
+ std::string const& filename) {
+ std::map<int, std::vector<std::pair<double, double>>> ret;
+ read_persistence_intervals_and_dimension(
+ filename, boost::make_function_output_iterator([&ret](std::tuple<int, double, double> t) {
+ ret[get<0>(t)].push_back(std::make_pair(get<1>(t), get<2>(t)));
+ }));
+ return ret;
+}
+
+/**
+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`
+(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`.
+Note: the function does not check that birth <= death.
+**/
+inline std::vector<std::pair<double, double>> read_persistence_intervals_in_dimension(std::string const& filename,
+ int only_this_dim = -1) {
+ std::vector<std::pair<double, double>> ret;
+ read_persistence_intervals_and_dimension(
+ filename, boost::make_function_output_iterator([only_this_dim, &ret](std::tuple<int, double, double> t) {
+ if (only_this_dim == get<0>(t) || only_this_dim == -1) ret.emplace_back(get<1>(t), get<2>(t));
+ }));
+ return ret;
+}
+
+} // namespace Gudhi
+
#endif // READER_UTILS_H_
diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt
index c695fbf4..de3e765a 100644
--- a/src/common/test/CMakeLists.txt
+++ b/src/common/test/CMakeLists.txt
@@ -4,15 +4,22 @@ project(Common_tests)
include(GUDHI_test_coverage)
add_executable ( Common_test_points_off_reader test_points_off_reader.cpp )
-target_link_libraries(Common_test_points_off_reader ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+target_link_libraries(Common_test_points_off_reader ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_executable ( Common_test_distance_matrix_reader test_distance_matrix_reader.cpp )
-target_link_libraries(Common_test_distance_matrix_reader ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+target_link_libraries(Common_test_distance_matrix_reader ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+
+add_executable ( Common_test_persistence_intervals_reader test_persistence_intervals_reader.cpp )
+target_link_libraries(Common_test_persistence_intervals_reader ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
# Do not forget to copy test files in current binary dir
file(COPY "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
file(COPY "${CMAKE_SOURCE_DIR}/data/distance_matrix/lower_triangular_distance_matrix.csv" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
file(COPY "${CMAKE_SOURCE_DIR}/data/distance_matrix/full_square_distance_matrix.csv" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
+file(COPY "${CMAKE_SOURCE_DIR}/src/common/test/persistence_intervals_with_dimension.pers" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
+file(COPY "${CMAKE_SOURCE_DIR}/src/common/test/persistence_intervals_with_field.pers" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
+file(COPY "${CMAKE_SOURCE_DIR}/src/common/test/persistence_intervals_without_dimension.pers" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
gudhi_add_coverage_test(Common_test_points_off_reader)
gudhi_add_coverage_test(Common_test_distance_matrix_reader)
+gudhi_add_coverage_test(Common_test_persistence_intervals_reader)
diff --git a/src/common/test/README b/src/common/test/README
index f2a7eb5a..a8e6efe9 100644
--- a/src/common/test/README
+++ b/src/common/test/README
@@ -7,7 +7,7 @@ make
To launch with details:
***********************
-./dtoffrw_UT --report_level=detailed --log_level=all
+./Common_test_points_off_reader --report_level=detailed --log_level=all
==> echo $? returns 0 in case of success (non-zero otherwise)
diff --git a/src/common/test/persistence_intervals_with_dimension.pers b/src/common/test/persistence_intervals_with_dimension.pers
new file mode 100644
index 00000000..406748c8
--- /dev/null
+++ b/src/common/test/persistence_intervals_with_dimension.pers
@@ -0,0 +1,5 @@
+# Simple persistence diagram with dimension
+0 2.7 3.7
+1 9.6 14.
+3 34.2 34.974
+1 3. inf
diff --git a/src/common/test/persistence_intervals_with_field.pers b/src/common/test/persistence_intervals_with_field.pers
new file mode 100644
index 00000000..41dd9f1e
--- /dev/null
+++ b/src/common/test/persistence_intervals_with_field.pers
@@ -0,0 +1,4 @@
+3 0 2.7 3.7
+3 1 9.6 14.
+3 3 34.2 34.974
+3 1 3. inf
diff --git a/src/common/test/persistence_intervals_without_dimension.pers b/src/common/test/persistence_intervals_without_dimension.pers
new file mode 100644
index 00000000..76fa27f3
--- /dev/null
+++ b/src/common/test/persistence_intervals_without_dimension.pers
@@ -0,0 +1,7 @@
+# Simple persistence diagram without dimension
+2.7 3.7
+9.6 14.
+# Another comment
+34.2 34.974
+3. inf
+# End of file
diff --git a/src/common/test/test_distance_matrix_reader.cpp b/src/common/test/test_distance_matrix_reader.cpp
index 95a73bd9..656e6f2e 100644
--- a/src/common/test/test_distance_matrix_reader.cpp
+++ b/src/common/test/test_distance_matrix_reader.cpp
@@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE( lower_triangular_distance_matrix )
{
Distance_matrix from_lower_triangular;
// Read lower_triangular_distance_matrix.csv file where the separator is a ','
- from_lower_triangular = read_lower_triangular_matrix_from_csv_file<double>("lower_triangular_distance_matrix.csv",
+ from_lower_triangular = Gudhi::read_lower_triangular_matrix_from_csv_file<double>("lower_triangular_distance_matrix.csv",
',');
for (auto& i : from_lower_triangular) {
for (auto j : i) {
@@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE( full_square_distance_matrix )
{
Distance_matrix from_full_square;
// Read full_square_distance_matrix.csv file where the separator is the default one ';'
- from_full_square = read_lower_triangular_matrix_from_csv_file<double>("full_square_distance_matrix.csv");
+ from_full_square = Gudhi::read_lower_triangular_matrix_from_csv_file<double>("full_square_distance_matrix.csv");
for (auto& i : from_full_square) {
for (auto j : i) {
std::cout << j << " ";
diff --git a/src/common/test/test_persistence_intervals_reader.cpp b/src/common/test/test_persistence_intervals_reader.cpp
new file mode 100644
index 00000000..be299376
--- /dev/null
+++ b/src/common/test/test_persistence_intervals_reader.cpp
@@ -0,0 +1,322 @@
+/* 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): Vincent Rouvreau
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <gudhi/reader_utils.h>
+
+#include <iostream>
+#include <vector>
+#include <utility> // for pair
+#include <tuple>
+#include <limits> // for inf
+#include <map>
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE "persistence_intervals_reader"
+#include <boost/test/unit_test.hpp>
+
+using Persistence_intervals_by_dimension = std::map<int, std::vector<std::pair<double, double>>>;
+using Persistence_intervals = std::vector<std::pair<double, double>>;
+// Test files with only 2 parameters (persistence birth and death) per line in file
+BOOST_AUTO_TEST_CASE( persistence_intervals_without_dimension )
+{
+ Persistence_intervals_by_dimension expected_intervals_by_dimension;
+ expected_intervals_by_dimension[-1].push_back(std::make_pair(2.7, 3.7));
+ expected_intervals_by_dimension[-1].push_back(std::make_pair(9.6, 14.));
+ expected_intervals_by_dimension[-1].push_back(std::make_pair(34.2, 34.974));
+ expected_intervals_by_dimension[-1].push_back(std::make_pair(3., std::numeric_limits<double>::infinity()));
+
+ Persistence_intervals_by_dimension persistence_intervals_by_dimension =
+ Gudhi::read_persistence_intervals_grouped_by_dimension("persistence_intervals_without_dimension.pers");
+
+ std::cout << "\nread_persistence_intervals_grouped_by_dimension - expected\n";
+ for (auto map_iter : expected_intervals_by_dimension) {
+ std::cout << "key=" << map_iter.first;
+ for (auto vec_iter : map_iter.second)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+ }
+
+ std::cout << "\nread_persistence_intervals_grouped_by_dimension - read\n";
+ for (auto map_iter : persistence_intervals_by_dimension) {
+ std::cout << "key=" << map_iter.first;
+ for (auto vec_iter : map_iter.second)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+ }
+
+ BOOST_CHECK(persistence_intervals_by_dimension == expected_intervals_by_dimension);
+
+ Persistence_intervals expected_intervals_in_dimension;
+ expected_intervals_in_dimension.push_back(std::make_pair(2.7, 3.7));
+ expected_intervals_in_dimension.push_back(std::make_pair(9.6, 14.));
+ expected_intervals_in_dimension.push_back(std::make_pair(34.2, 34.974));
+ expected_intervals_in_dimension.push_back(std::make_pair(3., std::numeric_limits<double>::infinity()));
+
+ Persistence_intervals persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_without_dimension.pers");
+
+ std::cout << "\nread_persistence_intervals_in_dimension - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension - read\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_without_dimension.pers", 0);
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_without_dimension.pers", 1);
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_without_dimension.pers", 2);
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_without_dimension.pers", 3);
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+}
+// Test files with 3 parameters (dimension birth death) per line in file
+BOOST_AUTO_TEST_CASE( persistence_intervals_with_dimension )
+{
+ Persistence_intervals_by_dimension expected_intervals_by_dimension;
+ expected_intervals_by_dimension[0].push_back(std::make_pair(2.7, 3.7));
+ expected_intervals_by_dimension[1].push_back(std::make_pair(9.6, 14.));
+ expected_intervals_by_dimension[3].push_back(std::make_pair(34.2, 34.974));
+ expected_intervals_by_dimension[1].push_back(std::make_pair(3., std::numeric_limits<double>::infinity()));
+
+ Persistence_intervals_by_dimension persistence_intervals_by_dimension =
+ Gudhi::read_persistence_intervals_grouped_by_dimension("persistence_intervals_with_dimension.pers");
+
+ std::cout << "\nread_persistence_intervals_grouped_by_dimension - expected\n";
+ for (auto map_iter : expected_intervals_by_dimension) {
+ std::cout << "key=" << map_iter.first;
+ for (auto vec_iter : map_iter.second)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+ }
+
+ std::cout << "\nread_persistence_intervals_grouped_by_dimension - read\n";
+ for (auto map_iter : persistence_intervals_by_dimension) {
+ std::cout << "key=" << map_iter.first;
+ for (auto vec_iter : map_iter.second)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+ }
+
+ BOOST_CHECK(persistence_intervals_by_dimension == expected_intervals_by_dimension);
+
+ Persistence_intervals expected_intervals_in_dimension;
+ expected_intervals_in_dimension.push_back(std::make_pair(2.7, 3.7));
+ expected_intervals_in_dimension.push_back(std::make_pair(9.6, 14.));
+ expected_intervals_in_dimension.push_back(std::make_pair(34.2, 34.974));
+ expected_intervals_in_dimension.push_back(std::make_pair(3., std::numeric_limits<double>::infinity()));
+
+ Persistence_intervals persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_with_dimension.pers");
+
+ std::cout << "\nread_persistence_intervals_in_dimension - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension - read\n";
+ for (auto vec_iter : persistence_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ expected_intervals_in_dimension.push_back(std::make_pair(2.7, 3.7));
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_with_dimension.pers", 0);
+
+ std::cout << "\nread_persistence_intervals_in_dimension 0 - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension 0 - read\n";
+ for (auto vec_iter : persistence_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ expected_intervals_in_dimension.push_back(std::make_pair(9.6, 14.));
+ expected_intervals_in_dimension.push_back(std::make_pair(3., std::numeric_limits<double>::infinity()));
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_with_dimension.pers", 1);
+
+ std::cout << "\nread_persistence_intervals_in_dimension 1 - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension 1 - read\n";
+ for (auto vec_iter : persistence_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_with_dimension.pers", 2);
+
+ std::cout << "\nread_persistence_intervals_in_dimension 2 - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension 2 - read\n";
+ for (auto vec_iter : persistence_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ expected_intervals_in_dimension.push_back(std::make_pair(34.2, 34.974));
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_with_dimension.pers", 3);
+
+ std::cout << "\nread_persistence_intervals_in_dimension 3 - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension 3 - read\n";
+ for (auto vec_iter : persistence_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+}
+
+// Test files with 4 parameters (field dimension birth death) per line in file
+BOOST_AUTO_TEST_CASE( persistence_intervals_with_field )
+{
+ Persistence_intervals_by_dimension expected_intervals_by_dimension;
+ expected_intervals_by_dimension[0].push_back(std::make_pair(2.7, 3.7));
+ expected_intervals_by_dimension[1].push_back(std::make_pair(9.6, 14.));
+ expected_intervals_by_dimension[3].push_back(std::make_pair(34.2, 34.974));
+ expected_intervals_by_dimension[1].push_back(std::make_pair(3., std::numeric_limits<double>::infinity()));
+
+ Persistence_intervals_by_dimension persistence_intervals_by_dimension =
+ Gudhi::read_persistence_intervals_grouped_by_dimension("persistence_intervals_with_field.pers");
+
+ std::cout << "\nread_persistence_intervals_grouped_by_dimension - expected\n";
+ for (auto map_iter : expected_intervals_by_dimension) {
+ std::cout << "key=" << map_iter.first;
+ for (auto vec_iter : map_iter.second)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+ }
+
+ std::cout << "\nread_persistence_intervals_grouped_by_dimension - read\n";
+ for (auto map_iter : persistence_intervals_by_dimension) {
+ std::cout << "key=" << map_iter.first;
+ for (auto vec_iter : map_iter.second)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+ }
+
+ BOOST_CHECK(persistence_intervals_by_dimension == expected_intervals_by_dimension);
+
+ Persistence_intervals expected_intervals_in_dimension;
+ expected_intervals_in_dimension.push_back(std::make_pair(2.7, 3.7));
+ expected_intervals_in_dimension.push_back(std::make_pair(9.6, 14.));
+ expected_intervals_in_dimension.push_back(std::make_pair(34.2, 34.974));
+ expected_intervals_in_dimension.push_back(std::make_pair(3., std::numeric_limits<double>::infinity()));
+
+ Persistence_intervals persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_with_field.pers");
+
+ std::cout << "\nread_persistence_intervals_in_dimension - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension - read\n";
+ for (auto vec_iter : persistence_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ expected_intervals_in_dimension.push_back(std::make_pair(2.7, 3.7));
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_with_field.pers", 0);
+
+ std::cout << "\nread_persistence_intervals_in_dimension 0 - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension 0 - read\n";
+ for (auto vec_iter : persistence_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ expected_intervals_in_dimension.push_back(std::make_pair(9.6, 14.));
+ expected_intervals_in_dimension.push_back(std::make_pair(3., std::numeric_limits<double>::infinity()));
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_with_field.pers", 1);
+
+ std::cout << "\nread_persistence_intervals_in_dimension 1 - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension 1 - read\n";
+ for (auto vec_iter : persistence_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_with_field.pers", 2);
+
+ std::cout << "\nread_persistence_intervals_in_dimension 2 - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension 2 - read\n";
+ for (auto vec_iter : persistence_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+ expected_intervals_in_dimension.clear();
+ expected_intervals_in_dimension.push_back(std::make_pair(34.2, 34.974));
+ persistence_intervals_in_dimension =
+ Gudhi::read_persistence_intervals_in_dimension("persistence_intervals_with_field.pers", 3);
+
+ std::cout << "\nread_persistence_intervals_in_dimension 3 - expected\n";
+ for (auto vec_iter : expected_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ std::cout << "\nread_persistence_intervals_in_dimension 3 - read\n";
+ for (auto vec_iter : persistence_intervals_in_dimension)
+ std::cout << " [" << vec_iter.first << " ," << vec_iter.second << "] ";
+
+ BOOST_CHECK(persistence_intervals_in_dimension == expected_intervals_in_dimension);
+
+}
diff --git a/src/common/utilities/CMakeLists.txt b/src/common/utilities/CMakeLists.txt
index c2e07e7e..b3e4b436 100644
--- a/src/common/utilities/CMakeLists.txt
+++ b/src/common/utilities/CMakeLists.txt
@@ -3,7 +3,6 @@ project(off_file_from_shape_generator)
if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0)
add_executable ( off_file_from_shape_generator off_file_from_shape_generator.cpp )
- target_link_libraries(off_file_from_shape_generator ${Boost_SYSTEM_LIBRARY})
add_test(NAME off_file_from_shape_generator_on_sphere_1000_3_15.2 COMMAND $<TARGET_FILE:off_file_from_shape_generator>
"on" "sphere" "onSphere.off" "1000" "3" "15.2")
add_test(NAME off_file_from_shape_generator_in_sphere_100_2 COMMAND $<TARGET_FILE:off_file_from_shape_generator>
diff --git a/src/common/utilities/off_file_from_shape_generator.cpp b/src/common/utilities/off_file_from_shape_generator.cpp
index 0f310a13..afcd558c 100644
--- a/src/common/utilities/off_file_from_shape_generator.cpp
+++ b/src/common/utilities/off_file_from_shape_generator.cpp
@@ -77,7 +77,7 @@ int main(int argc, char **argv) {
usage(argv[0]);
}
- enum class Data_shape { sphere, cube, curve, torus, klein, undefined } ;
+ enum class Data_shape { sphere, cube, curve, torus, klein, undefined};
Data_shape shape = Data_shape::undefined;
if (memcmp(argv[2], "sphere", sizeof("sphere")) == 0) {