Mech-Eye API 2.5.0
API reference documentation for Mech-Eye Industrial 3D Camera
All Classes Functions Variables Typedefs Enumerations Enumerator Pages
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
16enum struct CoordinateUnit { Millimeter, Meter };
17
18enum struct FileFormat {
19 PLY,
20 PCD,
21 CSV,
22};
23
27template <typename T>
28struct Range
29{
30 constexpr Range() : min(0), max(0) {}
31 constexpr Range(T min, T max) : min(min), max(max) {}
32 T min;
33 T max;
34};
35
39struct Size
40{
41 constexpr Size() : width(0), height(0) {}
42 constexpr Size(size_t width, size_t height) : width(width), height(height) {}
43 bool operator==(const Size& other) { return width == other.width && height == other.height; }
44
45 size_t width;
46 size_t height;
47};
48
53struct MMIND_API_EXPORT SizeF
54{
55 constexpr SizeF() : width(0), height(0) {}
56 constexpr SizeF(double width, double height) : width(width), height(height) {}
57 bool operator==(const SizeF& other);
58
59 double width;
60 double height;
61};
62
66struct ROI
67{
68 constexpr ROI() : upperLeftX(0), upperLeftY(0), width(0), height(0) {}
69 constexpr ROI(unsigned upperLeftX, unsigned upperLeftY, size_t width, size_t height)
70 : upperLeftX(upperLeftX), upperLeftY(upperLeftY), width(width), height(height)
71 {
72 }
73 bool operator==(const ROI& other) { return width == other.width && height == other.height; }
74
75 unsigned upperLeftX;
76 unsigned upperLeftY;
77 size_t width;
78 size_t height;
79};
80
84struct MMIND_API_EXPORT ProfileROI
85{
86 constexpr ProfileROI() : xAxisCenter(0), width(0), height(0) {}
87 constexpr ProfileROI(double xAxisCenter, double width, double height)
88 : xAxisCenter(xAxisCenter), width(width), height(height)
89 {
90 }
91 bool operator==(const ProfileROI& other);
92
93 double xAxisCenter;
94 double width;
95 double height;
96};
97
102{
103 float x{0};
104 float y{0};
105 float z{0};
106};
107
113{
114public:
115 FrameTransformation() = default;
116 FrameTransformation(double rotateX, double rotateY, double rotateZ, double translateX,
117 double translateY, double translateZ)
118 {
119 rotate(rotateX, Axis::X);
120 rotate(rotateY, Axis::Y);
121 rotate(rotateZ, Axis::Z);
122 translate(translateX, translateY, translateZ);
123 }
124
126 {
127 memcpy(&rotation, &rhs.rotation, 9 * sizeof(double));
128 memcpy(&translation, &rhs.translation, 3 * sizeof(double));
129 }
130
131 FrameTransformation& operator=(const FrameTransformation& rhs)
132 {
133 if (this == &rhs)
134 return *this;
135
136 memcpy(&rotation, &rhs.rotation, 9 * sizeof(double));
137 memcpy(&translation, &rhs.translation, 3 * sizeof(double));
138 return *this;
139 }
140
141 enum class Axis { X, Y, Z };
142
149 void rotate(double theta, Axis rotationAxis)
150 {
151 const double radians{theta * PI / 180.0};
152 const double cosValue{cos(radians)};
153 const double sinValue{sin(radians)};
154
155 switch (rotationAxis) {
156 case Axis::X:
157 {
158 double rotationXMatrix[3][3] = {
159 {1, 0, 0}, {0, cosValue, -sinValue}, {0, sinValue, cosValue}};
160 multiMatrix(rotationXMatrix);
161 } break;
162 case Axis::Y:
163 {
164 double rotationYMatrix[3][3] = {
165 {cosValue, 0, sinValue}, {0, 1, 0}, {-sinValue, 0, cosValue}};
166 multiMatrix(rotationYMatrix);
167 } break;
168 case Axis::Z:
169 {
170 double rotationZMatrix[3][3] = {
171 {cosValue, -sinValue, 0}, {sinValue, cosValue, 0}, {0, 0, 1}};
172 multiMatrix(rotationZMatrix);
173 } break;
174 default:
175 break;
176 }
177 }
184 void translate(double x, double y, double z)
185 {
186 translation[0] = x;
187 translation[1] = y;
188 translation[2] = z;
189 }
190
194 bool isValid() const
195 {
196 const double EPSILON = 1e-15;
197 double identityRotation[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
198 double zeroTranslation[3] = {0, 0, 0};
199 auto isApprox0 = [EPSILON](double d) { return std::fabs(d) <= EPSILON; };
200
201 for (int row = 0; row < 3; row++) {
202 for (int col = 0; col < 3; col++) {
203 if (!isApprox0(rotation[row][col] - identityRotation[row][col])) {
204 return true;
205 }
206 }
207 }
208
209 for (int row = 0; row < 3; row++) {
210 if (!isApprox0(translation[row] - zeroTranslation[row])) {
211 return true;
212 }
213 }
214
215 return false;
216 }
217
218 double rotation[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
219 double translation[3] = {0, 0, 0};
220private:
221 void multiMatrix(const double rotationMatrix[3][3])
222 {
223 double tempRotation[3][3];
224 memcpy(&tempRotation, &rotation, 9 * sizeof(double));
225
226 for (int row = 0; row < 3; row++) {
227 for (int col = 0; col < 3; col++) {
228 rotation[row][col] = rotationMatrix[row][0] * tempRotation[0][col] +
229 rotationMatrix[row][1] * tempRotation[1][col] +
230 rotationMatrix[row][2] * tempRotation[2][col];
231 }
232 }
233 }
234};
238enum struct IpAssignmentMethod { Unknown, DHCP = 4, Static, LLA };
239
243enum struct Platform {
244 PLATFORM_A,
245 PLATFORM_B,
246 PLATFORM_C,
247 PLATFORM_D,
248 PLATFORM_E,
249 PLATFORM_F,
250 PLATFORM_G,
251 PLATFORM_H
252};
253
254inline static std::string ipAssignmentMethodToString(IpAssignmentMethod type)
255{
256 switch (type) {
257 case IpAssignmentMethod::Static:
258 return "Static";
259 case IpAssignmentMethod::DHCP:
260 return "DHCP";
261 case IpAssignmentMethod::LLA:
262 return "LLA";
263 case IpAssignmentMethod::Unknown:
264 return "Unknown";
265 }
266 return "";
267}
268
269} // namespace eye
270
271} // namespace mmind
Defines the rigid body transformations from one reference frame to another, including the rotation ma...
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.
Represents a point in UntexturedPointCloud with the coordinate (x, y, z) information.
float z
Z channel, default unit: mm, invalid data: nan.
float y
Y channel, default unit: mm, invalid data: nan.
float x
X channel, default unit: mm, invalid data: nan.
Describes the region of interest (ROI) of a laser profiler.
Definition CommonTypes.h:85
double height
The Z-axis height (in mm) of the ROI.
Definition CommonTypes.h:95
double width
The X-axis width (in mm) of the ROI.
Definition CommonTypes.h:94
double xAxisCenter
The position (in mm) of the ROI's center on the X-axis.
Definition CommonTypes.h:93
Describes a region of interest (ROI).
Definition CommonTypes.h:67
unsigned upperLeftY
The row coordinate of the upper-left corner of the ROI.
Definition CommonTypes.h:76
unsigned upperLeftX
The column coordinate of the upper-left corner of the ROI.
Definition CommonTypes.h:75
Describes a value range.
Definition CommonTypes.h:29
Describes a two-dimensional size with a width and a height using double-precision floating-point numb...
Definition CommonTypes.h:54
Describes a two-dimensional size with a width and a height.
Definition CommonTypes.h:40