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