Cech_complex.h
1 /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2  * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3  * Author(s): Vincent Rouvreau
4  *
5  * Copyright (C) 2018 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef CECH_COMPLEX_H_
12 #define CECH_COMPLEX_H_
13 
14 #include <gudhi/Sphere_circumradius.h> // for Gudhi::cech_complex::Sphere_circumradius
15 #include <gudhi/graph_simplicial_complex.h> // for Gudhi::Proximity_graph
16 #include <gudhi/Debug_utils.h> // for GUDHI_CHECK
17 #include <gudhi/Cech_complex_blocker.h> // for Gudhi::cech_complex::Cech_blocker
18 
19 #include <iostream>
20 #include <stdexcept> // for exception management
21 
22 namespace Gudhi {
23 
24 namespace cech_complex {
25 
42 template <typename Kernel, typename SimplicialComplexForCechComplex>
43 class Cech_complex {
44  private:
45  // Required by compute_proximity_graph
46  using Vertex_handle = typename SimplicialComplexForCechComplex::Vertex_handle;
47  using Filtration_value = typename SimplicialComplexForCechComplex::Filtration_value;
49 
50  using cech_blocker = Cech_blocker<SimplicialComplexForCechComplex, Cech_complex, Kernel>;
51 
52  using Point_d = typename cech_blocker::Point_d;
53  using Point_cloud = std::vector<Point_d>;
54 
55  // Numeric type of coordinates in the kernel
56  using FT = typename cech_blocker::FT;
57  // Sphere is a pair of point and squared radius.
58  using Sphere = typename cech_blocker::Sphere;
59 
60  public:
70  template<typename InputPointRange >
71  Cech_complex(const InputPointRange & points, Filtration_value max_radius, const bool exact = false) : max_radius_(max_radius), exact_(exact) {
72 
73  point_cloud_.assign(std::begin(points), std::end(points));
74 
75  cech_skeleton_graph_ = Gudhi::compute_proximity_graph<SimplicialComplexForCechComplex>(
76  point_cloud_, max_radius_, Sphere_circumradius<Kernel, Filtration_value>(exact));
77  }
78 
87  void create_complex(SimplicialComplexForCechComplex& complex, int dim_max) {
88  GUDHI_CHECK(complex.num_vertices() == 0,
89  std::invalid_argument("Cech_complex::create_complex - simplicial complex is not empty"));
90 
91  // insert the proximity graph in the simplicial complex
92  complex.insert_graph(cech_skeleton_graph_);
93  // expand the graph until dimension dim_max
94  complex.expansion_with_blockers(dim_max, cech_blocker(&complex, this));
95  }
96 
98  Filtration_value max_radius() const { return max_radius_; }
99 
103  const Point_d& get_point(Vertex_handle vertex) const { return point_cloud_[vertex]; }
104 
108  std::vector<Sphere> & get_cache() { return cache_; }
109 
113  const bool is_exact() { return exact_; }
114 
115  private:
116  Proximity_graph cech_skeleton_graph_;
117  Filtration_value max_radius_;
118  Point_cloud point_cloud_;
119  std::vector<Sphere> cache_;
120  const bool exact_;
121 };
122 
123 } // namespace cech_complex
124 
125 } // namespace Gudhi
126 
127 #endif // CECH_COMPLEX_H_
Cech complex class.
Definition: Cech_complex.h:43
const Point_d & get_point(Vertex_handle vertex) const
Definition: Cech_complex.h:103
Cech_complex(const InputPointRange &points, Filtration_value max_radius, const bool exact=false)
Cech_complex constructor from a range of points.
Definition: Cech_complex.h:71
std::vector< Sphere > & get_cache()
Definition: Cech_complex.h:108
const bool is_exact()
Check exact option.
Definition: Cech_complex.h:113
void create_complex(SimplicialComplexForCechComplex &complex, int dim_max)
Initializes the simplicial complex from the proximity graph and expands it until a given maximal dime...
Definition: Cech_complex.h:87
Filtration_value max_radius() const
Definition: Cech_complex.h:98
Graph simplicial complex methods.
typename boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, boost::property< vertex_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >, boost::property< edge_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value > > Proximity_graph
Proximity_graph contains the vertices and edges with their filtration values in order to store the re...
Definition: graph_simplicial_complex.h:45
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:20