summaryrefslogtreecommitdiff
path: root/cython/include/Tangential_complex_interface.h
blob: 0c3a510e98d44964b83328c7af26ec6a54371c55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*    This file is part of the Gudhi Library. The Gudhi library
 *    (Geometric Understanding in Higher Dimensions) is a generic C++
 *    library for computational topology.
 *
 *    Author(s):       Vincent Rouvreau
 *
 *    Copyright (C) 2016 INRIA
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDE_TANGENTIAL_COMPLEX_INTERFACE_H_
#define INCLUDE_TANGENTIAL_COMPLEX_INTERFACE_H_

#include <gudhi/Simplex_tree.h>
#include <gudhi/Tangential_complex.h>
#include <gudhi/Points_off_io.h>
#include <CGAL/Epick_d.h>

#include "Simplex_tree_interface.h"

#include <vector>
#include <utility>  // std::pair
#include <iostream>
#include <string>

namespace Gudhi {

namespace tangential_complex {

class Tangential_complex_interface {
  using Dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >;
  using Point_d = Dynamic_kernel::Point_d;
  using TC = Tangential_complex<Dynamic_kernel, CGAL::Dynamic_dimension_tag, CGAL::Parallel_tag>;

 public:
  Tangential_complex_interface(const std::vector<std::vector<double>>& points) {
    Dynamic_kernel k;
    unsigned intrisic_dim = 0;
    if (points.size() > 0)
      intrisic_dim = points[0].size() - 1;

    tangential_complex_ = new TC(points, intrisic_dim, k);
    tangential_complex_->compute_tangential_complex();
    num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices();
  }

  Tangential_complex_interface(const std::string& off_file_name, bool from_file = true) {
    Gudhi::Points_off_reader<Point_d> off_reader(off_file_name);
    Dynamic_kernel k;
    unsigned intrisic_dim = 0;
    std::vector<Point_d> points = off_reader.get_point_cloud();
    if (points.size() > 0)
      intrisic_dim = points[0].size() - 1;

    tangential_complex_ = new TC(points, intrisic_dim, k);
    tangential_complex_->compute_tangential_complex();
    num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices();
  }

  ~Tangential_complex_interface() {
    delete tangential_complex_;
  }

  std::vector<double> get_point(unsigned vh) {
    std::vector<double> vd;
    if (vh < tangential_complex_->number_of_vertices()) {
      Point_d ph = tangential_complex_->get_point(vh);
      for (auto coord = ph.cartesian_begin(); coord < ph.cartesian_end(); coord++)
        vd.push_back(*coord);
    }
    return vd;
  }

  unsigned number_of_vertices() {
    return tangential_complex_->number_of_vertices();
  }

  unsigned number_of_simplices() {
    return num_inconsistencies_.num_simplices;
  }

  unsigned number_of_inconsistent_simplices() {
    return num_inconsistencies_.num_inconsistent_simplices;
  }

  unsigned number_of_inconsistent_stars() {
    return num_inconsistencies_.num_inconsistent_stars;
  }

  void fix_inconsistencies_using_perturbation(double max_perturb, double time_limit) {
      tangential_complex_->fix_inconsistencies_using_perturbation(max_perturb, time_limit);
      num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices();
  }

  void create_simplex_tree(Simplex_tree<>* simplex_tree) {
    tangential_complex_->create_complex<Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_full_featured>>(*simplex_tree);
    simplex_tree->initialize_filtration();
  }

 private:
  TC* tangential_complex_;
  TC::Num_inconsistencies num_inconsistencies_;
};

}  // namespace tangential_complex

}  // namespace Gudhi

#endif  // INCLUDE_TANGENTIAL_COMPLEX_INTERFACE_H_