CARLA
 
载入中...
搜索中...
未找到
GBufferUint8Serializer.h
浏览该文件的文档.
1// Copyright (c) 2022 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/Memory.h" // 包含内存管理相关定义,例如智能指针 SharedPtr
10#include "carla/sensor/RawData.h" // 包含传感器的原始数据类型定义
11
12#include <cstdint> // 提供固定宽度的整数类型
13#include <cstring> // 提供内存操作函数
14
15namespace carla {
16namespace sensor {
17
18 class SensorData; // 前向声明 SensorData,表示通用的传感器数据接口
19
20namespace s11n {
21
22 /// Serializes image buffers generated by camera sensors.
24 public:
25
26#pragma pack(push, 1)
27 struct ImageHeader { // 表示图像的元信息,用于描述图像的宽度、高度和视场角
28 uint32_t width; // 图像的宽度
29 uint32_t height; // 图像的高度
30 float fov_angle; // 图像的视场角
31 };
32#pragma pack(pop)
33
34 constexpr static auto header_offset = sizeof(ImageHeader); // 图像数据的偏移量(字节数),对应'ImageHeader'的大小
35
36 static const ImageHeader &DeserializeHeader(const RawData &data) {
37 // 将 RawData 的起始位置解释为 ImageHeader 结构
38 return *reinterpret_cast<const ImageHeader *>(data.begin());
39 }
40
41 /// @brief 序列化图像数据到缓冲区中
42 /// @tparam Sensor 传感器类型
43 /// @param sensor 输入的传感器对象
44 /// @param bitmap 图像数据缓冲区
45 /// @param ImageWidth 图像宽度
46 /// @param ImageHeight 图像高度
47 /// @param FovAngle 图像视场角
48 /// @return 返回更新后的缓冲区
49 template <typename Sensor>
50 static Buffer Serialize(const Sensor &sensor, Buffer &&bitmap,
51 uint32_t ImageWidth, uint32_t ImageHeight, float FovAngle);
52
54 };
55
56 template <typename Sensor>
57 inline Buffer GBufferUint8Serializer::Serialize(const Sensor &/*sensor*/, Buffer &&bitmap,
58 uint32_t ImageWidth, uint32_t ImageHeight, float FovAngle) {
59 DEBUG_ASSERT(bitmap.size() > sizeof(ImageHeader)); // 检查缓冲区大小是否足够存储图像头部信息
60 ImageHeader header = { // 构造图像头部信息
61 ImageWidth,
62 ImageHeight,
63 FovAngle
64 };
65 std::memcpy(bitmap.data(), reinterpret_cast<const void *>(&header), sizeof(header)); // 将头部信息拷贝到缓冲区的起始位置
66 return std::move(bitmap); // 返回更新后的缓冲区
67 }
68
69} // namespace s11n
70} // namespace sensor
71} // namespace carla
#define DEBUG_ASSERT(predicate)
Definition Debug.h:68
一块原始数据。 请注意,如果需要更多容量,则会分配一个新的内存块,并 删除旧的内存块。这意味着默认情况下,缓冲区只能增长。要释放内存,使用 clear 或 pop。
包装一个传感器生成的原始数据以及一些有用的元信息。
Definition RawData.h:20
auto begin() noexcept
指向传感器生成的数据的开始迭代器。
Definition RawData.h:52
Serializes image buffers generated by camera sensors.
static const ImageHeader & DeserializeHeader(const RawData &data)
static Buffer Serialize(const Sensor &sensor, Buffer &&bitmap, uint32_t ImageWidth, uint32_t ImageHeight, float FovAngle)
序列化图像数据到缓冲区中
static SharedPtr< SensorData > Deserialize(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