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