CARLA
 
载入中...
搜索中...
未找到
ImageSerializer.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
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
44 };
45
46 template <typename Sensor>
47 inline Buffer ImageSerializer::Serialize(const Sensor &sensor, Buffer &&bitmap) {
48 DEBUG_ASSERT(bitmap.size() > sizeof(ImageHeader));
49 ImageHeader header = {
50 sensor.GetImageWidth(),
51 sensor.GetImageHeight(),
52 sensor.GetFOVAngle()
53 };
54 std::memcpy(bitmap.data(), reinterpret_cast<const void *>(&header), sizeof(header));
55 return std::move(bitmap);
56 }
57
58} // namespace s11n
59} // namespace sensor
60} // 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)
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