CARLA
SemanticLidarSerializer.h
Go to the documentation of this file.
1 // Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/Debug.h"
10 #include "carla/Memory.h"
11 #include "carla/sensor/RawData.h"
13 
14 namespace carla {
15 namespace sensor {
16 
17 class SensorData;
18 
19 namespace s11n {
20 
21  // ===========================================================================
22  // -- SemanticLidarHeaderView --------------------------------------------------------
23  // ===========================================================================
24 
25  /// A view over the header of a Lidar measurement.
28 
29  public:
30 
31  float GetHorizontalAngle() const {
32  return reinterpret_cast<const float &>(_begin[Index::HorizontalAngle]);
33  }
34 
35  uint32_t GetChannelCount() const {
36  return _begin[Index::ChannelCount];
37  }
38 
39  uint32_t GetPointCount(size_t channel) const {
40  DEBUG_ASSERT(channel < GetChannelCount());
41  return _begin[Index::SIZE + channel];
42  }
43 
44  protected:
46 
47  explicit SemanticLidarHeaderView(const uint32_t *begin) : _begin(begin) {
48  DEBUG_ASSERT(_begin != nullptr);
49  }
50 
51  const uint32_t *_begin;
52  };
53 
54  // ===========================================================================
55  // -- LidarSerializer --------------------------------------------------------
56  // ===========================================================================
57 
58  /// Serializes the data generated by Lidar sensors.
60  public:
61 
63  return SemanticLidarHeaderView{reinterpret_cast<const uint32_t *>(data.begin())};
64  }
65 
66  static size_t GetHeaderOffset(const RawData &data) {
67  auto View = DeserializeHeader(data);
68  return sizeof(uint32_t) * (View.GetChannelCount() + data::SemanticLidarData::Index::SIZE);
69  }
70 
71  template <typename Sensor>
72  static Buffer Serialize(
73  const Sensor &sensor,
74  const data::SemanticLidarData &measurement,
75  Buffer &&output);
76 
77  static SharedPtr<SensorData> Deserialize(RawData &&data);
78  };
79 
80  // ===========================================================================
81  // -- LidarRawSerializer implementation -----------------------------------------
82  // ===========================================================================
83 
84  template <typename Sensor>
86  const Sensor &,
87  const data::SemanticLidarData &measurement,
88  Buffer &&output) {
89  std::array<boost::asio::const_buffer, 2u> seq = {
90  boost::asio::buffer(measurement._header),
91  boost::asio::buffer(measurement._ser_points)};
92  output.copy_from(seq);
93  return std::move(output);
94  }
95 
96 } // namespace s11n
97 } // namespace sensor
98 } // namespace carla
static const FString SIZE
static Buffer Serialize(const Sensor &sensor, const data::SemanticLidarData &measurement, Buffer &&output)
A view over the header of a Lidar measurement.
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition: Memory.h:20
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::vector< SemanticLidarDetection > _ser_points
auto begin() noexcept
Begin iterator to the data generated by the sensor.
Definition: RawData.h:52
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:66
Serializes the data generated by Lidar sensors.
A piece of raw data.
Definition: carla/Buffer.h:42
static size_t GetHeaderOffset(const RawData &data)
static SemanticLidarHeaderView DeserializeHeader(const RawData &data)
void copy_from(const T &source)
Copy source into this buffer. Allocates memory if necessary.
Definition: carla/Buffer.h:305
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition: RawData.h:21