Is_manifold.h
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): David Salinas
4  *
5  * Copyright (C) 2014 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 
12 #ifndef UTILS_IS_MANIFOLD_H_
13 #define UTILS_IS_MANIFOLD_H_
14 
15 #include "utils/UI_utils.h"
16 #include "utils/Edge_contractor.h"
17 
24 template<typename SkBlComplex> class Is_manifold {
25  private:
26  const SkBlComplex& input_complex_;
27  typedef typename SkBlComplex::Vertex_handle Vertex_handle;
28 
29  public:
30  /*
31  * return dim the maximum dimension around one simplex and res which is true if the complex is a manifold.
32  * If the complex has dimension <= 3 then if res is false, the complex is not a manifold.
33  * For d-manifold with d>=4, res may be false while the complex is a manifold.
34  */
35  Is_manifold(const SkBlComplex& input_complex, unsigned& dim, bool & res) : input_complex_(input_complex) {
36  res = true;
37  dim = -1;
38  if (!input_complex_.empty()) {
39  for (auto v : input_complex_.vertex_range()) {
40  dim = local_dimension(v);
41  break;
42  }
43  // check that the link of every vertex is a dim-1 sphere
44  for (auto v : input_complex_.vertex_range()) {
45  if (!is_k_sphere(v, dim - 1)) {
46  res = false;
47  break;
48  }
49  }
50  }
51  }
52 
53  private:
54  unsigned local_dimension(Vertex_handle v) {
55  unsigned dim = 0;
56  for (const auto& s : input_complex_.star_simplex_range(v))
57  dim = (std::max)(dim, (unsigned) s.dimension());
58  return dim;
59  }
60 
61  bool is_k_sphere(Vertex_handle v, int k) {
62  auto link = input_complex_.link(v);
63  Edge_contractor<Complex> contractor(link, link.num_vertices() - 1);
64  (void)contractor;
65  return (is_sphere_simplex(link) == k);
66  }
67 
68  // A minimal sphere is a complex that contains vertices v1...vn and all faces
69  // made upon this set except the face {v1,...,vn}
70  // return -2 if not a minimal sphere
71  // and d otherwise if complex is a d minimal sphere
72 
73  template<typename SubComplex>
74  int is_sphere_simplex(const SubComplex& complex) {
75  if (complex.empty()) return -1;
76  if (complex.num_blockers() != 1) return -2;
77 
78  // necessary and sufficient condition : there exists a unique blocker that passes through all vertices
79  auto first_blocker = *(complex.const_blocker_range().begin());
80 
81  if (first_blocker->dimension() + 1 != complex.num_vertices())
82  return -2;
83  else
84  return (first_blocker->dimension() - 1);
85  }
86 };
87 
88 #endif // UTILS_IS_MANIFOLD_H_
Definition: Edge_contractor.h:24
Definition: Is_manifold.h:24
GUDHIdev  Version 3.5.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Tue Aug 16 2022 14:01:50 for GUDHIdev by Doxygen 1.9.1