CARLA
Loading...
Searching...
No Matches
CarlaSemanticLidarPublisher.cpp
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
8
9#include <cstring>
10
11namespace carla {
12namespace ros2 {
13
14namespace {
15
16// Wire-compatible POD mirror of sensor::data::SemanticLidarDetection:
17// {x, y, z, cos_inc_angle, object_idx, object_tag}. The real struct lives
18// behind carla/sensor/data/SemanticLidarData.h, which transitively pulls
19// Boost; that header chain is unavailable in the carla-ros2-native
20// ExternalProject include path. Layout pinned by kSemanticLidarFields in
21// PointCloudFieldsLayout.h and by test_point_cloud_fields.cpp.
22struct SemanticLidarPoint {
23 float x;
24 float y;
25 float z;
27 std::uint32_t object_idx;
28 std::uint32_t object_tag;
29};
30
31static_assert(
32 sizeof(SemanticLidarPoint) == 24u,
33 "SemanticLidarPoint must be tightly packed (4 float32s + 2 uint32s) for the wire layout");
34
35} // namespace
36
38 return sizeof(SemanticLidarPoint);
39}
40
44
48
50 std::uint32_t height, std::uint32_t width, const std::uint8_t *data) const {
51 const std::size_t total_points =
52 static_cast<std::size_t>(height) * static_cast<std::size_t>(width);
53 const std::size_t total_bytes = total_points * sizeof(SemanticLidarPoint);
54
55 std::vector<std::uint8_t> bytes(total_bytes);
56 std::memcpy(bytes.data(), data, total_bytes);
57
58 // Mirror the Y axis for the ROS right-handed frame. The buffer is a
59 // contiguous array of SemanticLidarPoint PODs by contract.
60 auto *points = reinterpret_cast<SemanticLidarPoint *>(bytes.data());
61 for (std::size_t i = 0; i < total_points; ++i) {
62 points[i].y *= -1.0f;
63 }
64 return bytes;
65}
66
67} // namespace ros2
68} // namespace carla
float y
float x
float z
std::uint32_t object_idx
std::uint32_t object_tag
const PointFieldDescriptor * GetFieldDescriptors() const override
std::vector< std::uint8_t > ComputePointCloud(std::uint32_t height, std::uint32_t width, const std::uint8_t *data) const override
constexpr std::array< PointFieldDescriptor, 6 > kSemanticLidarFields
This file contains definitions of common data structures used in traffic manager.