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