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"
11
12#include <cstdint>
13#include <cstring>
14
15namespace carla {
16namespace sensor {
17
18 class 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);
35
36 static const ImageHeader &DeserializeHeader(const RawData &data) {
37 return *reinterpret_cast<const ImageHeader *>(data.begin());
38 }
39
40 template <typename Sensor>
41 static Buffer Serialize(const Sensor &sensor, Buffer &&bitmap,
42 uint32_t ImageWidth, uint32_t ImageHeight, float FovAngle);
43
45 };
46
47 template <typename Sensor>
48 inline Buffer GBufferUint8Serializer::Serialize(const Sensor &/*sensor*/, Buffer &&bitmap,
49 uint32_t ImageWidth, uint32_t ImageHeight, float FovAngle) {
50 DEBUG_ASSERT(bitmap.size() > sizeof(ImageHeader));
51 ImageHeader header = {
52 ImageWidth,
53 ImageHeight,
54 FovAngle
55 };
56 std::memcpy(bitmap.data(), reinterpret_cast<const void *>(&header), sizeof(header));
57 return std::move(bitmap);
58 }
59
60} // namespace s11n
61} // namespace sensor
62} // namespace carla
#define DEBUG_ASSERT(predicate)
Definition Debug.h:66
A piece of raw data.
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition RawData.h:21
auto begin() noexcept
Begin iterator to the data generated by the sensor.
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)
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition Memory.h:20