Skip to content

Commit f93b77b

Browse files
author
Emre Karincali
committed
improve support for compressed image topics in image display dropdowns
1 parent f0da52a commit f93b77b

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

rviz_common/include/rviz_common/properties/ros_topic_property.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define RVIZ_COMMON__PROPERTIES__ROS_TOPIC_PROPERTY_HPP_
3131

3232
#include <string>
33+
#include <vector>
3334

3435
#include "rviz_common/properties/editable_enum_property.hpp"
3536
#include "rviz_common/ros_integration/ros_node_abstraction_iface.hpp"
@@ -58,8 +59,13 @@ class RVIZ_COMMON_PUBLIC RosTopicProperty : public EditableEnumProperty
5859

5960
void setMessageType(const QString & message_type);
6061

62+
void setMessageTypes(const std::vector<QString> & message_types);
63+
6164
QString getMessageType() const
62-
{return message_type_;}
65+
{return message_types_.front();}
66+
67+
std::vector<QString> getMessageTypes() const
68+
{return message_types_;}
6369

6470
QString getTopic() const
6571
{return getValue().toString();}
@@ -75,7 +81,7 @@ protected Q_SLOTS:
7581

7682
private:
7783
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node_;
78-
QString message_type_;
84+
std::vector<QString> message_types_;
7985
};
8086

8187
class RVIZ_COMMON_PUBLIC RosFilteredTopicProperty

rviz_common/src/rviz_common/properties/ros_topic_property.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ RosTopicProperty::RosTopicProperty(
5151
QObject * receiver)
5252
: EditableEnumProperty(name, default_value, description, parent, changed_slot, receiver),
5353
rviz_ros_node_(),
54-
message_type_(message_type)
54+
message_types_({message_type})
5555
{
5656
connect(
5757
this, SIGNAL(requestOptions(EditableEnumProperty*)),
@@ -65,23 +65,31 @@ void RosTopicProperty::initialize(ros_integration::RosNodeAbstractionIface::Weak
6565

6666
void RosTopicProperty::setMessageType(const QString & message_type)
6767
{
68-
message_type_ = message_type;
68+
message_types_.clear();
69+
message_types_.push_back(message_type);
70+
}
71+
72+
void RosTopicProperty::setMessageTypes(const std::vector<QString> & message_types)
73+
{
74+
message_types_ = message_types;
6975
}
7076

7177
void RosTopicProperty::fillTopicList()
7278
{
7379
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
7480
clearOptions();
7581

76-
std::string std_message_type = message_type_.toStdString();
7782
std::map<std::string, std::vector<std::string>> published_topics =
7883
rviz_ros_node_.lock()->get_topic_names_and_types();
7984

8085
for (const auto & topic : published_topics) {
81-
// Only add topics whose type matches.
8286
for (const auto & type : topic.second) {
83-
if (type == std_message_type || (type == "sensor_msgs/msg/CompressedImage" && std_message_type == "sensor_msgs/msg/Image")) {
84-
addOptionStd(topic.first);
87+
for (const auto & message_type : message_types_) {
88+
std::string std_message_type = message_type.toStdString();
89+
if (type == std_message_type) {
90+
addOptionStd(topic.first);
91+
break;
92+
}
8593
}
8694
}
8795
}

rviz_default_plugins/include/rviz_default_plugins/displays/image/image_transport_display.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ class ImageTransportDisplay : public rviz_common::_RosTopicDisplay
6060
: messages_received_(0)
6161
{
6262
QString message_type = QString::fromStdString(rosidl_generator_traits::name<MessageType>());
63-
topic_property_->setMessageType(message_type);
63+
std::vector<QString> supported_types = {
64+
"sensor_msgs/msg/Image",
65+
"sensor_msgs/msg/CompressedImage",
66+
"ffmpeg_image_transport/msg/FFMPEGPacket",
67+
"theora_image_transport/msg/Packet"
68+
};
69+
70+
topic_property_->setMessageTypes(supported_types);
6471
topic_property_->setDescription(message_type + " topic to subscribe to.");
6572
}
6673

0 commit comments

Comments
 (0)