Gudhi  1.2.0
 All Classes Functions Variables Typedefs Friends Groups Pages
Top_faces.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): David Salinas
6  *
7  * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (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 #ifndef SKELETON_BLOCKER_INTERNAL_TOP_FACES_H_
23 #define SKELETON_BLOCKER_INTERNAL_TOP_FACES_H_
24 
25 #include <list>
26 #include <vector>
27 #include <set>
28 
29 namespace Gudhi {
30 
31 namespace skbl {
32 
33 template<typename SimplexHandle>
34 std::list<SimplexHandle> subfaces(SimplexHandle top_face) {
35  std::list<SimplexHandle> res;
36  if (top_face.dimension() == -1) return res;
37  if (top_face.dimension() == 0) {
38  res.push_back(top_face);
39  return res;
40  } else {
41  auto first_vertex = top_face.first_vertex();
42  top_face.remove_vertex(first_vertex);
43  res = subfaces(top_face);
44  std::list<SimplexHandle> copy = res;
45  for (auto& simplex : copy) {
46  simplex.add_vertex(first_vertex);
47  }
48  res.push_back(SimplexHandle(first_vertex));
49  res.splice(res.end(), copy);
50  return res;
51  }
52 }
53 
57 template<typename SimplexHandle>
58 void register_faces(std::vector< std::set<SimplexHandle> >& simplices_per_dimension,
59  const SimplexHandle& top_face) {
60  std::list<SimplexHandle> subfaces_list = subfaces(top_face);
61  for (auto& simplex : subfaces_list) {
62  simplices_per_dimension[simplex.dimension()].insert(simplex);
63  }
64 }
65 
66 } // namespace skbl
67 
68 } // namespace Gudhi
69 
70 #endif // SKELETON_BLOCKER_INTERNAL_TOP_FACES_H_