CARLA
 
载入中...
搜索中...
未找到
LidarData.h
浏览该文件的文档.
1// Copyright (c) 2017 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
11
12#include <cstdint>
13#include <vector>
14
15namespace carla {
16
17namespace ros2 {
18 class ROS2;
19}
20
21namespace sensor {
22
23namespace s11n {
24 class LidarSerializer;
25 class LidarHeaderView;
26}
27
28namespace data {
29
30 /// Helper class to store and serialize the data generated by a Lidar.
31 /// 辅助类,用于存储和序列化激光雷达生成的数据。
32 ///
33 /// The header of a Lidar measurement consists of an array of uint32_t's in
34 /// the following layout
35 /// 激光雷达测量的头部由一个uint32_t数组构成,其布局如下:
36 ///
37 /// {
38 /// Horizontal angle (float),
39 /// 水平角度(float)
40 /// Channel count,
41 /// 通道数,
42 /// Point count of channel 0,
43 /// 通道0的点数,
44 /// ...
45 /// Point count of channel n,
46 /// 通道n的点数,
47 /// }
48 ///
49 /// The points are stored in an array of floats
50
51/// 点数据存储在一个float数组中,格式如下:
52 ///
53 /// {
54 /// X0, Y0, Z0, I0
55 /// X0, Y0, Z0, I0 (第一个点的x, y, z坐标和强度)
56 /// ...
57 /// Xn, Yn, Zn, In
58
59 /// Xn, Yn, Zn, In (第n个点的x, y, z坐标和强度)
60 /// }
61 ///
62// LidarDetection类用于存储单个激光雷达检测点的数据
63class LidarDetection {
64public:
65 // 点的地理位置,使用carla::geom::Location表示
66 geom::Location point;
67 // 点的强度信息
68 float intensity;
69
70 // 默认构造函数,初始化点为(0,0,0),强度为0
71 LidarDetection() : point(0.0f, 0.0f, 0.0f), intensity(0.0f) {}
72 // 构造函数,根据提供的坐标和强度初始化
73 LidarDetection(float x, float y, float z, float intensity) : point(x, y, z), intensity(intensity) {}
74 // 构造函数,根据提供的geom::Location和强度初始化
75 LidarDetection(geom::Location p, float intensity) : point(p), intensity(intensity) {}
76
77 // 向输出流写入PLY文件头信息
78 void WritePlyHeaderInfo(std::ostream& out) const {
79 out << "property float32 x\n"
80 << "property float32 y\n"
81 << "property float32 z\n"
82 << "property float32 I";
83 }
84
85 void WriteDetection(std::ostream& out) const{
86 // 写入检测点的x, y, z坐标和强度,以空格分隔
87 out << point.x << ' ' << point.y << ' ' << point.z << ' ' << intensity;
88 }
89 };
90
91 // LidarData类继承自SemanticLidarData,用于存储和序列化激光雷达生成的数据
92class LidarData : public SemanticLidarData {
93
94public:
95 // 构造函数,接受一个可选的通道数参数,默认值为0
96 explicit LidarData(uint32_t ChannelCount = 0u)
97 : SemanticLidarData(ChannelCount) {
98 }
99
100 // 移动赋值运算符,使用默认实现
101 LidarData &operator=(LidarData &&) = default;
102
103 // 析构函数,使用默认实现
104 ~LidarData() = default;
105
106 // 重置内存的方法,接受一个包含每个通道点数的向量
107 // 根据提供的点数重新分配和初始化内部存储
108 virtual void ResetMemory(std::vector<uint32_t> points_per_channel) {
109 // 断言确保通道数大于points_per_channel的大小(这里可能是逻辑上的错误,通常应检查points_per_channel的大小不超过通道数)
110 DEBUG_ASSERT(GetChannelCount() > points_per_channel.size());
111
112 // 使用memset将_header中特定位置后的内存清零,准备存储新的数据
113 // 假设_header是一个包含头部信息的std::vector<uint32_t>,Index::SIZE是头部固定部分的大小
114 std::memset(_header.data() + Index::SIZE, 0, sizeof(uint32_t) * GetChannelCount());
115
116
117 // 计算所有通道的总点数,并据此重置_points的大小和预留空间
118 uint32_t total_points = static_cast<uint32_t>(
119 std::accumulate(points_per_channel.begin(), points_per_channel.end(), 0));
120
121 _points.clear(); // 清空_points
122 _points.reserve(total_points * 4); // 预留足够的空间,每个点包含x, y, z, intensity四个float值
123 }
124
125 // 将一个LidarDetection对象的数据同步写入到内部存储中
126 void WritePointSync(LidarDetection &detection) {
127 // 将检测点的x, y, z坐标和强度依次添加到_points向量中
128 _points.emplace_back(detection.point.x);
129 _points.emplace_back(detection.point.y);
130 _points.emplace_back(detection.point.z);
131 _points.emplace_back(detection.intensity);
132 }
133
134
135 // 一个重载的WritePointSync方法,用于SemanticLidarDetection对象
136 // 但在这个实现中,它仅断言失败,表明这个方法不应该被调用
137 // 这可能是因为SemanticLidarDetection和LidarDetection有不同的数据格式
138 virtual void WritePointSync(SemanticLidarDetection &detection) {
139 (void) detection; // 避免未使用变量的警告
140 DEBUG_ASSERT(false); // 断言失败,表明这个方法不应该被调用
141 }
142
143private:
144 // 存储点的数据,每个点包含x, y, z, intensity四个float值
145 std::vector<float> _points;
146
147 // 友元类,允许它们访问私有成员_points和_header
148 friend class s11n::LidarSerializer;
149 friend class s11n::LidarHeaderView;
150 friend class carla::ros2::ROS2;
151};
ConcurrentQueue & operator=(ConcurrentQueue const &) MOODYCAMEL_DELETE_FUNCTION
#define DEBUG_ASSERT(predicate)
Definition Debug.h:68
CARLA模拟器的主命名空间。
Definition Carla.cpp:139