33 : adc_junction_info_ptr_(nullptr), s_dist_to_junction_(0.0) {}
36 const ::google::protobuf::Message& message) {
37 adc_lane_ids_.clear();
38 adc_lane_seq_.clear();
39 adc_target_lane_ids_.clear();
40 adc_target_lane_seq_.clear();
41 adc_junction_polygon_ = std::move(
Polygon2d());
43 adc_trajectory_.CopyFrom(
dynamic_cast<const ADCTrajectory&
>(message));
44 ADEBUG <<
"Received a planning message ["
45 << adc_trajectory_.ShortDebugString() <<
"].";
49 ADEBUG <<
"Generate an ADC lane id sequence [" << ToString(adc_lane_seq_)
53 SetTargetLaneSequence();
54 ADEBUG <<
"Generate an ADC target lane id sequence ["
55 << ToString(adc_target_lane_seq_) <<
"].";
59 if (adc_junction_polygon_.
points().size() < 3) {
62 bool in_polygon = adc_junction_polygon_.
IsPointIn({point.
x(), point.
y()});
64 bool on_virtual_lane =
false;
65 if (point.has_lane_id()) {
68 if (!on_virtual_lane) {
70 FLAGS_virtual_lane_radius);
72 return in_polygon && on_virtual_lane;
76 return adc_trajectory_.has_right_of_way_status() &&
81 const double distance) {
82 std::shared_ptr<const JunctionInfo> junction_info =
84 if (junction_info !=
nullptr && junction_info->junction().has_polygon()) {
85 std::vector<Vec2d> vertices;
86 for (
const auto& point : junction_info->junction().polygon().point()) {
87 vertices.emplace_back(point.x(), point.y());
89 if (vertices.size() >= 3) {
90 adc_junction_info_ptr_ = junction_info;
91 s_dist_to_junction_ = distance;
92 adc_junction_polygon_ = std::move(
Polygon2d{vertices});
97void ADCTrajectoryContainer::SetJunctionPolygon() {
98 std::shared_ptr<const JunctionInfo> junction_info(
nullptr);
100 double s_start = 0.0;
101 double s_at_junction = 0.0;
102 if (adc_trajectory_.trajectory_point_size() > 0) {
105 for (
int i = 0; i < adc_trajectory_.trajectory_point_size(); ++i) {
108 if (s > FLAGS_adc_trajectory_search_length) {
112 if (junction_info !=
nullptr) {
119 std::vector<std::shared_ptr<const JunctionInfo>> junctions =
121 if (!junctions.empty() && junctions.front() !=
nullptr) {
122 junction_info = junctions.front();
126 if (junction_info !=
nullptr && junction_info->junction().has_polygon()) {
127 std::vector<Vec2d> vertices;
128 for (
const auto& point : junction_info->junction().polygon().point()) {
129 vertices.emplace_back(point.x(), point.y());
131 if (vertices.size() >= 3) {
132 adc_junction_info_ptr_ = junction_info;
133 s_dist_to_junction_ = s_at_junction - s_start;
134 adc_junction_polygon_ = std::move(Polygon2d{vertices});
139std::shared_ptr<const apollo::hdmap::JunctionInfo>
141 return adc_junction_info_ptr_;
145 return s_dist_to_junction_;
149 return adc_trajectory_;
153 const std::string& lane_id)
const {
154 return adc_lane_ids_.find(lane_id) != adc_lane_ids_.end();
158 const std::string& lane_id)
const {
159 return adc_target_lane_ids_.find(lane_id) != adc_target_lane_ids_.end();
162void ADCTrajectoryContainer::SetLaneSequence() {
163 for (
const auto& lane : adc_trajectory_.lane_id()) {
164 if (!lane.id().empty()) {
165 if (adc_lane_seq_.empty() || lane.id() != adc_lane_seq_.back()) {
166 adc_lane_seq_.emplace_back(lane.id());
170 adc_lane_ids_.clear();
171 adc_lane_ids_.insert(adc_lane_seq_.begin(), adc_lane_seq_.end());
174void ADCTrajectoryContainer::SetTargetLaneSequence() {
175 for (
const auto& lane : adc_trajectory_.target_lane_id()) {
176 if (!lane.id().empty()) {
177 if (adc_target_lane_seq_.empty() ||
178 lane.id() != adc_target_lane_seq_.back()) {
179 adc_target_lane_seq_.emplace_back(lane.id());
183 adc_target_lane_ids_.clear();
184 adc_target_lane_ids_.insert(adc_target_lane_seq_.begin(),
185 adc_target_lane_seq_.end());
188std::string ADCTrajectoryContainer::ToString(
189 const std::unordered_set<std::string>& lane_ids) {
190 std::string str_lane_sequence =
"";
191 auto it = lane_ids.begin();
192 if (it != lane_ids.end()) {
193 str_lane_sequence += (*it);
196 for (; it != lane_ids.end(); ++it) {
197 str_lane_sequence += (
"->" + *it);
199 return str_lane_sequence;
202std::string ADCTrajectoryContainer::ToString(
203 const std::vector<std::string>& lane_ids) {
204 std::string str_lane_sequence =
"";
205 auto it = lane_ids.begin();
206 if (it != lane_ids.end()) {
207 str_lane_sequence += (*it);
210 for (; it != lane_ids.end(); ++it) {
211 str_lane_sequence += (
"->" + *it);
213 return str_lane_sequence;
218 for (
const auto& lane_segment : lane_sequence.
lane_segment()) {
219 std::string lane_id = lane_segment.lane_id();
220 if (adc_lane_ids_.find(lane_id) != adc_lane_ids_.end()) {
228 for (
auto it = adc_lane_seq_.begin(); it != adc_lane_seq_.end(); ++it) {
230 if (lane_info !=
nullptr && lane_info->IsOnLane(position)) {
231 adc_lane_ids_.clear();
232 adc_lane_ids_.insert(it, adc_lane_seq_.end());
236 ADEBUG <<
"Generate an ADC lane ids [" << ToString(adc_lane_ids_) <<
"].";
241 return adc_lane_seq_;
244const std::vector<std::string>&
246 return adc_target_lane_seq_;
The class of polygon in 2-D.
bool IsPointIn(const Vec2d &point) const
Check if a point is within the polygon.
const std::vector< Vec2d > & points() const
Get the vertices of the polygon.
Implements a class of 2-dimensional vectors.
bool IsLaneIdInReferenceLine(const std::string &lane_id) const
Determine if a lane ID is in the reference line
const std::vector< std::string > & GetADCTargetLaneIDSequence() const
void SetJunction(const std::string &junction_id, const double distance)
bool IsPointInJunction(const common::PathPoint &point) const
Check if a point is in the first junction of the adc trajectory
const planning::ADCTrajectory & adc_trajectory() const
Get ADC planning trajectory
bool IsLaneIdInTargetReferenceLine(const std::string &lane_id) const
void Insert(const ::google::protobuf::Message &message) override
Insert a data message into the container
bool IsProtected() const
Get the right-of-way status of ADC
bool HasOverlap(const LaneSequence &lane_sequence) const
Has overlap with ADC trajectory
double ADCDistanceToJunction() const
Compute ADC's distance to junction
ADCTrajectoryContainer()
Constructor
void SetPosition(const common::math::Vec2d &position)
Set ADC position
std::shared_ptr< const hdmap::JunctionInfo > ADCJunction() const
Get ADC junction
const std::vector< std::string > & GetADCLaneIDSequence() const
static std::shared_ptr< const hdmap::JunctionInfo > JunctionById(const std::string &id)
Get a shared pointer to a junction by junction ID.
static bool OnVirtualLane(const Eigen::Vector2d &position, const double radius)
Determine if a point is on a virtual lane.
static bool IsVirtualLane(const std::string &lane_id)
Determine if a lane is a virtual lane.
static std::vector< std::shared_ptr< const apollo::hdmap::JunctionInfo > > GetJunctions(const Eigen::Vector2d &point, const double radius)
Get a list of junctions given a point and a search radius
static std::shared_ptr< const hdmap::LaneInfo > LaneById(const std::string &id)
Get a shared pointer to a lane by lane ID.
optional PathPoint path_point
repeated apollo::common::TrajectoryPoint trajectory_point
optional RightOfWayStatus right_of_way_status
repeated LaneSegment lane_segment