ros_msg_conversions.h
Go to the documentation of this file.
00001 
00060 #ifndef COB_VISION_UTILS_ROS_MSG_CONVERSIONS_H__
00061 #define COB_VISION_UTILS_ROS_MSG_CONVERSIONS_H__
00062 
00063 #include <cob_object_detection_msgs/Detection.h>
00064 #include <visualization_msgs/Marker.h>
00065 
00066 #include <Eigen/Geometry> // for transformations
00067 
00068 namespace cob_perception_common
00069 {
00070 
00071   // Eigen to ROS conversions
00072   inline void EigenToROSMsg(const Eigen::Vector3f& pt_eigen, geometry_msgs::Point& pt_msg)
00073   { pt_msg.x=pt_eigen[0]; pt_msg.y=pt_eigen[1]; pt_msg.z=pt_eigen[2]; }
00074 
00075   inline void EigenToROSMsg(const Eigen::Quaternion<float>& q_eigen, geometry_msgs::Quaternion& q_msg)
00076   { q_msg.x=q_eigen.x(); q_msg.y=q_eigen.y(); q_msg.z=q_eigen.z(); q_msg.w=q_eigen.w(); }
00077 
00078   inline void EigenToROSMsg(const Eigen::Vector3f& pt, const Eigen::Quaternion<float>& rot, geometry_msgs::Pose& pose)
00079   { EigenToROSMsg(pt, pose.position); EigenToROSMsg(rot, pose.orientation); }
00080 
00081 
00082   // ROS to Eigen conversions
00083   inline void ROSMsgToEigen(const geometry_msgs::Point& pt_msg, Eigen::Vector3f& pt_eigen)
00084   { pt_eigen[0]=pt_msg.x; pt_eigen[1]=pt_msg.y; pt_eigen[2]=pt_msg.z; }
00085 
00086   inline void ROSMsgToEigen(const geometry_msgs::Quaternion& q_msg, Eigen::Quaternion<float>& q_eigen)
00087   { q_eigen.x()=q_msg.x; q_eigen.y()=q_msg.y; q_eigen.z()=q_msg.z; q_eigen.w()=q_msg.w; }
00088 
00089   inline void ROSMsgToEigen(const geometry_msgs::Pose& pose, Eigen::Vector3f& pt, Eigen::Quaternion<float>& rot)
00090   { ROSMsgToEigen(pose.position, pt); ROSMsgToEigen(pose.orientation, rot); }
00091 
00092 
00093 
00094   // Marker properties type, lifetime, header and id should be set manually;
00095   void boundingBoxToMarker(const cob_object_detection_msgs::Detection& bb, visualization_msgs::Marker& marker)
00096   {
00097     marker.action = visualization_msgs::Marker::ADD;
00098     marker.type = visualization_msgs::Marker::LINE_LIST;
00099     geometry_msgs::Point pt;
00100 
00101     /*************************
00102      * Lines between point indices of 0-1, 2-3, 4-5, ...
00103      *
00104      * bottom of bounding box:
00105      *
00106      *   1,2,10   0,7,8
00107      *     +-------+
00108      *     |       |
00109      *     +-------+
00110      *   3,4,12   5,6,14
00111      *
00112      * top of bounding box:
00113      *
00114      * 11,17,18   9,16,23
00115      *     +-------+
00116      *     |       |
00117      *     +-------+
00118      * 13,19,20   15,21,22
00119      *
00120      *************************/
00121 
00122     marker.points.resize(24);
00123     pt.x = bb.bounding_box_lwh.x;
00124     pt.y = bb.bounding_box_lwh.y;
00125     pt.z = 0;
00126 
00127     marker.points[0]=marker.points[7]=marker.points[8] = pt;
00128 
00129     pt.x = -bb.bounding_box_lwh.x;
00130     marker.points[1]=marker.points[2]=marker.points[10] = pt;
00131 
00132     pt.y = -bb.bounding_box_lwh.y;
00133     marker.points[3]=marker.points[4]=marker.points[12] = pt;
00134 
00135     pt.x = bb.bounding_box_lwh.x;
00136     marker.points[5]=marker.points[6]=marker.points[14] = pt;
00137 
00138 
00139     pt.y = bb.bounding_box_lwh.y;
00140     pt.z = bb.bounding_box_lwh.z;
00141 
00142     marker.points[9]=marker.points[16]=marker.points[23] = pt;
00143 
00144     pt.x = -bb.bounding_box_lwh.x;
00145     marker.points[11]=marker.points[17]=marker.points[18] = pt;
00146 
00147     pt.y = -bb.bounding_box_lwh.y;
00148     marker.points[13]=marker.points[19]=marker.points[20] = pt;
00149 
00150     pt.x = bb.bounding_box_lwh.x;
00151     marker.points[15]=marker.points[21]=marker.points[22] = pt;
00152 
00153     marker.pose = bb.pose.pose;
00154 
00155     marker.scale.x = 0.01;
00156     marker.color.r = 0;
00157     marker.color.g = 1;
00158     marker.color.b = 0;
00159     marker.color.a = 1.0;
00160   }
00161 }
00162 
00163 #endif // COB_VISION_UTILS_ROS_MSG_CONVERSIONS_H__


cob_vision_utils
Author(s): Jan Fischer
autogenerated on Thu Aug 27 2015 12:46:31