Mech-Eye API 2.4.0
API reference documentation for Mech-Eye Industrial 3D Camera
Loading...
Searching...
No Matches
CommonTypes.h
1#pragma once
2#include <string>
3#include <cmath>
4#include <limits>
5#include <cstring>
6#include "api_global.h"
7
8#define PI (3.14159265358979323846)
9namespace mmind {
10
11namespace eye {
12
16template <typename T>
17struct Range
18{
19 constexpr Range() : min(0), max(0) {}
20 constexpr Range(T min, T max) : min(min), max(max) {}
21 T min;
22 T max;
23};
24
28struct Size
29{
30 constexpr Size() : width(0), height(0) {}
31 constexpr Size(size_t width, size_t height) : width(width), height(height) {}
32 bool operator==(const Size& other) { return width == other.width && height == other.height; }
33
34 size_t width;
35 size_t height;
36};
37
42struct MMIND_API_EXPORT SizeF
43{
44 constexpr SizeF() : width(0), height(0) {}
45 constexpr SizeF(double width, double height) : width(width), height(height) {}
46 bool operator==(const SizeF& other);
47
48 double width;
49 double height;
50};
51
55struct ROI
56{
57 constexpr ROI() : upperLeftX(0), upperLeftY(0), width(0), height(0) {}
58 constexpr ROI(unsigned upperLeftX, unsigned upperLeftY, size_t width, size_t height)
59 : upperLeftX(upperLeftX), upperLeftY(upperLeftY), width(width), height(height)
60 {
61 }
62 bool operator==(const ROI& other) { return width == other.width && height == other.height; }
63
64 unsigned upperLeftX;
65 unsigned upperLeftY;
66 size_t width;
67 size_t height;
68};
69
73struct MMIND_API_EXPORT ProfileROI
74{
75 constexpr ProfileROI() : xAxisCenter(0), width(0), height(0) {}
76 constexpr ProfileROI(double xAxisCenter, double width, double height)
77 : xAxisCenter(xAxisCenter), width(width), height(height)
78 {
79 }
80 bool operator==(const ProfileROI& other);
81
82 double xAxisCenter;
83 double width;
84 double height;
85};
86
92{
93public:
94 FrameTransformation() = default;
95 FrameTransformation(double rotateX, double rotateY, double rotateZ, double translateX,
96 double translateY, double translateZ)
97 {
98 rotate(rotateX, Axis::X);
99 rotate(rotateY, Axis::Y);
100 rotate(rotateZ, Axis::Z);
102 }
103
105 {
106 memcpy(&rotation, &rhs.rotation, 9 * sizeof(double));
107 memcpy(&translation, &rhs.translation, 3 * sizeof(double));
108 }
109
111 {
112 if (this == &rhs)
113 return *this;
114
115 memcpy(&rotation, &rhs.rotation, 9 * sizeof(double));
116 memcpy(&translation, &rhs.translation, 3 * sizeof(double));
117 return *this;
118 }
119
120 enum class Axis { X, Y, Z };
121
128 void rotate(double theta, Axis rotationAxis)
129 {
130 const double radians{theta * PI / 180.0};
131 const double cosValue{cos(radians)};
132 const double sinValue{sin(radians)};
133
134 switch (rotationAxis) {
135 case Axis::X:
136 {
137 double rotationXMatrix[3][3] = {
138 {1, 0, 0}, {0, cosValue, -sinValue}, {0, sinValue, cosValue}};
139 multiMatrix(rotationXMatrix);
140 } break;
141 case Axis::Y:
142 {
143 double rotationYMatrix[3][3] = {
144 {cosValue, 0, sinValue}, {0, 1, 0}, {-sinValue, 0, cosValue}};
145 multiMatrix(rotationYMatrix);
146 } break;
147 case Axis::Z:
148 {
149 double rotationZMatrix[3][3] = {
150 {cosValue, -sinValue, 0}, {sinValue, cosValue, 0}, {0, 0, 1}};
151 multiMatrix(rotationZMatrix);
152 } break;
153 default:
154 break;
155 }
156 }
163 void translate(double x, double y, double z)
164 {
165 translation[0] = x;
166 translation[1] = y;
167 translation[2] = z;
168 }
169
173 bool isValid() const
174 {
175 const double EPSILON = 1e-15;
176 double identityRotation[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
177 double zeroTranslation[3] = {0, 0, 0};
178 auto isApprox0 = [EPSILON](double d) { return std::fabs(d) <= EPSILON; };
179
180 for (int row = 0; row < 3; row++) {
181 for (int col = 0; col < 3; col++) {
183 return true;
184 }
185 }
186 }
187
188 for (int row = 0; row < 3; row++) {
190 return true;
191 }
192 }
193
194 return false;
195 }
196
197 double rotation[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
198 double translation[3] = {0, 0, 0};
199private:
200 void multiMatrix(const double rotationMatrix[3][3])
201 {
202 double tempRotation[3][3];
203 memcpy(&tempRotation, &rotation, 9 * sizeof(double));
204
205 for (int row = 0; row < 3; row++) {
206 for (int col = 0; col < 3; col++) {
210 }
211 }
212 }
213};
217enum struct IpAssignmentMethod { Unknown, DHCP = 4, Static, LLA };
218
222enum struct Platform { Windows, Tx2_Ubuntu16, Tx2_Ubuntu18, Nx, Rk3399, Zynq, Rk3588, OtherLinux };
223
224inline static std::string ipAssignmentMethodToString(IpAssignmentMethod type)
225{
226 switch (type) {
227 case IpAssignmentMethod::Static:
228 return "Static";
229 case IpAssignmentMethod::DHCP:
230 return "DHCP";
231 case IpAssignmentMethod::LLA:
232 return "LLA";
233 case IpAssignmentMethod::Unknown:
234 return "Unknown";
235 }
236 return "";
237}
238
239} // namespace eye
240
241} // namespace mmind
Represents a 2D container of data.
Definition Array2D.h:17
size_t height() const
Returns the height of the Array2D object.
Definition Array2D.h:36
size_t width() const
Returns the width of the Array2D object.
Definition Array2D.h:31
Defines the rigid body transformations from one reference frame to another, including the rotation ma...
Definition CommonTypes.h:92
double translation[3]
3*1 translation vector in [x(mm), y(mm), z(mm)].
double rotation[3][3]
3*3 rotation matrix.
void rotate(double theta, Axis rotationAxis)
Rotates the reference frame of the point cloud.
void translate(double x, double y, double z)
Translates the reference frame of the point cloud.
bool isValid() const
Check if a custom reference frame has been set using Mech-Eye Viewer.
Describes the region of interest (ROI) of a laser profiler.
Definition CommonTypes.h:74
double height
The Z-axis height (in mm) of the ROI.
Definition CommonTypes.h:84
double width
The X-axis width (in mm) of the ROI.
Definition CommonTypes.h:83
double xAxisCenter
The position (in mm) of the ROI's center on the X-axis.
Definition CommonTypes.h:82
Describes a region of interest (ROI).
Definition CommonTypes.h:56
unsigned upperLeftY
The row coordinate of the upper-left corner of the ROI.
Definition CommonTypes.h:65
unsigned upperLeftX
The column coordinate of the upper-left corner of the ROI.
Definition CommonTypes.h:64
Describes a value range.
Definition CommonTypes.h:18
Describes a two-dimensional size with a width and a height using double-precision floating-point numb...
Definition CommonTypes.h:43
Describes a two-dimensional size with a width and a height.
Definition CommonTypes.h:29