CARLA
 
载入中...
搜索中...
未找到
LidarSerializer.h
浏览该文件的文档.
1// Copyright (c) 2019 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"
13
14namespace carla {
15namespace sensor {
16
17 class SensorData;
18
19namespace s11n {
20
21 // ===========================================================================
22 // -- LidarHeaderView --------------------------------------------------------
23 // ===========================================================================
24
25 /// A view over the header of a Lidar measurement.
28
29 public:
30 float GetHorizontalAngle() const {
31 return reinterpret_cast<const float &>(_begin[Index::HorizontalAngle]);
32 }
33
34 uint32_t GetChannelCount() const {
35 return _begin[Index::ChannelCount];
36 }
37
38 uint32_t GetPointCount(size_t channel) const {
39 DEBUG_ASSERT(channel < GetChannelCount());
40 return _begin[Index::SIZE + channel];
41 }
42
43 private:
44 friend class LidarSerializer;
45
46 explicit LidarHeaderView(const uint32_t *begin) : _begin(begin) {
47 DEBUG_ASSERT(_begin != nullptr);
48 }
49
50 const uint32_t *_begin;
51 };
52
53 // ===========================================================================
54 // -- LidarSerializer --------------------------------------------------------
55 // ===========================================================================
56
57 /// Serializes the data generated by Lidar sensors.
59 public:
60
62 return LidarHeaderView{reinterpret_cast<const uint32_t *>(data.begin())};
63 }
64
65 static size_t GetHeaderOffset(const RawData &data) {
66 auto View = DeserializeHeader(data);
67 return sizeof(uint32_t) * (View.GetChannelCount() + data::LidarData::Index::SIZE);
68 }
69
70 template <typename Sensor>
71 static Buffer Serialize(
72 const Sensor &sensor,
73 const data::LidarData &data,
74 Buffer &&output);
75
77 };
78
79 // ===========================================================================
80 // -- LidarSerializer implementation -----------------------------------------
81 // ===========================================================================
82
83 template <typename Sensor>
85 const Sensor &,
86 const data::LidarData &data,
87 Buffer &&output) {
88 std::array<boost::asio::const_buffer, 2u> seq = {
89 boost::asio::buffer(data._header),
90 boost::asio::buffer(data._points)};
91 output.copy_from(seq);
92 return std::move(output);
93 }
94
95} // namespace s11n
96} // namespace sensor
97} // namespace carla
#define DEBUG_ASSERT(predicate)
Definition Debug.h:66
A piece of raw data.
void copy_from(const T &source)
Copy source into this buffer. Allocates memory if necessary.
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition RawData.h:21
auto begin() noexcept
Begin iterator to the data generated by the sensor.
Definition RawData.h:52
std::vector< float > _points
Definition LidarData.h:111
A view over the header of a Lidar measurement.
LidarHeaderView(const uint32_t *begin)
uint32_t GetPointCount(size_t channel) const
Serializes the data generated by Lidar sensors.
static SharedPtr< SensorData > Deserialize(RawData &&data)
static Buffer Serialize(const Sensor &sensor, const data::LidarData &data, Buffer &&output)
static LidarHeaderView DeserializeHeader(const RawData &data)
static size_t GetHeaderOffset(const RawData &data)
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
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