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/deserialize/deserialize_utils.hpp>
11 #include <ifm3d/deserialize/struct_calibration.hpp>
12 #include <ifm3d/device/device.h>
13 #include <ifm3d/device/err.h>
14 #include <ifm3d/fg/buffer.h>
15 #include <ifm3d/fg/organizer_utils.h>
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  auto version = mkval<std::uint32_t>(data + RGB_INFO_VERSION_INDEX);
41 
42  return size >= RGB_INFO_V1_SIZE && version >= 1;
43  }
44 
45  void
46  Read(const uint8_t* data, size_t size)
47  {
48  if (!IsValid(data, size))
49  {
50  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
51  }
52  const uint8_t* start_ptr = data;
53  version = mkval<std::uint32_t>(start_ptr + RGB_INFO_VERSION_INDEX);
54  frame_counter =
55  mkval<std::uint32_t>(start_ptr + RGB_INFO_FRAME_COUNTER_INDEX);
56  timestamp_ns =
57  mkval<std::uint64_t>(start_ptr + RGB_INFO_TIMESTAMPS_INDEX);
58  exposure_time = mkval<float>(start_ptr + RGB_INFO_EXPOSURE_TIMES_INDEX);
59  extrinsic_optic_to_user.Read(start_ptr +
60  RGB_INFO_EXTRINSIC_OPTICAL_TO_USER_INDEX);
61  intrinsic_calibration.Read(start_ptr +
62  RGB_INFO_INTRINSIC_CALIBRATION_INDEX);
63  inverse_intrinsic_calibration.Read(
64  start_ptr + RGB_INFO_INVERSE_INTRINSIC_CALIBRATION_INDEX);
65  };
66  /*@brief Version of the RGB_INFO data*/
67  std::uint32_t version;
68  /*@brief Frame count, The frame counter is initialized to 0 at the
69  * initialization */
70  std::uint32_t frame_counter;
71  /*@brief The timestamp of the 2D image, given in nano second*/
72  std::uint64_t timestamp_ns;
73  /*@brief Actual exposure time of the 2D image*/
74  float exposure_time;
75  /*@brief Extrinsic optic paramter of the 2D head*/
76  calibration::ExtrinsicOpticToUser extrinsic_optic_to_user;
77  /*@brief Intrinsic Calibration parameters*/
78  calibration::IntrinsicCalibration intrinsic_calibration;
79  /*@brief Inverse intrinsic Calibration parameters*/
80  calibration::InverseIntrinsicCalibration inverse_intrinsic_calibration;
81  /*@brief Size of RGB_INFO in bytes*/
82  static constexpr size_t RGB_INFO_V1_SIZE = 308;
83 
84  static RGBInfoV1
85  Deserialize(const Buffer& rgb_info_buffer)
86  {
87  RGBInfoV1 rgb_info_v1{};
88 
89  rgb_info_v1.Read(rgb_info_buffer.Ptr<uint8_t>(0),
90  rgb_info_buffer.Size());
91  return rgb_info_v1;
92  }
93  };
94 } // end namespace ifm3d
95 
96 #endif // IFM3D_DESERIALIZE_STRUCT_RGB_INFO_V1_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::RGBInfoV1
Definition: struct_rgb_info_v1.hpp:31
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