Cech_complex.h
1 /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): Vincent Rouvreau
6  *
7  * Copyright (C) 2018 Inria
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef CECH_COMPLEX_H_
24 #define CECH_COMPLEX_H_
25 
26 #include <gudhi/distance_functions.h> // for Gudhi::Minimal_enclosing_ball_radius
27 #include <gudhi/graph_simplicial_complex.h> // for Gudhi::Proximity_graph
28 #include <gudhi/Debug_utils.h> // for GUDHI_CHECK
29 #include <gudhi/Cech_complex_blocker.h> // for Gudhi::cech_complex::Cech_blocker
30 
31 #include <iostream>
32 #include <stdexcept> // for exception management
33 #include <vector>
34 
35 namespace Gudhi {
36 
37 namespace cech_complex {
38 
55 template <typename SimplicialComplexForProximityGraph, typename ForwardPointRange>
56 class Cech_complex {
57  private:
58  // Required by compute_proximity_graph
59  using Vertex_handle = typename SimplicialComplexForProximityGraph::Vertex_handle;
60  using Filtration_value = typename SimplicialComplexForProximityGraph::Filtration_value;
62 
63  // Retrieve Coordinate type from ForwardPointRange
64  using Point_from_range_iterator = typename boost::range_const_iterator<ForwardPointRange>::type;
65  using Point_from_range = typename std::iterator_traits<Point_from_range_iterator>::value_type;
66  using Coordinate_iterator = typename boost::range_const_iterator<Point_from_range>::type;
67  using Coordinate = typename std::iterator_traits<Coordinate_iterator>::value_type;
68 
69  public:
70  // Point and Point_cloud type definition
71  using Point = std::vector<Coordinate>;
72  using Point_cloud = std::vector<Point>;
73 
74  public:
83  Cech_complex(const ForwardPointRange& points, Filtration_value max_radius) : max_radius_(max_radius) {
84  // Point cloud deep copy
85  point_cloud_.reserve(boost::size(points));
86  for (auto&& point : points) point_cloud_.emplace_back(std::begin(point), std::end(point));
87 
88  cech_skeleton_graph_ = Gudhi::compute_proximity_graph<SimplicialComplexForProximityGraph>(
89  point_cloud_, max_radius_, Gudhi::Minimal_enclosing_ball_radius());
90  }
91 
100  template <typename SimplicialComplexForCechComplex>
101  void create_complex(SimplicialComplexForCechComplex& complex, int dim_max) {
102  GUDHI_CHECK(complex.num_vertices() == 0,
103  std::invalid_argument("Cech_complex::create_complex - simplicial complex is not empty"));
104 
105  // insert the proximity graph in the simplicial complex
106  complex.insert_graph(cech_skeleton_graph_);
107  // expand the graph until dimension dim_max
108  complex.expansion_with_blockers(dim_max,
109  Cech_blocker<SimplicialComplexForCechComplex, Cech_complex>(&complex, this));
110  }
111 
113  Filtration_value max_radius() const { return max_radius_; }
114 
118  const Point& get_point(Vertex_handle vertex) const { return point_cloud_[vertex]; }
119 
120  private:
121  Proximity_graph cech_skeleton_graph_;
122  Filtration_value max_radius_;
123  Point_cloud point_cloud_;
124 };
125 
126 } // namespace cech_complex
127 
128 } // namespace Gudhi
129 
130 #endif // CECH_COMPLEX_H_
Cech_complex(const ForwardPointRange &points, Filtration_value max_radius)
Cech_complex constructor from a list of points.
Definition: Cech_complex.h:83
Definition: SimplicialComplexForAlpha.h:26
typename boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, 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:54
Global distance functions.
Compute the radius of the minimal enclosing ball between Points given by a range of coordinates...
Definition: distance_functions.h:76
const Point & get_point(Vertex_handle vertex) const
Definition: Cech_complex.h:118
Cech complex data structure.
Definition: Cech_complex.h:56
Filtration_value max_radius() const
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:101
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Thu Jun 14 2018 15:00:54 for GUDHI by Doxygen 1.8.13