CARLA
Loading...
Searching...
No Matches
CarlaPointCloudPublisher.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 <cstddef>
13#include <cstdint>
14#include <memory>
15#include <vector>
16
17namespace carla {
18namespace ros2 {
19
20// Forward declarations keep the FastDDS-heavy PublisherImpl<> definition out
21// of the main carla-server compile unit. The full template definition + the
22// PointCloud2 Traits instantiation live in CarlaPointCloudPublisher.cpp,
23// which is built by the carla-ros2-native ExternalProject (where FastDDS
24// headers are on the include path). Same Pimpl pattern as PR-3's
25// CarlaCameraPublisher.{h,cpp}.
26template <typename Traits> class PublisherImpl;
27struct CarlaPointCloudMsgTraits;
28
29// Abstract base for ROS 2 publishers that ship sensor_msgs::msg::PointCloud2:
30// lidar, semantic-lidar, radar, and the point-cloud side of the DVS sensor.
31// Each subclass declares its PointField layout (via PointCloudFieldsLayout.h)
32// and implements ComputePointCloud(), which is responsible for any per-point
33// transform (handedness flip, polar-to-Cartesian conversion, etc.) and
34// returns the bytes that get written to the wire. The Init() call on the
35// underlying PublisherImpl happens in the ctor, so a subclass only has to
36// pass the (base_topic_name, frame_id) pair through.
38public:
39 // exact_topic: when true the writer publishes on base_topic_name verbatim
40 // (no "/point_cloud" suffix). Used by single-topic point-cloud sensors when
41 // the actor carries a ros_topic_name override — tier4's custom topic names
42 // replaced the whole topic for those publishers (e.g. Autoware expects
43 // exactly /sensing/lidar/top/pointcloud_raw_ex). The DVS point-cloud lane
44 // keeps the suffix: it shares its base with the image/camera_info topics.
46 std::string base_topic_name, std::string frame_id, bool exact_topic = false);
48
52 CarlaPointCloudPublisher &operator=(CarlaPointCloudPublisher &&) noexcept = default;
53
54 bool Publish() override;
55
56 bool WritePointCloud(
57 std::int32_t seconds,
58 std::uint32_t nanoseconds,
59 std::uint32_t height,
60 std::uint32_t width,
61 const std::uint8_t *data);
62
63protected:
64 [[nodiscard]] virtual std::size_t GetPointSize() const = 0;
65 [[nodiscard]] virtual const PointFieldDescriptor *GetFieldDescriptors() const = 0;
66 [[nodiscard]] virtual std::size_t GetFieldDescriptorCount() const = 0;
67 [[nodiscard]] virtual std::vector<std::uint8_t> ComputePointCloud(
68 std::uint32_t height, std::uint32_t width, const std::uint8_t *data) const = 0;
69
70private:
71 bool WritePointCloud(
72 std::int32_t seconds,
73 std::uint32_t nanoseconds,
74 std::uint32_t height,
75 std::uint32_t width,
76 std::vector<std::uint8_t> data);
77
79};
80
81} // namespace ros2
82} // namespace carla
virtual std::size_t GetPointSize() const =0
virtual std::size_t GetFieldDescriptorCount() const =0
CarlaPointCloudPublisher & operator=(const CarlaPointCloudPublisher &)=delete
bool WritePointCloud(std::int32_t seconds, std::uint32_t nanoseconds, std::uint32_t height, std::uint32_t width, const std::uint8_t *data)
virtual std::vector< std::uint8_t > ComputePointCloud(std::uint32_t height, std::uint32_t width, const std::uint8_t *data) const =0
virtual const PointFieldDescriptor * GetFieldDescriptors() const =0
CarlaPointCloudPublisher(const CarlaPointCloudPublisher &)=delete
CarlaPointCloudPublisher(CarlaPointCloudPublisher &&) noexcept=default
std::shared_ptr< PublisherImpl< CarlaPointCloudMsgTraits > > _impl
This file contains definitions of common data structures used in traffic manager.