Apollo 11.0
自动驾驶开放平台
discretized_path.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22
23#include <algorithm>
24
25#include "cyber/common/log.h"
27
28namespace apollo {
29namespace planning {
30
32
33DiscretizedPath::DiscretizedPath(std::vector<PathPoint> path_points)
34 : std::vector<PathPoint>(std::move(path_points)) {}
35
37 if (empty()) {
38 return 0.0;
39 }
40 return back().s() - front().s();
41}
42
43PathPoint DiscretizedPath::Evaluate(const double path_s) const {
44 ACHECK(!empty());
45 auto it_lower = QueryLowerBound(path_s);
46 if (it_lower == begin()) {
47 return front();
48 }
49 if (it_lower == end()) {
50 return back();
51 }
53 *it_lower, path_s);
54}
55
56std::vector<PathPoint>::const_iterator DiscretizedPath::QueryLowerBound(
57 const double path_s) const {
58 auto func = [](const PathPoint &tp, const double path_s) {
59 return tp.s() < path_s;
60 };
61 return std::lower_bound(begin(), end(), path_s, func);
62}
63
64PathPoint DiscretizedPath::EvaluateReverse(const double path_s) const {
65 ACHECK(!empty());
66 auto it_upper = QueryUpperBound(path_s);
67 if (it_upper == begin()) {
68 return front();
69 }
70 if (it_upper == end()) {
71 return back();
72 }
74 *it_upper, path_s);
75}
76
77std::vector<PathPoint>::const_iterator DiscretizedPath::QueryUpperBound(
78 const double path_s) const {
79 auto func = [](const double path_s, const PathPoint &tp) {
80 return tp.s() < path_s;
81 };
82 return std::upper_bound(begin(), end(), path_s, func);
83}
84
85} // namespace planning
86} // namespace apollo
common::PathPoint EvaluateReverse(const double path_s) const
std::vector< common::PathPoint >::const_iterator QueryUpperBound(const double path_s) const
std::vector< common::PathPoint >::const_iterator QueryLowerBound(const double path_s) const
common::PathPoint Evaluate(const double path_s) const
Planning module main class.
Linear interpolation functions.
#define ACHECK(cond)
Definition log.h:80
SLPoint InterpolateUsingLinearApproximation(const SLPoint &p0, const SLPoint &p1, const double w)
class register implement
Definition arena_queue.h:37
Definition future.h:29