ifm3d
struct_rgb_info_v1.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_RGB_INFO_V1_HPP
8 #define IFM3D_DESERIALIZE_STRUCT_RGB_INFO_V1_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 RGB_INFO_VERSION_INDEX = 0x0000;
24  constexpr auto RGB_INFO_FRAME_COUNTER_INDEX = 0x0004;
25  constexpr auto RGB_INFO_TIMESTAMPS_INDEX = 0x0008;
26  constexpr auto RGB_INFO_EXPOSURE_TIMES_INDEX = 0x0010;
27  constexpr auto RGB_INFO_EXTRINSIC_OPTICAL_TO_USER_INDEX = 0x0014;
28  constexpr auto RGB_INFO_INTRINSIC_CALIBRATION_INDEX = 0x002C;
29  constexpr auto RGB_INFO_INVERSE_INTRINSIC_CALIBRATION_INDEX = 0x00B0;
30  };
31 
33  class RGBInfoV1
34  {
35 
36  public:
37  using Ptr = std::shared_ptr<RGBInfoV1>;
38 
39  void
40  Read(const uint8_t* data, size_t size)
41  {
42  if (size < rgb_info_v1_size)
43  {
44  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
45  }
46  const uint8_t* start_ptr = data;
47  version = mkval<std::uint32_t>(start_ptr + RGB_INFO_VERSION_INDEX);
48  frame_counter =
49  mkval<std::uint32_t>(start_ptr + RGB_INFO_FRAME_COUNTER_INDEX);
50  timestamp_ns =
51  mkval<std::uint64_t>(start_ptr + RGB_INFO_TIMESTAMPS_INDEX);
52  exposure_time = mkval<float>(start_ptr + RGB_INFO_EXPOSURE_TIMES_INDEX);
53  extrinsic_optic_to_user.Read(start_ptr +
54  RGB_INFO_EXTRINSIC_OPTICAL_TO_USER_INDEX);
55  intrinsic_calibration.Read(start_ptr +
56  RGB_INFO_INTRINSIC_CALIBRATION_INDEX);
57  inverse_intrinsic_calibration.Read(
58  start_ptr + RGB_INFO_INVERSE_INTRINSIC_CALIBRATION_INDEX);
59  };
60  /*@brief Version of the RGB_INFO data*/
61  std::uint32_t version;
62  /*@brief Frame count, The frame counter is initialized to 0 at the
63  * initialization */
64  std::uint32_t frame_counter;
65  /*@brief The timestamp of the 2D image, given in nano second*/
66  std::uint64_t timestamp_ns;
67  /*@brief Actual exposure time of the 2D image*/
68  float exposure_time;
69  /*@brief Extrinsic optic paramter of the 2D head*/
70  calibration::ExtrinsicOpticToUser extrinsic_optic_to_user;
71  /*@brief Intrinsic Calibration parameters*/
72  calibration::IntrinsicCalibration intrinsic_calibration;
73  /*@brief Inverse intrinsic Calibration parameters*/
74  calibration::InverseIntrinsicCalibration inverse_intrinsic_calibration;
75  /*@brief Size of RGB_INFO in bytes*/
76  const size_t rgb_info_v1_size = 308;
77 
78  static RGBInfoV1
79  Deserialize(const Buffer& rgb_info_buffer)
80  {
81  RGBInfoV1 rgb_info_v1;
82 
83  rgb_info_v1.Read(rgb_info_buffer.ptr<uint8_t>(0),
84  rgb_info_buffer.size());
85  return rgb_info_v1;
86  }
87  };
88 } // end namespace ifm3d
89 
90 #endif // IFM3D_DESERIALIZE_STRUCT_RGB_INFO_V1_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::RGBInfoV1
Definition: struct_rgb_info_v1.hpp:33
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