CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
ros2
publishers
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
7
#include "
carla/ros2/publishers/CarlaSemanticLidarPublisher.h
"
8
9
#include <cstring>
10
11
namespace
carla
{
12
namespace
ros2
{
13
14
namespace
{
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.
22
struct
SemanticLidarPoint {
23
float
x;
24
float
y;
25
float
z;
26
float
cos_inc_angle;
27
std::uint32_t object_idx;
28
std::uint32_t object_tag;
29
};
30
31
static_assert
(
32
sizeof
(SemanticLidarPoint) == 24u,
33
"SemanticLidarPoint must be tightly packed (4 float32s + 2 uint32s) for the wire layout"
);
34
35
}
// namespace
36
37
std::size_t
CarlaSemanticLidarPublisher::GetPointSize
()
const
{
38
return
sizeof
(SemanticLidarPoint);
39
}
40
41
const
PointFieldDescriptor
*
CarlaSemanticLidarPublisher::GetFieldDescriptors
()
const
{
42
return
kSemanticLidarFields
.data();
43
}
44
45
std::size_t
CarlaSemanticLidarPublisher::GetFieldDescriptorCount
()
const
{
46
return
kSemanticLidarFields
.size();
47
}
48
49
std::vector<std::uint8_t>
CarlaSemanticLidarPublisher::ComputePointCloud
(
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
CarlaSemanticLidarPublisher.h
carla::ros2::CarlaSemanticLidarPublisher::GetFieldDescriptorCount
std::size_t GetFieldDescriptorCount() const override
Definition
CarlaSemanticLidarPublisher.cpp:45
carla::ros2::CarlaSemanticLidarPublisher::GetFieldDescriptors
const PointFieldDescriptor * GetFieldDescriptors() const override
Definition
CarlaSemanticLidarPublisher.cpp:41
carla::ros2::CarlaSemanticLidarPublisher::GetPointSize
std::size_t GetPointSize() const override
Definition
CarlaSemanticLidarPublisher.cpp:37
carla::ros2::CarlaSemanticLidarPublisher::ComputePointCloud
std::vector< std::uint8_t > ComputePointCloud(std::uint32_t height, std::uint32_t width, const std::uint8_t *data) const override
Definition
CarlaSemanticLidarPublisher.cpp:49
carla::ros2
Definition
AutowareSteeringCompensation.h:15
carla::ros2::kSemanticLidarFields
constexpr std::array< PointFieldDescriptor, 6 > kSemanticLidarFields
Definition
PointCloudFieldsLayout.h:68
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::ros2::PointFieldDescriptor
Definition
PointCloudFieldsLayout.h:33
Generated by
1.18.0