licornea_tools
point.h
Go to the documentation of this file.
1 #ifndef LICORNEA_POINT_H_
2 #define LICORNEA_POINT_H_
3 
4 #include "common.h"
5 #include "color.h"
6 #include "opencv.h"
7 #include <array>
8 
9 namespace tlz {
10 
11 static_assert(sizeof(float) == 4, "point cloud requires 32 bit float type");
12 
13 struct alignas(16) point_xyz {
14 public:
15  float x = 0.0, y = 0.0, z = 0.0, w = 0.0;
16 
17  point_xyz() = default;
18  point_xyz(const point_xyz&) = default;
19  point_xyz(float x_, float y_, float z_):
20  x(x_), y(y_), z(z_), w(1.0) { }
21  point_xyz(const vec3& pos) :
22  point_xyz(pos[0], pos[1], pos[2]) { }
23 
24  point_xyz& operator=(const point_xyz&) = default;
25  point_xyz& operator=(const vec3& pos)
26  { set_position(pos); return *this; }
27 
28  void set_position(const vec3& pos)
29  { x = pos[0]; y = pos[1]; z = pos[2]; w = 1.0; }
30  vec3 position() const { return vec3(x, y, z); }
31 
32  void set_non_null() { w = 1.0; }
33  void set_null() { w = 0.0; }
34  bool is_null() const { return (w != 1.0); }
35  explicit operator bool () const { return ! is_null(); }
36 };
37 static_assert(sizeof(point_xyz) == 16, "point_xyz must be 16 byte");
38 
39 
40 struct alignas(16) point_full : public point_xyz {
41 public:
43  int reserved : 13;
44 
45  point_full() = default;
46  point_full(const point_full&) = default;
47  point_full(const point_xyz& pt, const rgb_color& col = rgb_color::white) :
48  point_xyz(pt), color(col) { }
49 
50  point_full& operator=(const point_full&) = default;
51  point_full& operator=(const point_xyz& pt) { return operator=(point_full(pt)); }
52  point_full& operator=(const vec3& pos) { return operator=(point_full(pos)); }
53 };
54 static_assert(sizeof(point_full) == 32, "point_full must be 32 byte");
55 
56 }
57 
58 #endif
point_xyz & operator=(const vec3 &pos)
Definition: point.h:25
vec3 position() const
Definition: point.h:30
float y
Definition: point.h:15
bool is_null() const
Definition: point.h:34
point_xyz()=default
point_xyz(float x_, float y_, float z_)
Definition: point.h:19
point_full(const point_xyz &pt, const rgb_color &col=rgb_color::white)
Definition: point.h:47
point_xyz(const vec3 &pos)
Definition: point.h:21
cv::Vec< real, 3 > vec3
Definition: common.h:23
float x
Definition: point.h:15
float w
Definition: point.h:15
RGB color, 8 bit.
Definition: color.h:11
static const rgb_color white
Definition: color.h:24
point_xyz & operator=(const point_xyz &)=default
void set_null()
Definition: point.h:33
float z
Definition: point.h:15
void set_position(const vec3 &pos)
Definition: point.h:28
point_full & operator=(const vec3 &pos)
Definition: point.h:52
point_full & operator=(const point_xyz &pt)
Definition: point.h:51
void set_non_null()
Definition: point.h:32