util.cpp
Go to the documentation of this file.
1 
21 #include <boost/algorithm/string.hpp>
22 #include <vector>
23 #include <boost/lexical_cast.hpp>
24 #include <boost/accumulators/accumulators.hpp>
25 #include <boost/accumulators/statistics/stats.hpp>
26 #include <boost/accumulators/statistics/median.hpp>
27 #include <boost/accumulators/statistics/weighted_median.hpp>
28 
29 #include "util.h"
30 
32 
33 
34 
35 using namespace boost::accumulators;
36 
37 Eigen::Vector3d parseStringVector(std::string input_string, std::string delim) {
38 
39  std::vector<std::string> strvec;
40 
41  boost::algorithm::trim_if(input_string, boost::algorithm::is_any_of(delim));
42  boost::algorithm::split(strvec, input_string, boost::algorithm::is_any_of(delim), boost::algorithm::token_compress_on);
43 
44  Eigen::Vector3d vector;
45  for( unsigned int i=0; i < strvec.size(); i++) {
46  vector[i] = boost::lexical_cast<double>(strvec[i]);
47  }
48 
49  return vector;
50 }
51 
52 Eigen::Vector2i parseStringVector2i(std::string input_string, std::string delim)
53 {
54  std::vector<std::string> strvec;
55 
56  boost::algorithm::trim_if(input_string, boost::algorithm::is_any_of(delim));
57  boost::algorithm::split(strvec, input_string, boost::algorithm::is_any_of(delim), boost::algorithm::token_compress_on);
58 
59  Eigen::Vector2i vector;
60  for( unsigned int i=0; i < strvec.size(); i++) {
61  vector[i] = boost::lexical_cast<int>(strvec[i]);
62  }
63 
64  return vector;
65 }
66 
67 Eigen::Vector3d computeMedian(std::vector<Eigen::Vector3d> points)
68 {
69  if (points.size() > 0) {
70  Eigen::Vector3d median_point = points.at(0);
71 
72  for (unsigned int i = 0; i < 3; i++) {
73  std::vector<double> nums;
74  for (unsigned int j = 0; j < points.size(); j++) {
75  nums.push_back(points.at(j)[i]);
76  }
77  std::sort(nums.begin(), nums.end());
78  if (nums.size() % 2 == 0) {
79  median_point(i) = (nums[nums.size() / 2 - 1] + nums[nums.size() / 2]) / 2;
80  } else {
81  median_point(i) = nums[nums.size() / 2];
82  }
83  }
84  return median_point;
85  }
86  return Eigen::Vector3d(0, 0, 0);
87 }
88 
89 pcl::PointXYZ computeMedian(std::vector<pcl::PointXYZ> points)
90 {
91  if (points.size() > 0) {
92  std::vector<Eigen::Vector3d> points_eigen;
93  for (unsigned i = 0; i < points.size(); i++) {
94  if (pcl::isFinite(points.at(i))) {
95  points_eigen.push_back(Eigen::Vector3d(points.at(i).x, points.at(i).y, points.at(i).z));
96  }
97  }
98  Eigen::Vector3d median_point = computeMedian(points_eigen);
99  return pcl::PointXYZ(median_point[0], median_point[1], median_point[2]);
100  }
101  return pcl::PointXYZ();
102 }
103 
104 pcl::PointXYZ findPoint3D(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, pcl::PointXYZ current_point, int row, int column, int image_height, int image_width) {
105  int step_counter = 1;
106  bool finite_found = false;
107  while ((!pcl::isFinite(current_point)) && (row > 1) && (column > 1) && (row < image_height - 1 - step_counter) && (column < image_width - 1 - step_counter)) {
108  for (int i = 1; i <= step_counter; i++) {
109  row = row + i;
110  current_point = (*cloud)(column, row);
111  if (pcl::isFinite(current_point)) {
112  finite_found = true;
113  break;
114  }
115  }
116  if (finite_found) break;
117  for (int i = 1; i <= step_counter; i++) {
118  column = column + i;
119  current_point = (*cloud)(column, row);
120  if (pcl::isFinite(current_point)) {
121  finite_found = true;
122  break;
123  }
124  }
125  if (finite_found) break;
126  step_counter++;
127  for (int i = 1; i <= step_counter; i++) {
128  row = row - i;
129  current_point = (*cloud)(column, row);
130  if (pcl::isFinite(current_point)) {
131  finite_found = true;
132  break;
133  }
134  }
135  if (finite_found) break;
136  for (int i = 1; i <= step_counter; i++) {
137  column = column - i;
138  current_point = (*cloud)(column, row);
139  if (pcl::isFinite(current_point)) {
140  finite_found = true;
141  break;
142  }
143  }
144  if (finite_found) break;
145  step_counter++;
146  }
147  return current_point;
148 }
149 
150 
152 {
153  double hh, p, q, t, ff;
154  long i;
155  rgb out;
156 
157  if(in.s <= 0.0) {
158  out.r = in.v;
159  out.g = in.v;
160  out.b = in.v;
161  return out;
162  }
163  hh = in.h;
164  if(hh >= 360.0) hh = 0.0;
165  hh /= 60.0;
166  i = (long)hh;
167  ff = hh - i;
168  p = in.v * (1.0 - in.s);
169  q = in.v * (1.0 - (in.s * ff));
170  t = in.v * (1.0 - (in.s * (1.0 - ff)));
171 
172  switch(i) {
173  case 0:
174  out.r = in.v;
175  out.g = t;
176  out.b = p;
177  break;
178  case 1:
179  out.r = q;
180  out.g = in.v;
181  out.b = p;
182  break;
183  case 2:
184  out.r = p;
185  out.g = in.v;
186  out.b = t;
187  break;
188 
189  case 3:
190  out.r = p;
191  out.g = q;
192  out.b = in.v;
193  break;
194  case 4:
195  out.r = t;
196  out.g = p;
197  out.b = in.v;
198  break;
199  case 5:
200  default:
201  out.r = in.v;
202  out.g = p;
203  out.b = q;
204  break;
205  }
206  return out;
207 }
208 
209 
210 
211 }
pcl::PointXYZ findPoint3D(pcl::PointCloud< pcl::PointXYZ >::Ptr cloud, pcl::PointXYZ current_point, int row, int column, int image_height, int image_width)
Finds the corresponding 3D point to the given 2D point.
Definition: util.cpp:104
Eigen::Vector3d parseStringVector(std::string input_string, std::string delim)
Parses the given string and returns the 3D-double-vector described by it.
Definition: util.cpp:37
Eigen::Vector3d computeMedian(std::vector< Eigen::Vector3d > points)
Computes the median of the given points.
Definition: util.cpp:67
rgb hsv2rgb(hsv in)
Converts the given hsv-color to rgb.
Definition: util.cpp:151
Eigen::Vector2i parseStringVector2i(std::string input_string, std::string delim)
Parses the given string and returns the 2D-int-vector described by it.
Definition: util.cpp:52


asr_descriptor_surface_based_recognition
Author(s): Allgeyer Tobias, Hutmacher Robin, Meißner Pascal
autogenerated on Mon Dec 16 2019 03:31:15