Go to the documentation of this file.00001
00021 #include <boost/algorithm/string.hpp>
00022 #include <vector>
00023 #include <boost/lexical_cast.hpp>
00024 #include <boost/accumulators/accumulators.hpp>
00025 #include <boost/accumulators/statistics/stats.hpp>
00026 #include <boost/accumulators/statistics/median.hpp>
00027 #include <boost/accumulators/statistics/weighted_median.hpp>
00028
00029 #include "util.h"
00030
00031 namespace descriptor_surface_based_recognition {
00032
00033
00034
00035 using namespace boost::accumulators;
00036
00037 Eigen::Vector3d parseStringVector(std::string input_string, std::string delim) {
00038
00039 std::vector<std::string> strvec;
00040
00041 boost::algorithm::trim_if(input_string, boost::algorithm::is_any_of(delim));
00042 boost::algorithm::split(strvec, input_string, boost::algorithm::is_any_of(delim), boost::algorithm::token_compress_on);
00043
00044 Eigen::Vector3d vector;
00045 for( unsigned int i=0; i < strvec.size(); i++) {
00046 vector[i] = boost::lexical_cast<double>(strvec[i]);
00047 }
00048
00049 return vector;
00050 }
00051
00052 Eigen::Vector2i parseStringVector2i(std::string input_string, std::string delim)
00053 {
00054 std::vector<std::string> strvec;
00055
00056 boost::algorithm::trim_if(input_string, boost::algorithm::is_any_of(delim));
00057 boost::algorithm::split(strvec, input_string, boost::algorithm::is_any_of(delim), boost::algorithm::token_compress_on);
00058
00059 Eigen::Vector2i vector;
00060 for( unsigned int i=0; i < strvec.size(); i++) {
00061 vector[i] = boost::lexical_cast<int>(strvec[i]);
00062 }
00063
00064 return vector;
00065 }
00066
00067 Eigen::Vector3d computeMedian(std::vector<Eigen::Vector3d> points)
00068 {
00069 if (points.size() > 0) {
00070 Eigen::Vector3d median_point = points.at(0);
00071
00072 for (unsigned int i = 0; i < 3; i++) {
00073 std::vector<double> nums;
00074 for (unsigned int j = 0; j < points.size(); j++) {
00075 nums.push_back(points.at(j)[i]);
00076 }
00077 std::sort(nums.begin(), nums.end());
00078 if (nums.size() % 2 == 0) {
00079 median_point(i) = (nums[nums.size() / 2 - 1] + nums[nums.size() / 2]) / 2;
00080 } else {
00081 median_point(i) = nums[nums.size() / 2];
00082 }
00083 }
00084 return median_point;
00085 }
00086 return Eigen::Vector3d(0, 0, 0);
00087 }
00088
00089 pcl::PointXYZ computeMedian(std::vector<pcl::PointXYZ> points)
00090 {
00091 if (points.size() > 0) {
00092 std::vector<Eigen::Vector3d> points_eigen;
00093 for (unsigned i = 0; i < points.size(); i++) {
00094 if (pcl::isFinite(points.at(i))) {
00095 points_eigen.push_back(Eigen::Vector3d(points.at(i).x, points.at(i).y, points.at(i).z));
00096 }
00097 }
00098 Eigen::Vector3d median_point = computeMedian(points_eigen);
00099 return pcl::PointXYZ(median_point[0], median_point[1], median_point[2]);
00100 }
00101 return pcl::PointXYZ();
00102 }
00103
00104 pcl::PointXYZ findPoint3D(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, pcl::PointXYZ current_point, int row, int column, int image_height, int image_width) {
00105 int step_counter = 1;
00106 bool finite_found = false;
00107 while ((!pcl::isFinite(current_point)) && (row > 1) && (column > 1) && (row < image_height - 1 - step_counter) && (column < image_width - 1 - step_counter)) {
00108 for (int i = 1; i <= step_counter; i++) {
00109 row = row + i;
00110 current_point = (*cloud)(column, row);
00111 if (pcl::isFinite(current_point)) {
00112 finite_found = true;
00113 break;
00114 }
00115 }
00116 if (finite_found) break;
00117 for (int i = 1; i <= step_counter; i++) {
00118 column = column + i;
00119 current_point = (*cloud)(column, row);
00120 if (pcl::isFinite(current_point)) {
00121 finite_found = true;
00122 break;
00123 }
00124 }
00125 if (finite_found) break;
00126 step_counter++;
00127 for (int i = 1; i <= step_counter; i++) {
00128 row = row - i;
00129 current_point = (*cloud)(column, row);
00130 if (pcl::isFinite(current_point)) {
00131 finite_found = true;
00132 break;
00133 }
00134 }
00135 if (finite_found) break;
00136 for (int i = 1; i <= step_counter; i++) {
00137 column = column - i;
00138 current_point = (*cloud)(column, row);
00139 if (pcl::isFinite(current_point)) {
00140 finite_found = true;
00141 break;
00142 }
00143 }
00144 if (finite_found) break;
00145 step_counter++;
00146 }
00147 return current_point;
00148 }
00149
00150
00151 rgb hsv2rgb(hsv in)
00152 {
00153 double hh, p, q, t, ff;
00154 long i;
00155 rgb out;
00156
00157 if(in.s <= 0.0) {
00158 out.r = in.v;
00159 out.g = in.v;
00160 out.b = in.v;
00161 return out;
00162 }
00163 hh = in.h;
00164 if(hh >= 360.0) hh = 0.0;
00165 hh /= 60.0;
00166 i = (long)hh;
00167 ff = hh - i;
00168 p = in.v * (1.0 - in.s);
00169 q = in.v * (1.0 - (in.s * ff));
00170 t = in.v * (1.0 - (in.s * (1.0 - ff)));
00171
00172 switch(i) {
00173 case 0:
00174 out.r = in.v;
00175 out.g = t;
00176 out.b = p;
00177 break;
00178 case 1:
00179 out.r = q;
00180 out.g = in.v;
00181 out.b = p;
00182 break;
00183 case 2:
00184 out.r = p;
00185 out.g = in.v;
00186 out.b = t;
00187 break;
00188
00189 case 3:
00190 out.r = p;
00191 out.g = q;
00192 out.b = in.v;
00193 break;
00194 case 4:
00195 out.r = t;
00196 out.g = p;
00197 out.b = in.v;
00198 break;
00199 case 5:
00200 default:
00201 out.r = in.v;
00202 out.g = p;
00203 out.b = q;
00204 break;
00205 }
00206 return out;
00207 }
00208
00209
00210
00211 }