32
32
#include < memory>
33
33
#include < string>
34
34
#include < utility>
35
+ #include < algorithm>
36
+ #include < vector>
35
37
36
38
#include < OgreCamera.h>
37
39
#include < OgreManualObject.h>
54
56
#include " rviz_common/render_panel.hpp"
55
57
#include " rviz_common/validate_floats.hpp"
56
58
#include " rviz_common/uniform_string_stream.hpp"
59
+ #include " rviz_common/properties/ros_topic_multi_property.hpp"
57
60
#include " rviz_rendering/material_manager.hpp"
58
61
#include " rviz_rendering/render_window.hpp"
59
62
62
65
#include " rviz_default_plugins/displays/image/ros_image_texture_iface.hpp"
63
66
#include " rviz_default_plugins/displays/image/get_transport_from_topic.hpp"
64
67
68
+ #include < rviz_common/logging.hpp> // TODO remove when done
69
+
65
70
namespace rviz_default_plugins
66
71
{
67
72
namespace displays
@@ -73,16 +78,17 @@ ImageDisplay::ImageDisplay()
73
78
ImageDisplay::ImageDisplay (std::unique_ptr<ROSImageTextureIface> texture)
74
79
: texture_(std::move(texture))
75
80
{
81
+ delete this ->topic_property_ ;
82
+ this ->topic_property_ = new rviz_common::properties::RosTopicMultiProperty (
83
+ " Topic" ,
84
+ " " ,
85
+ std::vector<QString>(),
86
+ " Image transport topic to subscribe to." ,
87
+ this ,
88
+ SLOT (updateTopic ()));
76
89
77
- image_transport_property_ = new rviz_common::properties::EnumProperty (
78
- " Image Transport Hint" ,
79
- " raw" ,
80
- " What type of image transport to use." ,
81
- topic_property_, SLOT (updateTransport ()),
82
- this );
83
-
84
- for (const auto & [key, value] : transport_message_types_)
85
- image_transport_property_->addOption (key);
90
+ delete this ->qos_profile_property_ ;
91
+ this ->qos_profile_property_ = new rviz_common::properties::QosProfileProperty (this ->topic_property_ , rclcpp::QoS (5 ));
86
92
87
93
normalize_property_ = new rviz_common::properties::BoolProperty (
88
94
" Normalize Range" ,
@@ -152,6 +158,45 @@ void ImageDisplay::subscribe(){
152
158
if (!isEnabled ()) {
153
159
return ;
154
160
}
161
+
162
+ // TODO this should really be in onInitialize but setStatus does not work there
163
+ // Populate topic message types based on installed image_transport plugins
164
+ image_transport::ImageTransport image_transport_ (rviz_ros_node_.lock ()->get_raw_node ());
165
+ std::vector<std::string> transports = image_transport_.getLoadableTransports ();
166
+ std::vector<QString> message_types;
167
+ // Map to message types
168
+ const std::unordered_map<std::string, std::string> transport_message_types_ =
169
+ {
170
+ {" raw" , " sensor_msgs/msg/Image" },
171
+ {" compressed" , " sensor_msgs/msg/CompressedImage" },
172
+ {" compressedDepth" , " sensor_msgs/msg/CompressedImage" },
173
+ {" theora" , " theora_image_transport/msg/Packet" },
174
+ {" zstd" , " sensor_msgs/msg/CompressedImage" },
175
+ };
176
+ std::string transports_str = " " ;
177
+ rviz_common::properties::StatusProperty::Level transports_status_level =
178
+ rviz_common::properties::StatusProperty::Ok;
179
+ for (std::string & transport : transports){
180
+ transport = transport.substr (transport.find_last_of (' /' ) + 1 );
181
+ try {
182
+ message_types.push_back (QString::fromStdString (transport_message_types_.at (transport)));
183
+ transports_str += transport + " , " ;
184
+ }
185
+ catch (const std::out_of_range & e){
186
+ transports_status_level = rviz_common::properties::StatusProperty::Warn;
187
+ transports_str += " (unknown: " + transport + " ), " ;
188
+ }
189
+ }
190
+ setStatusStd (
191
+ transports_status_level,
192
+ " Image Transports" ,
193
+ transports_str);
194
+ // Remove duplicates
195
+ message_types.erase (std::unique (message_types.begin (), message_types.end () ), message_types.end ());
196
+ // Update the message types to allow in the topic_property_
197
+ ((rviz_common::properties::RosTopicMultiProperty*)topic_property_)->setMessageTypes (message_types);
198
+
199
+ RVIZ_COMMON_LOG_INFO (" subscribe" );
155
200
if (topic_property_->isEmpty ()) {
156
201
setStatus (
157
202
rviz_common::properties::StatusProperty::Error, " Topic" ,
@@ -171,7 +216,10 @@ void ImageDisplay::subscribe(){
171
216
(uint32_t )qos_profile.get_rmw_qos_profile ().depth , // TODO try without cast
172
217
&ImageDisplay::incomingMessage,
173
218
this ,
174
- new image_transport::TransportHints (node.get (),getTransportStd ()," image_transport" ));
219
+ new image_transport::TransportHints (
220
+ node.get (),
221
+ getTransportFromTopic (topic_property_->getStdString ()),
222
+ " image_transport" ));
175
223
176
224
setStatus (rviz_common::properties::StatusProperty::Ok, " Topic" , " OK" );
177
225
} catch (rclcpp::exceptions::InvalidTopicNameError & e) {
@@ -206,14 +254,6 @@ void ImageDisplay::updateNormalizeOptions()
206
254
}
207
255
}
208
256
209
- bool ImageDisplay::setTransport (const QString & str){
210
- return image_transport_property_->setValue (str.toLower ());
211
- }
212
-
213
- bool ImageDisplay::setTransportStd (const std::string & std_str){
214
- return image_transport_property_->setValue (QString::fromStdString (std_str).toLower ());
215
- }
216
-
217
257
void ImageDisplay::clear ()
218
258
{
219
259
texture_->clear ();
@@ -256,14 +296,6 @@ void ImageDisplay::reset()
256
296
clear ();
257
297
}
258
298
259
- QString ImageDisplay::getTransport (){
260
- return image_transport_property_->getString ();
261
- }
262
-
263
- std::string ImageDisplay::getTransportStd (){
264
- return image_transport_property_->getStdString ();
265
- }
266
-
267
299
/* This is called by incomingMessage(). */
268
300
void ImageDisplay::processMessage (sensor_msgs::msg::Image::ConstSharedPtr msg)
269
301
{
@@ -279,16 +311,6 @@ void ImageDisplay::processMessage(sensor_msgs::msg::Image::ConstSharedPtr msg)
279
311
texture_->addMessage (msg);
280
312
}
281
313
282
- void ImageDisplay::updateTransport (){
283
- topic_property_->setMessageType (
284
- transport_message_types_.at (image_transport_property_->getString ()));
285
-
286
- // If topic does not match desired transport, clear it.
287
- if (getTransportFromTopic (topic_property_->getStdString ()) !=
288
- image_transport_property_->getStdString ())
289
- topic_property_->setString (" " );
290
- }
291
-
292
314
void ImageDisplay::setupScreenRectangle ()
293
315
{
294
316
static int count = 0 ;
0 commit comments