00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00039 #ifndef GRAPH_MAPPING_UTILS_GEOMETRY_H
00040 #define GRAPH_MAPPING_UTILS_GEOMETRY_H
00041
00042 #include "general.h"
00043 #include <graph_mapping_msgs/LocalizationDistribution.h>
00044 #include <tf/transform_datatypes.h>
00045 #include <geometry_msgs/Pose.h>
00046 #include <geometry_msgs/Point32.h>
00047 #include <geometry_msgs/Pose2D.h>
00048 #include <sensor_msgs/PointCloud.h>
00049 #include <sensor_msgs/LaserScan.h>
00050
00051 namespace graph_mapping_utils
00052 {
00053
00054 namespace gm=geometry_msgs;
00055
00056
00059 inline
00060 tf::Pose relativePose (const tf::Pose& pose1, const tf::Pose& pose2)
00061 {
00062 return pose2.inverseTimes(pose1);
00063 }
00064
00066 inline
00067 tf::Transform transformBetween (const tf::Pose& pose1, const tf::Pose& pose2)
00068 {
00069 return pose2*pose1.inverse();
00070 }
00071
00073 inline
00074 gm::Point32 transformPoint (const tf::Transform& trans, const gm::Point32& point)
00075 {
00076 btVector3 p(point.x, point.y, point.z);
00077 btVector3 p2 = trans*p;
00078 gm::Point32 ret;
00079 ret.x = p2.x();
00080 ret.y = p2.y();
00081 ret.z = p2.z();
00082 return ret;
00083 }
00084
00085
00087 inline
00088 gm::Point transformPoint (const tf::Transform& trans, const gm::Point& point)
00089 {
00090 btVector3 p;
00091 tf::pointMsgToTF(point, p);
00092 const btVector3 p2 = trans*p;
00093 gm::Point ret;
00094 tf::pointTFToMsg(p2, ret);
00095 return ret;
00096 }
00097
00098
00100 inline
00101 gm::Pose transformPose (const tf::Transform& trans, const gm::Pose& pose)
00102 {
00103 tf::Pose bullet_pose;
00104 tf::poseMsgToTF(pose, bullet_pose);
00105 gm::Pose ret;
00106 tf::poseTFToMsg(trans*bullet_pose, ret);
00107 return ret;
00108 }
00109
00110
00111 inline
00112 btVector3 toPoint (const gm::Point& p)
00113 {
00114 return btVector3(p.x, p.y, p.z);
00115 }
00116
00117 inline
00118 gm::Point toPoint (const btVector3& p)
00119 {
00120 gm::Point pt;
00121 pt.x = p.x();
00122 pt.y = p.y();
00123 pt.z = p.z();
00124 return pt;
00125 }
00126
00127 inline
00128 gm::Pose toPose (const tf::Pose& p)
00129 {
00130 gm::Pose p2;
00131 tf::poseTFToMsg(p, p2);
00132 return p2;
00133 }
00134
00135 inline
00136 tf::Pose toPose (const gm::Pose& p)
00137 {
00138 const gm::Quaternion& q(p.orientation);
00139 const gm::Point& v(p.position);
00140 return tf::Pose(btQuaternion(q.x, q.y, q.z, q.w),
00141 btVector3(v.x, v.y, v.z));
00142 }
00143
00144 inline
00145 double length (const btVector3& v)
00146 {
00147 return v.x()*v.x() + v.y()*v.y() + v.z()*v.z();
00148 }
00149
00150 inline
00151 double length (const gm::Point& p)
00152 {
00153 return sqrt(p.x*p.x + p.y*p.y + p.z*p.z);
00154 }
00155
00156
00158 gm::Pose2D projectToPose2D (const gm::Pose& pose);
00159
00161 gm::Pose2D projectToPose2D (const tf::Pose& pose);
00162
00164 gm::Pose2D makePose2D (double x, double y, double theta=0.0);
00165
00167 tf::Pose makePose (double x, double y, double theta);
00168
00170 tf::Pose toPose (const gm::Pose2D& p);
00171
00173 inline
00174 gm::Point makePoint (const double x, const double y, const double z=0.0)
00175 {
00176 gm::Point p;
00177 p.x = x;
00178 p.y = y;
00179 p.z = z;
00180 return p;
00181 }
00182
00183
00185 inline
00186 gm::Pose absolutePose (const gm::Pose& base, const tf::Pose& offset)
00187 {
00188 return toPose(toPose(base)*offset);
00189 }
00190
00192 inline
00193 tf::Pose absolutePose (const tf::Pose& base, const gm::Pose& offset)
00194 {
00195 return base*toPose(offset);
00196 }
00197
00198
00200 gm::Point barycenter (const sensor_msgs::PointCloud& cloud);
00201
00203 btVector3 barycenter (const sensor_msgs::LaserScan& scan);
00204
00206 inline
00207 double euclideanDistance (const gm::Point& p1, const gm::Point& p2)
00208 {
00209 const double dx = p1.x - p2.x;
00210 const double dy = p1.y - p2.y;
00211 const double dz = p1.z - p2.z;
00212 return sqrt(dx*dx + dy*dy + dz*dz);
00213 }
00214
00215
00216
00217 }
00218
00219 #endif // include guard