CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
sensor
s11n
DVSEventArraySerializer.h
Go to the documentation of this file.
1
// Copyright (c) 2020 Robotics and Perception Group (GPR)
2
// University of Zurich and ETH Zurich
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/Memory.h
"
10
#include "
carla/sensor/RawData.h
"
11
#include "
carla/sensor/data/DVSEvent.h
"
12
13
#include <cstdint>
14
#include <cstring>
15
16
namespace
carla
{
17
namespace
sensor
{
18
19
class
SensorData
;
20
21
namespace
s11n
{
22
23
/// Serializes events array generated by DVS camera sensors.
24
class
DVSEventArraySerializer
{
25
public
:
26
27
#pragma pack(push, 1)
28
struct
DVSHeader
{
29
uint32_t
width
;
30
uint32_t
height
;
31
float
fov_angle
;
32
};
33
#pragma pack(pop)
34
35
constexpr
static
auto
header_offset
=
sizeof
(
DVSHeader
);
36
using
DVSEventArray
= std::vector<data::DVSEvent>;
37
38
static
const
DVSHeader
&
DeserializeHeader
(
const
RawData
&
data
) {
39
return
*
reinterpret_cast<
const
DVSHeader
*
>
(
data
.begin());
40
}
41
42
template
<
typename
Sensor>
43
static
Buffer
Serialize
(
const
Sensor &
sensor
,
const
DVSEventArray
&events,
Buffer
&&output);
44
45
static
SharedPtr<SensorData>
Deserialize
(
RawData
&&
data
);
46
};
47
48
template
<
typename
Sensor>
49
inline
Buffer
DVSEventArraySerializer::Serialize
(
const
Sensor &
sensor
,
const
DVSEventArray
&events,
Buffer
&&output) {
50
DEBUG_ASSERT
(events.size() >
sizeof
(
DVSHeader
));
51
DVSHeader
header = {
52
sensor
.GetImageWidth(),
53
sensor
.GetImageHeight(),
54
sensor
.GetFOVAngle(),
55
};
56
57
/// Reset the output buffer
58
output.reset(
sizeof
(
DVSHeader
) + (events.size() *
sizeof
(
data::DVSEvent
)));
59
60
/// Pointer to data in buffer
61
unsigned
char
*it = output.data();
62
63
/// Copy the header into the output buffer
64
std::memcpy(it,
reinterpret_cast<
const
void
*
>
(&header),
sizeof
(header));
65
it +=
sizeof
(
DVSHeader
);
66
67
/// Copy the events into the output buffer
68
for
(
auto
e : events) {
69
std::memcpy(it,
reinterpret_cast<
const
void
*
>
(&e),
sizeof
(
data::DVSEvent
));
70
it +=
sizeof
(
data::DVSEvent
);
71
}
72
return
std::move(output);
73
}
74
75
}
// namespace s11n
76
}
// namespace sensor
77
}
// namespace carla
DVSEvent.h
DEBUG_ASSERT
#define DEBUG_ASSERT(predicate)
Definition
Debug.h:66
Memory.h
RawData.h
carla::Buffer
A piece of raw data.
Definition
carla/Buffer.h:42
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::s11n::DVSEventArraySerializer
Serializes events array generated by DVS camera sensors.
Definition
DVSEventArraySerializer.h:24
carla::sensor::s11n::DVSEventArraySerializer::Serialize
static Buffer Serialize(const Sensor &sensor, const DVSEventArray &events, Buffer &&output)
Definition
DVSEventArraySerializer.h:49
carla::sensor::s11n::DVSEventArraySerializer::DVSEventArray
std::vector< data::DVSEvent > DVSEventArray
Definition
DVSEventArraySerializer.h:36
carla::sensor::s11n::DVSEventArraySerializer::Deserialize
static SharedPtr< SensorData > Deserialize(RawData &&data)
Definition
DVSEventArraySerializer.cpp:15
carla::sensor::s11n::DVSEventArraySerializer::DeserializeHeader
static const DVSHeader & DeserializeHeader(const RawData &data)
Definition
DVSEventArraySerializer.h:38
carla::sensor::s11n::DVSEventArraySerializer::header_offset
static constexpr auto header_offset
Definition
DVSEventArraySerializer.h:35
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
carla::sensor::data::DVSEvent
Definition
DVSEvent.h:16
carla::sensor::s11n::DVSEventArraySerializer::DVSHeader
Definition
DVSEventArraySerializer.h:28
carla::sensor::s11n::DVSEventArraySerializer::DVSHeader::height
uint32_t height
Definition
DVSEventArraySerializer.h:30
carla::sensor::s11n::DVSEventArraySerializer::DVSHeader::fov_angle
float fov_angle
Definition
DVSEventArraySerializer.h:31
carla::sensor::s11n::DVSEventArraySerializer::DVSHeader::width
uint32_t width
Definition
DVSEventArraySerializer.h:29
Generated by
1.18.0