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 <ifm3d/device/device.h>
11 #include <ifm3d/device/err.h>
12 #include <ifm3d/fg/organizer_utils.h>
13 #include <ifm3d/fg/buffer.h>
14 #include <ifm3d/deserialize/deserialize_utils.hpp>
15 #include <ifm3d/deserialize/struct_calibration.hpp>
16 
17 namespace ifm3d
18 {
19  namespace
20  {
21  constexpr auto RGB_INFO_VERSION_INDEX = 0x0000;
22  constexpr auto RGB_INFO_FRAME_COUNTER_INDEX = 0x0004;
23  constexpr auto RGB_INFO_TIMESTAMPS_INDEX = 0x0008;
24  constexpr auto RGB_INFO_EXPOSURE_TIMES_INDEX = 0x0010;
25  constexpr auto RGB_INFO_EXTRINSIC_OPTICAL_TO_USER_INDEX = 0x0014;
26  constexpr auto RGB_INFO_INTRINSIC_CALIBRATION_INDEX = 0x002C;
27  constexpr auto RGB_INFO_INVERSE_INTRINSIC_CALIBRATION_INDEX = 0x00B0;
28  };
29 
31  class RGBInfoV1
32  {
33 
34  public:
35  using Ptr = std::shared_ptr<RGBInfoV1>;
36 
37  static bool
38  IsValid(const uint8_t* data, size_t size)
39  {
40  uint32_t version = mkval<std::uint32_t>(data + RGB_INFO_VERSION_INDEX);
41 
42  if (size < rgb_info_v1_size || version < 1)
43  {
44  return false;
45  }
46  return true;
47  }
48 
49  void
50  Read(const uint8_t* data, size_t size)
51  {
52  if (!IsValid(data, size))
53  {
54  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
55  }
56  const uint8_t* start_ptr = data;
57  version = mkval<std::uint32_t>(start_ptr + RGB_INFO_VERSION_INDEX);
58  frame_counter =
59  mkval<std::uint32_t>(start_ptr + RGB_INFO_FRAME_COUNTER_INDEX);
60  timestamp_ns =
61  mkval<std::uint64_t>(start_ptr + RGB_INFO_TIMESTAMPS_INDEX);
62  exposure_time = mkval<float>(start_ptr + RGB_INFO_EXPOSURE_TIMES_INDEX);
63  extrinsic_optic_to_user.Read(start_ptr +
64  RGB_INFO_EXTRINSIC_OPTICAL_TO_USER_INDEX);
65  intrinsic_calibration.Read(start_ptr +
66  RGB_INFO_INTRINSIC_CALIBRATION_INDEX);
67  inverse_intrinsic_calibration.Read(
68  start_ptr + RGB_INFO_INVERSE_INTRINSIC_CALIBRATION_INDEX);
69  };
70  /*@brief Version of the RGB_INFO data*/
71  std::uint32_t version;
72  /*@brief Frame count, The frame counter is initialized to 0 at the
73  * initialization */
74  std::uint32_t frame_counter;
75  /*@brief The timestamp of the 2D image, given in nano second*/
76  std::uint64_t timestamp_ns;
77  /*@brief Actual exposure time of the 2D image*/
78  float exposure_time;
79  /*@brief Extrinsic optic paramter of the 2D head*/
80  calibration::ExtrinsicOpticToUser extrinsic_optic_to_user;
81  /*@brief Intrinsic Calibration parameters*/
82  calibration::IntrinsicCalibration intrinsic_calibration;
83  /*@brief Inverse intrinsic Calibration parameters*/
84  calibration::InverseIntrinsicCalibration inverse_intrinsic_calibration;
85  /*@brief Size of RGB_INFO in bytes*/
86  static constexpr size_t rgb_info_v1_size = 308;
87 
88  static RGBInfoV1
89  Deserialize(const Buffer& rgb_info_buffer)
90  {
91  RGBInfoV1 rgb_info_v1;
92 
93  rgb_info_v1.Read(rgb_info_buffer.ptr<uint8_t>(0),
94  rgb_info_buffer.size());
95  return rgb_info_v1;
96  }
97  };
98 } // end namespace ifm3d
99 
100 #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:99
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:31
ifm3d::Error
Definition: err.h:114
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