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
00031
00032
00033
00034
00036
00037 #include <laser_cb_detector/laser_interval_calc.h>
00038 #include <vector>
00039 #include <algorithm>
00040
00041 using namespace laser_cb_detector;
00042 using namespace std;
00043
00044 bool LaserIntervalCalc::computeInterval(const calibration_msgs::DenseLaserSnapshot& snapshot,
00045 const calibration_msgs::CalibrationPattern& features,
00046 calibration_msgs::Interval& result)
00047 {
00048 const unsigned int N = features.image_points.size();
00049
00050 vector<ros::Time> min_times, max_times;
00051 min_times.resize(N);
00052 max_times.resize(N);
00053
00054 if (N == 0)
00055 {
00056 result.start = snapshot.header.stamp;
00057 result.end = snapshot.header.stamp;
00058 return true;
00059 }
00060
00061
00062 for (unsigned int i=0; i<N; i++)
00063 {
00064
00065 int x_rounded = (int) features.image_points[i].x;
00066 int y_rounded = (int) features.image_points[i].y;
00067
00068
00069
00070
00071 if (features.image_points[i].y <= 0.0 || y_rounded >= (int) snapshot.num_scans-1)
00072 {
00073 ROS_ERROR("Image point #%u (%.2f, %.2f) is outside of Y range (0.00, %u)", i,
00074 features.image_points[i].x, features.image_points[i].y, snapshot.num_scans-1);
00075 return false;
00076 }
00077
00078 ros::Time min_scan_start = min( snapshot.scan_start[y_rounded],
00079 snapshot.scan_start[y_rounded+1] );
00080 ros::Time max_scan_start = max( snapshot.scan_start[y_rounded],
00081 snapshot.scan_start[y_rounded+1] );
00082
00083 min_times[i] = min_scan_start + ros::Duration(snapshot.time_increment * x_rounded);
00084 max_times[i] = max_scan_start + ros::Duration(snapshot.time_increment * (x_rounded+1));
00085 }
00086
00087
00088 ros::Time min_time = min_times[0];
00089 ros::Time max_time = max_times[0];
00090
00091 for (unsigned int i=0; i<N; i++)
00092 {
00093 min_time = min (min_time, min_times[i]);
00094 max_time = max (max_time, max_times[i]);
00095 }
00096
00097 result.start = min_time;
00098 result.end = max_time;
00099
00100 return true;
00101 }