ifm3d
distance_image_info.h
1 /*
2  * Copyright 2022-present ifm electronic, gmbh
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #ifndef IFM3D_DISTANCE_IMAGE_INFO_H
6 #define IFM3D_DISTANCE_IMAGE_INFO_H
7 
8 #include <cstddef>
9 #include <cstdint>
10 #include <vector>
11 #include <ifm3d/fg/buffer.h>
12 #include <memory>
13 
14 #include <ifm3d/fg/frame_grabber_export.h>
15 
16 namespace ifm3d
17 {
18  constexpr auto CHUNK_SIZE_INFO_OFFSET = 4;
19  constexpr auto HEADER_SIZE_INFO_OFFSET = 8;
20  constexpr auto HEADER_VERSION_INFO_OFFSET = 12;
21  constexpr auto DISTANCE_IMAGE_INFO_DATA_SIZE = 360;
22 
23  constexpr auto NR_MODEL_PARAMS = 32;
24  constexpr auto AMPL_NORM_FACTOR_VECTOR_SIZE = 3;
25  constexpr auto EXTR_OPTIC_USER_VECTOR_SIZE = 6;
26 
27  enum class extrinsic_param : std::uint32_t
28  {
29  TRANS_X = 0, // Translation along x-direction in meters.
30  TRANS_Y = 1, // Translation along y-direction in meters.
31  TRANS_Z = 2, // Translation along Z-direction in meters.
32  ROT_X = 3, // Rotation along x-axis in radians. Positive values indicate
33  // clockwise rotation.
34  ROT_Y = 4, // Rotation along y-axis in radians. Positive values indicate
35  // clockwise rotation.
36  ROT_Z = 5 // Rotation along z-axis in radians. Positive values indicate
37  // clockwise rotation.
38  };
39 
41  {
42  uint32_t model_iD;
43  float model_parameters[NR_MODEL_PARAMS];
44  };
45 
46  class IFM3D_FRAME_GRABBER_EXPORT DistanceImageInfo
47  {
48  const float dist_resolution;
49  const float ampl_resolution;
50  const std::vector<float> amp_norm_factors;
51  const std::vector<float> extrinsic_optic_to_user;
52  const IntrinsicCalibration intrinsic_calibration;
53  const IntrinsicCalibration inverse_intrinsic_calibration;
54  const std::vector<std::uint16_t> u16_distance_buffer;
55  const std::vector<std::uint16_t> u16_amplitude_buffer;
56  const std::uint32_t width, height;
57  const std::vector<uint64_t> timestamps_nsec;
58  const std::vector<float> exposure_times_sec;
59 
60  public:
61  DistanceImageInfo(const float dist_res,
62  const float ampl_res,
63  const std::vector<float>& amp_norm_fctrs,
64  const std::vector<float>& extr_opt_to_usr,
65  const IntrinsicCalibration& intr_calib,
66  const IntrinsicCalibration& inv_intr_calib,
67  const std::vector<std::uint16_t>& distance_buffer,
68  const std::vector<std::uint16_t>& amplitude_buffer,
69  const std::vector<uint64_t>& timestamps_nsec,
70  const std::vector<float>& exposure_times_sec,
71  const std::uint32_t width,
72  const std::uint32_t height);
73  ~DistanceImageInfo() = default;
74  std::vector<std::uint8_t> getXYZDVector();
75  std::vector<std::uint8_t> getAmplitudeVector();
76 
77  auto
78  getExtrinsicOpticToUser()
79  {
80  return extrinsic_optic_to_user;
81  }
82 
83  auto
84  getIntrinsicCalibration()
85  {
86  return intrinsic_calibration;
87  }
88 
89  auto
90  getInverseIntrinsicCalibration()
91  {
92  return inverse_intrinsic_calibration;
93  }
94  auto
95  getNPTS()
96  {
97  return (width * height);
98  }
99  auto
100  getWidth()
101  {
102  return width;
103  }
104  auto
105  getHeight()
106  {
107  return height;
108  }
109 
113  std::vector<uint64_t>
115  {
116  return timestamps_nsec;
117  }
118 
123  std::vector<float>
125  {
126  return exposure_times_sec;
127  }
128 
133  ifm3d::Buffer applyDistanceResolution(
134  const ifm3d::Buffer& ui16_distance_buffer);
135  };
136  using DistanceImageInfoPtr = std::unique_ptr<DistanceImageInfo>;
137  IFM3D_FRAME_GRABBER_EXPORT DistanceImageInfoPtr
138  CreateDistanceImageInfo(const std::vector<std::uint8_t>& data_buffer,
139  const std::size_t distimageinfo_idx,
140  const std::size_t dist_idx,
141  const std::size_t amp_idx,
142  const std::uint32_t width,
143  const std::uint32_t height);
144 } // end: namespace ifm3d
145 
146 #endif // IFM3D_DISTANCE_IMAGE_INFO_H
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::DistanceImageInfo::getTimestamps
std::vector< uint64_t > getTimestamps()
returns the timestamps in nano seconds
Definition: distance_image_info.h:114
ifm3d::DistanceImageInfo::getExposureTimes
std::vector< float > getExposureTimes()
return the exposure time for each phase data
Definition: distance_image_info.h:124
ifm3d::DistanceImageInfo
Definition: distance_image_info.h:46
ifm3d::IntrinsicCalibration
Definition: distance_image_info.h:40