ifm3d
struct_o3r_ods_polar_occupancy_grid_v1.hpp
1 // -*- c++ -*-
2 /*
3  * Copyright 2025-present ifm electronic, gmbh
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef IFM3D_DESERIALIZE_STRUCT_O3R_ODS_POLAR_OCCUPANCY_GRID_V1_HPP
8 #define IFM3D_DESERIALIZE_STRUCT_O3R_ODS_POLAR_OCCUPANCY_GRID_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 
18 namespace ifm3d
19 {
20  namespace
21  {
22  constexpr auto ODS_POLAR_OCCUPANCY_GRID_VERSION_INDEX = 0x0000;
23  constexpr auto ODS_POLAR_OCCUPANCY_GRID_POLAR_OCC_GRID_INDEX = 0x0004;
24  constexpr auto ARRAY_SIZE = 675;
25  };
26 
29  {
30  public:
31  using Ptr = std::shared_ptr<ODSPolarOccupancyGridV1>;
32 
33  void
34  Read(const uint8_t* start_ptr, size_t size)
35  {
36  if (size < ods_polar_occupancy_grid_v1_minimum_size)
37  {
38  throw ifm3d::Error(IFM3D_CORRUPTED_STRUCT);
39  }
40 
41  version = mkval<std::uint32_t>(start_ptr +
42  ODS_POLAR_OCCUPANCY_GRID_VERSION_INDEX);
43  mkarray<uint16_t, ARRAY_SIZE>(
44  start_ptr + ODS_POLAR_OCCUPANCY_GRID_POLAR_OCC_GRID_INDEX,
45  polarOccGrid);
46  };
47 
48  /*@brief Version number(current 1) of polar occupancy grid*/
49  uint32_t version;
50  /* @brief A compressed version of the grid using polar coordinates.
51  * The index corresponds to the angle slice i*360/675 degree to
52  * (i+1)*360/675 degree. The value is the distance to the nearest occupied
53  * cell on the ray from the vehicle origin, given in [mm]. In case there
54  * are no occupied cells on the ray, the value 65535 is set.
55  */
56  std::array<uint16_t, ARRAY_SIZE> polarOccGrid;
57 
58  private:
59  static constexpr size_t ods_polar_occupancy_grid_v1_minimum_size = 1354;
60 
61  public:
63  Deserialize(const Buffer& ods_polar_occupancy_buffer_grid)
64  {
65  ODSPolarOccupancyGridV1 ods_polar_occupancy_grid_v1;
66 
67  ods_polar_occupancy_grid_v1.Read(
68  ods_polar_occupancy_buffer_grid.ptr<uint8_t>(0),
69  ods_polar_occupancy_buffer_grid.size());
70  return ods_polar_occupancy_grid_v1;
71  }
72  };
73 } // end namespace ifm3d
74 
75 #endif // IFM3D_DESERIALIZE_STRUCT_O3R_ODS_POLAR_OCCUPANCY_GRID_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::Error
Definition: err.h:112
ifm3d::ODSPolarOccupancyGridV1
Definition: struct_o3r_ods_polar_occupancy_grid_v1.hpp:28