Loading...
Searching...
No Matches
graph_simplicial_complex.h
Go to the documentation of this file.
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): Clément Maria
4 *
5 * Copyright (C) 2014 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef GRAPH_SIMPLICIAL_COMPLEX_H_
12#define GRAPH_SIMPLICIAL_COMPLEX_H_
13
14#include <boost/graph/adjacency_list.hpp>
15
16#include <utility> // for pair<>
17#include <vector>
18#include <map>
19#include <tuple> // for std::tie
20
21namespace Gudhi {
26/* Edge tag for Boost PropertyGraph. */
27struct edge_filtration_t {
28 typedef boost::edge_property_tag kind;
29};
30
31/* Vertex tag for Boost PropertyGraph. */
32struct vertex_filtration_t {
33 typedef boost::vertex_property_tag kind;
34};
35
42template <typename SimplicialComplexForProximityGraph>
43using Proximity_graph = typename boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS
44, boost::property < vertex_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >
45, boost::property < edge_filtration_t, typename SimplicialComplexForProximityGraph::Filtration_value >>;
46
59template< typename SimplicialComplexForProximityGraph
60 , typename ForwardPointRange
61 , typename Distance >
63 const ForwardPointRange& points,
64 typename SimplicialComplexForProximityGraph::Filtration_value threshold,
65 Distance distance) {
66 using Vertex_handle = typename SimplicialComplexForProximityGraph::Vertex_handle;
67 using Filtration_value = typename SimplicialComplexForProximityGraph::Filtration_value;
68
69 std::vector<std::pair< Vertex_handle, Vertex_handle >> edges;
70 std::vector< Filtration_value > edges_fil;
71 std::map< Vertex_handle, Filtration_value > vertices;
72
73 Vertex_handle idx_u, idx_v;
75 idx_u = 0;
76 for (auto it_u = points.begin(); it_u != points.end(); ++it_u) {
77 idx_v = idx_u + 1;
78 for (auto it_v = it_u + 1; it_v != points.end(); ++it_v, ++idx_v) {
79 fil = distance(*it_u, *it_v);
80 if (fil <= threshold) {
81 edges.emplace_back(idx_u, idx_v);
82 edges_fil.push_back(fil);
83 }
84 }
85 ++idx_u;
86 }
87
88 // Points are labeled from 0 to idx_u-1
89 Proximity_graph<SimplicialComplexForProximityGraph> skel_graph(edges.begin(), edges.end(), edges_fil.begin(), idx_u);
90
91 auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph);
92
93 typename boost::graph_traits<Proximity_graph<SimplicialComplexForProximityGraph>>::vertex_iterator vi, vi_end;
94 for (std::tie(vi, vi_end) = boost::vertices(skel_graph);
95 vi != vi_end; ++vi) {
96 boost::put(vertex_prop, *vi, 0.);
97 }
98
99 return skel_graph;
100}
101
102} // namespace Gudhi
103
104#endif // GRAPH_SIMPLICIAL_COMPLEX_H_
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
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:15