Skip to content

Commit

Permalink
list image transport topics if parent image topic is not available (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Mar 6, 2014
1 parent ff05667 commit 5fa643e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
6 changes: 5 additions & 1 deletion rqt_image_view/include/rqt_image_view/image_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <ui_image_view.h>

#include <image_transport/image_transport.h>
#include <ros/macros.h>
#include <sensor_msgs/Image.h>

#include <opencv2/core/core.hpp>
Expand Down Expand Up @@ -75,7 +76,10 @@ protected slots:

protected:

virtual QList<QString> getTopicList(const QSet<QString>& message_types, const QList<QString>& transports);
// deprecated function for backward compatibility only, use getTopics() instead
ROS_DEPRECATED virtual QList<QString> getTopicList(const QSet<QString>& message_types, const QList<QString>& transports);

virtual QSet<QString> getTopics(const QSet<QString>& message_types, const QSet<QString>& message_sub_types, const QList<QString>& transports);

virtual void selectTopic(const QString& topic);

Expand Down
33 changes: 26 additions & 7 deletions rqt_image_view/src/rqt_image_view/image_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ void ImageView::updateTopicList()
{
QSet<QString> message_types;
message_types.insert("sensor_msgs/Image");
QSet<QString> message_sub_types;
message_sub_types.insert("sensor_msgs/CompressedImage");

// get declared transports
QList<QString> transports;
Expand All @@ -132,7 +134,7 @@ void ImageView::updateTopicList()
QString selected = ui_.topics_combo_box->currentText();

// fill combo box
QList<QString> topics = getTopicList(message_types, transports);
QList<QString> topics = getTopics(message_types, message_sub_types, transports).values();
topics.append("");
qSort(topics);
ui_.topics_combo_box->clear();
Expand All @@ -148,6 +150,12 @@ void ImageView::updateTopicList()
}

QList<QString> ImageView::getTopicList(const QSet<QString>& message_types, const QList<QString>& transports)
{
QSet<QString> message_sub_types;
return getTopics(message_types, message_sub_types, transports).values();
}

QSet<QString> ImageView::getTopics(const QSet<QString>& message_types, const QSet<QString>& message_sub_types, const QList<QString>& transports)
{
ros::master::V_TopicInfo topic_info;
ros::master::getTopics(topic_info);
Expand All @@ -158,28 +166,39 @@ QList<QString> ImageView::getTopicList(const QSet<QString>& message_types, const
all_topics.insert(it->name.c_str());
}

QList<QString> topics;
QSet<QString> topics;
for (ros::master::V_TopicInfo::const_iterator it = topic_info.begin(); it != topic_info.end(); it++)
{
if (message_types.contains(it->datatype.c_str()))
{
QString topic = it->name.c_str();

// add raw topic
topics.append(topic);
//qDebug("ImageView::getTopicList() raw topic '%s'", topic.toStdString().c_str());
topics.insert(topic);
//qDebug("ImageView::getTopics() raw topic '%s'", topic.toStdString().c_str());

// add transport specific sub-topics
for (QList<QString>::const_iterator jt = transports.begin(); jt != transports.end(); jt++)
{
if (all_topics.contains(topic + "/" + *jt))
{
QString sub = topic + " " + *jt;
topics.append(sub);
//qDebug("ImageView::getTopicList() transport specific sub-topic '%s'", sub.toStdString().c_str());
topics.insert(sub);
//qDebug("ImageView::getTopics() transport specific sub-topic '%s'", sub.toStdString().c_str());
}
}
}
if (message_sub_types.contains(it->datatype.c_str()))
{
QString topic = it->name.c_str();
int index = topic.lastIndexOf("/");
if (index != -1)
{
topic.replace(index, 1, " ");
topics.insert(topic);
//qDebug("ImageView::getTopics() transport specific sub-topic '%s'", topic.toStdString().c_str());
}
}
}
return topics;
}
Expand Down

0 comments on commit 5fa643e

Please sign in to comment.