[ros-users] Shared memory image plugin

Top Page
Attachments:
Message as email
+ (text/plain)
+ sharedmem_image_transport.tgz (application/x-compressed-tar)
+ publish-const.patch (text/x-patch)
+ itp-publish-const.patch (text/x-patch)
Delete this message
Reply to this message
Author: Cedric Pradalier
Date:  
To: ros-users
Subject: [ros-users] Shared memory image plugin
Hi All,

I've just written a small shared-memory based image_transport_plugin
using boost::interprocess and it raises 2 questions:

- First, I don't see how to write it efficiently while having the
publish function const in image_transport/publisher.h. I currently wait
to receive the first image to allocate the shared memory segment, and as
far as I could tell, I can only do it in the publish function of the
plugin, so this has to be non-const. Any reason why it would have to be
const? Or any hint on how to achieve the same result while having the
function const?

- Second, as it is written now, the plugin does not care at all that the
object it manipulates are images (it cares that the object are
constant/bounded size though). So would it be possible to extend/convert
the image_transport plugin architecture, to a generic message_transport
plugin architecture? I think sharedmem transfer would be particularly
suitable for big point clouds...

I attach the targz of the package if someone wants to review it. It will
NOT compile in a standard install, because of the "const" problem
mentioned above. I include a patch to image_transport that removes the
"const". Note that if you apply it, you also need to check the const in
the other image_transport_plugins (2nd patch).

Best,

--
Dr. Cedric Pradalier
http://www.asl.ethz.ch/people/cedricp

Index: include/image_transport/publisher.h
===================================================================
--- include/image_transport/publisher.h    (revision 29372)
+++ include/image_transport/publisher.h    (working copy)
@@ -79,12 +79,12 @@
   /*!
    * \brief Publish an image on the topics associated with this Publisher.
    */
-  void publish(const sensor_msgs::Image& message) const;
+  void publish(const sensor_msgs::Image& message) ;


   /*!
    * \brief Publish an image on the topics associated with this Publisher.
    */
-  void publish(const sensor_msgs::ImageConstPtr& message) const;
+  void publish(const sensor_msgs::ImageConstPtr& message) ;


   /*!
    * \brief Shutdown the advertisements associated with this Publisher.
Index: include/image_transport/raw_publisher.h
===================================================================
--- include/image_transport/raw_publisher.h    (revision 29372)
+++ include/image_transport/raw_publisher.h    (working copy)
@@ -22,7 +22,7 @@
   }


 protected:
-  virtual void publish(const sensor_msgs::Image& message, const PublishFn& publish_fn) const
+  virtual void publish(const sensor_msgs::Image& message, const PublishFn& publish_fn) 
   {
     publish_fn(message);
   }
Index: include/image_transport/publisher_plugin.h
===================================================================
--- include/image_transport/publisher_plugin.h    (revision 29372)
+++ include/image_transport/publisher_plugin.h    (working copy)
@@ -56,12 +56,12 @@
   /**
    * \brief Publish an image using the transport associated with this PublisherPlugin.
    */
-  virtual void publish(const sensor_msgs::Image& message) const = 0;
+  virtual void publish(const sensor_msgs::Image& message) = 0;


   /**
    * \brief Publish an image using the transport associated with this PublisherPlugin.
    */
-  virtual void publish(const sensor_msgs::ImageConstPtr& message) const
+  virtual void publish(const sensor_msgs::ImageConstPtr& message) 
   {
     publish(*message);
   }
Index: include/image_transport/simple_publisher_plugin.h
===================================================================
--- include/image_transport/simple_publisher_plugin.h    (revision 29372)
+++ include/image_transport/simple_publisher_plugin.h    (working copy)
@@ -41,7 +41,7 @@
     return std::string();
   }


-  virtual void publish(const sensor_msgs::Image& message) const
+  virtual void publish(const sensor_msgs::Image& message) 
   {
     if (!simple_impl_ || !simple_impl_->pub_) {
       ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::SimplePublisherPlugin");
@@ -82,7 +82,7 @@
    * SimpleSubscriberPlugin to use this function for both normal broadcast publishing and
    * single subscriber publishing (in subscription callbacks).
    */
-  virtual void publish(const sensor_msgs::Image& message, const PublishFn& publish_fn) const = 0;
+  virtual void publish(const sensor_msgs::Image& message, const PublishFn& publish_fn) = 0;


   /**
    * \brief Return the communication topic name for a given base topic.
@@ -161,7 +161,7 @@
     // Construct a function object for publishing sensor_msgs::Image through the
     // subclass-implemented publish() using the ros::SingleSubscriberPublisher to send
     // messages of the transport-specific type.
-    typedef void (SimplePublisherPlugin::*PublishMemFn)(const sensor_msgs::Image&, const PublishFn&) const;
+    typedef void (SimplePublisherPlugin::*PublishMemFn)(const sensor_msgs::Image&, const PublishFn&) ;
     PublishMemFn pub_mem_fn = &SimplePublisherPlugin::publish;
     ImagePublishFn image_publish_fn = boost::bind(pub_mem_fn, this, _1, bindInternalPublisher(ros_ssp));


Index: src/publisher.cpp
===================================================================
--- src/publisher.cpp    (revision 29372)
+++ src/publisher.cpp    (working copy)
@@ -137,27 +137,27 @@
   return std::string();
 }


-void Publisher::publish(const sensor_msgs::Image& message) const
+void Publisher::publish(const sensor_msgs::Image& message) 
 {
   if (!impl_ || !impl_->isValid()) {
     ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::Publisher");
     return;
   }


-  BOOST_FOREACH(const PublisherPlugin& pub, impl_->publishers_) {
+  BOOST_FOREACH(PublisherPlugin& pub, impl_->publishers_) {
     if (pub.getNumSubscribers() > 0)
       pub.publish(message);
   }
 }


-void Publisher::publish(const sensor_msgs::ImageConstPtr& message) const
+void Publisher::publish(const sensor_msgs::ImageConstPtr& message) 
 {
   if (!impl_ || !impl_->isValid()) {
     ROS_ASSERT_MSG(false, "Call to publish() on an invalid image_transport::Publisher");
     return;
   }


-  BOOST_FOREACH(const PublisherPlugin& pub, impl_->publishers_) {
+  BOOST_FOREACH(PublisherPlugin& pub, impl_->publishers_) {
     if (pub.getNumSubscribers() > 0)
       pub.publish(message);
   }
Index: src/republish.cpp
===================================================================
--- src/republish.cpp    (revision 29372)
+++ src/republish.cpp    (working copy)
@@ -22,7 +22,7 @@
     image_transport::Publisher pub = it.advertise(out_topic, 1);


     // Use Publisher::publish as the subscriber callback
-    typedef void (image_transport::Publisher::*PublishMemFn)(const sensor_msgs::ImageConstPtr&) const;
+    typedef void (image_transport::Publisher::*PublishMemFn)(const sensor_msgs::ImageConstPtr&) ;
     PublishMemFn pub_mem_fn = &image_transport::Publisher::publish;
     sub = it.subscribe(in_topic, 1, boost::bind(pub_mem_fn, &pub, _1), ros::VoidPtr(), in_transport);


@@ -41,7 +41,7 @@
                    image_transport::SubscriberStatusCallback(), ros::VoidPtr(), false);


     // Use PublisherPlugin::publish as the subscriber callback
-    typedef void (Plugin::*PublishMemFn)(const sensor_msgs::ImageConstPtr&) const;
+    typedef void (Plugin::*PublishMemFn)(const sensor_msgs::ImageConstPtr&) ;
     PublishMemFn pub_mem_fn = &Plugin::publish;
     sub = it.subscribe(in_topic, 1, boost::bind(pub_mem_fn, pub.get(), _1), pub, in_transport);


Index: theora_image_transport/include/theora_image_transport/theora_publisher.h
===================================================================
--- theora_image_transport/include/theora_image_transport/theora_publisher.h    (revision 29372)
+++ theora_image_transport/include/theora_image_transport/theora_publisher.h    (working copy)
@@ -28,7 +28,7 @@


   //Main publish function
   virtual void publish(const sensor_msgs::Image& message,
-                       const PublishFn& publish_fn) const;
+                       const PublishFn& publish_fn) ;


 private:
   //Utility functions
Index: theora_image_transport/src/theora_publisher.cpp
===================================================================
--- theora_image_transport/src/theora_publisher.cpp    (revision 29372)
+++ theora_image_transport/src/theora_publisher.cpp    (working copy)
@@ -36,7 +36,7 @@
     }
 }


-void TheoraPublisher::publish(const sensor_msgs::Image& message, const PublishFn& publish_fn) const
+void TheoraPublisher::publish(const sensor_msgs::Image& message, const PublishFn& publish_fn) 
 {
   if (img_bridge_.fromImage(message, "bgr8"))
   {
Index: compressed_image_transport/include/compressed_image_transport/compressed_publisher.h
===================================================================
--- compressed_image_transport/include/compressed_image_transport/compressed_publisher.h    (revision 29372)
+++ compressed_image_transport/include/compressed_image_transport/compressed_publisher.h    (working copy)
@@ -15,7 +15,7 @@


 protected:
   virtual void publish(const sensor_msgs::Image& message,
-                       const PublishFn& publish_fn) const;
+                       const PublishFn& publish_fn) ;
 };


 } //namespace compressed_image_transport
Index: compressed_image_transport/src/compressed_publisher.cpp
===================================================================
--- compressed_image_transport/src/compressed_publisher.cpp    (revision 29372)
+++ compressed_image_transport/src/compressed_publisher.cpp    (working copy)
@@ -6,7 +6,7 @@
 namespace compressed_image_transport {


 void CompressedPublisher::publish(const sensor_msgs::Image& message,
-                                  const PublishFn& publish_fn) const
+                                  const PublishFn& publish_fn) 
 {
   // View/convert as mono or RGB
   sensor_msgs::CvBridge bridge;