CARLA
Loading...
Searching...
No Matches
CarlaDVSCameraPublisher.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
12
13#include <cstdint>
14#include <memory>
15#include <string>
16#include <vector>
17
18namespace carla {
19namespace ros2 {
20
21// Image-side companion publisher: writes the dense visualisation of the DVS
22// event stream as a 3-channel BGR sensor_msgs/Image to the existing wire
23// format ROS 2 subscribers depend on. The encoding (positive polarity =
24// red, negative polarity = blue) lives in DvsEventEncoding.h so a GTest
25// pins it without instantiating FastDDS.
27public:
28 CarlaDVSImagePublisher(std::string base_topic_name, std::string frame_id)
29 : CarlaCameraPublisher(std::move(base_topic_name), std::move(frame_id)) {}
30
31 // Encode-from-events overload: walks the DVSEvent stream and writes the
32 // dense image via the seam.
34 std::int32_t seconds,
35 std::uint32_t nanoseconds,
36 std::uint32_t height,
37 std::uint32_t width,
38 const std::uint8_t *events,
39 std::size_t event_count,
40 std::size_t event_stride);
41
42protected:
43 [[nodiscard]] std::uint8_t GetChannels() const override { return 3u; }
44 [[nodiscard]] std::string GetEncoding() const override { return "bgr8"; }
45};
46
47// Point-cloud-side companion publisher: emits the raw DVS events as a
48// sensor_msgs/PointCloud2 with the (x, y, t, pol) field layout shared with
49// PR-3's pre-existing ue5-dev wire format.
51public:
52 CarlaDVSPointCloudPublisher(std::string base_topic_name, std::string frame_id)
53 : CarlaPointCloudPublisher(std::move(base_topic_name), std::move(frame_id)) {}
54
55private:
56 [[nodiscard]] std::size_t GetPointSize() const override;
57 [[nodiscard]] const PointFieldDescriptor *GetFieldDescriptors() const override;
58 [[nodiscard]] std::size_t GetFieldDescriptorCount() const override;
59 [[nodiscard]] std::vector<std::uint8_t> ComputePointCloud(
60 std::uint32_t height, std::uint32_t width, const std::uint8_t *data) const override;
61};
62
63// Public composite. Each tick the simulator hands the raw DVS event buffer
64// once; the composite fans the data out to the image-side (encoded BGR
65// visualisation) and the point-cloud-side (raw events) publishers.
67public:
68 CarlaDVSCameraPublisher(std::string base_topic_name, std::string frame_id);
70
74 CarlaDVSCameraPublisher &operator=(CarlaDVSCameraPublisher &&) noexcept = default;
75
76 bool Publish() override;
77
78 bool WriteCameraInfo(
79 std::int32_t seconds,
80 std::uint32_t nanoseconds,
81 std::uint32_t x_offset,
82 std::uint32_t y_offset,
83 std::uint32_t height,
84 std::uint32_t width,
85 float fov,
86 bool do_rectify);
87
88 bool WriteImage(
89 std::int32_t seconds,
90 std::uint32_t nanoseconds,
91 std::uint32_t height,
92 std::uint32_t width,
93 std::size_t event_count,
94 const std::uint8_t *events,
95 std::size_t event_stride);
96
97 bool WritePointCloud(
98 std::int32_t seconds,
99 std::uint32_t nanoseconds,
100 std::uint32_t height,
101 std::uint32_t width,
102 const std::uint8_t *data);
103
104private:
107};
108
109} // namespace ros2
110} // namespace carla
std::shared_ptr< CarlaDVSPointCloudPublisher > _point_cloud_pub
bool WriteCameraInfo(std::int32_t seconds, std::uint32_t nanoseconds, std::uint32_t x_offset, std::uint32_t y_offset, std::uint32_t height, std::uint32_t width, float fov, bool do_rectify)
bool WriteImage(std::int32_t seconds, std::uint32_t nanoseconds, std::uint32_t height, std::uint32_t width, std::size_t event_count, const std::uint8_t *events, std::size_t event_stride)
CarlaDVSCameraPublisher(CarlaDVSCameraPublisher &&) noexcept=default
bool WritePointCloud(std::int32_t seconds, std::uint32_t nanoseconds, std::uint32_t height, std::uint32_t width, const std::uint8_t *data)
std::shared_ptr< CarlaDVSImagePublisher > _image_pub
CarlaDVSCameraPublisher(const CarlaDVSCameraPublisher &)=delete
CarlaDVSCameraPublisher & operator=(const CarlaDVSCameraPublisher &)=delete
std::string GetEncoding() const override
std::uint8_t GetChannels() const override
CarlaDVSImagePublisher(std::string base_topic_name, std::string frame_id)
bool WriteImageFromEvents(std::int32_t seconds, std::uint32_t nanoseconds, std::uint32_t height, std::uint32_t width, const std::uint8_t *events, std::size_t event_count, std::size_t event_stride)
std::vector< std::uint8_t > ComputePointCloud(std::uint32_t height, std::uint32_t width, const std::uint8_t *data) const override
CarlaDVSPointCloudPublisher(std::string base_topic_name, std::string frame_id)
const PointFieldDescriptor * GetFieldDescriptors() const override
This file contains definitions of common data structures used in traffic manager.