41 const std::string& filename) {
42 std::vector<Eigen::Vector2d> raw_points;
43 std::ifstream ifs(filename.c_str(), std::ifstream::in);
44 std::string point_str;
47 FLAGS_minimum_point_spacing * FLAGS_minimum_point_spacing;
49 while (std::getline(ifs, point_str)) {
50 size_t idx = point_str.find(
',');
51 if (idx == std::string::npos) {
54 auto x_str = point_str.substr(0, idx);
55 auto y_str = point_str.substr(idx + 1);
57 auto x = std::stod(x_str);
58 auto y = std::stod(y_str);
60 if (raw_points.size() > 0) {
61 auto last_x = raw_points.back().x();
62 auto last_y = raw_points.back().y();
66 if (dx * dx + dy * dy < spacing_thres) {
70 raw_points.emplace_back(x, y);
75 static bool Smooth(std::vector<Eigen::Vector2d> raw_points,
76 std::vector<common::PathPoint>* ptr_smooth_points) {
77 if (raw_points.size() <= 2) {
78 AERROR <<
"the original point size is " << raw_points.size();
82 std::vector<Eigen::Vector2d> processed_points;
83 processed_points.push_back(raw_points.front());
85 for (
const Eigen::Vector2d& p : raw_points) {
86 Eigen::Vector2d d = p - processed_points.back();
87 if (d.norm() < FLAGS_minimum_point_spacing) {
90 processed_points.push_back(p);
93 if (processed_points.size() < 2) {
94 processed_points.push_back(raw_points.back());
97 Eigen::Vector2d start_point = processed_points.front();
98 std::for_each(processed_points.begin(), processed_points.end(),
99 [&start_point](Eigen::Vector2d& p) { p = p - start_point; });
104 "conf/spiral_smoother_config.pb.txt",
107 std::vector<double> opt_theta;
108 std::vector<double> opt_kappa;
109 std::vector<double> opt_dkappa;
110 std::vector<double> opt_s;
111 std::vector<double> opt_x;
112 std::vector<double> opt_y;
116 &opt_kappa, &opt_dkappa, &opt_s,
120 AWARN <<
"Optimization failed; the result may not be smooth";
122 AINFO <<
"Optimal solution found";
125 std::for_each(opt_x.begin(), opt_x.end(),
126 [&start_point](
double& x) { x += start_point.x(); });
127 std::for_each(opt_y.begin(), opt_y.end(),
128 [&start_point](
double& y) { y += start_point.y(); });
131 spiral_smoother.
Interpolate(opt_theta, opt_kappa, opt_dkappa, opt_s,