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 
45 template <typename SimplicialComplexForProximityGraph>
46 using Proximity_graph = typename boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS
47 , boost::property < vertex_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >
48 , boost::property < edge_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >>;
49 
60 template< typename SimplicialComplexForProximityGraph
61  , typename ForwardPointRange
62  , typename Distance >
63 Proximity_graph<SimplicialComplexForProximityGraph> compute_proximity_graph(
64  const ForwardPointRange& points,
65  typename SimplicialComplexForProximityGraph::Filtration_value threshold,
66  Distance distance) {
67  using Vertex_handle = typename SimplicialComplexForProximityGraph::Vertex_handle;
68  using Filtration_value = typename SimplicialComplexForProximityGraph::Filtration_value;
69 
70  std::vector<std::pair< Vertex_handle, Vertex_handle >> edges;
71  std::vector< Filtration_value > edges_fil;
72  std::map< Vertex_handle, Filtration_value > vertices;
73 
74  Vertex_handle idx_u, idx_v;
75  Filtration_value fil;
76  idx_u = 0;
77  for (auto it_u = points.begin(); it_u != points.end(); ++it_u) {
78  idx_v = idx_u + 1;
79  for (auto it_v = it_u + 1; it_v != points.end(); ++it_v, ++idx_v) {
80  fil = distance(*it_u, *it_v);
81  if (fil <= threshold) {
82  edges.emplace_back(idx_u, idx_v);
83  edges_fil.push_back(fil);
84  }
85  }
86  ++idx_u;
87  }
88 
89  // Points are labeled from 0 to idx_u-1
90  Proximity_graph<SimplicialComplexForProximityGraph> skel_graph(edges.begin(), edges.end(), edges_fil.begin(), idx_u);
91 
92  auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph);
93 
94  typename boost::graph_traits<Proximity_graph<SimplicialComplexForProximityGraph>>::vertex_iterator vi, vi_end;
95  for (std::tie(vi, vi_end) = boost::vertices(skel_graph);
96  vi != vi_end; ++vi) {
97  boost::put(vertex_prop, *vi, 0.);
98  }
99 
100  return skel_graph;
101 }
102 
103 } // namespace Gudhi
104 
105 #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:63
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:32
GUDHI  Version 2.1.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Thu May 24 2018 09:46:12 for GUDHI by Doxygen 1.8.13