blob_store.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  *
00029  */
00030 
00039 #ifndef SEMANTICMODEL_BLOB_STORE_H
00040 #define SEMANTICMODEL_BLOB_STORE_H
00041 
00042 #include <mongo_ros/message_collection.h>
00043 #include <semanticmodel/blob.hh>
00044 #include <semanticmodel/BlobMessage.h>
00045 #include <semanticmodel/SwitchDB.h>
00046 #include <ros/ros.h>
00047 #include <boost/thread.hpp>
00048 #include <boost/circular_buffer.hpp>
00049 #include <image_transport/image_transport.h>
00050 #include <image_transport/camera_subscriber.h>
00051 #include <image_transport/camera_publisher.h>
00052 #include <image_geometry/pinhole_camera_model.h>
00053 #include <tf/transform_listener.h>
00054 #include <geometry_msgs/Pose2D.h>
00055 
00056 namespace semanticmodel
00057 {
00058 
00059 
00060 class BlobStore
00061 {
00062 public:
00063 
00064   BlobStore (const std::string& canonical_frame,
00065              const std::string& rgb_camera_frame,
00066              const std::string& db_name,
00067              const std::string& collection_namespace);
00068 
00069 
00073   void update (const std::vector<Blob*>& blobs,
00074                const sensor_msgs::Image& img,
00075                const sensor_msgs::CameraInfo& info);
00076 
00078   bool switchDb (SwitchDB::Request& req, SwitchDB::Response& resp);
00079 
00080 private:
00081 
00082   // Highlight 3d blob in 2d image
00083   sensor_msgs::Image::Ptr
00084   highlightBlobInImage (const Blob& blob,
00085                         const sensor_msgs::Image& img,
00086                         const sensor_msgs::CameraInfo& info);
00087 
00088   
00089   // Return the 3d pose of the base frame in the canonical frame
00090   // at the time that the image was taken
00091   geometry_msgs::Pose2D getViewpoint (const sensor_msgs::Image& img);
00092 
00093   // How fast is head moving wrt base?
00094   double headAngularSpeed (const ros::Time& t);
00095 
00096   // Where is head wrt base?
00097   btQuaternion headAngleAt (const ros::Time& t);
00098 
00099   const std::string canonical_frame_;
00100   const std::string rgb_camera_frame_;
00101   const std::string base_frame_;
00102   const std::string db_name_;
00103   const double max_head_angular_speed_;
00104 
00105   boost::mutex mutex_;
00106   ros::NodeHandle nh_;
00107   image_transport::ImageTransport it_;
00108 
00109   tf::TransformListener tf_;
00110 
00111   // Camera model for conversion
00112   image_geometry::PinholeCameraModel cam_model_;
00113 
00114   typedef mongo_ros::MessageCollection<BlobMessage> BlobCollection;
00115   typedef mongo_ros::MessageCollection<sensor_msgs::Image> ImageCollection;
00116   
00117   // DB collection where blobs are stored
00118   boost::shared_ptr<BlobCollection> blobs_;
00119 
00120   // Collection where images are stored
00121   boost::shared_ptr<ImageCollection> images_;
00122 
00123   // Publisher for last image
00124   image_transport::Publisher pub_;
00125 
00126   // Service for switching db
00127   ros::ServiceServer switch_srv_;
00128 };
00129 
00130 
00131 } // namespace
00132 
00133 #endif // include guard


semanticmodel
Author(s): Julian ("Mac") Mason
autogenerated on Thu Dec 12 2013 12:39:10