CVB++ 15.0
point_3d_c.hpp
1#pragma once
2
3#include <cmath>
4#include <cassert>
5
6#include "global.hpp"
7
8#include "angle.hpp"
9#include "point_3d.hpp"
10
11namespace Cvb
12{
13
14CVB_BEGIN_INLINE_NS
15
16#pragma pack ( push, 4 )
17
19
21template< class T, class ENABLE = void>
22class Point3DC final
23{
24
25#ifndef CVB_DOXYGEN
26 static_assert(std::is_arithmetic<T>::value, "CVB: Unsupported data type - must be arithmetic!");
27};
28
29
30template <class T>
31class Point3DC<T,
32 typename EnableIfArithmetic<T>::type> final
33{
34
35#endif
36
37 public:
38
39 using ValueType = T;
40
42
45 Point3DC() noexcept = default;
46
47
49
55 Point3DC(T x, T y, T z) noexcept
56 : x_(x)
57 , y_(y)
58 , z_(z)
59 {
60 }
61
63
70 Point3DC(T x, T y, T z, T c) noexcept
71 : x_(x)
72 , y_(y)
73 , z_(z)
74 , c_(c)
75 {
76 }
77
78
80
84 explicit Point3DC(Point3D<T> point3d) noexcept
85 : Point3DC(point3d.X(), point3d.Y(), point3d.Z())
86 {
87 }
88
90
94 template<std::size_t N>
95 Point3DC(const T(&list)[N]) noexcept // NOLINT
96 {
97 static_assert(N == 4, "CVB: Point3DC must have 4 elements");
98 std::copy(std::begin(list), std::end(list), &x_);
99 }
100
101
102
104
108 T X() const noexcept
109 {
110 return x_;
111 }
112
114
118 void SetX(T x) noexcept
119 {
120 x_ = x;
121 }
122
124
128 T Y() const noexcept
129 {
130 return y_;
131 }
132
134
138 void SetY(T y)
139 {
140 y_ = y;
141 }
142
144
148 T Z() const noexcept
149 {
150 return z_;
151 }
152
154
158 void SetZ(T z)
159 {
160 z_ = z;
161 }
162
164
168 T Confidence() const noexcept
169 {
170 return c_;
171 }
172
174
179 {
180 c_ = c;
181 }
182
184
188 T Length() const noexcept
189 {
190 return sqrt(x_ * x_ + y_ * y_ + z_ * z_);
191 }
192
193
195
200 bool operator==(const Point3DC<T>& other) const noexcept
201 {
202 return (x_ == other.x_ && y_ == other.y_ && z_ == other.z_ && c_ == other.c_);
203 }
204
205
207
212 bool operator!=(const Point3DC<T>& other) const noexcept
213 {
214 return !(*this == other);
215 }
216
218 template <class C>
219 explicit operator Point3DC<C>() const noexcept
220 {
221 static_assert(std::is_floating_point<C>::value, "CVB: Unsupported data type - must be floating point!");
222 return Point3DC<C>(static_cast<C>(X()), static_cast<C>(Y()), static_cast<C>(Z()), static_cast<C>(C()));
223 }
224
226
231 Point3DC<T>& operator +=(const Point3DC<T> & point) noexcept
232 {
233 x_ += point.x_;
234 y_ += point.y_;
235 z_ += point.z_;
236 c_ = std::min(c_, point.c_);
237
238 return *this;
239 }
240
242
247 Point3DC<T>& operator -=(const Point3DC<T> & point) noexcept
248 {
249 x_ -= point.x_;
250 y_ -= point.y_;
251 z_ -= point.z_;
252 c_ = std::min(c_, point.c_);
253
254 return *this;
255 }
256
258
263 Point3DC<T>& operator *=(const T & value) noexcept
264 {
265 x_ *= value;
266 y_ *= value;
267 z_ *= value;
268 return *this;
269 }
270
272
277 Point3DC<T>& operator /=(const T & value) noexcept
278 {
279 x_ /= value;
280 y_ /= value;
281 z_ /= value;
282 return *this;
283 }
284
286
291 const T& operator[](int index) const noexcept
292 {
293 assert(index < 4 && index >= 0);
294 return *(&x_ + index);
295 }
296
298
303 T& operator[](int index) noexcept
304 {
305 assert(index < 4 && index >= 0);
306 return *(&x_ + index);
307 }
308
309 private:
310
311 T x_ = static_cast<T>(0.0);
312 T y_ = static_cast<T>(0.0);
313 T z_ = static_cast<T>(0.0);
314 T c_ = static_cast<T>(1.0);
315
316};
317
319
327template <class T>
328inline Point3DC<T> operator+(const Point3DC<T> & lhs, const Point3DC<T> & rhs)
329{
330 Point3DC<T> retval(lhs);
331 retval += rhs;
332 return retval;
333}
334
336
344template <class T>
345inline Point3DC<T> operator-(const Point3DC<T> & lhs, const Point3DC<T> & rhs)
346{
347 Point3DC<T> retval(lhs);
348 retval -= rhs;
349 return retval;
350}
351
353
361template <class T>
362inline T operator*(const Point3DC<T> & lhs, const Point3DC<T> & rhs)
363{
364 return lhs.X() * rhs.X() + lhs.Y() * rhs.Y() + lhs.Z() * rhs.Z() ;
365}
366
368
376template <class T>
377inline Point3DC<T> operator*(const Point3DC<T> & lhs, const T & rhs)
378{
379 Point3DC<T> retval(lhs);
380 retval *= rhs;
381 return retval;
382}
383
385
393template <class T>
394inline Point3DC<T> operator*(const T & lhs, const Point3DC<T> & rhs)
395{
396 return rhs * lhs;
397}
398
400
408template <class T>
409inline Point3DC<T> operator/(const Point3DC<T> & lhs, const T & rhs)
410{
411 Point3DC<T> retval(lhs);
412 retval /= rhs;
413 return retval;
414}
415
416
418template<class T>
420
421#pragma pack ( pop )
422
423
424CVB_END_INLINE_NS
425
426
427}
Multi-purpose 3D vector class with confidence.
Definition: point_3d_c.hpp:23
Point3DC() noexcept=default
Creates a default point at (0, 0).
const T & operator[](int index) const noexcept
Index based element access.
Definition: point_3d_c.hpp:291
Point3DC(Point3D< T > point3d) noexcept
Create a 3D point with confidence from a point.
Definition: point_3d_c.hpp:84
Point3DC< T > & operator+=(const Point3DC< T > &point) noexcept
Adds and assigns to this point.
Definition: point_3d_c.hpp:231
T X() const noexcept
Gets the x-component of the point.
Definition: point_3d_c.hpp:108
T Y() const noexcept
Gets the y-component of the point.
Definition: point_3d_c.hpp:128
void SetX(T x) noexcept
Sets the x-component of the point.
Definition: point_3d_c.hpp:118
Point3DC(const T(&list)[N]) noexcept
Construct a point with an initializer list.
Definition: point_3d_c.hpp:95
void SetY(T y)
Sets the y-component of the point.
Definition: point_3d_c.hpp:138
Point3DC< T > & operator/=(const T &value) noexcept
Divide by a scalar and assigns to this point.
Definition: point_3d_c.hpp:277
bool operator!=(const Point3DC< T > &other) const noexcept
Compares to an other point.
Definition: point_3d_c.hpp:212
Point3DC< T > operator+(const Point3DC< T > &lhs, const Point3DC< T > &rhs)
Add two points.
Definition: point_3d_c.hpp:328
Point3DC< T > & operator-=(const Point3DC< T > &point) noexcept
Subtracts and assigns to this point.
Definition: point_3d_c.hpp:247
T Z() const noexcept
Gets the z-component of the point.
Definition: point_3d_c.hpp:148
void SetConfidence(T c)
Sets confidence of the point.
Definition: point_3d_c.hpp:178
Point3DC(T x, T y, T z, T c) noexcept
Create a point from the x-, y-, z- component and confidence.
Definition: point_3d_c.hpp:70
Point3DC< T > & operator*=(const T &value) noexcept
Multiplies by a scalar and assigns to this point.
Definition: point_3d_c.hpp:263
Point3DC< T > operator/(const Point3DC< T > &lhs, const T &rhs)
Divide point by scalar.
Definition: point_3d_c.hpp:409
Point3DC< T > operator*(const Point3DC< T > &lhs, const T &rhs)
Multiply point with scalar.
Definition: point_3d_c.hpp:377
T Confidence() const noexcept
Gets confidence of the point.
Definition: point_3d_c.hpp:168
T Length() const noexcept
Gets the length of this point.
Definition: point_3d_c.hpp:188
Point3DC< T > operator-(const Point3DC< T > &lhs, const Point3DC< T > &rhs)
Subtracts two points.
Definition: point_3d_c.hpp:345
bool operator==(const Point3DC< T > &other) const noexcept
Compares to an other point.
Definition: point_3d_c.hpp:200
T & operator[](int index) noexcept
Index based element access.
Definition: point_3d_c.hpp:303
void SetZ(T z)
Sets the z-component of the point.
Definition: point_3d_c.hpp:158
T operator*(const Point3DC< T > &lhs, const Point3DC< T > &rhs)
Inner product of two point vectors.
Definition: point_3d_c.hpp:362
Multi-purpose 3D vector class.
Definition: point_3d.hpp:22
Point3DC< T > operator*(const T &lhs, const Point3DC< T > &rhs)
Multiply scalar with point.
Definition: point_3d_c.hpp:394
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24