Open3D (C++ API)  0.12.0
GridSubsampling.h
Go to the documentation of this file.
1 // Source code from: https://github.com/HuguesTHOMAS/KPConv.
2 //
3 // MIT License
4 //
5 // Copyright (c) 2019 HuguesTHOMAS
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 
25 #include <cstdint>
26 #include <set>
27 
29 
30 namespace open3d {
31 namespace ml {
32 namespace contrib {
33 
34 class SampledData {
35 public:
36  // Elements
37  // ********
38 
39  int count;
41  std::vector<float> features;
42  std::vector<std::unordered_map<int, int>> labels;
43 
44  // Methods
45  // *******
46 
47  // Constructor
49  count = 0;
50  point = PointXYZ();
51  }
52 
53  SampledData(const size_t fdim, const size_t ldim) {
54  count = 0;
55  point = PointXYZ();
56  features = std::vector<float>(fdim);
57  labels = std::vector<std::unordered_map<int, int>>(ldim);
58  }
59 
60  // Method Update
61  void update_all(const PointXYZ p,
62  std::vector<float>::iterator f_begin,
63  std::vector<int>::iterator l_begin) {
64  count += 1;
65  point += p;
66  transform(features.begin(), features.end(), f_begin, features.begin(),
67  std::plus<float>());
68  int i = 0;
69  for (std::vector<int>::iterator it = l_begin;
70  it != l_begin + labels.size(); ++it) {
71  labels[i][*it] += 1;
72  i++;
73  }
74  return;
75  }
76 
77  void update_features(const PointXYZ p,
78  std::vector<float>::iterator f_begin) {
79  count += 1;
80  point += p;
81  transform(features.begin(), features.end(), f_begin, features.begin(),
82  std::plus<float>());
83  return;
84  }
85 
86  void update_classes(const PointXYZ p, std::vector<int>::iterator l_begin) {
87  count += 1;
88  point += p;
89  int i = 0;
90  for (std::vector<int>::iterator it = l_begin;
91  it != l_begin + labels.size(); ++it) {
92  labels[i][*it] += 1;
93  i++;
94  }
95  return;
96  }
97 
98  void update_points(const PointXYZ p) {
99  count += 1;
100  point += p;
101  return;
102  }
103 };
104 
105 void grid_subsampling(std::vector<PointXYZ>& original_points,
106  std::vector<PointXYZ>& subsampled_points,
107  std::vector<float>& original_features,
108  std::vector<float>& subsampled_features,
109  std::vector<int>& original_classes,
110  std::vector<int>& subsampled_classes,
111  float sampleDl,
112  int verbose);
113 
114 void batch_grid_subsampling(std::vector<PointXYZ>& original_points,
115  std::vector<PointXYZ>& subsampled_points,
116  std::vector<float>& original_features,
117  std::vector<float>& subsampled_features,
118  std::vector<int>& original_classes,
119  std::vector<int>& subsampled_classes,
120  std::vector<int>& original_batches,
121  std::vector<int>& subsampled_batches,
122  float sampleDl,
123  int max_p);
124 
125 } // namespace contrib
126 } // namespace ml
127 } // namespace open3d
PointXYZ point
Definition: GridSubsampling.h:40
Definition: GridSubsampling.h:34
SampledData()
Definition: GridSubsampling.h:48
void update_all(const PointXYZ p, std::vector< float >::iterator f_begin, std::vector< int >::iterator l_begin)
Definition: GridSubsampling.h:61
void update_classes(const PointXYZ p, std::vector< int >::iterator l_begin)
Definition: GridSubsampling.h:86
void batch_grid_subsampling(std::vector< PointXYZ > &original_points, std::vector< PointXYZ > &subsampled_points, std::vector< float > &original_features, std::vector< float > &subsampled_features, std::vector< int > &original_classes, std::vector< int > &subsampled_classes, std::vector< int > &original_batches, std::vector< int > &subsampled_batches, float sampleDl, int max_p)
Definition: GridSubsampling.cpp:139
Definition: PinholeCameraIntrinsic.cpp:35
SampledData(const size_t fdim, const size_t ldim)
Definition: GridSubsampling.h:53
void update_features(const PointXYZ p, std::vector< float >::iterator f_begin)
Definition: GridSubsampling.h:77
std::vector< float > features
Definition: GridSubsampling.h:41
std::vector< std::unordered_map< int, int > > labels
Definition: GridSubsampling.h:42
int count
Definition: GridSubsampling.h:39
void update_points(const PointXYZ p)
Definition: GridSubsampling.h:98
void grid_subsampling(std::vector< PointXYZ > &original_points, std::vector< PointXYZ > &subsampled_points, std::vector< float > &original_features, std::vector< float > &subsampled_features, std::vector< int > &original_classes, std::vector< int > &subsampled_classes, float sampleDl, int verbose)
Definition: GridSubsampling.cpp:31
Definition: Cloud.h:63