summaryrefslogtreecommitdiff
path: root/example/Cech_complex
diff options
context:
space:
mode:
authorGard Spreemann <gspreemann@gmail.com>2018-06-14 20:39:01 +0200
committerGard Spreemann <gspreemann@gmail.com>2018-06-14 20:39:01 +0200
commitc524232f734de875d69e2f190f01a6c976024368 (patch)
treed8bba27646c367cb2b7c718354dd036892bcd629 /example/Cech_complex
parent9899ae167f281d10b1684dfcd02c6838c5bf28df (diff)
GUDHI 2.2.0 as released by upstream in a tarball.upstream/2.2.0
Diffstat (limited to 'example/Cech_complex')
-rw-r--r--example/Cech_complex/CMakeLists.txt16
-rw-r--r--example/Cech_complex/cech_complex_example_from_points.cpp54
-rw-r--r--example/Cech_complex/cech_complex_example_from_points_for_doc.txt31
-rw-r--r--example/Cech_complex/cech_complex_step_by_step.cpp166
4 files changed, 267 insertions, 0 deletions
diff --git a/example/Cech_complex/CMakeLists.txt b/example/Cech_complex/CMakeLists.txt
new file mode 100644
index 00000000..ab391215
--- /dev/null
+++ b/example/Cech_complex/CMakeLists.txt
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 2.6)
+project(Cech_complex_examples)
+
+add_executable ( Cech_complex_example_step_by_step cech_complex_step_by_step.cpp )
+target_link_libraries(Cech_complex_example_step_by_step ${Boost_PROGRAM_OPTIONS_LIBRARY})
+if (TBB_FOUND)
+ target_link_libraries(Cech_complex_example_step_by_step ${TBB_LIBRARIES})
+endif()
+add_test(NAME Cech_complex_utility_from_rips_on_tore_3D COMMAND $<TARGET_FILE:Cech_complex_example_step_by_step>
+ "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "-r" "0.25" "-d" "3")
+
+add_executable ( Cech_complex_example_from_points cech_complex_example_from_points.cpp)
+if (TBB_FOUND)
+ target_link_libraries(Cech_complex_example_from_points ${TBB_LIBRARIES})
+endif()
+add_test(NAME Cech_complex_example_from_points COMMAND $<TARGET_FILE:Cech_complex_example_from_points>)
diff --git a/example/Cech_complex/cech_complex_example_from_points.cpp b/example/Cech_complex/cech_complex_example_from_points.cpp
new file mode 100644
index 00000000..3cc5a4df
--- /dev/null
+++ b/example/Cech_complex/cech_complex_example_from_points.cpp
@@ -0,0 +1,54 @@
+#include <gudhi/Cech_complex.h>
+#include <gudhi/Simplex_tree.h>
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <array>
+
+int main() {
+ // Type definitions
+ using Point_cloud = std::vector<std::array<double, 2>>;
+ using Simplex_tree = Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_fast_persistence>;
+ using Filtration_value = Simplex_tree::Filtration_value;
+ using Cech_complex = Gudhi::cech_complex::Cech_complex<Simplex_tree, Point_cloud>;
+
+ Point_cloud points;
+ points.push_back({1., 0.}); // 0
+ points.push_back({0., 1.}); // 1
+ points.push_back({2., 1.}); // 2
+ points.push_back({3., 2.}); // 3
+ points.push_back({0., 3.}); // 4
+ points.push_back({3. + std::sqrt(3.), 3.}); // 5
+ points.push_back({1., 4.}); // 6
+ points.push_back({3., 4.}); // 7
+ points.push_back({2., 4. + std::sqrt(3.)}); // 8
+ points.push_back({0., 4.}); // 9
+ points.push_back({-0.5, 2.}); // 10
+
+ // ----------------------------------------------------------------------------
+ // Init of a Cech complex from points
+ // ----------------------------------------------------------------------------
+ Filtration_value max_radius = 1.;
+ Cech_complex cech_complex_from_points(points, max_radius);
+
+ Simplex_tree stree;
+ cech_complex_from_points.create_complex(stree, 2);
+ // ----------------------------------------------------------------------------
+ // Display information about the one skeleton Cech complex
+ // ----------------------------------------------------------------------------
+ std::cout << "Cech complex is of dimension " << stree.dimension() << " - " << stree.num_simplices() << " simplices - "
+ << stree.num_vertices() << " vertices." << std::endl;
+
+ std::cout << "Iterator on Cech 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/Cech_complex/cech_complex_example_from_points_for_doc.txt b/example/Cech_complex/cech_complex_example_from_points_for_doc.txt
new file mode 100644
index 00000000..be0afc76
--- /dev/null
+++ b/example/Cech_complex/cech_complex_example_from_points_for_doc.txt
@@ -0,0 +1,31 @@
+Iterator on Cech complex simplices in the filtration order, with [filtration value]:
+ ( 0 ) -> [0]
+ ( 1 ) -> [0]
+ ( 2 ) -> [0]
+ ( 3 ) -> [0]
+ ( 4 ) -> [0]
+ ( 5 ) -> [0]
+ ( 6 ) -> [0]
+ ( 7 ) -> [0]
+ ( 8 ) -> [0]
+ ( 9 ) -> [0]
+ ( 10 ) -> [0]
+ ( 9 4 ) -> [0.5]
+ ( 9 6 ) -> [0.5]
+ ( 10 1 ) -> [0.559017]
+ ( 10 4 ) -> [0.559017]
+ ( 1 0 ) -> [0.707107]
+ ( 2 0 ) -> [0.707107]
+ ( 3 2 ) -> [0.707107]
+ ( 6 4 ) -> [0.707107]
+ ( 9 6 4 ) -> [0.707107]
+ ( 2 1 ) -> [1]
+ ( 2 1 0 ) -> [1]
+ ( 4 1 ) -> [1]
+ ( 5 3 ) -> [1]
+ ( 7 3 ) -> [1]
+ ( 7 5 ) -> [1]
+ ( 7 6 ) -> [1]
+ ( 8 6 ) -> [1]
+ ( 8 7 ) -> [1]
+ ( 10 4 1 ) -> [1]
diff --git a/example/Cech_complex/cech_complex_step_by_step.cpp b/example/Cech_complex/cech_complex_step_by_step.cpp
new file mode 100644
index 00000000..d2dc8b65
--- /dev/null
+++ b/example/Cech_complex/cech_complex_step_by_step.cpp
@@ -0,0 +1,166 @@
+/* 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) 2018 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/graph_simplicial_complex.h>
+#include <gudhi/distance_functions.h>
+#include <gudhi/Simplex_tree.h>
+#include <gudhi/Points_off_io.h>
+
+#include <gudhi/Miniball.hpp>
+
+#include <boost/program_options.hpp>
+
+#include <string>
+#include <vector>
+#include <limits> // infinity
+#include <utility> // for pair
+#include <map>
+
+// ----------------------------------------------------------------------------
+// rips_persistence_step_by_step is an example of each step that is required to
+// build a Rips over a Simplex_tree. Please refer to rips_persistence to see
+// how to do the same thing with the Rips_complex wrapper for less detailed
+// steps.
+// ----------------------------------------------------------------------------
+
+// Types definition
+using Simplex_tree = Gudhi::Simplex_tree<>;
+using Simplex_handle = Simplex_tree::Simplex_handle;
+using Filtration_value = Simplex_tree::Filtration_value;
+using Point = std::vector<double>;
+using Points_off_reader = Gudhi::Points_off_reader<Point>;
+using Proximity_graph = Gudhi::Proximity_graph<Simplex_tree>;
+
+class Cech_blocker {
+ private:
+ using Point_cloud = std::vector<Point>;
+ using Point_iterator = Point_cloud::const_iterator;
+ using Coordinate_iterator = Point::const_iterator;
+ using Min_sphere = Gudhi::Miniball::Miniball<Gudhi::Miniball::CoordAccessor<Point_iterator, Coordinate_iterator>>;
+
+ public:
+ bool operator()(Simplex_handle sh) {
+ std::vector<Point> points;
+ for (auto vertex : simplex_tree_.simplex_vertex_range(sh)) {
+ points.push_back(point_cloud_[vertex]);
+#ifdef DEBUG_TRACES
+ std::cout << "#(" << vertex << ")#";
+#endif // DEBUG_TRACES
+ }
+ Filtration_value radius = Gudhi::Minimal_enclosing_ball_radius()(points);
+#ifdef DEBUG_TRACES
+ std::cout << "radius = " << radius << " - " << (radius > max_radius_) << std::endl;
+#endif // DEBUG_TRACES
+ simplex_tree_.assign_filtration(sh, radius);
+ return (radius > max_radius_);
+ }
+ Cech_blocker(Simplex_tree& simplex_tree, Filtration_value max_radius, const std::vector<Point>& point_cloud)
+ : simplex_tree_(simplex_tree), max_radius_(max_radius), point_cloud_(point_cloud) {
+ dimension_ = point_cloud_[0].size();
+ }
+
+ private:
+ Simplex_tree simplex_tree_;
+ Filtration_value max_radius_;
+ std::vector<Point> point_cloud_;
+ int dimension_;
+};
+
+void program_options(int argc, char* argv[], std::string& off_file_points, Filtration_value& max_radius, int& dim_max);
+
+int main(int argc, char* argv[]) {
+ std::string off_file_points;
+ Filtration_value max_radius;
+ int dim_max;
+
+ program_options(argc, argv, off_file_points, max_radius, dim_max);
+
+ // Extract the points from the file filepoints
+ Points_off_reader off_reader(off_file_points);
+
+ // Compute the proximity graph of the points
+ Proximity_graph prox_graph = Gudhi::compute_proximity_graph<Simplex_tree>(off_reader.get_point_cloud(), max_radius,
+ Gudhi::Minimal_enclosing_ball_radius());
+
+ // Construct the Rips complex in a Simplex Tree
+ Simplex_tree st;
+ // insert the proximity graph in the simplex tree
+ st.insert_graph(prox_graph);
+ // expand the graph until dimension dim_max
+ st.expansion_with_blockers(dim_max, Cech_blocker(st, max_radius, off_reader.get_point_cloud()));
+
+ std::cout << "The complex contains " << st.num_simplices() << " simplices \n";
+ std::cout << " and has dimension " << st.dimension() << " \n";
+
+ // Sort the simplices in the order of the filtration
+ st.initialize_filtration();
+
+#if DEBUG_TRACES
+ std::cout << "********************************************************************\n";
+ std::cout << "* The complex contains " << st.num_simplices() << " simplices - dimension=" << st.dimension() << "\n";
+ std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n";
+ for (auto f_simplex : st.filtration_simplex_range()) {
+ std::cout << " "
+ << "[" << st.filtration(f_simplex) << "] ";
+ for (auto vertex : st.simplex_vertex_range(f_simplex)) {
+ std::cout << static_cast<int>(vertex) << " ";
+ }
+ std::cout << std::endl;
+ }
+#endif // DEBUG_TRACES
+
+ return 0;
+}
+
+void program_options(int argc, char* argv[], std::string& off_file_points, Filtration_value& max_radius, int& dim_max) {
+ namespace po = boost::program_options;
+ po::options_description hidden("Hidden options");
+ hidden.add_options()("input-file", po::value<std::string>(&off_file_points),
+ "Name of an OFF file containing a point set.\n");
+
+ po::options_description visible("Allowed options", 100);
+ visible.add_options()("help,h", "produce help message")(
+ "max-radius,r",
+ po::value<Filtration_value>(&max_radius)->default_value(std::numeric_limits<Filtration_value>::infinity()),
+ "Maximal length of an edge for the Rips complex construction.")(
+ "cpx-dimension,d", po::value<int>(&dim_max)->default_value(1),
+ "Maximal dimension of the Rips complex we want to compute.");
+
+ po::positional_options_description pos;
+ pos.add("input-file", 1);
+
+ po::options_description all;
+ all.add(visible).add(hidden);
+
+ po::variables_map vm;
+ po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm);
+ po::notify(vm);
+
+ if (vm.count("help") || !vm.count("input-file")) {
+ std::cout << std::endl;
+ std::cout << "Construct a Cech complex defined on a set of input points.\n \n";
+
+ std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl;
+ std::cout << visible << std::endl;
+ std::abort();
+ }
+}