Open3D (C++ API)  0.16.0
Cloud.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//
51//
52// 0==========================0
53// | Local feature test |
54// 0==========================0
55//
56// version 1.0 :
57// >
58//
59//---------------------------------------------------
60//
61// Cloud header
62//
63//----------------------------------------------------
64//
65// Hugues THOMAS - 10/02/2017
66//
67
68#pragma once
69
70#include <time.h>
71
72#include <algorithm>
73#include <cmath>
74#include <iomanip>
75#include <iostream>
76#include <map>
77#include <numeric>
78#include <unordered_map>
79#include <vector>
80
81namespace open3d {
82namespace ml {
83namespace contrib {
84
85// Point class
86// ***********
87
88class PointXYZ {
89public:
90 // Elements
91 // ********
92
93 float x, y, z;
94
95 // Methods
96 // *******
97
98 // Constructor
99 PointXYZ() = default;
100
101 PointXYZ(float x0, float y0, float z0) {
102 x = x0;
103 y = y0;
104 z = z0;
105 }
106
107 // array type accessor
108 float operator[](int i) const {
109 if (i == 0)
110 return x;
111 else if (i == 1)
112 return y;
113 else
114 return z;
115 }
116
117 // operations
118 float dot(const PointXYZ P) const { return x * P.x + y * P.y + z * P.z; }
119
120 float sq_norm() { return x * x + y * y + z * z; }
121
122 PointXYZ cross(const PointXYZ P) const {
123 return PointXYZ(y * P.z - z * P.y, z * P.x - x * P.z,
124 x * P.y - y * P.x);
125 }
126
128 x += P.x;
129 y += P.y;
130 z += P.z;
131 return *this;
132 }
133
135 x -= P.x;
136 y -= P.y;
137 z -= P.z;
138 return *this;
139 }
140
141 PointXYZ& operator*=(const float& a) {
142 x *= a;
143 y *= a;
144 z *= a;
145 return *this;
146 }
147
148 static PointXYZ floor(const PointXYZ P) {
149 return PointXYZ(std::floor(P.x), std::floor(P.y), std::floor(P.z));
150 }
151};
152
153// Point Operations
154// *****************
155
156inline PointXYZ operator+(const PointXYZ A, const PointXYZ B) {
157 return PointXYZ(A.x + B.x, A.y + B.y, A.z + B.z);
158}
159
160inline PointXYZ operator-(const PointXYZ A, const PointXYZ B) {
161 return PointXYZ(A.x - B.x, A.y - B.y, A.z - B.z);
162}
163
164inline PointXYZ operator*(const PointXYZ P, const float a) {
165 return PointXYZ(P.x * a, P.y * a, P.z * a);
166}
167
168inline PointXYZ operator*(const float a, const PointXYZ P) {
169 return PointXYZ(P.x * a, P.y * a, P.z * a);
170}
171
172inline std::ostream& operator<<(std::ostream& os, const PointXYZ P) {
173 return os << "[" << P.x << ", " << P.y << ", " << P.z << "]";
174}
175
176inline bool operator==(const PointXYZ A, const PointXYZ B) {
177 return A.x == B.x && A.y == B.y && A.z == B.z;
178}
179
180PointXYZ max_point(std::vector<PointXYZ> points);
181PointXYZ min_point(std::vector<PointXYZ> points);
182
184 std::vector<PointXYZ> pts;
185
186 // Must return the number of data points
187 inline size_t kdtree_get_point_count() const { return pts.size(); }
188
189 // Returns the dim'th component of the idx'th point in the class:
190 // Since this is inlined and the "dim" argument is typically an immediate
191 // value, the
192 // "if/else's" are actually solved at compile time.
193 inline float kdtree_get_pt(const size_t idx, const size_t dim) const {
194 if (dim == 0)
195 return pts[idx].x;
196 else if (dim == 1)
197 return pts[idx].y;
198 else
199 return pts[idx].z;
200 }
201
202 // Optional bounding-box computation: return false to default to a standard
203 // bbox computation loop.
204 // Return true if the BBOX was already computed by the class and returned
205 // in "bb" so it can be avoided to redo it again. Look at bb.size() to
206 // find out the expected dimensionality (e.g. 2 or 3 for point clouds)
207 template <class BBOX>
208 bool kdtree_get_bbox(BBOX& /* bb */) const {
209 return false;
210 }
211};
212
213} // namespace contrib
214} // namespace ml
215} // namespace open3d
Definition: Cloud.h:88
PointXYZ(float x0, float y0, float z0)
Definition: Cloud.h:101
PointXYZ & operator*=(const float &a)
Definition: Cloud.h:141
float z
Definition: Cloud.h:93
PointXYZ & operator+=(const PointXYZ &P)
Definition: Cloud.h:127
float y
Definition: Cloud.h:93
PointXYZ cross(const PointXYZ P) const
Definition: Cloud.h:122
static PointXYZ floor(const PointXYZ P)
Definition: Cloud.h:148
float operator[](int i) const
Definition: Cloud.h:108
float sq_norm()
Definition: Cloud.h:120
PointXYZ & operator-=(const PointXYZ &P)
Definition: Cloud.h:134
float dot(const PointXYZ P) const
Definition: Cloud.h:118
float x
Definition: Cloud.h:93
int points
Definition: FilePCD.cpp:73
bool operator==(const PointXYZ A, const PointXYZ B)
Definition: Cloud.h:176
PointXYZ operator-(const PointXYZ A, const PointXYZ B)
Definition: Cloud.h:160
std::ostream & operator<<(std::ostream &os, const PointXYZ P)
Definition: Cloud.h:172
PointXYZ max_point(std::vector< PointXYZ > points)
Definition: Cloud.cpp:80
PointXYZ operator+(const PointXYZ A, const PointXYZ B)
Definition: Cloud.h:156
PointXYZ operator*(const PointXYZ P, const float a)
Definition: Cloud.h:164
PointXYZ min_point(std::vector< PointXYZ > points)
Definition: Cloud.cpp:96
FN_SPECIFIERS MiniVec< float, N > floor(const MiniVec< float, N > &a)
Definition: MiniVec.h:94
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Cloud.h:183
bool kdtree_get_bbox(BBOX &) const
Definition: Cloud.h:208
size_t kdtree_get_point_count() const
Definition: Cloud.h:187
float kdtree_get_pt(const size_t idx, const size_t dim) const
Definition: Cloud.h:193
std::vector< PointXYZ > pts
Definition: Cloud.h:184