graph_simplicial_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): ClĂ©ment Maria
6  *
7  * Copyright (C) 2014 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 GRAPH_SIMPLICIAL_COMPLEX_H_
24 #define GRAPH_SIMPLICIAL_COMPLEX_H_
25 
26 #include <boost/graph/adjacency_list.hpp>
27 
28 #include <utility> // for pair<>
29 #include <vector>
30 #include <map>
31 #include <tuple> // for std::tie
32 
33 namespace Gudhi {
34 
35 /* Edge tag for Boost PropertyGraph. */
36 struct edge_filtration_t {
37  typedef boost::edge_property_tag kind;
38 };
39 
40 /* Vertex tag for Boost PropertyGraph. */
41 struct vertex_filtration_t {
42  typedef boost::vertex_property_tag kind;
43 };
44 
51 template <typename SimplicialComplexForProximityGraph>
52 using Proximity_graph = typename boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS
53 , boost::property < vertex_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >
54 , boost::property < edge_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >>;
55 
66 template< typename SimplicialComplexForProximityGraph
67  , typename ForwardPointRange
68  , typename Distance >
70  const ForwardPointRange& points,
71  typename SimplicialComplexForProximityGraph::Filtration_value threshold,
72  Distance distance) {
73  using Vertex_handle = typename SimplicialComplexForProximityGraph::Vertex_handle;
74  using Filtration_value = typename SimplicialComplexForProximityGraph::Filtration_value;
75 
76  std::vector<std::pair< Vertex_handle, Vertex_handle >> edges;
77  std::vector< Filtration_value > edges_fil;
78  std::map< Vertex_handle, Filtration_value > vertices;
79 
80  Vertex_handle idx_u, idx_v;
81  Filtration_value fil;
82  idx_u = 0;
83  for (auto it_u = points.begin(); it_u != points.end(); ++it_u) {
84  idx_v = idx_u + 1;
85  for (auto it_v = it_u + 1; it_v != points.end(); ++it_v, ++idx_v) {
86  fil = distance(*it_u, *it_v);
87  if (fil <= threshold) {
88  edges.emplace_back(idx_u, idx_v);
89  edges_fil.push_back(fil);
90  }
91  }
92  ++idx_u;
93  }
94 
95  // Points are labeled from 0 to idx_u-1
96  Proximity_graph<SimplicialComplexForProximityGraph> skel_graph(edges.begin(), edges.end(), edges_fil.begin(), idx_u);
97 
98  auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph);
99 
100  typename boost::graph_traits<Proximity_graph<SimplicialComplexForProximityGraph>>::vertex_iterator vi, vi_end;
101  for (std::tie(vi, vi_end) = boost::vertices(skel_graph);
102  vi != vi_end; ++vi) {
103  boost::put(vertex_prop, *vi, 0.);
104  }
105 
106  return skel_graph;
107 }
108 
109 } // namespace Gudhi
110 
111 #endif // GRAPH_SIMPLICIAL_COMPLEX_H_
Definition: SimplicialComplexForAlpha.h:26
Proximity_graph< SimplicialComplexForProximityGraph > compute_proximity_graph(const ForwardPointRange &points, typename SimplicialComplexForProximityGraph::Filtration_value threshold, Distance distance)
Computes the proximity graph of the points.
Definition: graph_simplicial_complex.h:69
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:32
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
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Tue Jul 17 2018 12:56:28 for GUDHI by Doxygen 1.8.13