summaryrefslogtreecommitdiff
path: root/src/Rips_complex
diff options
context:
space:
mode:
authorglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-01-31 13:41:06 +0000
committerglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-01-31 13:41:06 +0000
commitc68ef729971d88818ceae9f1aa8e33f62a4dea7a (patch)
tree2425f2d0f3d1e05799b0d5480d32449f8a3bd2ff /src/Rips_complex
parent258439dfbe0d109b1ab26e9b60370cafdc78ac3e (diff)
Add example.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/sparserips-glisse@3195 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b8ded704563c6794c098f9b80b1a5e0200e84694
Diffstat (limited to 'src/Rips_complex')
-rw-r--r--src/Rips_complex/doc/Intro_rips_complex.h16
-rw-r--r--src/Rips_complex/example/CMakeLists.txt4
-rw-r--r--src/Rips_complex/example/example_sparse_rips.cpp38
3 files changed, 58 insertions, 0 deletions
diff --git a/src/Rips_complex/doc/Intro_rips_complex.h b/src/Rips_complex/doc/Intro_rips_complex.h
index a9cfc0ab..96d90d98 100644
--- a/src/Rips_complex/doc/Intro_rips_complex.h
+++ b/src/Rips_complex/doc/Intro_rips_complex.h
@@ -182,6 +182,22 @@ namespace rips_complex {
*
* \include Rips_complex/full_skeleton_rips_for_doc.txt
*
+ * \subsection sparseripspointscloudexample Example of a sparse Rips from a point cloud
+ *
+ * This example builds the full sparse Rips of a set of 2D Euclidean points, then prints some minimal information about the complex.
+ *
+ * \include Rips_complex/example_sparse_rips.cpp
+ *
+ * When launching:
+ *
+ * \code $> ./Rips_complex_example_sparse
+ * \endcode
+ *
+ * the program output may be (the exact output varies from one run to the next):
+ *
+ * \code Sparse Rips complex is of dimension 2 - 19 simplices - 7 vertices.
+ * \endcode
+ *
* \copyright GNU General Public License v3.
* \verbatim Contact: gudhi-users@lists.gforge.inria.fr \endverbatim
*/
diff --git a/src/Rips_complex/example/CMakeLists.txt b/src/Rips_complex/example/CMakeLists.txt
index 2940f164..8a22a6d8 100644
--- a/src/Rips_complex/example/CMakeLists.txt
+++ b/src/Rips_complex/example/CMakeLists.txt
@@ -11,11 +11,15 @@ add_executable ( Rips_complex_example_one_skeleton_from_distance_matrix example_
add_executable ( Rips_complex_example_from_csv_distance_matrix example_rips_complex_from_csv_distance_matrix_file.cpp )
+# Point cloud
+add_executable ( Rips_complex_example_sparse example_sparse_rips_complex.cpp )
+
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})
+ target_link_libraries(Rips_complex_example_sparse ${TBB_LIBRARIES})
endif()
add_test(NAME Rips_complex_example_one_skeleton_from_points
diff --git a/src/Rips_complex/example/example_sparse_rips.cpp b/src/Rips_complex/example/example_sparse_rips.cpp
new file mode 100644
index 00000000..49725f0a
--- /dev/null
+++ b/src/Rips_complex/example/example_sparse_rips.cpp
@@ -0,0 +1,38 @@
+#include <gudhi/Sparse_rips_complex.h>
+#include <gudhi/Simplex_tree.h>
+#include <gudhi/distance_functions.h>
+
+#include <iostream>
+#include <vector>
+
+int main() {
+ using Point = std::vector<double>;
+ using Simplex_tree = Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_fast_persistence>;
+ using Filtration_value = Simplex_tree::Filtration_value;
+ using Complex = Gudhi::rips_complex::Sparse_rips_complex<Filtration_value>;
+
+ Point points[] = {
+ {1.0, 1.0},
+ {7.0, 0.0},
+ {4.0, 6.0},
+ {9.0, 6.0},
+ {0.0, 14.0},
+ {2.0, 19.0},
+ {9.0, 17.0}};
+
+ // ----------------------------------------------------------------------------
+ // Init from Euclidean points
+ // ----------------------------------------------------------------------------
+ double epsilon = 2; // very rough, no guarantees
+ Complex cpx(points, Gudhi::Euclidean_distance(), epsilon);
+
+ Simplex_tree stree;
+ cpx.create_complex(stree, 10);
+
+ // ----------------------------------------------------------------------------
+ // Display information about the complex
+ // ----------------------------------------------------------------------------
+ std::cout << "Sparse Rips complex is of dimension " << stree.dimension() <<
+ " - " << stree.num_simplices() << " simplices - " <<
+ stree.num_vertices() << " vertices." << std::endl;
+}