MYNT EYE D SDK  1.7.1
http://www.myntai.com/mynteye/depth
types_data.h
1 // Copyright 2018 Slightech Co., Ltd. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #ifndef MYNTEYE_TYPES_DATA_H_
15 #define MYNTEYE_TYPES_DATA_H_
16 #pragma once
17 
18 #include <algorithm>
19 #include <bitset>
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "mynteyed/device/image.h"
26 #include "mynteyed/stubs/types_calib.h"
27 
28 MYNTEYE_BEGIN_NAMESPACE
29 
34 struct MYNTEYE_API ImgInfo {
36  std::uint16_t frame_id;
37 
39  std::uint32_t timestamp;
40 
42  std::uint16_t exposure_time;
43 
44  void Reset() {
45  frame_id = 0;
46  timestamp = 0;
47  exposure_time = 0;
48  }
49 
50  ImgInfo() {
51  Reset();
52  }
53  ImgInfo(const ImgInfo &other) {
54  frame_id = other.frame_id;
55  timestamp = other.timestamp;
56  exposure_time = other.exposure_time;
57  }
58  ImgInfo &operator=(const ImgInfo &other) {
59  frame_id = other.frame_id;
60  timestamp = other.timestamp;
61  exposure_time = other.exposure_time;
62  return *this;
63  }
64 };
65 
66 #define MYNTEYE_IMU_ACCEL 1
67 #define MYNTEYE_IMU_GYRO 2
68 
73 struct MYNTEYE_API ImuData {
79  std::uint8_t flag;
80 
82  std::uint64_t timestamp;
83 
85  double temperature;
86 
88  double accel[3];
89 
91  double gyro[3];
92 
93  void Reset() {
94  flag = 0;
95  timestamp = 0;
96  temperature = 0;
97  std::fill(accel, accel + 3, 0);
98  std::fill(gyro, gyro + 3, 0);
99  }
100 
101  ImuData() {
102  Reset();
103  }
104 };
105 
110 struct MYNTEYE_API StreamData {
112  std::shared_ptr<Image> img;
114  std::shared_ptr<ImgInfo> img_info;
115 
116  bool operator==(const StreamData& other) const {
117  if (img_info && other.img_info) {
118  return img_info->frame_id == other.img_info->frame_id &&
119  img_info->timestamp == other.img_info->timestamp;
120  }
121  return false;
122  }
123 };
124 
129 struct MYNTEYE_API MotionData {
131  std::shared_ptr<ImuData> imu;
132 
133  bool operator==(const MotionData &other) const {
134  if (imu && other.imu) {
135  return imu->flag == other.imu->flag &&
136  imu->timestamp == other.imu->timestamp;
137  }
138  return false;
139  }
140 };
141 
142 
143 #define MYNTEYE_PROPERTY(TYPE, NAME) \
144  public: \
145  void set_##NAME(TYPE NAME) { NAME##_ = NAME; } \
146  TYPE NAME() const { return NAME##_; } \
147  private: \
148  TYPE NAME##_; \
149 
150 
153 class MYNTEYE_API Version {
154  public:
155  using size_t = std::size_t;
156  using value_t = std::uint8_t;
157 
158  Version() = default;
159  Version(value_t major, value_t minor) : major_(major), minor_(minor) {}
160  explicit Version(const std::string &name)
161  : major_(parse_part(name, 0)), minor_(parse_part(name, 1)) {}
162  virtual ~Version() {}
163 
164  bool operator==(const Version &other) const {
165  return major_ == other.major_ && minor_ == other.minor_;
166  }
167  bool operator<=(const Version &other) const {
168  if (major_ < other.major_)
169  return true;
170  if (major_ > other.major_)
171  return false;
172  return minor_ <= other.minor_;
173  }
174  bool operator!=(const Version &other) const {
175  return !(*this == other);
176  }
177  bool operator<(const Version &other) const {
178  return !(*this == other) && (*this <= other);
179  }
180  bool operator>(const Version &other) const {
181  return !(*this <= other);
182  }
183  bool operator>=(const Version &other) const {
184  return (*this == other) || (*this > other);
185  }
186  bool is_between(const Version &from, const Version &until) {
187  return (from <= *this) && (*this <= until);
188  }
189 
190  std::string to_string() const;
191 
192  static std::vector<std::string> split(const std::string &s);
193  static value_t parse_part(const std::string &name, size_t part);
194 
195  MYNTEYE_PROPERTY(value_t, major)
196  MYNTEYE_PROPERTY(value_t, minor)
197 };
198 
202 class MYNTEYE_API HardwareVersion : public Version {
203  public:
204  using flag_t = std::bitset<8>;
205 
206  HardwareVersion() = default;
207  HardwareVersion(value_t major, value_t minor, value_t flag = 0)
208  : Version(major, minor), flag_(flag) {}
209  explicit HardwareVersion(const std::string &name, value_t flag = 0)
210  : Version(parse_part(name, 0), parse_part(name, 1)), flag_(flag) {}
211 
212  MYNTEYE_PROPERTY(flag_t, flag)
213 };
214 
218 class MYNTEYE_API Type {
219  public:
220  using size_t = std::size_t;
221  using value_t = std::uint16_t;
222 
223  Type() = default;
224  Type(value_t vendor, value_t product) : vendor_(vendor), product_(product) {}
225  explicit Type(const std::string &name)
226  : vendor_(parse_part(name, 0, 2)), product_(parse_part(name, 2, 2)) {}
227  virtual ~Type() {}
228 
229  std::string to_string() const;
230  static value_t parse_part(const std::string &name, size_t pos, size_t count);
231 
232  MYNTEYE_PROPERTY(value_t, vendor)
233  MYNTEYE_PROPERTY(value_t, product)
234 };
235 
236 namespace device {
237 
242 struct MYNTEYE_API Descriptors {
243  bool ok;
244  std::string name;
245  std::string serial_number;
246  Version firmware_version;
247  HardwareVersion hardware_version;
248  Version spec_version;
249  Type lens_type;
250  Type imu_type;
251  std::uint16_t nominal_baseline;
252 };
253 
258 struct MYNTEYE_API ImuParams {
259  bool ok;
260  ImuIntrinsics in_accel;
261  ImuIntrinsics in_gyro;
262  Extrinsics ex_left_to_imu;
263 };
264 
265 } // namespace device
266 
267 MYNTEYE_END_NAMESPACE
268 
269 #endif // MYNTEYE_TYPES_DATA_H_
Version.
Definition: types_data.h:153
Extrinsics, represent how the different datas are connected.
Definition: types_calib.h:119
std::uint32_t timestamp
Image timestamp.
Definition: types_data.h:39
std::shared_ptr< ImgInfo > img_info
Image information.
Definition: types_data.h:114
Device descriptors.
Definition: types_data.h:242
std::uint16_t frame_id
Image frame id.
Definition: types_data.h:36
double temperature
temperature
Definition: types_data.h:85
Stream data.
Definition: types_data.h:110
Device imu paramters.
Definition: types_data.h:258
std::shared_ptr< ImuData > imu
ImuData.
Definition: types_data.h:131
Type.
Definition: types_data.h:218
Imu data.
Definition: types_data.h:73
std::uint16_t exposure_time
Image exposure time.
Definition: types_data.h:42
Hardware version.
Definition: types_data.h:202
Image information.
Definition: types_data.h:34
std::shared_ptr< Image > img
Image data.
Definition: types_data.h:112
std::uint64_t timestamp
Imu gyroscope or accelerometer or frame timestamp.
Definition: types_data.h:82
std::uint8_t flag
Data type MYNTEYE_IMU_ACCEL: accelerometer MYNTEYE_IMU_GYRO: gyroscope.
Definition: types_data.h:79
Motion data.
Definition: types_data.h:129
IMU intrinsics: scale, drift and variances.
Definition: types_calib.h:66