From 8d7329f3e5ad843e553c3c5503cecc28ef2eead6 Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Thu, 20 Apr 2017 11:10:45 +0200 Subject: GUDHI 2.0.0 as released by upstream in a tarball. --- example/Rips_complex/CMakeLists.txt | 58 +++++++++++++++++ ...mple_one_skeleton_rips_from_distance_matrix.cpp | 58 +++++++++++++++++ .../example_one_skeleton_rips_from_points.cpp | 52 ++++++++++++++++ ..._rips_complex_from_csv_distance_matrix_file.cpp | 72 ++++++++++++++++++++++ .../example_rips_complex_from_off_file.cpp | 71 +++++++++++++++++++++ .../Rips_complex/full_skeleton_rips_for_doc.txt | 26 ++++++++ example/Rips_complex/one_skeleton_rips_for_doc.txt | 20 ++++++ 7 files changed, 357 insertions(+) create mode 100644 example/Rips_complex/CMakeLists.txt create mode 100644 example/Rips_complex/example_one_skeleton_rips_from_distance_matrix.cpp create mode 100644 example/Rips_complex/example_one_skeleton_rips_from_points.cpp create mode 100644 example/Rips_complex/example_rips_complex_from_csv_distance_matrix_file.cpp create mode 100644 example/Rips_complex/example_rips_complex_from_off_file.cpp create mode 100644 example/Rips_complex/full_skeleton_rips_for_doc.txt create mode 100644 example/Rips_complex/one_skeleton_rips_for_doc.txt (limited to 'example/Rips_complex') diff --git a/example/Rips_complex/CMakeLists.txt b/example/Rips_complex/CMakeLists.txt new file mode 100644 index 00000000..8aee79e2 --- /dev/null +++ b/example/Rips_complex/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 2.6) +project(Rips_complex_examples) + +# Point cloud +add_executable ( Rips_complex_example_from_off example_rips_complex_from_off_file.cpp ) +target_link_libraries(Rips_complex_example_from_off ${Boost_SYSTEM_LIBRARY}) + +add_executable ( Rips_complex_example_one_skeleton_from_points example_one_skeleton_rips_from_points.cpp ) +target_link_libraries(Rips_complex_example_one_skeleton_from_points ${Boost_SYSTEM_LIBRARY}) + +# Distance matrix +add_executable ( Rips_complex_example_one_skeleton_from_distance_matrix example_one_skeleton_rips_from_distance_matrix.cpp ) +target_link_libraries(Rips_complex_example_one_skeleton_from_distance_matrix ${Boost_SYSTEM_LIBRARY}) + +add_executable ( Rips_complex_example_from_csv_distance_matrix example_rips_complex_from_csv_distance_matrix_file.cpp ) +target_link_libraries(Rips_complex_example_from_csv_distance_matrix ${Boost_SYSTEM_LIBRARY}) + +if (TBB_FOUND) + target_link_libraries(Rips_complex_example_from_off ${TBB_LIBRARIES}) + target_link_libraries(Rips_complex_example_one_skeleton_from_points ${TBB_LIBRARIES}) + target_link_libraries(Rips_complex_example_one_skeleton_from_distance_matrix ${TBB_LIBRARIES}) + target_link_libraries(Rips_complex_example_from_csv_distance_matrix ${TBB_LIBRARIES}) +endif() + +add_test(NAME Rips_complex_example_one_skeleton_from_points + COMMAND $) +add_test(NAME Rips_complex_example_one_skeleton_from_distance_matrix + COMMAND $) + +add_test(NAME Rips_complex_example_from_off_doc_12_1 COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" "12.0" "1" "${CMAKE_CURRENT_BINARY_DIR}/ripsoffreader_result_12_1.txt") +add_test(NAME Rips_complex_example_from_off_doc_12_3 COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" "12.0" "3" "${CMAKE_CURRENT_BINARY_DIR}/ripsoffreader_result_12_3.txt") + +add_test(NAME Rips_complex_example_from_csv_distance_matrix_doc_12_1 COMMAND $ + "${CMAKE_SOURCE_DIR}/data/distance_matrix/full_square_distance_matrix.csv" "12.0" "1" "${CMAKE_CURRENT_BINARY_DIR}/ripscsvreader_result_12_1.txt") +add_test(NAME Rips_complex_example_from_csv_distance_matrix_doc_12_3 COMMAND $ + "${CMAKE_SOURCE_DIR}/data/distance_matrix/full_square_distance_matrix.csv" "12.0" "3" "${CMAKE_CURRENT_BINARY_DIR}/ripscsvreader_result_12_3.txt") + + +if (DIFF_PATH) + # Do not forget to copy test results files in current binary dir + file(COPY "one_skeleton_rips_for_doc.txt" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + file(COPY "full_skeleton_rips_for_doc.txt" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + + add_test(Rips_complex_example_from_off_doc_12_1_diff_files ${DIFF_PATH} + ${CMAKE_CURRENT_BINARY_DIR}/ripsoffreader_result_12_1.txt + ${CMAKE_CURRENT_BINARY_DIR}/one_skeleton_rips_for_doc.txt) + add_test(Rips_complex_example_from_off_doc_12_3_diff_files ${DIFF_PATH} + ${CMAKE_CURRENT_BINARY_DIR}/ripsoffreader_result_12_3.txt + ${CMAKE_CURRENT_BINARY_DIR}/full_skeleton_rips_for_doc.txt) + add_test(Rips_complex_example_from_csv_distance_matrix_doc_12_1_diff_files ${DIFF_PATH} + ${CMAKE_CURRENT_BINARY_DIR}/ripscsvreader_result_12_1.txt + ${CMAKE_CURRENT_BINARY_DIR}/one_skeleton_rips_for_doc.txt) + add_test(Rips_complex_example_from_csv_distance_matrix_doc_12_3_diff_files ${DIFF_PATH} + ${CMAKE_CURRENT_BINARY_DIR}/ripscsvreader_result_12_3.txt + ${CMAKE_CURRENT_BINARY_DIR}/full_skeleton_rips_for_doc.txt) +endif() diff --git a/example/Rips_complex/example_one_skeleton_rips_from_distance_matrix.cpp b/example/Rips_complex/example_one_skeleton_rips_from_distance_matrix.cpp new file mode 100644 index 00000000..bbc3c755 --- /dev/null +++ b/example/Rips_complex/example_one_skeleton_rips_from_distance_matrix.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + +#include +#include +#include +#include // for std::numeric_limits + +int main() { + // Type definitions + using Simplex_tree = Gudhi::Simplex_tree<>; + using Filtration_value = Simplex_tree::Filtration_value; + using Rips_complex = Gudhi::rips_complex::Rips_complex; + using Distance_matrix = std::vector>; + + // User defined distance matrix is: + // | 0 0.94 0.77 0.99 0.11 | + // | 0.94 0 0.26 0.99 0.39 | + // | 0.77 0.26 0 0.28 0.97 | + // | 0.99 0.99 0.28 0 0.30 | + // | 0.11 0.39 0.97 0.30 0 | + + Distance_matrix distances; + distances.push_back({}); + distances.push_back({0.94}); + distances.push_back({0.77, 0.26}); + distances.push_back({0.99, 0.99, 0.28}); + distances.push_back({0.11, 0.39, 0.97, 0.30}); + + // ---------------------------------------------------------------------------- + // Init of a Rips complex from points + // ---------------------------------------------------------------------------- + double threshold = 1.0; + Rips_complex rips_complex_from_points(distances, threshold); + + Simplex_tree stree; + rips_complex_from_points.create_complex(stree, 1); + // ---------------------------------------------------------------------------- + // Display information about the one skeleton Rips complex + // ---------------------------------------------------------------------------- + std::cout << "Rips complex is of dimension " << stree.dimension() << + " - " << stree.num_simplices() << " simplices - " << + stree.num_vertices() << " vertices." << std::endl; + + std::cout << "Iterator on Rips complex simplices in the filtration order, with [filtration value]:" << + std::endl; + for (auto f_simplex : stree.filtration_simplex_range()) { + std::cout << " ( "; + for (auto vertex : stree.simplex_vertex_range(f_simplex)) { + std::cout << vertex << " "; + } + std::cout << ") -> " << "[" << stree.filtration(f_simplex) << "] "; + std::cout << std::endl; + } + + return 0; +} diff --git a/example/Rips_complex/example_one_skeleton_rips_from_points.cpp b/example/Rips_complex/example_one_skeleton_rips_from_points.cpp new file mode 100644 index 00000000..a1db8910 --- /dev/null +++ b/example/Rips_complex/example_one_skeleton_rips_from_points.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +#include +#include +#include +#include // for std::numeric_limits + +int main() { + // Type definitions + using Point = std::vector; + using Simplex_tree = Gudhi::Simplex_tree; + using Filtration_value = Simplex_tree::Filtration_value; + using Rips_complex = Gudhi::rips_complex::Rips_complex; + + std::vector points; + points.push_back({1.0, 1.0}); + points.push_back({7.0, 0.0}); + points.push_back({4.0, 6.0}); + points.push_back({9.0, 6.0}); + points.push_back({0.0, 14.0}); + points.push_back({2.0, 19.0}); + points.push_back({9.0, 17.0}); + + // ---------------------------------------------------------------------------- + // Init of a Rips complex from points + // ---------------------------------------------------------------------------- + double threshold = 12.0; + Rips_complex rips_complex_from_points(points, threshold, Gudhi::Euclidean_distance()); + + Simplex_tree stree; + rips_complex_from_points.create_complex(stree, 1); + // ---------------------------------------------------------------------------- + // Display information about the one skeleton Rips complex + // ---------------------------------------------------------------------------- + std::cout << "Rips complex is of dimension " << stree.dimension() << + " - " << stree.num_simplices() << " simplices - " << + stree.num_vertices() << " vertices." << std::endl; + + std::cout << "Iterator on Rips complex simplices in the filtration order, with [filtration value]:" << + std::endl; + for (auto f_simplex : stree.filtration_simplex_range()) { + std::cout << " ( "; + for (auto vertex : stree.simplex_vertex_range(f_simplex)) { + std::cout << vertex << " "; + } + std::cout << ") -> " << "[" << stree.filtration(f_simplex) << "] "; + std::cout << std::endl; + } + return 0; +} diff --git a/example/Rips_complex/example_rips_complex_from_csv_distance_matrix_file.cpp b/example/Rips_complex/example_rips_complex_from_csv_distance_matrix_file.cpp new file mode 100644 index 00000000..7ae8126f --- /dev/null +++ b/example/Rips_complex/example_rips_complex_from_csv_distance_matrix_file.cpp @@ -0,0 +1,72 @@ +#include +// to construct Rips_complex from a csv file representing a distance matrix +#include +#include +#include + +#include +#include +#include + +void usage(int nbArgs, char * const progName) { + std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n"; + std::cerr << "Usage: " << progName << " filename.csv threshold dim_max [ouput_file.txt]\n"; + std::cerr << " i.e.: " << progName << " ../../data/distance_matrix/full_square_distance_matrix.csv 1.0 3\n"; + exit(-1); // ----- >> +} + +int main(int argc, char **argv) { + if ((argc != 4) && (argc != 5)) usage(argc, (argv[0] - 1)); + + std::string csv_file_name(argv[1]); + double threshold = atof(argv[2]); + int dim_max = atoi(argv[3]); + + // Type definitions + using Simplex_tree = Gudhi::Simplex_tree<>; + using Filtration_value = Simplex_tree::Filtration_value; + using Rips_complex = Gudhi::rips_complex::Rips_complex; + using Distance_matrix = std::vector>; + + // ---------------------------------------------------------------------------- + // Init of a Rips complex from a distance matrix in a csv file + // Default separator is ';' + // ---------------------------------------------------------------------------- + Distance_matrix distances = read_lower_triangular_matrix_from_csv_file(csv_file_name); + Rips_complex rips_complex_from_file(distances, threshold); + + std::streambuf* streambufffer; + std::ofstream ouput_file_stream; + + if (argc == 5) { + ouput_file_stream.open(std::string(argv[4])); + streambufffer = ouput_file_stream.rdbuf(); + } else { + streambufffer = std::cout.rdbuf(); + } + + Simplex_tree stree; + rips_complex_from_file.create_complex(stree, dim_max); + std::ostream output_stream(streambufffer); + + // ---------------------------------------------------------------------------- + // Display information about the Rips complex + // ---------------------------------------------------------------------------- + output_stream << "Rips complex is of dimension " << stree.dimension() << + " - " << stree.num_simplices() << " simplices - " << + stree.num_vertices() << " vertices." << std::endl; + + output_stream << "Iterator on Rips complex simplices in the filtration order, with [filtration value]:" << + std::endl; + for (auto f_simplex : stree.filtration_simplex_range()) { + output_stream << " ( "; + for (auto vertex : stree.simplex_vertex_range(f_simplex)) { + output_stream << vertex << " "; + } + output_stream << ") -> " << "[" << stree.filtration(f_simplex) << "] "; + output_stream << std::endl; + } + + ouput_file_stream.close(); + return 0; +} diff --git a/example/Rips_complex/example_rips_complex_from_off_file.cpp b/example/Rips_complex/example_rips_complex_from_off_file.cpp new file mode 100644 index 00000000..de2e4ea4 --- /dev/null +++ b/example/Rips_complex/example_rips_complex_from_off_file.cpp @@ -0,0 +1,71 @@ +#include +// to construct Rips_complex from a OFF file of points +#include +#include +#include + +#include +#include +#include + +void usage(int nbArgs, char * const progName) { + std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n"; + std::cerr << "Usage: " << progName << " filename.off threshold dim_max [ouput_file.txt]\n"; + std::cerr << " i.e.: " << progName << " ../../data/points/alphacomplexdoc.off 60.0\n"; + exit(-1); // ----- >> +} + +int main(int argc, char **argv) { + if ((argc != 4) && (argc != 5)) usage(argc, (argv[0] - 1)); + + std::string off_file_name(argv[1]); + double threshold = atof(argv[2]); + int dim_max = atoi(argv[3]); + + // Type definitions + using Point = std::vector; + using Simplex_tree = Gudhi::Simplex_tree<>; + using Filtration_value = Simplex_tree::Filtration_value; + using Rips_complex = Gudhi::rips_complex::Rips_complex; + + // ---------------------------------------------------------------------------- + // Init of a Rips complex from an OFF file + // ---------------------------------------------------------------------------- + Gudhi::Points_off_reader off_reader(off_file_name); + Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); + + std::streambuf* streambufffer; + std::ofstream ouput_file_stream; + + if (argc == 5) { + ouput_file_stream.open(std::string(argv[4])); + streambufffer = ouput_file_stream.rdbuf(); + } else { + streambufffer = std::cout.rdbuf(); + } + + Simplex_tree stree; + rips_complex_from_file.create_complex(stree, dim_max); + std::ostream output_stream(streambufffer); + + // ---------------------------------------------------------------------------- + // Display information about the Rips complex + // ---------------------------------------------------------------------------- + output_stream << "Rips complex is of dimension " << stree.dimension() << + " - " << stree.num_simplices() << " simplices - " << + stree.num_vertices() << " vertices." << std::endl; + + output_stream << "Iterator on Rips complex simplices in the filtration order, with [filtration value]:" << + std::endl; + for (auto f_simplex : stree.filtration_simplex_range()) { + output_stream << " ( "; + for (auto vertex : stree.simplex_vertex_range(f_simplex)) { + output_stream << vertex << " "; + } + output_stream << ") -> " << "[" << stree.filtration(f_simplex) << "] "; + output_stream << std::endl; + } + + ouput_file_stream.close(); + return 0; +} diff --git a/example/Rips_complex/full_skeleton_rips_for_doc.txt b/example/Rips_complex/full_skeleton_rips_for_doc.txt new file mode 100644 index 00000000..55de4ab8 --- /dev/null +++ b/example/Rips_complex/full_skeleton_rips_for_doc.txt @@ -0,0 +1,26 @@ +Rips complex is of dimension 3 - 24 simplices - 7 vertices. +Iterator on Rips complex simplices in the filtration order, with [filtration value]: + ( 0 ) -> [0] + ( 1 ) -> [0] + ( 2 ) -> [0] + ( 3 ) -> [0] + ( 4 ) -> [0] + ( 5 ) -> [0] + ( 6 ) -> [0] + ( 3 2 ) -> [5] + ( 5 4 ) -> [5.38516] + ( 2 0 ) -> [5.83095] + ( 1 0 ) -> [6.08276] + ( 3 1 ) -> [6.32456] + ( 2 1 ) -> [6.7082] + ( 2 1 0 ) -> [6.7082] + ( 3 2 1 ) -> [6.7082] + ( 6 5 ) -> [7.28011] + ( 4 2 ) -> [8.94427] + ( 3 0 ) -> [9.43398] + ( 3 1 0 ) -> [9.43398] + ( 3 2 0 ) -> [9.43398] + ( 3 2 1 0 ) -> [9.43398] + ( 6 4 ) -> [9.48683] + ( 6 5 4 ) -> [9.48683] + ( 6 3 ) -> [11] diff --git a/example/Rips_complex/one_skeleton_rips_for_doc.txt b/example/Rips_complex/one_skeleton_rips_for_doc.txt new file mode 100644 index 00000000..706512a5 --- /dev/null +++ b/example/Rips_complex/one_skeleton_rips_for_doc.txt @@ -0,0 +1,20 @@ +Rips complex is of dimension 1 - 18 simplices - 7 vertices. +Iterator on Rips complex simplices in the filtration order, with [filtration value]: + ( 0 ) -> [0] + ( 1 ) -> [0] + ( 2 ) -> [0] + ( 3 ) -> [0] + ( 4 ) -> [0] + ( 5 ) -> [0] + ( 6 ) -> [0] + ( 3 2 ) -> [5] + ( 5 4 ) -> [5.38516] + ( 2 0 ) -> [5.83095] + ( 1 0 ) -> [6.08276] + ( 3 1 ) -> [6.32456] + ( 2 1 ) -> [6.7082] + ( 6 5 ) -> [7.28011] + ( 4 2 ) -> [8.94427] + ( 3 0 ) -> [9.43398] + ( 6 4 ) -> [9.48683] + ( 6 3 ) -> [11] -- cgit v1.2.3