Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define RVIZ_COMMON__PROPERTIES__ROS_TOPIC_PROPERTY_HPP_

#include <string>
#include <vector>

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

void setMessageType(const QString & message_type);

void setMessageTypes(const std::vector<QString> & message_types);

QString getMessageType() const
{return message_type_;}
{return message_types_.empty() ? QString() : message_types_.front();}

std::vector<QString> getMessageTypes() const
{return message_types_;}

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

private:
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node_;
QString message_type_;
std::vector<QString> message_types_;
};

class RVIZ_COMMON_PUBLIC RosFilteredTopicProperty
Expand Down
20 changes: 14 additions & 6 deletions rviz_common/src/rviz_common/properties/ros_topic_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RosTopicProperty::RosTopicProperty(
QObject * receiver)
: EditableEnumProperty(name, default_value, description, parent, changed_slot, receiver),
rviz_ros_node_(),
message_type_(message_type)
message_types_({message_type})
{
connect(
this, SIGNAL(requestOptions(EditableEnumProperty*)),
Expand All @@ -65,23 +65,31 @@ void RosTopicProperty::initialize(ros_integration::RosNodeAbstractionIface::Weak

void RosTopicProperty::setMessageType(const QString & message_type)
{
message_type_ = message_type;
message_types_.clear();
message_types_.push_back(message_type);
}

void RosTopicProperty::setMessageTypes(const std::vector<QString> & message_types)
{
message_types_ = message_types;
}

void RosTopicProperty::fillTopicList()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
clearOptions();

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

for (const auto & topic : published_topics) {
// Only add topics whose type matches.
for (const auto & type : topic.second) {
if (type == std_message_type) {
addOptionStd(topic.first);
for (const auto & message_type : message_types_) {
std::string std_message_type = message_type.toStdString();
if (type == std_message_type) {
addOptionStd(topic.first);
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ class ImageTransportDisplay : public rviz_common::_RosTopicDisplay
: messages_received_(0)
{
QString message_type = QString::fromStdString(rosidl_generator_traits::name<MessageType>());
topic_property_->setMessageType(message_type);
std::vector<QString> supported_types = {
message_type,
"sensor_msgs/msg/CompressedImage",
"ffmpeg_image_transport/msg/FFMPEGPacket",
"theora_image_transport/msg/Packet"
};

topic_property_->setMessageTypes(supported_types);
topic_property_->setDescription(message_type + " topic to subscribe to.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ class PointCloud2TransportDisplay : public rviz_common::_RosTopicDisplay
: messages_received_(0)
{
QString message_type = QString::fromStdString(rosidl_generator_traits::name<MessageType>());
topic_property_->setMessageType(message_type);
std::vector<QString> supported_types = {
message_type,
"point_cloud_interfaces/msg/CompressedPointCloud2"
};

topic_property_->setMessageTypes(supported_types);
topic_property_->setDescription(message_type + " topic to subscribe to.");
}

Expand Down
8 changes: 7 additions & 1 deletion rviz_default_plugins/plugins_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
<description>
Displays an image from a camera, with the visualized world rendered behind it. &lt;a href="http://www.ros.org/wiki/rviz/DisplayTypes/Camera"&gt;More Information&lt;/a&gt;.
</description>
<message_type>sensor_msgs/msg/Image</message_type>
<message_type>ffmpeg_image_transport_msgs/msg/FFMPEGPacket</message_type>
<message_type>sensor_msgs/msg/CompressedImage</message_type>
<message_type>sensor_msgs/msg/Image</message_type>
<message_type>theora_image_transport/msg/Packet</message_type>
</class>

<class
Expand Down Expand Up @@ -119,7 +121,10 @@
<description>
The Image display creates a new rendering window with an image.
</description>
<message_type>ffmpeg_image_transport_msgs/msg/FFMPEGPacket</message_type>
<message_type>sensor_msgs/msg/CompressedImage</message_type>
<message_type>sensor_msgs/msg/Image</message_type>
<message_type>theora_image_transport/msg/Packet</message_type>
</class>

<class
Expand Down Expand Up @@ -173,6 +178,7 @@
<description>
The Point Cloud2 display shows data from a (recommended) sensor_msgs/PointCloud2 message.
</description>
<message_type>point_cloud_interfaces/msg/CompressedPointCloud2</message_type>
<message_type>sensor_msgs/msg/PointCloud2</message_type>
</class>

Expand Down