Go to the documentation of this file.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 #include <srs_ui_but/but_services/point_cloud_tools.h>
00029
00030 #include <srs_ui_but/topics_list.h>
00031 #include <srs_ui_but/services_list.h>
00032
00033 namespace srs_ui_but
00034 {
00035
00036 PointCloudTools::PointCloudTools()
00037 {
00038 tfListener = new tf::TransformListener();
00039
00040 transform_filter = new tf::MessageFilter<sensor_msgs::PointCloud2>(point_cloud, *tfListener, "/map", 1);
00041
00042
00043
00044 transform_filter->registerCallback(boost::bind(&PointCloudTools::incomingCloudCallback, this, _1));
00045 }
00046
00047 void PointCloudTools::incomingCloudCallback(const sensor_msgs::PointCloud2ConstPtr& cloud)
00048 {
00049
00050 pointCloud_stamp = cloud->header.stamp;
00051
00052
00053 pcl::fromROSMsg(*cloud, pcl_pointCloud);
00054 }
00055
00056 srs_ui_but::ClosestPoint PointCloudTools::getClosestPoint(std::string link)
00057 {
00058 closestPoint.time_stamp = pointCloud_stamp;
00059 closestPoint.status = false;
00060
00061 try
00062 {
00063 tfListener->waitForTransform(link, CAMERA_LINK, pointCloud_stamp, ros::Duration(0.2));
00064 tfListener->lookupTransform(link, CAMERA_LINK, pointCloud_stamp, sensorToLinkTf);
00065 tfListener->waitForTransform(CAMERA_LINK, link, pointCloud_stamp, ros::Duration(0.2));
00066 tfListener->lookupTransform(CAMERA_LINK, link, pointCloud_stamp, linkToSensorTf);
00067 }
00068 catch (tf::TransformException& ex)
00069 {
00070 ROS_WARN("Transform ERROR");
00071 return closestPoint;
00072 }
00073 transformer.setTransform(linkToSensorTf);
00074
00075
00076 tf::Stamped<btVector3> p;
00077 p.setX(0);
00078 p.setY(0);
00079 p.setZ(0);
00080 p.frame_id_ = link;
00081 transformer.transformPoint(CAMERA_LINK, p, p);
00082
00083 float d;
00084 closestPoint.distance = FLT_MAX;
00085
00086
00087 BOOST_FOREACH (const pcl::PointXYZ& pt, pcl_pointCloud.points)
00088 {
00089 d = pow((pt.x - p.getX()), 2) + pow((pt.y - p.getY()), 2) + pow((pt.z - p.getZ()), 2);
00090
00091 if (d < closestPoint.distance)
00092 {
00093 closestPoint.distance = d;
00094 closestPoint.position.x = pt.x;
00095 closestPoint.position.y = pt.y;
00096 closestPoint.position.z = pt.z;
00097 }
00098 }
00099
00100
00101 transformer.setTransform(sensorToLinkTf);
00102 p.setX(closestPoint.position.x);
00103 p.setY(closestPoint.position.y);
00104 p.setZ(closestPoint.position.z);
00105 p.frame_id_ = CAMERA_LINK;
00106 transformer.transformPoint(link, p, p);
00107
00108 closestPoint.position.x = p.getX();
00109 closestPoint.position.y = p.getY();
00110 closestPoint.position.z = p.getZ();
00111 closestPoint.distance = sqrt(closestPoint.distance);
00112 closestPoint.status = true;
00113
00114 return closestPoint;
00115 }
00116 }