ifm3d
struct_tof_info_v3.hpp
1 // -*- c++ -*-
2 /*
3  * Copyright 2022-present ifm electronic, gmbh
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef IFM3D_DESERIALIZE_STRUCT_TOF_INFO_V3_HPP
8 #define IFM3D_DESERIALIZE_STRUCT_TOF_INFO_V3_HPP
9 
10 #include <array>
11 #include <string>
12 #include <chrono>
13 #include <ifm3d/device/device.h>
14 #include <ifm3d/device/err.h>
15 #include <ifm3d/fg/organizer_utils.h>
16 #include <ifm3d/fg/buffer.h>
17 #include <ifm3d/deserialize/deserialize_utils.hpp>
18 #include <ifm3d/deserialize/struct_calibration.hpp>
19 
20 namespace ifm3d
21 {
22  namespace
23  {
24  constexpr auto TOF_INFO_VERSION_INDEX = 0x0000;
25  constexpr auto TOF_INFO_DISTANCE_RESOLUTION_INDEX = 0x0004;
26  constexpr auto TOF_INFO_AMPLITUDE_RESOLUTION_INDEX = 0x0008;
27  constexpr auto TOF_INFO_AMPLITUDE_NORM_FACTOR_INDEX = 0x000C;
28  constexpr auto TOF_INFO_EXTRINSIC_OPTICAL_TO_USER_INDEX = 0x0018;
29  constexpr auto TOF_INFO_INTRINSIC_CALIBRATION_INDEX = 0x0030;
30  constexpr auto TOF_INFO_INVERSE_INTRINSIC_CALIBRATION_INDEX = 0x00B4;
31  constexpr auto TOF_INFO_EXPOSURE_TIMESTAMPS_INDEX = 0x0138;
32  constexpr auto TOF_INFO_EXPOSURE_TIMES_INDEX = 0x0150;
33  constexpr auto TOF_INFO_ILLUTEMPERATURE_INDEX = 0x015C;
34  constexpr auto TOF_INFO_MODE_INDEX = 0x0160;
35  constexpr auto TOF_INFO_IMAGER_INDEX = 0x0180;
36  };
37 
39  class TOFInfoV3
40  {
41 
42  public:
43  using Ptr = std::shared_ptr<TOFInfoV3>;
44 
45  void
46  Read(const uint8_t* data, size_t size)
47  {
48  if (size < tof_info_v3_size)
49  {
50  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
51  }
52  const uint8_t* start_ptr = data;
53  std::array<char, 32> buff;
54  version = mkval<std::uint32_t>(start_ptr + TOF_INFO_VERSION_INDEX);
55  distance_resolution =
56  mkval<float>(start_ptr + TOF_INFO_DISTANCE_RESOLUTION_INDEX);
57  amplitude_resolution =
58  mkval<float>(start_ptr + TOF_INFO_AMPLITUDE_RESOLUTION_INDEX);
59  mkarray<float, 3>(start_ptr + TOF_INFO_AMPLITUDE_NORM_FACTOR_INDEX,
60  amp_normalization_factors);
61  extrinsic_optic_to_user.Read(start_ptr +
62  TOF_INFO_EXTRINSIC_OPTICAL_TO_USER_INDEX);
63  intrinsic_calibration.Read(start_ptr +
64  TOF_INFO_INTRINSIC_CALIBRATION_INDEX);
65  inverse_intrinsic_calibration.Read(
66  start_ptr + TOF_INFO_INVERSE_INTRINSIC_CALIBRATION_INDEX);
67  mkarray<uint64_t, 3>(start_ptr + TOF_INFO_EXPOSURE_TIMESTAMPS_INDEX,
68  exposure_timestamps_ns);
69  mkarray<float, 3>(start_ptr + TOF_INFO_EXPOSURE_TIMES_INDEX,
70  exposure_times_s);
71  illu_temperature =
72  mkval<float>(start_ptr + TOF_INFO_ILLUTEMPERATURE_INDEX);
73  mkarray<char, 32>(start_ptr + TOF_INFO_MODE_INDEX, buff);
74  mode = std::string(buff.begin(), buff.end());
75  buff.fill('\0');
76  mkarray<char, 32>(start_ptr + TOF_INFO_IMAGER_INDEX, buff);
77  imager = std::string(buff.begin(), buff.end());
78  buff.fill('\0');
79  };
80  /*@brief Version of the TOF_INFO data */
81  uint32_t version;
82  /*@brief Resolution of distance buffer per digit[m]*/
83  float distance_resolution;
84  /*@brief Resolution of the amplitude buffer*/
85  float amplitude_resolution;
86  /*@brief Amplitude normalization factors for the individual exposure
87  * times*/
88  std::array<float, 3> amp_normalization_factors;
89  /*@brief Extrinsic optic parameter to user*/
90  calibration::ExtrinsicOpticToUser extrinsic_optic_to_user;
91  /*@brief Intrinsic calibration parameters*/
92  calibration::IntrinsicCalibration intrinsic_calibration;
93  /*@brief Inverse intrinsic calibration parameters*/
94  calibration::InverseIntrinsicCalibration inverse_intrinsic_calibration;
95  /*@brief The timestamp of the individual exposure time [nano seconds]*/
96  std::array<uint64_t, 3> exposure_timestamps_ns;
97  /*@brief Actual exposure times of a single phase image [seconds].*/
98  std::array<float, 3> exposure_times_s;
99  /*@brief Illumination temperature*/
100  float illu_temperature;
101  /*@brief Mode of the head*/
102  std::string mode;
103  /*@brief Imager type*/
104  std::string imager;
105  /*@brief TOF_INFO data size in bytes*/
106  const size_t tof_info_v3_size = 416;
107 
108  static TOFInfoV3
109  Deserialize(const Buffer& tof_info_buffer)
110  {
111  TOFInfoV3 tof_info_v3;
112 
113  tof_info_v3.Read(tof_info_buffer.ptr<uint8_t>(0),
114  tof_info_buffer.size());
115  return tof_info_v3;
116  }
117  };
118 } // end namespace ifm3d
119 
120 #endif // IFM3D_DESERIALIZE_STRUCT_TOF_INFO_V3_HPP
ifm3d::Buffer::size
size_t size() const
Return the size of the buffer in bytes.
ifm3d::Buffer
The class Buffer represent a STL container to store data from the ifm devices in 2 dimension and supp...
Definition: buffer.h:98
ifm3d::Buffer::ptr
T * ptr(const std::uint32_t row)
returns a pointer to the specified Buffer row.
ifm3d::TOFInfoV3
Definition: struct_tof_info_v3.hpp:39
ifm3d::Error
Definition: err.h:112
ifm3d::calibration::ExtrinsicOpticToUser
All items are given in SI units, i.e. transXYZ are in [m] and rotXYZ are in [rad].
Definition: struct_calibration.hpp:24
ifm3d::calibration::Calibration
Definition: struct_calibration.hpp:61