Alpha_complex_interface.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): Vincent Rouvreau
4  *
5  * Copyright (C) 2016 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef INCLUDE_ALPHA_COMPLEX_INTERFACE_H_
12 #define INCLUDE_ALPHA_COMPLEX_INTERFACE_H_
13 
14 #include "Alpha_complex_factory.h"
15 #include <gudhi/Alpha_complex_options.h>
16 
17 #include "Simplex_tree_interface.h"
18 
19 #include <iostream>
20 #include <vector>
21 #include <string>
22 #include <memory> // for std::unique_ptr
23 
24 namespace Gudhi {
25 
26 namespace alpha_complex {
27 
28 class Alpha_complex_interface {
29  public:
30  Alpha_complex_interface(const std::vector<std::vector<double>>& points, bool fast_version, bool exact_version)
31  : points_(points),
32  fast_version_(fast_version),
33  exact_version_(exact_version) {
34  }
35 
36  std::vector<double> get_point(int vh) {
37  return alpha_ptr_->get_point(vh);
38  }
39 
40  void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
41  bool default_filtration_value) {
42  if (points_.size() > 0) {
43  std::size_t dimension = points_[0].size();
44  if (dimension == 3 && !default_filtration_value) {
45  if (fast_version_)
46  alpha_ptr_ = std::make_unique<Alphacomplex_3D<Gudhi::alpha_complex::complexity::FAST>>(points_);
47  else if (exact_version_)
48  alpha_ptr_ = std::make_unique<Alphacomplex_3D<Gudhi::alpha_complex::complexity::EXACT>>(points_);
49  else
50  alpha_ptr_ = std::make_unique<Alphacomplex_3D<Gudhi::alpha_complex::complexity::SAFE>>(points_);
51  if (!alpha_ptr_->create_simplex_tree(simplex_tree, max_alpha_square, default_filtration_value)) {
52  // create_simplex_tree will fail if all points are on a plane - Retry with dD by setting dimension to 2
53  dimension--;
54  alpha_ptr_.reset();
55  }
56  }
57  // Not ** else ** because we have to take into account if 3d fails
58  if (dimension != 3 || default_filtration_value) {
59  if (fast_version_) {
60  alpha_ptr_ = std::make_unique<Inexact_Alphacomplex_dD>(points_, exact_version_);
61  } else {
62  alpha_ptr_ = std::make_unique<Exact_Alphacomplex_dD>(points_, exact_version_);
63  }
64  alpha_ptr_->create_simplex_tree(simplex_tree, max_alpha_square, default_filtration_value);
65  }
66  }
67  }
68 
69  private:
70  std::unique_ptr<Abstract_alpha_complex> alpha_ptr_;
71  std::vector<std::vector<double>> points_;
72  bool fast_version_;
73  bool exact_version_;
74 };
75 
76 } // namespace alpha_complex
77 
78 } // namespace Gudhi
79 
80 #endif // INCLUDE_ALPHA_COMPLEX_INTERFACE_H_
GUDHIdev  Version 3.5.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Wed Apr 6 2022 19:26:28 for GUDHIdev by Doxygen 1.9.1