CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
sensor
s11n
LidarSerializer.h
Go to the documentation of this file.
1
// Copyright (c) 2026 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
"
12
#include "
carla/sensor/data/LidarData.h
"
13
14
namespace
carla
{
15
namespace
sensor
{
16
17
class
SensorData
;
18
19
namespace
s11n
{
20
21
// ===========================================================================
22
// -- LidarHeaderView --------------------------------------------------------
23
// ===========================================================================
24
25
/// A view over the header of a Lidar measurement.
26
class
LidarHeaderView
{
27
using
Index
=
data::LidarData::Index
;
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.
58
class
LidarSerializer
{
59
public
:
60
61
static
LidarHeaderView
DeserializeHeader
(
const
RawData
&
data
) {
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
76
static
SharedPtr<SensorData>
Deserialize
(
RawData
&&
data
);
77
};
78
79
// ===========================================================================
80
// -- LidarSerializer implementation -----------------------------------------
81
// ===========================================================================
82
83
template
<
typename
Sensor>
84
inline
Buffer
LidarSerializer::Serialize
(
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
Debug.h
DEBUG_ASSERT
#define DEBUG_ASSERT(predicate)
Definition
Debug.h:66
LidarData.h
Memory.h
RawData.h
carla::Buffer
A piece of raw data.
Definition
carla/Buffer.h:42
carla::Buffer::copy_from
void copy_from(const T &source)
Copy source into this buffer. Allocates memory if necessary.
Definition
carla/Buffer.h:305
carla::sensor::RawData
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition
RawData.h:21
carla::sensor::SensorData
Base class for all the objects containing data generated by a sensor.
Definition
SensorData.h:22
carla::sensor::data::LidarData
Definition
LidarData.h:78
carla::sensor::data::SemanticLidarData::Index
Index
Definition
SemanticLidarData.h:90
carla::sensor::data::SemanticLidarData::SIZE
@ SIZE
Definition
SemanticLidarData.h:93
carla::sensor::s11n::LidarHeaderView
A view over the header of a Lidar measurement.
Definition
LidarSerializer.h:26
carla::sensor::s11n::LidarHeaderView::LidarHeaderView
LidarHeaderView(const uint32_t *begin)
Definition
LidarSerializer.h:46
carla::sensor::s11n::LidarHeaderView::GetPointCount
uint32_t GetPointCount(size_t channel) const
Definition
LidarSerializer.h:38
carla::sensor::s11n::LidarHeaderView::LidarSerializer
friend class LidarSerializer
Definition
LidarSerializer.h:44
carla::sensor::s11n::LidarHeaderView::GetHorizontalAngle
float GetHorizontalAngle() const
Definition
LidarSerializer.h:30
carla::sensor::s11n::LidarHeaderView::GetChannelCount
uint32_t GetChannelCount() const
Definition
LidarSerializer.h:34
carla::sensor::s11n::LidarHeaderView::Index
data::LidarData::Index Index
Definition
LidarSerializer.h:27
carla::sensor::s11n::LidarHeaderView::_begin
const uint32_t * _begin
Definition
LidarSerializer.h:50
carla::sensor::s11n::LidarSerializer
Serializes the data generated by Lidar sensors.
Definition
LidarSerializer.h:58
carla::sensor::s11n::LidarSerializer::Deserialize
static SharedPtr< SensorData > Deserialize(RawData &&data)
Definition
LidarSerializer.cpp:15
carla::sensor::s11n::LidarSerializer::Serialize
static Buffer Serialize(const Sensor &sensor, const data::LidarData &data, Buffer &&output)
Definition
LidarSerializer.h:84
carla::sensor::s11n::LidarSerializer::DeserializeHeader
static LidarHeaderView DeserializeHeader(const RawData &data)
Definition
LidarSerializer.h:61
carla::sensor::s11n::LidarSerializer::GetHeaderOffset
static size_t GetHeaderOffset(const RawData &data)
Definition
LidarSerializer.h:65
carla::sensor::data
Definition
ROS2.h:33
carla::sensor::s11n
Definition
ROS2.h:39
carla::sensor
Definition
client/detail/Client.h:58
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::SharedPtr
std::shared_ptr< T > SharedPtr
Definition
Memory.h:15
Generated by
1.18.0