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