Rips_builder.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 #ifndef UTILS_RIPS_BUILDER_H_
12 #define UTILS_RIPS_BUILDER_H_
13 
14 #include <boost/iterator/iterator_facade.hpp>
15 
16 #include <CGAL/Euclidean_distance.h>
17 #include <CGAL/Orthogonal_k_neighbor_search.h>
18 #include <CGAL/Search_traits_d.h>
19 
20 #include "utils/UI_utils.h"
21 #include "model/Complex_typedefs.h"
22 
23 template<typename SkBlComplex> class Rips_builder {
24  private:
25  SkBlComplex& complex_;
26 
27  public:
32  Rips_builder(SkBlComplex& complex, double alpha) : complex_(complex) {
33  complex.keep_only_vertices();
34  if (alpha <= 0) return;
35  compute_edges(alpha);
36  }
37 
38  private:
39  double squared_eucl_distance(const Point& p1, const Point& p2) const {
40  return Geometry_trait::Squared_distance_d()(p1, p2);
41  }
42 
43  void compute_edges(double alpha) {
44  auto vertices = complex_.vertex_range();
45  for (auto p = vertices.begin(); p != vertices.end(); ++p) {
46  std::clog << *p << " ";
47  std::clog.flush();
48  for (auto q = p; ++q != vertices.end(); )
49  if (squared_eucl_distance(complex_.point(*p), complex_.point(*q)) < 4 * alpha * alpha)
50  complex_.add_edge_without_blockers(*p, *q);
51  }
52  std::clog << std::endl;
53  }
54 };
55 
56 #endif // UTILS_RIPS_BUILDER_H_
GUDHIdev  Version 3.5.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Sun May 1 2022 09:19:32 for GUDHIdev by Doxygen 1.9.1