prediction_map.h 10.4 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 44 45
      std::shared_ptr<const apollo::hdmap::LaneInfo> lane_info,
      const double s);

46 47 48 49 50 51
  /**
   * @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.
   */
52
  static double HeadingOnLane(
53 54 55
      std::shared_ptr<const apollo::hdmap::LaneInfo> lane_info,
      const double s);

56 57 58 59 60 61
  /**
   * @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.
   */
62
  static double LaneTotalWidth(
63
      std::shared_ptr<const apollo::hdmap::LaneInfo> lane_info,
64 65
      const double s);

66 67 68 69 70
  /**
   * @brief Get a shared pointer to a lane by lane ID.
   * @param id The ID of the target lane ID.
   * @return A shared pointer to the lane with the input lane ID.
   */
71 72 73
  std::shared_ptr<const apollo::hdmap::LaneInfo> LaneById(
      const apollo::hdmap::Id& id);

74 75 76 77 78
  /**
   * @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.
   */
79 80 81
  std::shared_ptr<const apollo::hdmap::LaneInfo> LaneById(
      const std::string& str_id);

82 83 84 85 86 87 88
  /**
   * @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.
   */
89
  static void GetProjection(
90
      const Eigen::Vector2d& position,
91
      std::shared_ptr<const apollo::hdmap::LaneInfo> lane_info,
92 93 94
      double* s,
      double* l);

95 96 97 98 99 100 101
  /**
   * @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.
   */
102
  static bool ProjectionFromLane(
103
      std::shared_ptr<const apollo::hdmap::LaneInfo> lane_info,
104 105
      double s, apollo::hdmap::MapPathPoint* path_point);

106 107 108 109 110 111 112 113
  /**
   * @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.
   * @param lanes The searched lanes. 
   */
114 115 116 117 118
  void OnLane(
      const std::vector<std::shared_ptr<const apollo::hdmap::LaneInfo>>&
          prev_lanes,
      const Eigen::Vector2d& point, const double heading,
      const double radius,
119 120 121 122 123 124 125 126 127
      const bool on_lane,
      std::vector<std::shared_ptr<const apollo::hdmap::LaneInfo>>* lanes);

  /**
   * @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.
   */
128
  static double PathHeading(
129
      std::shared_ptr<const apollo::hdmap::LaneInfo> lane_info,
130 131
      const apollo::common::PointENU& point);

132 133 134 135 136 137 138 139 140
  /**
   * @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.
   * @return If the process is successful. 0: success, -1: failure.
   */
141 142 143 144
  int SmoothPointFromLane(
      const apollo::hdmap::Id& id, const double s,
      const double l, Eigen::Vector2d* point,
      double* heading);
K
kechxu 已提交
145

146 147 148 149 150 151 152 153
  /**
   * @brief Get nearby lanes by a position and current lanes.
   * @param point The position to search its nearby lanes.
   * @param heading The heading.
   * @param radius The searching radius.
   * @param lanes The current lanes.
   * @param nearby_lanes The searched nearby lanes.
   */
K
kechxu 已提交
154 155
  void NearbyLanesByCurrentLanes(
      const Eigen::Vector2d& point,
156 157
      double heading,
      double radius,
158 159 160
      const std::vector<std::shared_ptr<const apollo::hdmap::LaneInfo>>& lanes,
      std::vector<std::shared_ptr<const apollo::hdmap::LaneInfo>>*
          nearby_lanes);
K
kechxu 已提交
161

162 163 164 165 166 167
  /**
   * @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.
   */
168
  static bool IsLeftNeighborLane(
169 170
      std::shared_ptr<const apollo::hdmap::LaneInfo> left_lane,
      std::shared_ptr<const apollo::hdmap::LaneInfo> curr_lane);
K
kechxu 已提交
171

172 173 174 175 176 177
  /**
   * @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.
   */
178
  static bool IsLeftNeighborLane(
179 180
      std::shared_ptr<const apollo::hdmap::LaneInfo> left_lane,
      const std::vector<std::shared_ptr<const apollo::hdmap::LaneInfo>>& lanes);
K
kechxu 已提交
181

182 183 184 185 186 187
  /**
   * @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.
   */
188
  static bool IsRightNeighborLane(
189 190
      std::shared_ptr<const apollo::hdmap::LaneInfo> right_lane,
      std::shared_ptr<const apollo::hdmap::LaneInfo> curr_lane);
K
kechxu 已提交
191

192 193 194 195 196 197
  /**
   * @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.
   */
198
  static bool IsRightNeighborLane(
199 200
      std::shared_ptr<const apollo::hdmap::LaneInfo> right_lane,
      const std::vector<std::shared_ptr<const apollo::hdmap::LaneInfo>>& lanes);
K
kechxu 已提交
201

202 203 204 205 206 207
  /**
   * @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.
   */
208
  static bool IsSuccessorLane(
209 210
      std::shared_ptr<const apollo::hdmap::LaneInfo> succ_lane,
      std::shared_ptr<const apollo::hdmap::LaneInfo> curr_lane);
K
kechxu 已提交
211

212 213 214 215 216 217
  /**
   * @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.
   */
218
  static bool IsSuccessorLane(
219 220
      std::shared_ptr<const apollo::hdmap::LaneInfo> succ_lane,
      const std::vector<std::shared_ptr<const apollo::hdmap::LaneInfo>>& lanes);
K
kechxu 已提交
221

222 223 224 225 226 227
  /**
   * @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.
   */
228
  static bool IsPredecessorLane(
229 230
      std::shared_ptr<const apollo::hdmap::LaneInfo> pred_lane,
      std::shared_ptr<const apollo::hdmap::LaneInfo> curr_lane);
K
kechxu 已提交
231

232 233 234 235 236 237
  /**
   * @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.
   */
238
  static bool IsPredecessorLane(
239 240
      std::shared_ptr<const apollo::hdmap::LaneInfo> pred_lane,
      const std::vector<std::shared_ptr<const apollo::hdmap::LaneInfo>>& lanes);
K
kechxu 已提交
241

242 243 244 245 246 247
  /**
   * @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.
   */
248
  static bool IsIdenticalLane(
249 250
      std::shared_ptr<const apollo::hdmap::LaneInfo> other_lane,
      std::shared_ptr<const apollo::hdmap::LaneInfo> curr_lane);
K
kechxu 已提交
251

252 253 254 255 256 257
  /**
   * @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.
   */
258
  static bool IsIdenticalLane(
259 260
      std::shared_ptr<const apollo::hdmap::LaneInfo> other_lane,
      const std::vector<std::shared_ptr<const apollo::hdmap::LaneInfo>>& lanes);
K
kechxu 已提交
261

262 263 264 265 266
  /**
   * @brief Get lane turn type.
   * @param id The lane ID.
   * @return Integer corresponding to the lane turn type.
   */
K
kechxu 已提交
267 268
  int LaneTurnType(const apollo::hdmap::Id& id);

269 270 271 272 273
  /**
   * @brief Get lane turn type.
   * @param lane_id The lane ID.
   * @return Integer corresponding to the lane turn type.
   */
K
kechxu 已提交
274 275
  int LaneTurnType(const std::string& lane_id);

276 277 278 279 280
  /**
   * @brief Get the ID in the form of string.
   * @param info Map information.
   * @return String of ID.
   */
281
  template <class MapInfo>
282
  static std::string id_string(std::shared_ptr<const MapInfo> info) {
K
kechxu 已提交
283 284
    return info->id().id();
  }
K
kechxu 已提交
285

K
kechxu 已提交
286
 private:
287
  const apollo::hdmap::HDMap& hdmap_;
K
kechxu 已提交
288 289 290 291 292 293
  DECLARE_SINGLETON(PredictionMap);
};

}  // namespace prediction
}  // namespace apollo

294
#endif  // MODULES_PREDICTION_COMMON_PREDICTION_MAP_H_