CARLA
Loading...
Searching...
No Matches
DistanceImageSerializer.h
Go to the documentation of this file.
1// Copyright (c) 2026 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 the single-channel float32 distance images produced by the
23 /// path-traced distance camera. The header is layout-identical to
24 /// ImageSerializer::ImageHeader (every image serializer shares it, see
25 /// data::ImageTmpl); only the pixel type differs.
27 public:
28
29#pragma pack(push, 1)
30 struct ImageHeader {
31 uint32_t width;
32 uint32_t height;
33 float fov_angle;
34 };
35#pragma pack(pop)
36
37 constexpr static auto header_offset = sizeof(ImageHeader);
38
39 static const ImageHeader &DeserializeHeader(const RawData &data) {
40 return *reinterpret_cast<const ImageHeader *>(data.begin());
41 }
42
43 template <typename Sensor>
44 static Buffer Serialize(const Sensor &sensor, Buffer &&bitmap);
45
47 };
48
49 template <typename Sensor>
50 inline Buffer DistanceImageSerializer::Serialize(const Sensor &sensor, Buffer &&bitmap) {
51 DEBUG_ASSERT(bitmap.size() > sizeof(ImageHeader));
52 ImageHeader header = {
53 sensor.GetImageWidth(),
54 sensor.GetImageHeight(),
55 sensor.GetFOVAngle()
56 };
57 std::memcpy(bitmap.data(), reinterpret_cast<const void *>(&header), sizeof(header));
58 return std::move(bitmap);
59 }
60
61} // namespace s11n
62} // namespace sensor
63} // 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 the single-channel float32 distance images produced by the path-traced distance camera.
static SharedPtr< SensorData > Deserialize(RawData &&data)
static Buffer Serialize(const Sensor &sensor, Buffer &&bitmap)
static const ImageHeader & DeserializeHeader(const RawData &data)
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15