CARLA
 
载入中...
搜索中...
未找到
DVSEventArraySerializer.h
浏览该文件的文档.
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"
12
13#include <cstdint>
14#include <cstring>
15
16namespace carla {
17namespace sensor {
18
19 class SensorData;
20
21namespace s11n {
22
23 /// 序列化 DVS 摄像机传感器生成的事件数组。
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
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 /// 重置输出缓冲区。
58 output.reset(sizeof(DVSHeader) + (events.size() * sizeof(data::DVSEvent)));
59
60 /// 指向缓冲区数据的指针。
61 unsigned char *it = output.data();
62
63 /// 将表头复制到输出缓冲区中。
64 std::memcpy(it, reinterpret_cast<const void *>(&header), sizeof(header));
65 it += sizeof(DVSHeader);
66
67 /// 将结果复制到输出缓冲区中。
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
#define DEBUG_ASSERT(predicate)
Definition Debug.h:68
一块原始数据。 请注意,如果需要更多容量,则会分配一个新的内存块,并 删除旧的内存块。这意味着默认情况下,缓冲区只能增长。要释放内存,使用 clear 或 pop。
包装一个传感器生成的原始数据以及一些有用的元信息。
Definition RawData.h:20
auto begin() noexcept
指向传感器生成的数据的开始迭代器。
Definition RawData.h:52
序列化 DVS 摄像机传感器生成的事件数组。
static Buffer Serialize(const Sensor &sensor, const DVSEventArray &events, Buffer &&output)
static SharedPtr< SensorData > Deserialize(RawData &&data)
static const DVSHeader & DeserializeHeader(const RawData &data)
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
boost::shared_ptr< T > SharedPtr
使用这个SharedPtr(boost::shared_ptr)以保持与boost::python的兼容性, 但未来如果可能的话,我们希望能为std::shared_ptr制作一个Python适配器。
Definition Memory.h:19