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 <chrono>
12 #include <ifm3d/device/device.h>
13 #include <ifm3d/device/err.h>
14 #include <ifm3d/fg/organizer_utils.h>
15 #include <ifm3d/fg/buffer.h>
16 #include <ifm3d/deserialize/deserialize_utils.hpp>
17 #include <ifm3d/deserialize/struct_calibration.hpp>
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  void
45  Read(const uint8_t* data, size_t size)
46  {
47  if (size < tof_info_v3_size)
48  {
49  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
50  }
51  const uint8_t* start_ptr = data;
52  version = mkval<std::uint32_t>(start_ptr + TOF_INFO_VERSION_INDEX);
53  distance_resolution =
54  mkval<float>(start_ptr + TOF_INFO_DISTANCE_RESOLUTION_INDEX);
55  amplitude_resolution =
56  mkval<float>(start_ptr + TOF_INFO_AMPLITUDE_RESOLUTION_INDEX);
57  mkarray<float, 3>(start_ptr + TOF_INFO_AMPLITUDE_NORM_FACTOR_INDEX,
58  amp_normalization_factors);
59  extrinsic_optic_to_user.Read(start_ptr +
60  TOF_INFO_EXTRINSIC_OPTICAL_TO_USER_INDEX);
61  intrinsic_calibration.Read(start_ptr +
62  TOF_INFO_INTRINSIC_CALIBRATION_INDEX);
63  inverse_intrinsic_calibration.Read(
64  start_ptr + TOF_INFO_INVERSE_INTRINSIC_CALIBRATION_INDEX);
65  mkarray<uint64_t, 3>(start_ptr + TOF_INFO_EXPOSURE_TIMESTAMPS_INDEX,
66  exposure_timestamps_ns);
67  mkarray<uint32_t, 3>(start_ptr + TOF_INFO_EXPOSURE_TIMES_INDEX,
68  exposure_times_s);
69  illu_temperature =
70  mkval<float>(start_ptr + TOF_INFO_ILLUTEMPERATURE_INDEX);
71  mkarray<char, 32>(start_ptr + TOF_INFO_MODE_INDEX, mode);
72  mkarray<char, 32>(start_ptr + TOF_INFO_IMAGER_INDEX, imager);
73  };
74  /*@brief Version of the TOF_INFO data */
75  uint32_t version;
76  /*@brief Resolution of distance buffer per digit[m]*/
77  float distance_resolution;
78  /*@brief Resolution of the amplitude buffer*/
79  float amplitude_resolution;
80  /*@brief Amplitude normalization factors for the individual exposure
81  * times*/
82  std::array<float, 3> amp_normalization_factors;
83  /*@brief Extrinsic optic parameter to user*/
84  calibration::ExtrinsicOpticToUser extrinsic_optic_to_user;
85  /*@brief Intrinsic calibration parameters*/
86  calibration::IntrinsicCalibration intrinsic_calibration;
87  /*@brief Inverse intrinsic calibration parameters*/
88  calibration::InverseIntrinsicCalibration inverse_intrinsic_calibration;
89  /*@brief The timestamp of the individual exposure time [nano seconds]*/
90  std::array<uint64_t, 3> exposure_timestamps_ns;
91  /*@brief Actual exposure times of a single phase image [seconds].*/
92  std::array<uint32_t, 3> exposure_times_s;
93  /*@brief Illumination temperature*/
94  float illu_temperature;
95  /*@brief Mode of the head*/
96  std::array<char, 32> mode;
97  /*@brief Imager type*/
98  std::array<char, 32> imager;
99  /*@brief TOF_INFO data size in bytes*/
100  const size_t tof_info_v3_size = 416;
101 
102  static TOFInfoV3
103  Deserialize(const Buffer& tof_info_buffer)
104  {
105  TOFInfoV3 tof_info_v3;
106 
107  tof_info_v3.Read(tof_info_buffer.ptr<uint8_t>(0),
108  tof_info_buffer.size());
109  return tof_info_v3;
110  }
111  };
112 } // end namespace ifm3d
113 
114 #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:38
ifm3d::Error
Definition: err.h:117
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:48