Gudhi  1.1.0
 All Classes Functions Typedefs Friends Groups Pages
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 Sophia Antipolis-Méditerranée (France)
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 GUDHI_GRAPH_SIMPLICIAL_COMPLEX_FILTRATION_TAG_H
24 #define GUDHI_GRAPH_SIMPLICIAL_COMPLEX_FILTRATION_TAG_H
25 
26 #include <boost/graph/adjacency_list.hpp>
27 
28 /* Edge tag for Boost PropertyGraph. */
29 struct edge_filtration_t {
30  typedef boost::edge_property_tag kind;
31 };
32 /* Vertex tag for Boost PropertyGraph. */
33 struct vertex_filtration_t {
34  typedef boost::vertex_property_tag kind;
35 };
36 
37 typedef int Vertex_handle;
38 typedef double Filtration_value;
39 typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS
40  , boost::property < vertex_filtration_t, Filtration_value >
41  , boost::property < edge_filtration_t, Filtration_value >
42  > Graph_t;
43 typedef std::pair< Vertex_handle, Vertex_handle > Edge_t;
44 
54 template< typename PointCloud
55  , typename Point >
56 Graph_t compute_proximity_graph( PointCloud &points
57  , Filtration_value threshold
58  , Filtration_value distance(Point p1, Point p2) )
59 {
60  std::vector< Edge_t > edges;
61  std::vector< Filtration_value > edges_fil;
62  std::map< Vertex_handle, Filtration_value > vertices;
63 
64  Vertex_handle idx_u, idx_v;
65  Filtration_value fil;
66  idx_u = 0;
67  for(auto it_u = points.begin(); it_u != points.end(); ++it_u)
68  {
69  idx_v = idx_u+1;
70  for(auto it_v = it_u+1; it_v != points.end(); ++it_v, ++idx_v)
71  {
72  fil = distance(*it_u,*it_v);
73  if(fil <= threshold) {
74  edges.emplace_back(idx_u,idx_v);
75  edges_fil.push_back(fil);
76  }
77  }
78  ++idx_u;
79  }
80 
81  Graph_t skel_graph( edges.begin()
82  , edges.end()
83  , edges_fil.begin()
84  , idx_u); //number of points labeled from 0 to idx_u-1
85 
86  auto vertex_prop = boost::get(vertex_filtration_t(),skel_graph);
87 
88  boost::graph_traits<Graph_t>::vertex_iterator vi, vi_end;
89  for ( tie(vi, vi_end) = boost::vertices(skel_graph);
90  vi != vi_end; ++vi )
91  { boost::put(vertex_prop, *vi, 0.); }
92 
93  return skel_graph;
94 }
95 
96 #endif // GUDHI_GRAPH_SIMPLICIAL_COMPLEX_FILTRATION_TAG_H