CARLA
LidarData.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/rpc/Location.h"
11 
12 #include <cstdint>
13 #include <vector>
14 
15 namespace carla {
16 
17 namespace ros2 {
18  class ROS2;
19 }
20 
21 namespace sensor {
22 
23 namespace s11n {
24  class LidarSerializer;
25  class LidarHeaderView;
26 }
27 
28 namespace data {
29 
30  /// Helper class to store and serialize the data generated by a Lidar.
31  ///
32  /// The header of a Lidar measurement consists of an array of uint32_t's in
33  /// the following layout
34  ///
35  /// {
36  /// Horizontal angle (float),
37  /// Channel count,
38  /// Point count of channel 0,
39  /// ...
40  /// Point count of channel n,
41  /// }
42  ///
43  /// The points are stored in an array of floats
44  ///
45  /// {
46  /// X0, Y0, Z0, I0
47  /// ...
48  /// Xn, Yn, Zn, In
49  /// }
50  ///
51 
53  public:
55  float intensity;
56 
58  point(0.0f, 0.0f, 0.0f), intensity{0.0f} { }
59  LidarDetection(float x, float y, float z, float intensity) :
60  point(x, y, z), intensity{intensity} { }
61  LidarDetection(geom::Location p, float intensity) :
62  point(p), intensity{intensity} { }
63 
64  void WritePlyHeaderInfo(std::ostream& out) const{
65  out << "property float32 x\n" \
66  "property float32 y\n" \
67  "property float32 z\n" \
68  "property float32 I";
69  }
70 
71  void WriteDetection(std::ostream& out) const{
72  out << point.x << ' ' << point.y << ' ' << point.z << ' ' << intensity;
73  }
74  };
75 
76  class LidarData : public SemanticLidarData{
77 
78  public:
79  explicit LidarData(uint32_t ChannelCount = 0u)
80  : SemanticLidarData(ChannelCount) {
81  }
82 
83  LidarData &operator=(LidarData &&) = default;
84 
85  ~LidarData() = default;
86 
87  virtual void ResetMemory(std::vector<uint32_t> points_per_channel) {
88  DEBUG_ASSERT(GetChannelCount() > points_per_channel.size());
89  std::memset(_header.data() + Index::SIZE, 0, sizeof(uint32_t) * GetChannelCount());
90 
91  uint32_t total_points = static_cast<uint32_t>(
92  std::accumulate(points_per_channel.begin(), points_per_channel.end(), 0));
93 
94  _points.clear();
95  _points.reserve(total_points * 4);
96  }
97 
98  void WritePointSync(LidarDetection &detection) {
99  _points.emplace_back(detection.point.x);
100  _points.emplace_back(detection.point.y);
101  _points.emplace_back(detection.point.z);
102  _points.emplace_back(detection.intensity);
103  }
104 
105  virtual void WritePointSync(SemanticLidarDetection &detection) {
106  (void) detection;
107  DEBUG_ASSERT(false);
108  }
109 
110  private:
111  std::vector<float> _points;
112 
113  friend class s11n::LidarSerializer;
114  friend class s11n::LidarHeaderView;
115  friend class carla::ros2::ROS2;
116  };
117 
118 } // namespace s11n
119 } // namespace sensor
120 } // namespace carla
virtual void ResetMemory(std::vector< uint32_t > points_per_channel)
Definition: LidarData.h:87
static const FString SIZE
Serializes the data generated by Lidar sensors.
Helper class to store and serialize the data generated by a RawLidar.
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
void WritePlyHeaderInfo(std::ostream &out) const
Definition: LidarData.h:64
A view over the header of a Lidar measurement.
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:66
void WriteDetection(std::ostream &out) const
Definition: LidarData.h:71
LidarData(uint32_t ChannelCount=0u)
Definition: LidarData.h:79
virtual void WritePointSync(SemanticLidarDetection &detection)
Definition: LidarData.h:105
void WritePointSync(LidarDetection &detection)
Definition: LidarData.h:98
LidarDetection(float x, float y, float z, float intensity)
Definition: LidarData.h:59
LidarDetection(geom::Location p, float intensity)
Definition: LidarData.h:61
Helper class to store and serialize the data generated by a Lidar.
Definition: LidarData.h:52
std::vector< float > _points
Definition: LidarData.h:111