SRSDK  0.10.39
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "leia/common/api.h"
4#include "leia/common/types.h"
5
6#include <string_view>
7#include <string>
8#include <array>
9
10namespace leia {
11
17
19};
20
25
27};
28
32};
33
39
42{
43 switch (backend)
44 {
46 return "kLeiaFaceDetectorBackendCPU";
48 return "kLeiaFaceDetectorBackendGPU";
50 return "kLeiaFaceDetectorBackendDSP";
51 default:
52 return "kLeiaFaceDetectorBackendUnknown";
53 }
54}
57{
58 switch (backend)
59 {
61 return "CPU";
63 return "GPU";
65 return "DSP";
66 default:
67 return "Unknown";
68 }
69}
72{
73 switch (inputType)
74 {
76 return "kLeiaFaceDetectorInputTypeCPU";
78 return "kLeiaFaceDetectorInputTypeGPU";
79 default:
80 return "kLeiaFaceDetectorInputTypeUnknown";
81 }
82}
85{
86 switch (inputType)
87 {
89 return "CPU";
91 return "GPU";
92 default:
93 return "Unknown";
94 }
95}
97LEIA_FORCE_INLINE const char* ToUiStr(Orientation orientation)
98{
99 return leia_orientation_to_ui_str(orientation);
100}
101
102inline bool FromStr(std::string_view const& str, Orientation* out)
103{
104 if (str == "Landscape")
105 {
107 }
108 else if (str == "Portrait")
109 {
111 }
112 else if (str == "ReverseLandscape")
113 {
115 }
116 else if (str == "ReversePortrait")
117 {
119 }
120 else
121 {
122 return false;
123 }
124 return true;
125}
126
127inline constexpr bool IsValid(Orientation orientation)
128{
129 return orientation >= LEIA_ORIENTATION_LANDSCAPE && orientation <= LEIA_ORIENTATION_REVERSE_PORTRAIT;
130}
131
132inline constexpr int32_t GetRelativeClockwiseAngle(Orientation from, Orientation to)
133{
134 if (!IsValid(from) || !IsValid(to))
135 {
136 return 0;
137 }
138
139 int32_t numSteps = 0;
140 int32_t it = int32_t(from);
141 int32_t end = int32_t(to);
142 while (it != end)
143 {
144 it = (it + 1) % LEIA_ORIENTATION_COUNT;
145 numSteps++;
146 }
147 return numSteps * 90;
148}
149
154
155// Want to keep it trivially copyable, so using this struct instead of std::string.
156struct CameraID {
157 enum {
158 kMaxSize = 16
159 };
160
162 {
163 std::memset(v, 0, sizeof(v));
164 }
165 CameraID(int id) : CameraID()
166 {
167 std::string str = std::to_string(id);
168 std::memcpy(v, str.data(), std::min(str.size(), sizeof(v)));
169 }
170 CameraID(std::string_view const& str) : CameraID()
171 {
172 std::memcpy(v, str.data(), std::min(str.size(), sizeof(v)));
173 }
174
175 explicit operator std::string_view() const
176 {
177 return {v, strnlen(v, sizeof(v))};
178 }
179 explicit operator bool() const
180 {
181 return *v != '\0';
182 }
183 bool operator==(CameraID const& rhs) const
184 {
185 return std::string_view{*this} == std::string_view{rhs};
186 }
187
188private:
189 char v[kMaxSize];
190};
191static_assert(std::is_trivially_copyable_v<CameraID>);
192
193struct Camera {
197 std::array<float, 3> translation;
198 std::array<float, 3> rotation;
200};
201
204 Camera* camera = nullptr;
205 int32_t width;
206 int32_t height;
207 int32_t fps;
208 std::array<float, 4> filterParams;
210};
211
212} // namespace leia
LEIA_NODISCARD const char * leia_orientation_to_ui_str(enum leia_orientation orientation)
Definition types.h:130
leia_orientation
Definition types.h:108
@ LEIA_ORIENTATION_LANDSCAPE
Definition types.h:110
@ LEIA_ORIENTATION_UNSPECIFIED
Definition types.h:109
@ LEIA_ORIENTATION_REVERSE_PORTRAIT
Definition types.h:113
@ LEIA_ORIENTATION_COUNT
Definition types.h:114
@ LEIA_ORIENTATION_PORTRAIT
Definition types.h:111
@ LEIA_ORIENTATION_REVERSE_LANDSCAPE
Definition types.h:112
leia_timestamp_space
Definition types.h:16
#define LEIA_FORCE_INLINE
Definition defines.h:56
#define LEIA_NODISCARD
Definition defines.h:86
Definition types.hpp:10
FaceDetectorBackend
Definition types.hpp:12
@ kLeiaFaceDetectorBackendGPU
Definition types.hpp:15
@ kNumLeiaFaceDetectorBackends
Definition types.hpp:18
@ kLeiaFaceDetectorBackendUnknown
Definition types.hpp:13
@ kLeiaFaceDetectorBackendDSP
Definition types.hpp:16
@ kLeiaFaceDetectorBackendCPU
Definition types.hpp:14
LEIA_NODISCARD LEIA_FORCE_INLINE const char * ToStr(FaceDetectorBackend backend)
Definition types.hpp:41
constexpr int32_t GetRelativeClockwiseAngle(Orientation from, Orientation to)
Definition types.hpp:132
LEIA_NODISCARD LEIA_FORCE_INLINE const char * ToUiStr(FaceDetectorBackend backend)
Definition types.hpp:56
constexpr bool IsValid(Orientation orientation)
Definition types.hpp:127
FaceDetectorInputType
Definition types.hpp:21
@ kLeiaFaceDetectorInputTypeUnknown
Definition types.hpp:22
@ kLeiaFaceDetectorInputTypeGPU
Definition types.hpp:24
@ kNumLeiaFaceDetectorInputTypes
Definition types.hpp:26
@ kLeiaFaceDetectorInputTypeCPU
Definition types.hpp:23
bool FromStr(std::string_view const &str, Orientation *out)
Definition types.hpp:102
Definition types.hpp:193
std::array< float, 3 > rotation
Definition types.hpp:198
std::array< float, 3 > translation
Definition types.hpp:197
CameraID id
Definition types.hpp:194
struct leia_camera_intrinsics intrinsics
Definition types.hpp:199
Orientation sensorOrientation
Definition types.hpp:196
bool frontFacing
Definition types.hpp:195
Definition types.hpp:156
bool operator==(CameraID const &rhs) const
Definition types.hpp:183
CameraID(std::string_view const &str)
Definition types.hpp:170
CameraID()
Definition types.hpp:161
@ kMaxSize
Definition types.hpp:158
CameraID(int id)
Definition types.hpp:165
Definition types.hpp:29
enum FaceDetectorInputType inputType
Definition types.hpp:31
enum FaceDetectorBackend backend
Definition types.hpp:30
Definition types.hpp:202
int32_t width
Definition types.hpp:205
CameraID cameraId
Definition types.hpp:203
int32_t height
Definition types.hpp:206
int32_t fps
Definition types.hpp:207
std::array< float, 4 > filterParams
Definition types.hpp:208
float headPoseZLowPassAlpha
Definition types.hpp:209
Camera * camera
Definition types.hpp:204
Definition types.h:48
Definition types.h:38
Definition types.h:33