55#include < realdds/dds-defines.h>
66#include < fastdds/rtps/common/Time_t.h>
77
8+ #include < realdds/topics/ros2/ros2image.h>
9+
810#include < string>
911#include < memory>
1012#include < vector>
1315namespace sensor_msgs {
1416namespace msg {
1517class ImagePubSubType ;
16- class Image ;
1718} // namespace msg
1819} // namespace sensor_msgs
1920
@@ -31,6 +32,8 @@ namespace topics {
3132
3233class image_msg
3334{
35+ sensor_msgs::msg::Image _raw;
36+
3437public:
3538 using type = sensor_msgs::msg::ImagePubSubType;
3639
@@ -46,8 +49,34 @@ class image_msg
4649 image_msg & operator =( image_msg && ) = default ;
4750 image_msg & operator =( sensor_msgs::msg::Image && );
4851
49- bool is_valid () const { return width != -1 && height != -1 ; }
50- void invalidate () { width = -1 ; }
52+ bool is_valid () const { return ! _raw.data ().empty (); }
53+ void invalidate () { _raw.data ().clear (); }
54+
55+ sensor_msgs::msg::Image & raw () { return _raw; }
56+ sensor_msgs::msg::Image const & raw () const { return _raw; }
57+
58+ auto width () const { return _raw.width (); }
59+ void set_width ( uint32_t w ) { _raw.width ( w ); }
60+ auto height () const { return _raw.height (); }
61+ void set_height ( uint32_t h ) { _raw.height ( h ); }
62+ auto step () const { return _raw.step (); }
63+ void set_step ( uint32_t step ) { _raw.step ( step ); }
64+
65+ std::string const & frame_id () const { return _raw.header ().frame_id (); }
66+ void set_frame_id ( std::string new_id ) { _raw.header ().frame_id ( std::move ( new_id ) ); }
67+
68+ std::string const & encoding () const { return _raw.encoding (); }
69+ void set_encoding ( std::string new_encoding ) { _raw.encoding ( std::move ( new_encoding ) ); }
70+
71+ bool is_bigendian () const { return _raw.is_bigendian (); }
72+
73+ void set_timestamp ( dds_time const & t )
74+ {
75+ _raw.header ().stamp ().sec ( t.seconds );
76+ _raw.header ().stamp ().nanosec ( t.nanosec );
77+ }
78+ dds_time timestamp () const { return { _raw.header ().stamp ().sec (), _raw.header ().stamp ().nanosec () }; }
79+
5180
5281 static std::shared_ptr< dds_topic > create_topic ( std::shared_ptr< dds_participant > const & participant,
5382 char const * topic_name );
@@ -63,11 +92,6 @@ class image_msg
6392 static bool take_next ( dds_topic_reader &,
6493 image_msg * output,
6594 dds_sample * optional_sample = nullptr );
66-
67- std::vector< uint8_t > raw_data;
68- int width = -1 ;
69- int height = -1 ;
70- dds_time timestamp;
7195};
7296
7397
0 commit comments