prediction_map.h 10.9 KB
Newer Older
K
kechxu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/******************************************************************************
 * Copyright 2017 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

17 18
#ifndef MODULES_PREDICTION_COMMON_PREDICTION_MAP_H_
#define MODULES_PREDICTION_COMMON_PREDICTION_MAP_H_
K
kechxu 已提交
19 20

#include <memory>
K
kechxu 已提交
21
#include <string>
K
kechxu 已提交
22
#include <vector>
K
kechxu 已提交
23

K
kechxu 已提交
24 25
#include "Eigen/Dense"

K
kechxu 已提交
26
#include "modules/common/macro.h"
K
kechxu 已提交
27
#include "modules/map/hdmap/hdmap_common.h"
28
#include "modules/map/hdmap/hdmap_impl.h"
K
kechxu 已提交
29
#include "modules/map/pnc_map/path.h"
K
kechxu 已提交
30 31 32 33 34 35

namespace apollo {
namespace prediction {

class PredictionMap {
 public:
36 37 38 39 40 41
  /**
   * @brief Get the position of a point on a specific distance along a lane.
   * @param lane_info The lane to get a position.
   * @param s The distance along the lane.
   * @return The position with coordinates.
   */
42
  static Eigen::Vector2d PositionOnLane(
43
      std::shared_ptr<const hdmap::LaneInfo> lane_info, const double s);
44

45 46 47 48 49 50
  /**
   * @brief Get the heading of a point on a specific distance along a lane.
   * @param lane_info The lane to get a heading.
   * @param s The distance along the lane.
   * @return The heading of the point.
   */
51 52
  static double HeadingOnLane(std::shared_ptr<const hdmap::LaneInfo> lane_info,
                              const double s);
53

54 55 56 57 58 59
  /**
   * @brief Get the width on a specified distance on a lane.
   * @param lane_info The lane to get the width.
   * @param s The distance along the lane.
   * @return The width on the distance s.
   */
60 61
  static double LaneTotalWidth(std::shared_ptr<const hdmap::LaneInfo> lane_info,
                               const double s);
62

63 64 65 66 67
  /**
   * @brief Get a shared pointer to a lane by lane ID.
   * @param id The ID of the target lane ID in the form of string.
   * @return A shared pointer to the lane with the input lane ID.
   */
68
  static std::shared_ptr<const hdmap::LaneInfo> LaneById(const std::string& id);
69

70 71 72 73 74 75 76
  /**
   * @brief Get the frenet coordinates (s, l) on a lane by a position.
   * @param position The position to get its frenet coordinates.
   * @param lane_info The lane on which to get the frenet coordinates.
   * @param s The longitudinal coordinate of the position.
   * @param l The lateral coordinate of the position.
   */
77 78 79
  static bool GetProjection(const Eigen::Vector2d& position,
                            std::shared_ptr<const hdmap::LaneInfo> lane_info,
                            double* s, double* l);
80

81 82 83 84 85 86 87
  /**
   * @brief Get the nearest path point to a longitudinal coordinate on a lane.
   * @param lane_info The lane on which to get the projected point.
   * @param s The longitudinal coordinate.
   * @param path_point The nearest path point.
   * @param If the process is successful.
   */
88
  static bool ProjectionFromLane(
89 90
      std::shared_ptr<const hdmap::LaneInfo> lane_info, const double s,
      hdmap::MapPathPoint* path_point);
91

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  /**
   * @brief Determine if a lane is a virtual lane.
   * @param The lane ID of the lane.
   * @return If the lane is a virtual lane.
   */
  static bool IsVirtualLane(const std::string& lane_id);

  /**
   * @brief Determine if a point is on a virtual lane.
   * @param The point coordinate.
   * @return If the point is on a virtual lane.
   */
  static bool OnVirtualLane(const Eigen::Vector2d& position,
                            const double radius);

107 108 109 110 111 112
  /**
   * @brief Get the connected lanes from some specified lanes.
   * @param prev_lanes The lanes from which to search their connected lanes.
   * @param heading The specified heading.
   * @param radius The searching radius.
   * @param on_lane If the position is on lane.
113
   * @param lanes The searched lanes.
114
   */
115
  void OnLane(
116 117
      const std::vector<std::shared_ptr<const hdmap::LaneInfo>>& prev_lanes,
      const Eigen::Vector2d& point, const double heading, const double radius,
118
      const bool on_lane,
119
      std::vector<std::shared_ptr<const hdmap::LaneInfo>>* lanes);
120

C
Calvin Miao 已提交
121 122 123 124 125 126 127
  /**
   * @brief Check if there are any junctions within the range centered at
   *        a certain point with a radius.
   * @param point The position.
   * @param radius The radius to search junctions.
   * @return If any junctions exist.
   */
C
Calvin Miao 已提交
128
  static bool NearJunction(const Eigen::Vector2d& point, const double radius);
C
Calvin Miao 已提交
129

130 131 132 133 134 135 136 137
  /**
   * @brief Get a list of junctions given a point and a search radius
   * @param Point
   * @param Search radius
   * @return A list of junctions
   */
  std::vector<std::shared_ptr<const apollo::hdmap::JunctionInfo>> GetJunctions(
      const Eigen::Vector2d& point, const double radius);
138

139 140 141 142 143 144
  /**
   * @brief Get the lane heading on a point.
   * @param lane_info The target lane.
   * @param point The point to get the heading.
   * @return The heading of the input point on the input lane.
   */
145 146
  static double PathHeading(std::shared_ptr<const hdmap::LaneInfo> lane_info,
                            const common::PointENU& point);
147

148 149 150 151 152 153 154
  /**
   * @brief Get the smooth point on a lane by a longitudinal coordinate.
   * @param id The lane ID.
   * @param s The longitudinal coordinate along the lane.
   * @param l The lateral coordinate of the position.
   * @param point The point corresponding to the s,l-value coordinate.
   * @param heading The lane heading on the point.
155
   * @return If the process is successful.
156
   */
157 158 159
  bool SmoothPointFromLane(const std::string& id, const double s,
                           const double l, Eigen::Vector2d* point,
                           double* heading);
K
kechxu 已提交
160

161 162 163
  /**
   * @brief Get nearby lanes by a position and current lanes.
   * @param point The position to search its nearby lanes.
164
   * @param heading The heading of an obstacle.
165 166 167 168
   * @param radius The searching radius.
   * @param lanes The current lanes.
   * @param nearby_lanes The searched nearby lanes.
   */
K
kechxu 已提交
169
  void NearbyLanesByCurrentLanes(
170 171 172
      const Eigen::Vector2d& point, const double heading, const double radius,
      const std::vector<std::shared_ptr<const hdmap::LaneInfo>>& lanes,
      std::vector<std::shared_ptr<const hdmap::LaneInfo>>* nearby_lanes);
K
kechxu 已提交
173

174 175 176 177 178 179 180 181
  /**
   * @brief Get nearby lanes by a position.
   * @param point The position to search its nearby lanes.
   * @param radius The searching radius.
   * @return A vector of nearby lane IDs.
   */
  std::vector<std::string> NearbyLaneIds(const Eigen::Vector2d& point,
                                         const double radius);
182

183 184 185 186 187 188
  /**
   * @brief Check if a lane is a left neighbor of another lane.
   * @param left_lane The lane to check if it is a left neighbor.
   * @param curr_lane The current lane.
   * @return If left_lane is a left neighbor of curr_lane.
   */
189
  static bool IsLeftNeighborLane(
190 191
      std::shared_ptr<const hdmap::LaneInfo> left_lane,
      std::shared_ptr<const hdmap::LaneInfo> curr_lane);
K
kechxu 已提交
192

193 194 195 196 197 198
  /**
   * @brief Check if a lane is a left neighbor of one of some lanes.
   * @param left_lane The lane to check if it is a left neighbor.
   * @param lanes The current lanes.
   * @return If left_lane is a left neighbor of one of lanes.
   */
199
  static bool IsLeftNeighborLane(
200 201
      std::shared_ptr<const hdmap::LaneInfo> left_lane,
      const std::vector<std::shared_ptr<const hdmap::LaneInfo>>& lanes);
K
kechxu 已提交
202

203 204 205 206 207 208
  /**
   * @brief Check if a lane is a right neighbor of another lane.
   * @param right_lane The lane to check if it is a right neighbor.
   * @param curr_lane The current lane.
   * @return If right_lane is a right neighbor of curr_lane.
   */
209
  static bool IsRightNeighborLane(
210 211
      std::shared_ptr<const hdmap::LaneInfo> right_lane,
      std::shared_ptr<const hdmap::LaneInfo> curr_lane);
K
kechxu 已提交
212

213 214 215 216 217 218
  /**
   * @brief Check if a lane is a right neighbor of one of some lanes.
   * @param right_lane The lane to check if it is a right neighbor.
   * @param lanes The current lanes.
   * @return If right_lane is a right neighbor of one of lanes.
   */
219
  static bool IsRightNeighborLane(
220 221
      std::shared_ptr<const hdmap::LaneInfo> right_lane,
      const std::vector<std::shared_ptr<const hdmap::LaneInfo>>& lanes);
K
kechxu 已提交
222

223 224 225 226 227 228
  /**
   * @brief Check if a lane is a successor of another lane.
   * @param succ_lane The lane to check if it is a successor.
   * @param curr_lane The current lane.
   * @return If succ_lane is a successor of curr_lane.
   */
229 230
  static bool IsSuccessorLane(std::shared_ptr<const hdmap::LaneInfo> succ_lane,
                              std::shared_ptr<const hdmap::LaneInfo> curr_lane);
K
kechxu 已提交
231

232 233 234 235 236 237
  /**
   * @brief Check if a lane is a successor of one of some lanes.
   * @param succ_lane The lane to check if it is a successor.
   * @param lanes The current lanes.
   * @return If succ_lane is a successor of one of lanes.
   */
238
  static bool IsSuccessorLane(
239 240
      std::shared_ptr<const hdmap::LaneInfo> succ_lane,
      const std::vector<std::shared_ptr<const hdmap::LaneInfo>>& lanes);
K
kechxu 已提交
241

242 243 244 245 246 247
  /**
   * @brief Check if a lane is a predecessor of another lane.
   * @param pred_lane The lane to check if it is a predecessor.
   * @param curr_lane The current lane.
   * @return If pred_lane is a predecessor of curr_lane.
   */
248
  static bool IsPredecessorLane(
249 250
      std::shared_ptr<const hdmap::LaneInfo> pred_lane,
      std::shared_ptr<const hdmap::LaneInfo> curr_lane);
K
kechxu 已提交
251

252 253 254 255 256 257
  /**
   * @brief Check if a lane is a predecessor of one of some lanes.
   * @param pred_lane The lane to check if it is a predecessor.
   * @param lanes The current lanes.
   * @return If pred_lane is a predecessor of one of lanes.
   */
258
  static bool IsPredecessorLane(
259 260
      std::shared_ptr<const hdmap::LaneInfo> pred_lane,
      const std::vector<std::shared_ptr<const hdmap::LaneInfo>>& lanes);
K
kechxu 已提交
261

262 263 264 265 266 267
  /**
   * @brief Check if two lanes are identical.
   * @param other_lane The other lane.
   * @param curr_lane The current lane.
   * @return If other_lane is identical to curr_lane.
   */
268 269
  static bool IsIdenticalLane(std::shared_ptr<const hdmap::LaneInfo> other_lane,
                              std::shared_ptr<const hdmap::LaneInfo> curr_lane);
K
kechxu 已提交
270

271 272 273 274 275 276
  /**
   * @brief Check if a lane is identical to one of some lanes.
   * @param other_lane The other lane.
   * @param lanes The lanes.
   * @return If other_lane is identical to one of lanes.
   */
277
  static bool IsIdenticalLane(
278 279
      std::shared_ptr<const hdmap::LaneInfo> other_lane,
      const std::vector<std::shared_ptr<const hdmap::LaneInfo>>& lanes);
K
kechxu 已提交
280

281 282 283 284 285
  /**
   * @brief Get lane turn type.
   * @param lane_id The lane ID.
   * @return Integer corresponding to the lane turn type.
   */
286
  static int LaneTurnType(const std::string& lane_id);
K
kechxu 已提交
287

K
kechxu 已提交
288 289 290 291 292 293 294
 private:
  DECLARE_SINGLETON(PredictionMap);
};

}  // namespace prediction
}  // namespace apollo

295
#endif  // MODULES_PREDICTION_COMMON_PREDICTION_MAP_H_