From fc466fbd2798fe8feb46bb0e791b03f5d258ca58 Mon Sep 17 00:00:00 2001 From: AndyZe Date: Tue, 9 Oct 2018 09:01:49 -0500 Subject: [PATCH 1/4] Adding a service to set the image topic. --- CMakeLists.txt | 20 ++++++++++++++++---- include/rqt_image_view/image_view.h | 8 +++++++- package.xml | 24 ++++++++++-------------- src/rqt_image_view/image_view.cpp | 14 +++++++++++++- srv/SetImageTopic.srv | 2 ++ 5 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 srv/SetImageTopic.srv diff --git a/CMakeLists.txt b/CMakeLists.txt index e47e6e3..bfcd6cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(rqt_image_view) add_compile_options(-std=c++11) # Load catkin and all dependencies required for this package -find_package(catkin REQUIRED COMPONENTS rqt_gui rqt_gui_cpp image_transport sensor_msgs geometry_msgs cv_bridge) +find_package(catkin REQUIRED COMPONENTS cv_bridge rqt_gui rqt_gui_cpp geometry_msgs image_transport message_generation sensor_msgs) if("${qt_gui_cpp_USE_QT_MAJOR_VERSION} " STREQUAL "5 ") find_package(Qt5Widgets REQUIRED) @@ -36,12 +36,22 @@ if(NOT EXISTS "${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}") file(MAKE_DIRECTORY "${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}") endif() +add_service_files(DIRECTORY srv + FILES + SetImageTopic.srv +) + +catkin_python_setup() + +generate_messages( + DEPENDENCIES +) + catkin_package( INCLUDE_DIRS ${rqt_image_view_INCLUDE_DIRECTORIES} LIBRARIES ${PROJECT_NAME} - CATKIN_DEPENDS rqt_gui rqt_gui_cpp image_transport sensor_msgs cv_bridge geometry_msgs + CATKIN_DEPENDS rqt_gui rqt_gui_cpp image_transport sensor_msgs cv_bridge geometry_msgs message_runtime ) -catkin_python_setup() if("${qt_gui_cpp_USE_QT_MAJOR_VERSION} " STREQUAL "5 ") qt5_wrap_cpp(rqt_image_view_MOCS ${rqt_image_view_HDRS}) @@ -70,6 +80,8 @@ endif() find_package(class_loader) class_loader_hide_library_symbols(${PROJECT_NAME}) +add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS}) + install(FILES plugin.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) @@ -86,4 +98,4 @@ catkin_install_python(PROGRAMS scripts/rqt_image_view install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} -) +) \ No newline at end of file diff --git a/include/rqt_image_view/image_view.h b/include/rqt_image_view/image_view.h index 06020e2..69d02e4 100644 --- a/include/rqt_image_view/image_view.h +++ b/include/rqt_image_view/image_view.h @@ -37,11 +37,12 @@ #include +#include #include #include #include +#include "rqt_image_view/SetImageTopic.h" #include -#include #include @@ -116,6 +117,9 @@ protected slots: virtual void callbackImage(const sensor_msgs::Image::ConstPtr& msg); + bool changeImageService(rqt_image_view::SetImageTopic::Request &req, + rqt_image_view::SetImageTopic::Response &res); + virtual void invertPixels(int x, int y); QList getGridIndices(int size) const; @@ -153,6 +157,8 @@ protected slots: int num_gridlines_; RotateState rotate_state_; + + ros::ServiceServer change_topic_service_; }; } diff --git a/package.xml b/package.xml index 6469c38..6633103 100644 --- a/package.xml +++ b/package.xml @@ -1,4 +1,4 @@ - + rqt_image_view 0.4.13 rqt_image_view provides a GUI plugin for displaying images using image_transport. @@ -15,19 +15,15 @@ catkin - cv_bridge - geometry_msgs - image_transport - qtbase5-dev - rqt_gui - rqt_gui_cpp - sensor_msgs - cv_bridge - geometry_msgs - image_transport - rqt_gui - rqt_gui_cpp - sensor_msgs + cv_bridge + geometry_msgs + image_transport + message_generation + qtbase5-dev + rqt_gui + rqt_gui_cpp + sensor_msgs + message_runtime diff --git a/src/rqt_image_view/image_view.cpp b/src/rqt_image_view/image_view.cpp index a0dd199..c14fd21 100644 --- a/src/rqt_image_view/image_view.cpp +++ b/src/rqt_image_view/image_view.cpp @@ -115,12 +115,15 @@ void ImageView::initPlugin(qt_gui_cpp::PluginContext& context) hide_toolbar_action_->setCheckable(true); ui_.image_frame->addAction(hide_toolbar_action_); connect(hide_toolbar_action_, SIGNAL(toggled(bool)), this, SLOT(onHideToolbarChanged(bool))); + + change_topic_service_ = getNodeHandle().advertiseService("/rqt_image_view/change_image_topic", &ImageView::changeImageService, this); } void ImageView::shutdownPlugin() { subscriber_.shutdown(); pub_mouse_left_.shutdown(); + change_topic_service_.shutdown(); } void ImageView::saveSettings(qt_gui_cpp::Settings& plugin_settings, qt_gui_cpp::Settings& instance_settings) const @@ -483,6 +486,15 @@ void ImageView::syncRotateLabel() } } +bool ImageView::changeImageService(rqt_image_view::SetImageTopic::Request &req, + rqt_image_view::SetImageTopic::Response &res) +{ + selectTopic( QString::fromStdString(req.image_topic) ); + updateTopicList(); + + return true; +} + void ImageView::invertPixels(int x, int y) { // Could do 255-conversion_mat_.at(cv::Point(x,y))[i], but that doesn't work well on gray @@ -662,4 +674,4 @@ void ImageView::callbackImage(const sensor_msgs::Image::ConstPtr& msg) } } -PLUGINLIB_EXPORT_CLASS(rqt_image_view::ImageView, rqt_gui_cpp::Plugin) +PLUGINLIB_EXPORT_CLASS(rqt_image_view::ImageView, rqt_gui_cpp::Plugin) \ No newline at end of file diff --git a/srv/SetImageTopic.srv b/srv/SetImageTopic.srv new file mode 100644 index 0000000..0045faa --- /dev/null +++ b/srv/SetImageTopic.srv @@ -0,0 +1,2 @@ +string image_topic +--- \ No newline at end of file From 94dba83cb18cec9d699a0d5aecafbe8f7b1e813c Mon Sep 17 00:00:00 2001 From: George Stavrinos Date: Fri, 19 Oct 2018 19:36:48 +0300 Subject: [PATCH 2/4] Fixed multiple image views being run through the rqt gui. This does not fix the problem if you rosrun multiple image views --- CMakeLists.txt | 1 + src/rqt_image_view/image_view.cpp | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfcd6cb..c40ff2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 2.8.3) +add_compile_options(-std=c++11) project(rqt_image_view) diff --git a/src/rqt_image_view/image_view.cpp b/src/rqt_image_view/image_view.cpp index c14fd21..6909ad5 100644 --- a/src/rqt_image_view/image_view.cpp +++ b/src/rqt_image_view/image_view.cpp @@ -115,8 +115,7 @@ void ImageView::initPlugin(qt_gui_cpp::PluginContext& context) hide_toolbar_action_->setCheckable(true); ui_.image_frame->addAction(hide_toolbar_action_); connect(hide_toolbar_action_, SIGNAL(toggled(bool)), this, SLOT(onHideToolbarChanged(bool))); - - change_topic_service_ = getNodeHandle().advertiseService("/rqt_image_view/change_image_topic", &ImageView::changeImageService, this); + change_topic_service_ = getNodeHandle().advertiseService( getNodeHandle().getNamespace() + std::to_string(context.serialNumber()) + "/change_image_topic", &ImageView::changeImageService, this); } void ImageView::shutdownPlugin() From bd82bb7c1b756bb150d623170c19754b42ba526b Mon Sep 17 00:00:00 2001 From: AndyZe Date: Wed, 20 Mar 2019 15:17:54 -0500 Subject: [PATCH 3/4] Address review from @dirk-thomas --- CMakeLists.txt | 1 - include/rqt_image_view/image_view.h | 2 +- src/rqt_image_view/image_view.cpp | 7 ++++--- srv/SetImageTopic.srv | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c40ff2e..f8d6cb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,6 @@ add_service_files(DIRECTORY srv catkin_python_setup() generate_messages( - DEPENDENCIES ) catkin_package( diff --git a/include/rqt_image_view/image_view.h b/include/rqt_image_view/image_view.h index 69d02e4..fb0075b 100644 --- a/include/rqt_image_view/image_view.h +++ b/include/rqt_image_view/image_view.h @@ -117,7 +117,7 @@ protected slots: virtual void callbackImage(const sensor_msgs::Image::ConstPtr& msg); - bool changeImageService(rqt_image_view::SetImageTopic::Request &req, + bool setImageService(rqt_image_view::SetImageTopic::Request &req, rqt_image_view::SetImageTopic::Response &res); virtual void invertPixels(int x, int y); diff --git a/src/rqt_image_view/image_view.cpp b/src/rqt_image_view/image_view.cpp index 6909ad5..27c2e01 100644 --- a/src/rqt_image_view/image_view.cpp +++ b/src/rqt_image_view/image_view.cpp @@ -115,7 +115,8 @@ void ImageView::initPlugin(qt_gui_cpp::PluginContext& context) hide_toolbar_action_->setCheckable(true); ui_.image_frame->addAction(hide_toolbar_action_); connect(hide_toolbar_action_, SIGNAL(toggled(bool)), this, SLOT(onHideToolbarChanged(bool))); - change_topic_service_ = getNodeHandle().advertiseService( getNodeHandle().getNamespace() + std::to_string(context.serialNumber()) + "/change_image_topic", &ImageView::changeImageService, this); + change_topic_service_ = getNodeHandle().advertiseService( + getNodeHandle().getNamespace() + std::to_string(context.serialNumber()) + "/set_image_topic", &ImageView::setImageService, this); } void ImageView::shutdownPlugin() @@ -485,7 +486,7 @@ void ImageView::syncRotateLabel() } } -bool ImageView::changeImageService(rqt_image_view::SetImageTopic::Request &req, +bool ImageView::setImageService(rqt_image_view::SetImageTopic::Request &req, rqt_image_view::SetImageTopic::Response &res) { selectTopic( QString::fromStdString(req.image_topic) ); @@ -673,4 +674,4 @@ void ImageView::callbackImage(const sensor_msgs::Image::ConstPtr& msg) } } -PLUGINLIB_EXPORT_CLASS(rqt_image_view::ImageView, rqt_gui_cpp::Plugin) \ No newline at end of file +PLUGINLIB_EXPORT_CLASS(rqt_image_view::ImageView, rqt_gui_cpp::Plugin) diff --git a/srv/SetImageTopic.srv b/srv/SetImageTopic.srv index 0045faa..c205b1f 100644 --- a/srv/SetImageTopic.srv +++ b/srv/SetImageTopic.srv @@ -1,2 +1,2 @@ string image_topic ---- \ No newline at end of file +--- From 613dba0266cb3e3ee434fd7704aab491ea93b352 Mon Sep 17 00:00:00 2001 From: Andy Zelenak Date: Fri, 12 Apr 2019 23:35:10 -0600 Subject: [PATCH 4/4] Touchups to package.xml, CMakeLists --- CMakeLists.txt | 3 +-- package.xml | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8d6cb3..eae1dc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 2.8.3) -add_compile_options(-std=c++11) project(rqt_image_view) @@ -98,4 +97,4 @@ catkin_install_python(PROGRAMS scripts/rqt_image_view install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} -) \ No newline at end of file +) diff --git a/package.xml b/package.xml index 6633103..50930f5 100644 --- a/package.xml +++ b/package.xml @@ -18,12 +18,12 @@ cv_bridge geometry_msgs image_transport - message_generation - qtbase5-dev + message_generation + qtbase5-dev rqt_gui rqt_gui_cpp sensor_msgs - message_runtime + message_runtime