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
14 CVB_BEGIN_INLINE_NS
15
16#pragma pack(push, 4)
17
19
21 template <class T, class ENABLE = void>
22 class 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 template <class T>
30 class Point3DC<T, typename EnableIfArithmetic<T>::type> final
31 {
32
33#endif
34
35 public:
36 using ValueType = T;
37
39
42 Point3DC() noexcept = default;
43
45
51 Point3DC(T x, T y, T z) noexcept
52 : x_(x)
53 , y_(y)
54 , z_(z)
55 {
56 }
57
59
66 Point3DC(T x, T y, T z, T c) noexcept
67 : x_(x)
68 , y_(y)
69 , z_(z)
70 , c_(c)
71 {
72 }
73
75
79 explicit Point3DC(Point3D<T> point3d) noexcept
80 : Point3DC(point3d.X(), point3d.Y(), point3d.Z())
81 {
82 }
83
85
89 template <std::size_t N>
90 Point3DC(const T (&list)[N]) noexcept // NOLINT
91 {
92 static_assert(N == 4, "CVB: Point3DC must have 4 elements");
93 std::copy(std::begin(list), std::end(list), &x_);
94 }
95
97
101 T X() const noexcept
102 {
103 return x_;
104 }
105
107
111 void SetX(T x) noexcept
112 {
113 x_ = x;
114 }
115
117
121 T Y() const noexcept
122 {
123 return y_;
124 }
125
127
131 void SetY(T y)
132 {
133 y_ = y;
134 }
135
137
141 T Z() const noexcept
142 {
143 return z_;
144 }
145
147
151 void SetZ(T z)
152 {
153 z_ = z;
154 }
155
157
161 T Confidence() const noexcept
162 {
163 return c_;
164 }
165
167
172 {
173 c_ = c;
174 }
175
177
181 T Length() const noexcept
182 {
183 return sqrt(x_ * x_ + y_ * y_ + z_ * z_);
184 }
185
187
192 bool operator==(const Point3DC<T> &other) const noexcept
193 {
194 return (x_ == other.x_ && y_ == other.y_ && z_ == other.z_ && c_ == other.c_);
195 }
196
198
203 bool operator!=(const Point3DC<T> &other) const noexcept
204 {
205 return !(*this == other);
206 }
207
209 template <class C>
210 explicit operator Point3DC<C>() const noexcept
211 {
212 static_assert(std::is_floating_point<C>::value, "CVB: Unsupported data type - must be floating point!");
213 return Point3DC<C>(static_cast<C>(X()), static_cast<C>(Y()), static_cast<C>(Z()), static_cast<C>(C()));
214 }
215
217
222 Point3DC<T> &operator+=(const Point3DC<T> &point) noexcept
223 {
224 x_ += point.x_;
225 y_ += point.y_;
226 z_ += point.z_;
227 c_ = std::min(c_, point.c_);
228
229 return *this;
230 }
231
233
238 Point3DC<T> &operator-=(const Point3DC<T> &point) noexcept
239 {
240 x_ -= point.x_;
241 y_ -= point.y_;
242 z_ -= point.z_;
243 c_ = std::min(c_, point.c_);
244
245 return *this;
246 }
247
249
254 Point3DC<T> &operator*=(const T &value) noexcept
255 {
256 x_ *= value;
257 y_ *= value;
258 z_ *= value;
259 return *this;
260 }
261
263
268 Point3DC<T> &operator/=(const T &value) noexcept
269 {
270 x_ /= value;
271 y_ /= value;
272 z_ /= value;
273 return *this;
274 }
275
277
282 const T &operator[](int index) const noexcept
283 {
284 assert(index < 4 && index >= 0);
285 return *(&x_ + index);
286 }
287
289
294 T &operator[](int index) noexcept
295 {
296 assert(index < 4 && index >= 0);
297 return *(&x_ + index);
298 }
299
300 private:
301 T x_ = static_cast<T>(0.0);
302 T y_ = static_cast<T>(0.0);
303 T z_ = static_cast<T>(0.0);
304 T c_ = static_cast<T>(1.0);
305 };
306
308
316 template <class T>
317 inline Point3DC<T> operator+(const Point3DC<T> &lhs, const Point3DC<T> &rhs)
318 {
319 Point3DC<T> retval(lhs);
320 retval += rhs;
321 return retval;
322 }
323
325
333 template <class T>
334 inline Point3DC<T> operator-(const Point3DC<T> &lhs, const Point3DC<T> &rhs)
335 {
336 Point3DC<T> retval(lhs);
337 retval -= rhs;
338 return retval;
339 }
340
342
350 template <class T>
351 inline T operator*(const Point3DC<T> &lhs, const Point3DC<T> &rhs)
352 {
353 return lhs.X() * rhs.X() + lhs.Y() * rhs.Y() + lhs.Z() * rhs.Z();
354 }
355
357
365 template <class T>
366 inline Point3DC<T> operator*(const Point3DC<T> &lhs, const T &rhs)
367 {
368 Point3DC<T> retval(lhs);
369 retval *= rhs;
370 return retval;
371 }
372
374
382 template <class T>
383 inline Point3DC<T> operator*(const T &lhs, const Point3DC<T> &rhs)
384 {
385 return rhs * lhs;
386 }
387
389
397 template <class T>
398 inline Point3DC<T> operator/(const Point3DC<T> &lhs, const T &rhs)
399 {
400 Point3DC<T> retval(lhs);
401 retval /= rhs;
402 return retval;
403 }
404
406 template <class T>
408
409#pragma pack(pop)
410
411 CVB_END_INLINE_NS
412
413} // namespace Cvb
T begin(T... args)
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:282
Point3DC(Point3D< T > point3d) noexcept
Create a 3D point with confidence from a point.
Definition point_3d_c.hpp:79
Point3DC< T > & operator+=(const Point3DC< T > &point) noexcept
Adds and assigns to this point.
Definition point_3d_c.hpp:222
T X() const noexcept
Gets the x-component of the point.
Definition point_3d_c.hpp:101
T Y() const noexcept
Gets the y-component of the point.
Definition point_3d_c.hpp:121
void SetX(T x) noexcept
Sets the x-component of the point.
Definition point_3d_c.hpp:111
Point3DC(const T(&list)[N]) noexcept
Construct a point with an initializer list.
Definition point_3d_c.hpp:90
void SetY(T y)
Sets the y-component of the point.
Definition point_3d_c.hpp:131
Point3DC< T > & operator/=(const T &value) noexcept
Divide by a scalar and assigns to this point.
Definition point_3d_c.hpp:268
bool operator!=(const Point3DC< T > &other) const noexcept
Compares to an other point.
Definition point_3d_c.hpp:203
Point3DC< T > operator+(const Point3DC< T > &lhs, const Point3DC< T > &rhs)
Add two points.
Definition point_3d_c.hpp:317
Point3DC< T > & operator-=(const Point3DC< T > &point) noexcept
Subtracts and assigns to this point.
Definition point_3d_c.hpp:238
T Z() const noexcept
Gets the z-component of the point.
Definition point_3d_c.hpp:141
void SetConfidence(T c)
Sets confidence of the point.
Definition point_3d_c.hpp:171
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:66
Point3DC< T > & operator*=(const T &value) noexcept
Multiplies by a scalar and assigns to this point.
Definition point_3d_c.hpp:254
Point3DC< T > operator/(const Point3DC< T > &lhs, const T &rhs)
Divide point by scalar.
Definition point_3d_c.hpp:398
Point3DC< T > operator*(const Point3DC< T > &lhs, const T &rhs)
Multiply point with scalar.
Definition point_3d_c.hpp:366
T Confidence() const noexcept
Gets confidence of the point.
Definition point_3d_c.hpp:161
T Length() const noexcept
Gets the length of this point.
Definition point_3d_c.hpp:181
Point3DC< T > operator-(const Point3DC< T > &lhs, const Point3DC< T > &rhs)
Subtracts two points.
Definition point_3d_c.hpp:334
bool operator==(const Point3DC< T > &other) const noexcept
Compares to an other point.
Definition point_3d_c.hpp:192
T & operator[](int index) noexcept
Index based element access.
Definition point_3d_c.hpp:294
void SetZ(T z)
Sets the z-component of the point.
Definition point_3d_c.hpp:151
T operator*(const Point3DC< T > &lhs, const Point3DC< T > &rhs)
Inner product of two point vectors.
Definition point_3d_c.hpp:351
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:383
T copy(T... args)
T end(T... args)
T min(T... args)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
Point3DC< T > Vector3DC
Alias for Point3D.
Definition point_3d_c.hpp:407