CARLA
OpticalFlowImageSerializer.h
Go to the documentation of this file.
1 //
2 // Created by flo on 09.11.20.
3 //
4 
5 #pragma once
6 
7 #include "carla/Memory.h"
8 #include "carla/sensor/RawData.h"
9 
10 #include <cstdint>
11 #include <cstring>
12 
13 namespace carla {
14  namespace sensor {
15 
16  class SensorData;
17 
18  namespace s11n {
19 
20  /// Serializes image buffers generated by camera sensors.
22  public:
23 
24 #pragma pack(push, 1)
25  struct ImageHeader {
26  uint32_t width;
27  uint32_t height;
28  float fov_angle;
29  };
30 #pragma pack(pop)
31 
32  constexpr static auto header_offset = sizeof(ImageHeader);
33 
34  static const ImageHeader &DeserializeHeader(const RawData &data) {
35  return *reinterpret_cast<const ImageHeader *>(data.begin());
36  }
37 
38  template <typename Sensor>
39  static Buffer Serialize(const Sensor &sensor, Buffer &&bitmap);
40 
42  };
43 
44  template <typename Sensor>
45  inline Buffer OpticalFlowImageSerializer::Serialize(const Sensor &sensor, Buffer &&bitmap) {
46  DEBUG_ASSERT(bitmap.size() > sizeof(ImageHeader));
47  ImageHeader header = {
48  sensor.GetImageWidth(),
49  sensor.GetImageHeight(),
50  sensor.GetFOVAngle()
51  };
52  std::memcpy(bitmap.data(), reinterpret_cast<const void *>(&header), sizeof(header));
53  return std::move(bitmap);
54  }
55 
56  } // namespace s11n
57  } // namespace sensor
58 } // namespace carla
59 
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
static SharedPtr< SensorData > Deserialize(RawData &&data)
auto begin() noexcept
Begin iterator to the data generated by the sensor.
Definition: RawData.h:51
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:66
Serializes image buffers generated by camera sensors.
A piece of raw data.
Definition: carla/Buffer.h:41
static Buffer Serialize(const Sensor &sensor, Buffer &&bitmap)
static const ImageHeader & DeserializeHeader(const RawData &data)
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition: RawData.h:20