CARLA
 
载入中...
搜索中...
未找到
SemanticLidarSerializer.h
浏览该文件的文档.
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
10#include "carla/Debug.h"
11// 引入carla项目中名为Debug的头文件
12#include "carla/Memory.h"
13// 引入carla项目中关于内存管理相关的头文件
15// 引入carla项目里传感器相关的RawData头文件
17// 引入carla项目中传感器数据里关于语义激光雷达数据(Semantic Lidar Data)的头文件,应该包含了语义激光雷达数据相关的结构体、类等具体定义
18
19namespace carla {
20namespace sensor {
21
22class SensorData;
23// 前向声明SensorData类,告知编译器后续会有这个类的完整定义,先允许在这里使用该类的指针、引用等相关类型,方便代码的组织结构和编译流程
24
25namespace s11n {
26
27 // ===========================================================================
28 // -- SemanticLidarHeaderView --------------------------------------------------------
29 // ===========================================================================
30
31 /// A view over the header of a Lidar measurement.
32// 类的功能注释,说明这个类用于提供对激光雷达测量数据头部信息的一种视图(也就是一种访问方式,不实际拥有数据,只是查看)
33
36 // 使用using关键字定义一个类型别名Index,它等同于data::SemanticLidarData::Index类型,这样后续使用Index时就相当于使用那个具体的索引相关类型,方便代码书写和理解,应该是用于在访问头部数据成员时做索引定位用
37
38 public:
39
40 float GetHorizontalAngle() const {
41 return reinterpret_cast<const float &>(_begin[Index::HorizontalAngle]);
42// 定义一个常成员函数,用于获取水平角度信息。
43// 位置的数据强制转换为float类型的引用并返回,这里使用reinterpret_cast进行强制类型转换,从底层内存角度获取对应的数据并转换为期望的类型
44 // 前提是内存中对应位置存储的数据确实符合float类型的格式要求
45
46 }
47
48 uint32_t GetChannelCount() const {
49 return _begin[Index::ChannelCount];
50 // 常成员函数,用于获取通道数量信息。
51 }
52
53 uint32_t GetPointCount(size_t channel) const {
54 DEBUG_ASSERT(channel < GetChannelCount());
55// 先使用DEBUG_ASSERT宏(来自之前引入的Debug.h文件)进行断言检查,确保传入的通道索引(channel)小于获取到的总通道数量
56// 即保证访问的通道索引是合法有效的,防止越界访问等错误情况发生
57 return _begin[Index::SIZE + channel]; // 返回指定通道的点数量信息。
58 }
59
60 protected:
62// 声明SemanticLidarSerializer类为友元类
63 // 一般用于在相关联的类之间提供一种特殊的访问权限,便于协同完成功能,比如这里可能是在序列化和反序列化过程中需要这种访问权限
64
65 explicit SemanticLidarHeaderView(const uint32_t *begin) : _begin(begin) {
66 DEBUG_ASSERT(_begin != nullptr);
67// 在构造函数中,使用DEBUG_ASSERT宏进行断言检查,确保传入的指向头部数据起始地址的指针(begin)不为空,
68 // 保证后续基于这个指针访问数据的操作是安全可靠的
69 }
70
71 const uint32_t *_begin;
72 // 定义一个指向uint32_t类型的常指针成员变量
73 };
74
75 // ===========================================================================
76 // -- LidarSerializer --------------------------------------------------------
77 // ===========================================================================
78
79 /// Serializes the data generated by Lidar sensors.
81 public:
82
84 return SemanticLidarHeaderView{reinterpret_cast<const uint32_t *>(data.begin())};
85// 定义一个静态函数DeserializeHeader
86 }
87
88 static size_t GetHeaderOffset(const RawData &data) {
89 auto View = DeserializeHeader(data);
90 return sizeof(uint32_t) * (View.GetChannelCount() + data::SemanticLidarData::Index::SIZE);
91 // 定义一个静态函数GetHeaderOffset,用于获取原始数据中头部信息所占的偏移量(字节数)。
92// 首先调用DeserializeHeader函数获取头部信息的视图对象(View),然后根据视图对象获取的通道数量(View.GetChannelCount())以及data::SemanticLidarData::Index::SIZE来计算总的偏移量
93// 通过将uint32_t类型的大小(sizeof(uint32_t))乘以相应的数量得出字节数形式的偏移量
94
95 }
96
97 template <typename Sensor>
98 static Buffer Serialize(
99 const Sensor &sensor,
100 const data::SemanticLidarData &measurement,
101 Buffer &&output);
102// 定义一个静态模板函数Serialize
103// 参数sensor是传感器对象引用,measurement是要序列化的语义激光雷达数据,output是用于存放序列化结果的缓冲区
104
106 // 定义一个静态函数Deserialize
107// 最终返回一个指向SensorData类型的共享智能指针(SharedPtr表示共享所有权,便于内存管理和对象生命周期控制),将原始数据还原为相应的传感器数据对象
108
109 };
110
111 // ===========================================================================
112 // -- LidarRawSerializer implementation -----------------------------------------
113 // ===========================================================================
114
115 template <typename Sensor>
117 const Sensor &,
118 const data::SemanticLidarData &measurement,
119 Buffer &&output) {
120 std::array<boost::asio::const_buffer, 2u> seq = {
121 boost::asio::buffer(measurement._header),
122 boost::asio::buffer(measurement._ser_points)};
123 output.copy_from(seq);
124 return std::move(output);
125 // 这是SemanticLidarSerializer类中Serialize函数的具体实现(针对特定模板参数Sensor的情况)。
126 // 首先创建一个包含两个const_buffer类型元素的数组(seq),这两个元素分别通过boost::asio::buffer函数将语义激光雷达数据(measurement)中的
127 // _header和_ser_points成员(具体含义由SemanticLidarData结构体定义决定)转换为const_buffer类型,以便后续进行数据复制操作。
128// 然后调用output缓冲区的copy_from函数,将数组seq中的数据复制到output缓冲区中,实现将语义激光雷达数据序列化到缓冲区的操作,
129 // 最后通过移动语义(std::move)返回填充好数据的output缓冲区,避免不必要的拷贝开销,提高效率
130 }
131
132} // namespace s11n
133} // namespace sensor
134} // namespace carla
auto begin() const noexcept
名称范围迭代支持
#define DEBUG_ASSERT(predicate)
Definition Debug.h:68
一块原始数据。 请注意,如果需要更多容量,则会分配一个新的内存块,并 删除旧的内存块。这意味着默认情况下,缓冲区只能增长。要释放内存,使用 clear 或 pop。
void copy_from(const T &source)
将 source复制到此缓冲区。如果需要,则分配内存。
包装一个传感器生成的原始数据以及一些有用的元信息。
Definition RawData.h:20
auto begin() noexcept
指向传感器生成的数据的开始迭代器。
Definition RawData.h:52
std::vector< SemanticLidarDetection > _ser_points
A view over the header of a Lidar measurement.
Serializes the data generated by Lidar sensors.
static SharedPtr< SensorData > Deserialize(RawData &&data)
static Buffer Serialize(const Sensor &sensor, const data::SemanticLidarData &measurement, Buffer &&output)
static size_t GetHeaderOffset(const RawData &data)
static SemanticLidarHeaderView 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