CARLA
Loading...
Searching...
No Matches
PointCloudFieldsLayout.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
9#include <array>
10#include <cstdint>
11#include <string_view>
12
13namespace carla {
14namespace ros2 {
15
16// PointField datatype constants mirror the numeric constants in
17// carla/ros2/types/msg/PointField.h (carla::ros2::msg::PointField::*). They are
18// kept here as an enum class so this header does not pull the message types into
19// the Build-Tests/ compile unit. Producers in publishers/Carla*Publisher.cpp map
20// these values onto carla::ros2::msg::PointField; this enum mirrors the same
21// numeric values so layout tests can verify field offsets / sizes.
22enum class PointFieldDataType : std::uint8_t {
23 Int8 = 1,
24 UInt8 = 2,
25 Int16 = 3,
26 UInt16 = 4,
27 Int32 = 5,
28 UInt32 = 6,
29 Float32 = 7,
30 Float64 = 8,
31};
32
34 std::string_view name;
35 std::uint32_t offset;
37 std::uint32_t count;
38};
39
40// Lidar: 4 FLOAT32 fields. Point stride = 16 B = sizeof(sensor::data::LidarDetection).
41inline constexpr std::array<PointFieldDescriptor, 4> kLidarFields = {{
42 {"x", 0u, PointFieldDataType::Float32, 1u},
43 {"y", 4u, PointFieldDataType::Float32, 1u},
44 {"z", 8u, PointFieldDataType::Float32, 1u},
45 {"intensity", 12u, PointFieldDataType::Float32, 1u},
46}};
47
48// Extended lidar (Autoware PointXYZIRCAEDT, tier4 SetDataEx port): x/y/z
49// FLOAT32, intensity + return_type UINT8, channel UINT16, azimuth/elevation/
50// distance FLOAT32, time_stamp UINT32. Point stride = 32 B, matching both the
51// tightly packed field layout and the naturally aligned LidarPointEx POD in
52// CarlaLidarPublisher.cpp (the uint16 lands on offset 14, so no padding).
53inline constexpr std::array<PointFieldDescriptor, 10> kLidarFieldsEx = {{
54 {"x", 0u, PointFieldDataType::Float32, 1u},
55 {"y", 4u, PointFieldDataType::Float32, 1u},
56 {"z", 8u, PointFieldDataType::Float32, 1u},
57 {"intensity", 12u, PointFieldDataType::UInt8, 1u},
58 {"return_type", 13u, PointFieldDataType::UInt8, 1u},
59 {"channel", 14u, PointFieldDataType::UInt16, 1u},
60 {"azimuth", 16u, PointFieldDataType::Float32, 1u},
61 {"elevation", 20u, PointFieldDataType::Float32, 1u},
62 {"distance", 24u, PointFieldDataType::Float32, 1u},
63 {"time_stamp", 28u, PointFieldDataType::UInt32, 1u},
64}};
65
66// Semantic lidar: 6 fields. 4 FLOAT32 + 2 UINT32. Point stride = 24 B =
67// sizeof(sensor::data::SemanticLidarDetection).
68inline constexpr std::array<PointFieldDescriptor, 6> kSemanticLidarFields = {{
69 {"x", 0u, PointFieldDataType::Float32, 1u},
70 {"y", 4u, PointFieldDataType::Float32, 1u},
71 {"z", 8u, PointFieldDataType::Float32, 1u},
72 {"cos_inc_angle", 12u, PointFieldDataType::Float32, 1u},
73 {"object_idx", 16u, PointFieldDataType::UInt32, 1u},
74 {"object_tag", 20u, PointFieldDataType::UInt32, 1u},
75}};
76
77// Radar: 7 FLOAT32 fields. Point stride = 28 B =
78// sizeof(RadarDetectionWithPosition) — 3 Cartesian floats prepended to the
79// raw RadarDetection payload (velocity, azimuth, altitude, depth).
80inline constexpr std::array<PointFieldDescriptor, 7> kRadarFields = {{
81 {"x", 0u, PointFieldDataType::Float32, 1u},
82 {"y", 4u, PointFieldDataType::Float32, 1u},
83 {"z", 8u, PointFieldDataType::Float32, 1u},
84 {"velocity", 12u, PointFieldDataType::Float32, 1u},
85 {"azimuth", 16u, PointFieldDataType::Float32, 1u},
86 {"altitude", 20u, PointFieldDataType::Float32, 1u},
87 {"depth", 24u, PointFieldDataType::Float32, 1u},
88}};
89
90// DVS events: x/y UINT16, t FLOAT64, pol INT8. The producer converts the
91// underlying int64 event timestamp to a real double in the 8-byte t slot
92// (sensor_msgs PointField has no 8-byte integer datatype). Per-point stride
93// matches the packed sensor::data::DVSEvent (13 B with #pragma pack(push, 1)).
94inline constexpr std::array<PointFieldDescriptor, 4> kDvsFields = {{
95 {"x", 0u, PointFieldDataType::UInt16, 1u},
96 {"y", 2u, PointFieldDataType::UInt16, 1u},
97 {"t", 4u, PointFieldDataType::Float64, 1u},
98 {"pol", 12u, PointFieldDataType::Int8, 1u},
99}};
100
101// Each table's last field's offset + datatype size must equal the
102// corresponding sensor's point stride. The producers check that with a
103// runtime sizeof() assertion against the underlying POD; layout tests in
104// test_point_cloud_fields.cpp verify the same property at compile time.
105
106} // namespace ros2
107} // namespace carla
constexpr std::array< PointFieldDescriptor, 4 > kLidarFields
constexpr std::array< PointFieldDescriptor, 7 > kRadarFields
constexpr std::array< PointFieldDescriptor, 4 > kDvsFields
constexpr std::array< PointFieldDescriptor, 6 > kSemanticLidarFields
constexpr std::array< PointFieldDescriptor, 10 > kLidarFieldsEx
This file contains definitions of common data structures used in traffic manager.