|
From: <pmi...@us...> - 2009-09-04 20:30:29
|
Revision: 23864
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=23864&view=rev
Author: pmihelich
Date: 2009-09-04 20:30:21 +0000 (Fri, 04 Sep 2009)
Log Message:
-----------
image_transport: Can now override transports used by ImagePublisher and their topics. Added transform utility for republishing an image topic in alternate form.
Modified Paths:
--------------
pkg/trunk/stacks/image_common/image_transport/CMakeLists.txt
pkg/trunk/stacks/image_common/image_transport/manifest.xml
pkg/trunk/stacks/image_common/image_transport/src/image_publisher.cpp
Added Paths:
-----------
pkg/trunk/stacks/image_common/image_transport/src/transform.cpp
Removed Paths:
-------------
pkg/trunk/stacks/image_common/image_transport/src/encoder.cpp
Modified: pkg/trunk/stacks/image_common/image_transport/CMakeLists.txt
===================================================================
--- pkg/trunk/stacks/image_common/image_transport/CMakeLists.txt 2009-09-04 20:28:41 UTC (rev 23863)
+++ pkg/trunk/stacks/image_common/image_transport/CMakeLists.txt 2009-09-04 20:30:21 UTC (rev 23864)
@@ -18,8 +18,8 @@
rosbuild_add_library(${PROJECT_NAME} src/image_publisher.cpp src/image_subscriber.cpp src/raw_publisher.cpp src/raw_subscriber.cpp src/manifest.cpp)
-rosbuild_add_executable(encoder src/encoder.cpp)
-target_link_libraries(encoder ${PROJECT_NAME})
+rosbuild_add_executable(transform src/transform.cpp)
+target_link_libraries(transform ${PROJECT_NAME})
#rosbuild_add_executable(test_publisher src/test_publisher.cpp)
#target_link_libraries(test_publisher ${PROJECT_NAME})
Modified: pkg/trunk/stacks/image_common/image_transport/manifest.xml
===================================================================
--- pkg/trunk/stacks/image_common/image_transport/manifest.xml 2009-09-04 20:28:41 UTC (rev 23863)
+++ pkg/trunk/stacks/image_common/image_transport/manifest.xml 2009-09-04 20:30:21 UTC (rev 23864)
@@ -1,7 +1,9 @@
<package>
<description brief="image_transport">
- image_transport
+ image_transport provides specialized publisher and subscriber classes for transporting images.
+ These classes use a plugin architecture to provide specialized transport options, such as
+ through a video codec.
</description>
<author>Patrick Mihelich</author>
Deleted: pkg/trunk/stacks/image_common/image_transport/src/encoder.cpp
===================================================================
--- pkg/trunk/stacks/image_common/image_transport/src/encoder.cpp 2009-09-04 20:28:41 UTC (rev 23863)
+++ pkg/trunk/stacks/image_common/image_transport/src/encoder.cpp 2009-09-04 20:30:21 UTC (rev 23864)
@@ -1,16 +0,0 @@
-#include "image_transport/image_publisher.h"
-
-int main(int argc, char** argv)
-{
- ros::init(argc, argv, "encoder", ros::init_options::AnonymousName);
- ros::NodeHandle nh;
- {
- // @todo: need to suppress default publisher
- std::string topic = nh.resolveName("image");
- image_transport::ImagePublisher image_pub;
- image_pub.advertise(nh, topic, 1);
-
- ros::spin();
- }
- return 0;
-}
Modified: pkg/trunk/stacks/image_common/image_transport/src/image_publisher.cpp
===================================================================
--- pkg/trunk/stacks/image_common/image_transport/src/image_publisher.cpp 2009-09-04 20:28:41 UTC (rev 23863)
+++ pkg/trunk/stacks/image_common/image_transport/src/image_publisher.cpp 2009-09-04 20:30:21 UTC (rev 23864)
@@ -37,6 +37,7 @@
#include <pluginlib/class_loader.h>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/foreach.hpp>
+#include <boost/algorithm/string/erase.hpp>
namespace image_transport {
@@ -57,7 +58,8 @@
: impl_(new Impl)
{
// Default behavior: load all plugins and use default topic names.
- BOOST_FOREACH(const std::string& lookup_name, impl_->loader.getDeclaredClasses()) {
+ BOOST_FOREACH(std::string lookup_name, impl_->loader.getDeclaredClasses()) {
+ boost::erase_last(lookup_name, "_pub");
impl_->topic_map[lookup_name] = "";
}
}
@@ -77,9 +79,10 @@
impl_->topic = nh.resolveName(topic);
BOOST_FOREACH(const TransportTopicMap::value_type& value, impl_->topic_map) {
- //ROS_INFO("Loading %s", value.first.c_str());
+ std::string lookup_name = value.first + "_pub";
+ //ROS_INFO("Loading %s", lookup_name.c_str());
try {
- PublisherPlugin* pub = impl_->loader.createClassInstance(value.first);
+ PublisherPlugin* pub = impl_->loader.createClassInstance(lookup_name);
impl_->publishers.push_back(pub);
std::string sub_topic = value.second;
if (sub_topic.empty())
@@ -89,7 +92,7 @@
}
catch (const std::runtime_error& e) {
ROS_WARN("Failed to load plugin %s, error string: %s",
- value.first.c_str(), e.what());
+ lookup_name.c_str(), e.what());
}
}
}
Added: pkg/trunk/stacks/image_common/image_transport/src/transform.cpp
===================================================================
--- pkg/trunk/stacks/image_common/image_transport/src/transform.cpp (rev 0)
+++ pkg/trunk/stacks/image_common/image_transport/src/transform.cpp 2009-09-04 20:30:21 UTC (rev 23864)
@@ -0,0 +1,34 @@
+#include "image_transport/image_subscriber.h"
+#include "image_transport/image_publisher.h"
+#include <ros/names.h>
+#include <boost/foreach.hpp>
+
+using namespace image_transport;
+
+int main(int argc, char** argv)
+{
+ ros::init(argc, argv, "image_transformer", ros::init_options::AnonymousName);
+ if (argc < 2) {
+ printf("Usage: %s raw in:=/camera/image_compressed out:=/camera/image_decompressed", argv[0]);
+ return 0;
+ }
+ ros::NodeHandle nh;
+ std::string out_topic = nh.resolveName("out");
+ std::string in_topic = nh.resolveName("in");
+
+ ImagePublisher image_pub;
+ ImagePublisher::TransportTopicMap& topic_map = image_pub.getTopicMap();
+ topic_map.clear();
+ topic_map[ argv[1] ] = out_topic;
+ image_pub.advertise(nh, out_topic, 1);
+
+ ImageSubscriber image_sub;
+ // Use ImagePublisher::publish as the subscriber callback
+ typedef void (ImagePublisher::*PublishMemFn)(const sensor_msgs::ImageConstPtr&) const;
+ PublishMemFn pub_mem_fn = &ImagePublisher::publish;
+ image_sub.subscribe(nh, in_topic, 1, boost::bind(pub_mem_fn, &image_pub, _1));
+
+ ros::spin();
+
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|