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