Apollo 10.0
自动驾驶开放平台
path.h
浏览该文件的文档.
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
17#pragma once
18
19#include <string>
20#include <utility>
21#include <vector>
22
23#include "modules/common_msgs/map_msgs/map_lane.pb.h"
24
31
32namespace apollo {
33namespace hdmap {
34
35// class LaneInfoConstPtr;
36// class OverlapInfoConstPtr;
37
39 LaneWaypoint() = default;
41 : lane(CHECK_NOTNULL(lane)), s(s) {}
42 LaneWaypoint(LaneInfoConstPtr lane, const double s, const double l)
43 : lane(CHECK_NOTNULL(lane)), s(s), l(l) {}
45 double s = 0.0;
46 double l = 0.0;
47
48 std::string DebugString() const;
49};
50
55
60
66
72
74 LaneSegment() = default;
75 LaneSegment(LaneInfoConstPtr lane, const double start_s, const double end_s)
76 : lane(CHECK_NOTNULL(lane)), start_s(start_s), end_s(end_s) {}
78 double start_s = 0.0;
79 double end_s = 0.0;
80 double Length() const { return end_s - start_s; }
81
85 static void Join(std::vector<LaneSegment>* segments);
86
87 std::string DebugString() const;
88};
89
91 PathOverlap() = default;
92 PathOverlap(std::string object_id, const double start_s, const double end_s)
94
95 std::string object_id;
96 double start_s = 0.0;
97 double end_s = 0.0;
98
99 std::string DebugString() const;
100};
101
103 public:
104 MapPathPoint() = default;
106 : Vec2d(point.x(), point.y()), heading_(heading) {}
108 LaneWaypoint lane_waypoint)
109 : Vec2d(point.x(), point.y()), heading_(heading) {
110 lane_waypoints_.emplace_back(std::move(lane_waypoint));
111 }
113 std::vector<LaneWaypoint> lane_waypoints)
114 : Vec2d(point.x(), point.y()),
117
118 double heading() const { return heading_; }
119 void set_heading(const double heading) { heading_ = heading; }
120
121 const std::vector<LaneWaypoint>& lane_waypoints() const {
122 return lane_waypoints_;
123 }
124
125 void add_lane_waypoint(LaneWaypoint lane_waypoint) {
126 lane_waypoints_.emplace_back(std::move(lane_waypoint));
127 }
128 void add_lane_waypoints(const std::vector<LaneWaypoint>& lane_waypoints) {
129 lane_waypoints_.insert(lane_waypoints_.end(), lane_waypoints.begin(),
130 lane_waypoints.end());
131 }
132
134
135 static void RemoveDuplicates(std::vector<MapPathPoint>* points);
136
137 static std::vector<MapPathPoint> GetPointsFromSegment(
138 const LaneSegment& segment);
139
140 static std::vector<MapPathPoint> GetPointsFromLane(LaneInfoConstPtr lane,
141 const double start_s,
142 const double end_s);
143
144 std::string DebugString() const;
145
146 protected:
147 double heading_ = 0.0;
148 std::vector<LaneWaypoint> lane_waypoints_;
149};
150
151class Path;
152
154 public:
155 PathApproximation() = default;
156 PathApproximation(const Path& path, const double max_error)
158 Init(path);
159 }
160 double max_error() const { return max_error_; }
161 const std::vector<int>& original_ids() const { return original_ids_; }
162 const std::vector<common::math::LineSegment2d>& segments() const {
163 return segments_;
164 }
165
166 bool GetProjection(const Path& path, const common::math::Vec2d& point,
167 double* accumulate_s, double* lateral,
168 double* distance) const;
169
170 bool OverlapWith(const Path& path, const common::math::Box2d& box,
171 double width) const;
172
173 protected:
174 void Init(const Path& path);
175 bool is_within_max_error(const Path& path, const int s, const int t);
176 double compute_max_error(const Path& path, const int s, const int t);
177
178 void InitDilute(const Path& path);
179 void InitProjections(const Path& path);
180
181 protected:
182 double max_error_ = 0;
183 double max_sqr_error_ = 0;
184
185 int num_points_ = 0;
186 std::vector<int> original_ids_;
187 std::vector<common::math::LineSegment2d> segments_;
188 std::vector<double> max_error_per_segment_;
189
190 // TODO(All): use direction change checks to early stop.
191
192 // Projection of points onto the diluated segments.
193 std::vector<double> projections_;
196
197 // The original_projection is the projection of original points onto the
198 // diluated segments.
199 std::vector<double> original_projections_;
200 // max_p_to_left[i] = max(p[0], p[1], ... p[i]).
201 // min_p_to_right[i] = min(p[i], p[i + 1], ... p[size - 1]).
205};
206
208 public:
209 InterpolatedIndex(int id, double offset) : id(id), offset(offset) {}
210 int id = 0;
211 double offset = 0.0;
212};
213
214class Path {
215 public:
216 Path() = default;
217 explicit Path(const std::vector<MapPathPoint>& path_points);
218 explicit Path(std::vector<MapPathPoint>&& path_points);
219 explicit Path(std::vector<LaneSegment>&& path_points);
220 explicit Path(const std::vector<LaneSegment>& path_points);
221
222 Path(const std::vector<MapPathPoint>& path_points,
223 const std::vector<LaneSegment>& lane_segments);
224 Path(std::vector<MapPathPoint>&& path_points,
225 std::vector<LaneSegment>&& lane_segments);
226
227 Path(const std::vector<MapPathPoint>& path_points,
228 const std::vector<LaneSegment>& lane_segments,
229 const double max_approximation_error);
230 Path(std::vector<MapPathPoint>&& path_points,
231 std::vector<LaneSegment>&& lane_segments,
232 const double max_approximation_error);
233
234 // Return smooth coordinate by interpolated index or accumulate_s.
236 MapPathPoint GetSmoothPoint(double s) const;
237
238 // Compute accumulate s value of the index.
239 double GetSFromIndex(const InterpolatedIndex& index) const;
240 // Compute interpolated index by accumulate_s.
241 InterpolatedIndex GetIndexFromS(double s) const;
242
243 // get the index of the lane from s by accumulate_s
244 InterpolatedIndex GetLaneIndexFromS(double s) const;
245
246 std::vector<hdmap::LaneSegment> GetLaneSegments(const double start_s,
247 const double end_s) const;
248
249 bool GetNearestPoint(const common::math::Vec2d& point, double* accumulate_s,
250 double* lateral) const;
251 bool GetNearestPoint(const common::math::Vec2d& point, double* accumulate_s,
252 double* lateral, double* distance) const;
254 const double hueristic_start_s,
255 const double hueristic_end_s,
256 double* accumulate_s, double* lateral,
257 double* min_distance) const;
258 bool GetProjection(const common::math::Vec2d& point, double* accumulate_s,
259 double* lateral) const;
260
261 bool GetProjection(const double heading, const common::math::Vec2d& point,
262 double* accumulate_s, double* lateral) const;
263
265 double* accumulate_s, double* lateral) const;
266
267 bool GetProjection(const common::math::Vec2d& point, double* accumulate_s,
268 double* lateral, double* distance) const;
269
270 bool GetProjection(const common::math::Vec2d& point, const double heading,
271 double* accumulate_s, double* lateral,
272 double* distance) const;
273
275 double* heading) const;
276
277 int num_points() const { return num_points_; }
278 int num_segments() const { return num_segments_; }
279 const std::vector<MapPathPoint>& path_points() const { return path_points_; }
280 const std::vector<LaneSegment>& lane_segments() const {
281 return lane_segments_;
282 }
283 const std::vector<LaneSegment>& lane_segments_to_next_point() const {
285 }
286 const std::vector<common::math::Vec2d>& unit_directions() const {
287 return unit_directions_;
288 }
289 const std::vector<double>& accumulated_s() const { return accumulated_s_; }
290 const std::vector<common::math::LineSegment2d>& segments() const {
291 return segments_;
292 }
294 double length() const { return length_; }
295
296 const PathOverlap* NextLaneOverlap(double s) const;
297
298 const std::vector<PathOverlap>& lane_overlaps() const {
299 return lane_overlaps_;
300 }
301 const std::vector<PathOverlap>& signal_overlaps() const {
302 return signal_overlaps_;
303 }
304 const std::vector<PathOverlap>& yield_sign_overlaps() const {
306 }
307 const std::vector<PathOverlap>& stop_sign_overlaps() const {
308 return stop_sign_overlaps_;
309 }
310 const std::vector<PathOverlap>& crosswalk_overlaps() const {
311 return crosswalk_overlaps_;
312 }
313 const std::vector<PathOverlap>& junction_overlaps() const {
314 return junction_overlaps_;
315 }
316 const std::vector<PathOverlap>& pnc_junction_overlaps() const {
318 }
319 const std::vector<PathOverlap>& clear_area_overlaps() const {
321 }
322 const std::vector<PathOverlap>& speed_bump_overlaps() const {
324 }
325 const std::vector<PathOverlap>& parking_space_overlaps() const {
327 }
328 const std::vector<PathOverlap>& dead_end_overlaps() const {
329 return dead_end_overlaps_;
330 }
331 const std::vector<PathOverlap>& area_overlaps() const {
332 return area_overlaps_;
333 }
334
335 double GetLaneLeftWidth(const double s) const;
336 double GetLaneRightWidth(const double s) const;
337 bool GetLaneWidth(const double s, double* lane_left_width,
338 double* lane_right_width) const;
339
340 double GetRoadLeftWidth(const double s) const;
341 double GetRoadRightWidth(const double s) const;
342 bool GetRoadWidth(const double s, double* road_left_width,
343 double* road_ight_width) const;
344
345 bool IsOnPath(const common::math::Vec2d& point) const;
346 bool OverlapWith(const common::math::Box2d& box, double width) const;
347
348 std::string DebugString() const;
349
350 protected:
351 void Init();
352 void InitPoints();
353 void InitLaneSegments();
354 void InitWidth();
355 void InitPointIndex();
356 void InitOverlaps();
357
358 double GetSample(const std::vector<double>& samples, const double s) const;
359
361 std::function<const std::vector<OverlapInfoConstPtr>&(const LaneInfo&)>;
362 void GetAllOverlaps(GetOverlapFromLaneFunc GetOverlaps_from_lane,
363 std::vector<PathOverlap>* const overlaps) const;
364
365 protected:
366 int num_points_ = 0;
368 std::vector<MapPathPoint> path_points_;
369 std::vector<LaneSegment> lane_segments_;
370 std::vector<double> lane_accumulated_s_;
371 std::vector<LaneSegment> lane_segments_to_next_point_;
372 std::vector<common::math::Vec2d> unit_directions_;
373 double length_ = 0.0;
374 std::vector<double> accumulated_s_;
375 std::vector<common::math::LineSegment2d> segments_;
378
379 // Sampled every fixed length.
381 std::vector<double> lane_left_width_;
382 std::vector<double> lane_right_width_;
383 std::vector<double> road_left_width_;
384 std::vector<double> road_right_width_;
385 std::vector<int> last_point_index_;
386
387 std::vector<PathOverlap> lane_overlaps_;
388 std::vector<PathOverlap> signal_overlaps_;
389 std::vector<PathOverlap> yield_sign_overlaps_;
390 std::vector<PathOverlap> stop_sign_overlaps_;
391 std::vector<PathOverlap> crosswalk_overlaps_;
392 std::vector<PathOverlap> parking_space_overlaps_;
393 std::vector<PathOverlap> dead_end_overlaps_;
394 std::vector<PathOverlap> junction_overlaps_;
395 std::vector<PathOverlap> pnc_junction_overlaps_;
396 std::vector<PathOverlap> clear_area_overlaps_;
397 std::vector<PathOverlap> speed_bump_overlaps_;
398 std::vector<PathOverlap> area_overlaps_;
399
400 private:
408 void FindIndex(int left_index, int right_index, double target_s,
409 int* mid_index) const;
410};
411
412} // namespace hdmap
413} // namespace apollo
The class of Box2d.
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double y() const
Getter for y component
Definition vec2d.h:57
double x() const
Getter for x component
Definition vec2d.h:54
InterpolatedIndex(int id, double offset)
Definition path.h:209
std::vector< LaneWaypoint > lane_waypoints_
Definition path.h:148
MapPathPoint(const common::math::Vec2d &point, double heading)
Definition path.h:105
void add_lane_waypoints(const std::vector< LaneWaypoint > &lane_waypoints)
Definition path.h:128
MapPathPoint(const common::math::Vec2d &point, double heading, LaneWaypoint lane_waypoint)
Definition path.h:107
static void RemoveDuplicates(std::vector< MapPathPoint > *points)
Definition path.cc:241
void add_lane_waypoint(LaneWaypoint lane_waypoint)
Definition path.h:125
MapPathPoint(const common::math::Vec2d &point, double heading, std::vector< LaneWaypoint > lane_waypoints)
Definition path.h:112
const std::vector< LaneWaypoint > & lane_waypoints() const
Definition path.h:121
double heading() const
Definition path.h:118
static std::vector< MapPathPoint > GetPointsFromSegment(const LaneSegment &segment)
Definition path.cc:201
static std::vector< MapPathPoint > GetPointsFromLane(LaneInfoConstPtr lane, const double start_s, const double end_s)
Definition path.cc:206
void set_heading(const double heading)
Definition path.h:119
std::string DebugString() const
Definition path.cc:258
bool is_within_max_error(const Path &path, const int s, const int t)
Definition path.cc:1081
std::vector< common::math::LineSegment2d > segments_
Definition path.h:187
void InitProjections(const Path &path)
Definition path.cc:1143
PathApproximation(const Path &path, const double max_error)
Definition path.h:156
std::vector< double > min_original_projections_to_right_
Definition path.h:203
std::vector< int > sampled_max_original_projections_to_left_
Definition path.h:204
void Init(const Path &path)
Definition path.cc:1096
std::vector< double > max_error_per_segment_
Definition path.h:188
void InitDilute(const Path &path)
Definition path.cc:1101
double compute_max_error(const Path &path, const int s, const int t)
Definition path.cc:1066
std::vector< double > projections_
Definition path.h:193
const std::vector< common::math::LineSegment2d > & segments() const
Definition path.h:162
std::vector< int > original_ids_
Definition path.h:186
bool GetProjection(const Path &path, const common::math::Vec2d &point, double *accumulate_s, double *lateral, double *distance) const
Definition path.cc:1215
const std::vector< int > & original_ids() const
Definition path.h:161
std::vector< double > original_projections_
Definition path.h:199
std::vector< double > max_original_projections_to_left_
Definition path.h:202
bool OverlapWith(const Path &path, const common::math::Box2d &box, double width) const
Definition path.cc:1350
const std::vector< PathOverlap > & dead_end_overlaps() const
Definition path.h:328
const std::vector< PathOverlap > & area_overlaps() const
Definition path.h:331
const std::vector< common::math::LineSegment2d > & segments() const
Definition path.h:290
void InitLaneSegments()
Definition path.cc:402
std::vector< MapPathPoint > path_points_
Definition path.h:368
InterpolatedIndex GetIndexFromS(double s) const
Definition path.cc:638
int num_segments() const
Definition path.h:278
const std::vector< LaneSegment > & lane_segments_to_next_point() const
Definition path.h:283
bool GetProjectionWithWarmStartS(const common::math::Vec2d &point, double *accumulate_s, double *lateral) const
Definition path.cc:751
double GetSample(const std::vector< double > &samples, const double s) const
Definition path.cc:1016
const std::vector< PathOverlap > & parking_space_overlaps() const
Definition path.h:325
std::vector< PathOverlap > speed_bump_overlaps_
Definition path.h:397
double length() const
Definition path.h:294
bool GetProjectionWithHueristicParams(const common::math::Vec2d &point, const double hueristic_start_s, const double hueristic_end_s, double *accumulate_s, double *lateral, double *min_distance) const
Definition path.cc:806
void InitPointIndex()
Definition path.cc:488
std::vector< double > lane_accumulated_s_
Definition path.h:370
double GetLaneRightWidth(const double s) const
Definition path.cc:977
bool IsOnPath(const common::math::Vec2d &point) const
Definition path.cc:1032
void InitPoints()
Definition path.cc:362
std::vector< double > accumulated_s_
Definition path.h:374
std::vector< PathOverlap > stop_sign_overlaps_
Definition path.h:390
bool GetLaneWidth(const double s, double *lane_left_width, double *lane_right_width) const
Definition path.cc:981
std::vector< PathOverlap > pnc_junction_overlaps_
Definition path.h:395
std::vector< PathOverlap > parking_space_overlaps_
Definition path.h:392
std::function< const std::vector< OverlapInfoConstPtr > &(const LaneInfo &)> GetOverlapFromLaneFunc
Definition path.h:361
double GetRoadLeftWidth(const double s) const
Definition path.cc:994
std::vector< hdmap::LaneSegment > GetLaneSegments(const double start_s, const double end_s) const
Definition path.cc:690
std::vector< PathOverlap > crosswalk_overlaps_
Definition path.h:391
std::vector< int > last_point_index_
Definition path.h:385
const std::vector< PathOverlap > & crosswalk_overlaps() const
Definition path.h:310
std::vector< double > lane_left_width_
Definition path.h:381
std::vector< PathOverlap > lane_overlaps_
Definition path.h:387
std::vector< PathOverlap > signal_overlaps_
Definition path.h:388
double GetRoadRightWidth(const double s) const
Definition path.cc:998
bool GetHeadingAlongPath(const common::math::Vec2d &point, double *heading) const
Definition path.cc:960
const PathOverlap * NextLaneOverlap(double s) const
Definition path.cc:564
bool GetRoadWidth(const double s, double *road_left_width, double *road_ight_width) const
Definition path.cc:1002
bool GetProjection(const common::math::Vec2d &point, double *accumulate_s, double *lateral) const
Definition path.cc:739
InterpolatedIndex GetLaneIndexFromS(double s) const
Definition path.cc:666
double GetSFromIndex(const InterpolatedIndex &index) const
Definition path.cc:628
std::vector< common::math::Vec2d > unit_directions_
Definition path.h:372
std::vector< PathOverlap > yield_sign_overlaps_
Definition path.h:389
void InitOverlaps()
Definition path.cc:575
std::string DebugString() const
Definition path.cc:266
const std::vector< PathOverlap > & junction_overlaps() const
Definition path.h:313
MapPathPoint GetSmoothPoint(const InterpolatedIndex &index) const
Definition path.cc:591
const std::vector< PathOverlap > & signal_overlaps() const
Definition path.h:301
std::vector< PathOverlap > clear_area_overlaps_
Definition path.h:396
int num_sample_points_
Definition path.h:380
const std::vector< PathOverlap > & speed_bump_overlaps() const
Definition path.h:322
bool GetNearestPoint(const common::math::Vec2d &point, double *accumulate_s, double *lateral) const
Definition path.cc:718
const std::vector< PathOverlap > & lane_overlaps() const
Definition path.h:298
bool OverlapWith(const common::math::Box2d &box, double width) const
Definition path.cc:1049
std::vector< PathOverlap > area_overlaps_
Definition path.h:398
const std::vector< common::math::Vec2d > & unit_directions() const
Definition path.h:286
std::vector< double > road_left_width_
Definition path.h:383
int num_points() const
Definition path.h:277
const std::vector< PathOverlap > & yield_sign_overlaps() const
Definition path.h:304
std::vector< double > lane_right_width_
Definition path.h:382
const std::vector< PathOverlap > & pnc_junction_overlaps() const
Definition path.h:316
std::vector< PathOverlap > dead_end_overlaps_
Definition path.h:393
std::vector< common::math::LineSegment2d > segments_
Definition path.h:375
bool use_path_approximation_
Definition path.h:376
const PathApproximation * approximation() const
Definition path.h:293
std::vector< PathOverlap > junction_overlaps_
Definition path.h:394
std::vector< LaneSegment > lane_segments_to_next_point_
Definition path.h:371
const std::vector< PathOverlap > & stop_sign_overlaps() const
Definition path.h:307
const std::vector< MapPathPoint > & path_points() const
Definition path.h:279
void GetAllOverlaps(GetOverlapFromLaneFunc GetOverlaps_from_lane, std::vector< PathOverlap > *const overlaps) const
Definition path.cc:504
std::vector< LaneSegment > lane_segments_
Definition path.h:369
double GetLaneLeftWidth(const double s) const
Definition path.cc:973
PathApproximation approximation_
Definition path.h:377
const std::vector< PathOverlap > & clear_area_overlaps() const
Definition path.h:319
const std::vector< double > & accumulated_s() const
Definition path.h:289
const std::vector< LaneSegment > & lane_segments() const
Definition path.h:280
std::vector< double > road_right_width_
Definition path.h:384
Define the LineSegment2d class.
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
LaneBoundaryType::Type LeftBoundaryType(const LaneWaypoint &waypoint)
get left boundary type at a waypoint.
Definition path.cc:75
LaneBoundaryType::Type RightBoundaryType(const LaneWaypoint &waypoint)
get left boundary type at a waypoint.
Definition path.cc:92
LaneWaypoint RightNeighborWaypoint(const LaneWaypoint &waypoint)
get left neighbor lane waypoint.
Definition path.cc:165
LaneWaypoint LeftNeighborWaypoint(const LaneWaypoint &waypoint)
get left neighbor lane waypoint.
Definition path.cc:109
class register implement
Definition arena_queue.h:37
Definition future.h:29
LaneSegment(LaneInfoConstPtr lane, const double start_s, const double end_s)
Definition path.h:75
double Length() const
Definition path.h:80
static void Join(std::vector< LaneSegment > *segments)
Join neighboring lane segments if they have the same lane id
Definition path.cc:138
LaneInfoConstPtr lane
Definition path.h:77
std::string DebugString() const
Definition path.cc:193
std::string DebugString() const
Definition path.cc:68
LaneWaypoint(LaneInfoConstPtr lane, const double s)
Definition path.h:40
LaneInfoConstPtr lane
Definition path.h:44
LaneWaypoint(LaneInfoConstPtr lane, const double s, const double l)
Definition path.h:42
std::string DebugString() const
Definition path.cc:280
std::string object_id
Definition path.h:95
PathOverlap(std::string object_id, const double start_s, const double end_s)
Definition path.h:92
Defines the Vec2d class.