From 452cf2181433a317fcc4d8c0661df3401073eec9 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 29 Sep 2016 10:56:50 +0000 Subject: New example and texts for doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/rips_complex_module@1587 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 332335f6f101f08e246b35de6e3a84c2348fd4ee --- src/Rips_complex/example/CMakeLists.txt | 6 ++ .../example/example_rips_complex_from_points.cpp | 69 ++++++++++++++++++++++ .../example/rips_points_for_doc_12_2.txt | 20 +++++++ .../example/rips_points_for_doc_12_3.txt | 26 ++++++++ 4 files changed, 121 insertions(+) create mode 100644 src/Rips_complex/example/example_rips_complex_from_points.cpp create mode 100644 src/Rips_complex/example/rips_points_for_doc_12_2.txt create mode 100644 src/Rips_complex/example/rips_points_for_doc_12_3.txt (limited to 'src/Rips_complex/example') diff --git a/src/Rips_complex/example/CMakeLists.txt b/src/Rips_complex/example/CMakeLists.txt index 6d0deecf..f8dcf94d 100644 --- a/src/Rips_complex/example/CMakeLists.txt +++ b/src/Rips_complex/example/CMakeLists.txt @@ -6,3 +6,9 @@ target_link_libraries(ripsoffreader ${Boost_SYSTEM_LIBRARY}) if (TBB_FOUND) target_link_libraries(ripsoffreader ${TBB_LIBRARIES}) endif() + +add_executable ( ripspoints example_rips_complex_from_points.cpp ) +target_link_libraries(ripspoints ${Boost_SYSTEM_LIBRARY}) +if (TBB_FOUND) + target_link_libraries(ripspoints ${TBB_LIBRARIES}) +endif() diff --git a/src/Rips_complex/example/example_rips_complex_from_points.cpp b/src/Rips_complex/example/example_rips_complex_from_points.cpp new file mode 100644 index 00000000..c241d137 --- /dev/null +++ b/src/Rips_complex/example/example_rips_complex_from_points.cpp @@ -0,0 +1,69 @@ +#include +// to construct Rips_complex from a OFF file of points +#include +// to construct a simplex_tree from rips complex +#include +#include + +#include +#include +#include // for std::numeric_limits + +void usage(int nbArgs, char * const progName) { + std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n"; + std::cerr << "Usage: " << progName << " dim_max [threshold]\n"; + std::cerr << " i.e.: " << progName << " 3 12.0\n"; + exit(-1); // ----- >> +} + +int main(int argc, char **argv) { + if ((argc != 2) && (argc != 3)) usage(argc, argv[0]); + + double threshold = std::numeric_limits::infinity(); + int dim_max = atoi(argv[1]); + + if (argc == 3) { + threshold = atof(argv[2]); + } + + // Type definitions + using Point = std::vector; + using Simplex_tree = Gudhi::Simplex_tree<>; + 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 an OFF file + // ---------------------------------------------------------------------------- + Rips_complex rips_complex_from_file(points, threshold, euclidean_distance); + + Simplex_tree simplex; + if (rips_complex_from_file.create_complex(simplex, dim_max)) { + // ---------------------------------------------------------------------------- + // Display information about the rips complex + // ---------------------------------------------------------------------------- + std::cout << "Rips complex is of dimension " << simplex.dimension() << + " - " << simplex.num_simplices() << " simplices - " << + simplex.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 : simplex.filtration_simplex_range()) { + std::cout << " ( "; + for (auto vertex : simplex.simplex_vertex_range(f_simplex)) { + std::cout << vertex << " "; + } + std::cout << ") -> " << "[" << simplex.filtration(f_simplex) << "] "; + std::cout << std::endl; + } + } + return 0; +} diff --git a/src/Rips_complex/example/rips_points_for_doc_12_2.txt b/src/Rips_complex/example/rips_points_for_doc_12_2.txt new file mode 100644 index 00000000..b0e25cc5 --- /dev/null +++ b/src/Rips_complex/example/rips_points_for_doc_12_2.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] diff --git a/src/Rips_complex/example/rips_points_for_doc_12_3.txt b/src/Rips_complex/example/rips_points_for_doc_12_3.txt new file mode 100644 index 00000000..319931e0 --- /dev/null +++ b/src/Rips_complex/example/rips_points_for_doc_12_3.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] -- cgit v1.2.3