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