CARLA
ImageSerializer.h
Go to the documentation of this file.
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"
10 #include "carla/sensor/RawData.h"
11 
12 #include <cstdint>
13 #include <cstring>
14 
15 namespace carla {
16 namespace sensor {
17 
18  class SensorData;
19 
20 namespace 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
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
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
auto begin() noexcept
Begin iterator to the data generated by the sensor.
Definition: RawData.h:52
static SharedPtr< SensorData > Deserialize(RawData &&data)
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:66
static const ImageHeader & DeserializeHeader(const RawData &data)
A piece of raw data.
Definition: carla/Buffer.h:42
static Buffer Serialize(const Sensor &sensor, Buffer &&bitmap)
Serializes image buffers generated by camera sensors.
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition: RawData.h:21