Subsampling_interface.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): Vincent Rouvreau
6  *
7  * Copyright (C) 2016 Inria
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 
23 #ifndef INCLUDE_SUBSAMPLING_INTERFACE_H_
24 #define INCLUDE_SUBSAMPLING_INTERFACE_H_
25 
26 #include <gudhi/choose_n_farthest_points.h>
27 #include <gudhi/pick_n_random_points.h>
28 #include <gudhi/sparsify_point_set.h>
29 #include <gudhi/Points_off_io.h>
30 #include <CGAL/Epick_d.h>
31 
32 #include <iostream>
33 #include <vector>
34 #include <string>
35 
36 namespace Gudhi {
37 
38 namespace subsampling {
39 
40 using Subsampling_dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >;
41 using Subsampling_point_d = Subsampling_dynamic_kernel::Point_d;
42 using Subsampling_ft = Subsampling_dynamic_kernel::FT;
43 
44 // ------ choose_n_farthest_points ------
45 std::vector<std::vector<double>> subsampling_n_farthest_points(const std::vector<std::vector<double>>& points,
46  unsigned nb_points) {
47  std::vector<std::vector<double>> landmarks;
48  Subsampling_dynamic_kernel k;
49  choose_n_farthest_points(k, points, nb_points, random_starting_point, std::back_inserter(landmarks));
50 
51  return landmarks;
52 }
53 
54 std::vector<std::vector<double>> subsampling_n_farthest_points(const std::vector<std::vector<double>>& points,
55  unsigned nb_points, unsigned starting_point) {
56  std::vector<std::vector<double>> landmarks;
57  Subsampling_dynamic_kernel k;
58  choose_n_farthest_points(k, points, nb_points, starting_point, std::back_inserter(landmarks));
59 
60  return landmarks;
61 }
62 
63 std::vector<std::vector<double>> subsampling_n_farthest_points_from_file(const std::string& off_file,
64  unsigned nb_points) {
66  std::vector<std::vector<double>> points = off_reader.get_point_cloud();
67  return subsampling_n_farthest_points(points, nb_points);
68 }
69 
70 std::vector<std::vector<double>> subsampling_n_farthest_points_from_file(const std::string& off_file,
71  unsigned nb_points, unsigned starting_point) {
73  std::vector<std::vector<double>> points = off_reader.get_point_cloud();
74  return subsampling_n_farthest_points(points, nb_points, starting_point);
75 }
76 
77 // ------ pick_n_random_points ------
78 std::vector<std::vector<double>> subsampling_n_random_points(const std::vector<std::vector<double>>& points,
79  unsigned nb_points) {
80  std::vector<std::vector<double>> landmarks;
81  pick_n_random_points(points, nb_points, std::back_inserter(landmarks));
82 
83  return landmarks;
84 }
85 
86 std::vector<std::vector<double>> subsampling_n_random_points_from_file(const std::string& off_file,
87  unsigned nb_points) {
89  std::vector<std::vector<double>> points = off_reader.get_point_cloud();
90  return subsampling_n_random_points(points, nb_points);
91 }
92 
93 // ------ sparsify_point_set ------
94 std::vector<std::vector<double>> subsampling_sparsify_points(const std::vector<std::vector<double>>& points,
95  double min_squared_dist) {
96  std::vector<Subsampling_point_d> input, output;
97  for (auto point : points)
98  input.push_back(Subsampling_point_d(point.size(), point.begin(), point.end()));
99  Subsampling_dynamic_kernel k;
100  sparsify_point_set(k, input, min_squared_dist, std::back_inserter(output));
101 
102  std::vector<std::vector<double>> landmarks;
103  for (auto point : output)
104  landmarks.push_back(std::vector<double>(point.cartesian_begin(), point.cartesian_end()));
105  return landmarks;
106 }
107 
108 std::vector<std::vector<double>> subsampling_sparsify_points_from_file(const std::string& off_file,
109  double min_squared_dist) {
110  Gudhi::Points_off_reader<std::vector<double>> off_reader(off_file);
111  std::vector<std::vector<double>> points = off_reader.get_point_cloud();
112  return subsampling_sparsify_points(points, min_squared_dist);
113 }
114 
115 } // namespace subsampling
116 
117 } // namespace Gudhi
118 
119 #endif // INCLUDE_SUBSAMPLING_INTERFACE_H_
OFF file reader implementation in order to read points from an OFF file.
Definition: Points_off_io.h:134
void choose_n_farthest_points(Kernel const &k, Point_range const &input_pts, std::size_t final_size, std::size_t starting_point, PointOutputIterator output_it, DistanceOutputIterator dist_it={})
Subsample by a greedy strategy of iteratively adding the farthest point from the current chosen point...
Definition: choose_n_farthest_points.h:78
void sparsify_point_set(const Kernel &k, Point_range const &input_pts, typename Kernel::FT min_squared_dist, OutputIterator output_it)
Outputs a subset of the input points so that the squared distance between any two points is greater t...
Definition: sparsify_point_set.h:60
void pick_n_random_points(Point_container const &points, std::size_t final_size, OutputIterator output_it)
Subsample a point set by picking random vertices.
Definition: pick_n_random_points.h:52
Definition: SimplicialComplexForAlpha.h:26
Definition: choose_n_farthest_points.h:46
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Tue Aug 21 2018 01:41:05 for GUDHI by Doxygen 1.8.13