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 #include <graph_mapping_utils/geometry.h>
00040 #include <boost/foreach.hpp>
00041 #include <stdexcept>
00042
00043 namespace graph_mapping_utils
00044 {
00045
00046 namespace sm=sensor_msgs;
00047
00048 gm::Pose2D projectToPose2D (const tf::Transform& pose)
00049 {
00050 gm::Pose2D pose2d;
00051 pose2d.x = pose.getOrigin().x();
00052 pose2d.y = pose.getOrigin().y();
00053 pose2d.theta = tf::getYaw(pose.getRotation());
00054 return pose2d;
00055 }
00056
00057 gm::Pose2D projectToPose2D (const gm::Pose& pose)
00058 {
00059 gm::Pose2D pose2d;
00060 pose2d.x = pose.position.x;
00061 pose2d.y = pose.position.y;
00062 pose2d.theta = tf::getYaw(pose.orientation);
00063 return pose2d;
00064 }
00065
00066
00068 gm::Pose2D makePose2D (double x, double y, double theta)
00069 {
00070 gm::Pose2D p;
00071 p.x = x;
00072 p.y = y;
00073 p.theta = theta;
00074 return p;
00075 }
00076
00077 tf::Pose makePose (double x, double y, double theta)
00078 {
00079 return tf::Pose(tf::createQuaternionFromYaw(theta), btVector3(x, y, 0));
00080 }
00081
00082
00083 gm::Point barycenter (const sensor_msgs::PointCloud& cloud)
00084 {
00085 double sx=0, sy=0, sz=0;
00086 if (cloud.points.empty())
00087 throw std::invalid_argument("Can't find barycenter of empty cloud");
00088 BOOST_FOREACH (const gm::Point32& p, cloud.points)
00089 {
00090 sx += p.x;
00091 sy += p.y;
00092 sz += p.z;
00093 }
00094 gm::Point b;
00095 const unsigned n = cloud.points.size();
00096 b.x = sx/n;
00097 b.y = sy/n;
00098 b.z = sz/n;
00099 return b;
00100 }
00101
00102 btVector3 barycenter (const sm::LaserScan& scan)
00103 {
00104 unsigned n = 0;
00105 double theta = scan.angle_min;
00106 double sx=0, sy=0;
00107 BOOST_FOREACH (const double r, scan.ranges)
00108 {
00109 if ((scan.range_min < r) && (r < scan.range_max))
00110 {
00111 sx += r*cos(theta);
00112 sy += r*sin(theta);
00113 n++;
00114 }
00115 theta += scan.angle_increment;
00116 }
00117 ROS_ASSERT_MSG (n>0, "Can't find barycenter of scan because all "
00118 "%zu points are out of range", scan.ranges.size());
00119 return btVector3(sx/n, sy/n, 0);
00120 }
00121
00122 tf::Pose toPose (const gm::Pose2D& p)
00123 {
00124 return makePose(p.x, p.y, p.theta);
00125 }
00126
00127
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 }