48 explicit SmootherUtil(
const std::string& filename) : filename_(filename) {
49 std::ifstream ifs(filename.c_str(), std::ifstream::in);
50 std::string point_str;
51 while (std::getline(ifs, point_str)) {
52 size_t idx = point_str.find(
',');
53 if (idx == std::string::npos) {
56 auto x_str = point_str.substr(0, idx);
57 auto y_str = point_str.substr(idx + 1);
58 raw_points_.emplace_back(std::stod(x_str), std::stod(y_str));
62 <<
"Failed to read smoother config file: "
63 << FLAGS_smoother_config_filename;
67 if (raw_points_.size() <= 2) {
68 AERROR <<
"the original point size is " << raw_points_.size();
73 std::vector<ReferencePoint> ref_points;
75 for (; s < FLAGS_smooth_length && i < raw_points_.size(); ++i) {
85 std::make_unique<QpSplineReferenceLineSmoother>(config_);
88 smoother_ptr->SetAnchorPoints(anchors);
90 if (!smoother_ptr->Smooth(init_ref, &smoothed_init_ref)) {
91 AERROR <<
"smooth initial reference line failed";
96 for (; i < raw_points_.size(); ++i) {
98 size_t j = ref_points_.size() - 1;
99 while (j > 0 && s < FLAGS_smooth_length / 2.0) {
100 s += DistanceXY(ref_points_[j - 1], ref_points_[j]);
103 ReferenceLine prev_half_ref(ref_points_.begin() + j, ref_points_.end());
104 ref_points_.erase(ref_points_.begin() + j, ref_points_.end());
106 prev_half_ref.
XYToSL(raw_points_[i], &sl);
107 while (sl.
s() <= prev_half_ref.
Length() && i + 1 < raw_points_.size()) {
108 prev_half_ref.
XYToSL(raw_points_[i + 1], &sl);
114 while (j + 1 < raw_points_.size() && s < FLAGS_smooth_length / 2.0) {
115 Vec2d vec = raw_points_[j + 1] - raw_points_[j];
123 auto anchors = CreateAnchorPoints(ref_points.front(), local_ref);
127 std::make_unique<QpSplineReferenceLineSmoother>(config_);
128 smoother_ptr->SetAnchorPoints(anchors);
130 if (!smoother_ptr->Smooth(local_ref, &smoothed_local_ref)) {
131 AERROR <<
"Failed to smooth reference line";
134 ref_points_.insert(ref_points_.end(),