20#include <unordered_set>
27template <
typename Po
ints>
28void VectorNet::GetOnePolyline(
29 const Points& points,
double* start_length,
30 const common::PointENU& center_point,
const double obstacle_phi,
32 std::vector<std::vector<double>>*
const one_polyline,
33 std::vector<double>*
const one_p_id) {
34 size_t size = points.size();
35 std::vector<double> s(size, 0);
37 for (
size_t i = 1; i < size; ++i) {
38 s[i] = std::hypot(points.at(i).x() - points.at(i - 1).x(),
39 points.at(i).y() - points.at(i - 1).y()) +
43 std::vector<double> x;
44 std::vector<double> y;
45 double cur_length = *start_length;
47 auto it_lower = std::lower_bound(s.begin(), s.end(), cur_length);
48 while (it_lower != s.end()) {
49 if (it_lower == s.begin()) {
50 x.push_back(points.at(0).x());
51 y.push_back(points.at(0).y());
53 const auto distance = std::distance(s.begin(), it_lower);
55 s[distance - 1], points.at(distance).x(),
56 s[distance], cur_length));
58 s[distance - 1], points.at(distance).y(),
59 s[distance], cur_length));
61 cur_length += FLAGS_point_distance;
62 it_lower = std::lower_bound(s.begin(), s.end(), cur_length);
64 size_t point_size = x.size();
66 *start_length = cur_length - s[size - 1];
67 if (point_size == 0)
return;
68 const double attr = attribute_map.at(attr_type);
69 const double bound = boundary_map.at(bound_type);
71 {x[0] - center_point.x(), y[0] - center_point.y()},
72 M_PI_2 - obstacle_phi);
74 for (
size_t i = 1; i < point_size; ++i) {
75 if (one_p_id->at(0) > last_point_after_rotate.x()) {
76 one_p_id->at(0) = last_point_after_rotate.x();
78 if (one_p_id->at(1) > last_point_after_rotate.y()) {
79 one_p_id->at(1) = last_point_after_rotate.y();
82 std::vector<double> one_vector;
85 one_vector.push_back(last_point_after_rotate.x());
86 one_vector.push_back(last_point_after_rotate.y());
89 {x[i] - center_point.x(), y[i] - center_point.y()},
90 M_PI_2 - obstacle_phi);
92 one_vector.push_back(point_after_rotate.x());
93 one_vector.push_back(point_after_rotate.y());
94 last_point_after_rotate = std::move(point_after_rotate);
97 one_vector.insert(one_vector.end(), {0.0, 0.0, attr, bound});
99 one_vector.push_back(count);
100 one_polyline->push_back(std::move(one_vector));
105 const double obstacle_phi,
108 CHECK_NOTNULL(feature_ptr);
110 GetRoads(center_point, obstacle_phi, feature_ptr, p_id_ptr);
111 GetLanes(center_point, obstacle_phi, feature_ptr, p_id_ptr);
112 GetJunctions(center_point, obstacle_phi, feature_ptr, p_id_ptr);
113 GetCrosswalks(center_point, obstacle_phi, feature_ptr, p_id_ptr);
118 const double obstacle_phi) {
122 FLAGS_prediction_target_file);
126 const double obstacle_y,
127 const double obstacle_phi,
128 const std::string file_name) {
133 query(center_point, obstacle_phi, &offline_feature, &p_id);
136 vector_net_pb_.mutable_car_position()->set_x(obstacle_x);
137 vector_net_pb_.mutable_car_position()->set_y(obstacle_y);
138 vector_net_pb_.mutable_car_position()->set_phi(obstacle_phi);
141 for (
const auto& polyline : offline_feature) {
142 auto* polyline_pb = vector_net_pb_.add_polyline();
143 polyline_pb->set_p_id_x(p_id[i][0]);
144 polyline_pb->set_p_id_y(p_id[i][1]);
146 for (
const auto& vector : polyline) {
147 auto* vector_pb = polyline_pb->add_vector();
148 for (
const auto& element : vector) {
149 vector_pb->add_element(element);
160 const double obstacle_phi,
163 std::vector<apollo::hdmap::RoadInfoConstPtr> roads;
165 FLAGS_road_distance, &roads);
167 for (
const auto& road : roads) {
168 for (
const auto& section : road->road().section()) {
169 for (
const auto& edge : section.boundary().outer_polygon().edge()) {
170 std::vector<std::vector<double>> one_polyline;
171 std::vector<double> one_p_id{std::numeric_limits<float>::max(),
172 std::numeric_limits<float>::max()};
173 double start_length = 0;
185 for (
const auto& segment : edge.curve().segment()) {
186 GetOnePolyline(segment.line_segment().point(), &start_length,
187 center_point, obstacle_phi,
ROAD, bound_type, count_,
188 &one_polyline, &one_p_id);
190 if (one_polyline.size() == 0)
continue;
192 feature_ptr->push_back(std::move(one_polyline));
193 p_id_ptr->push_back(std::move(one_p_id));
200void VectorNet::GetLaneQueue(
201 const std::vector<hdmap::LaneInfoConstPtr>& lanes,
202 std::vector<std::deque<hdmap::LaneInfoConstPtr>>*
const lane_deque_ptr) {
203 std::unordered_set<hdmap::LaneInfoConstPtr> lane_set(lanes.begin(),
206 while (!lane_set.empty()) {
207 std::deque<apollo::hdmap::LaneInfoConstPtr> one_lane_deque;
208 auto cur_lane = *lane_set.begin();
209 lane_set.erase(lane_set.begin());
210 one_lane_deque.push_back(cur_lane);
211 while (cur_lane->lane().successor_id_size() > 0) {
212 auto id = cur_lane->lane().successor_id(0);
214 if (lane_set.find(cur_lane) != lane_set.end()) {
215 lane_set.erase(cur_lane);
216 one_lane_deque.push_back(cur_lane);
222 cur_lane = one_lane_deque.front();
223 while (cur_lane->lane().predecessor_id_size() > 0) {
224 auto id = cur_lane->lane().predecessor_id(0);
226 if (lane_set.find(cur_lane) != lane_set.end()) {
227 lane_set.erase(cur_lane);
228 one_lane_deque.push_front(cur_lane);
234 lane_deque_ptr->push_back(one_lane_deque);
238void VectorNet::GetLanes(
const common::PointENU& center_point,
239 const double obstacle_phi,
242 std::vector<apollo::hdmap::LaneInfoConstPtr> lanes;
244 FLAGS_road_distance, &lanes);
246 std::vector<std::deque<apollo::hdmap::LaneInfoConstPtr>> lane_deque_vector;
247 GetLaneQueue(lanes, &lane_deque_vector);
249 for (
const auto& lane_deque : lane_deque_vector) {
251 std::vector<std::vector<double>> left_polyline;
252 std::vector<double> left_p_id{std::numeric_limits<float>::max(),
253 std::numeric_limits<float>::max()};
254 double start_length = 0;
255 for (
const auto& lane : lane_deque) {
256 std::cout << lane->lane().id().id() <<
" ";
258 for (
const auto& segment :
259 lane->lane().left_boundary().curve().segment()) {
261 lane->lane().left_boundary().boundary_type(0).types(0);
262 GetOnePolyline(segment.line_segment().point(), &start_length,
263 center_point, obstacle_phi, lane_attr_map.at(bound_type),
268 if (left_polyline.size() < 2)
continue;
269 feature_ptr->push_back(std::move(left_polyline));
270 p_id_ptr->push_back(std::move(left_p_id));
273 std::vector<std::vector<double>> right_polyline;
274 std::vector<double> right_p_id{std::numeric_limits<float>::max(),
275 std::numeric_limits<float>::max()};
278 for (
const auto& lane : lane_deque) {
280 for (
const auto& segment :
281 lane->lane().right_boundary().curve().segment()) {
283 lane->lane().left_boundary().boundary_type(0).types(0);
284 GetOnePolyline(segment.line_segment().point(), &start_length,
285 center_point, obstacle_phi, lane_attr_map.at(bound_type),
290 if (right_polyline.size() < 2)
continue;
291 feature_ptr->push_back(std::move(right_polyline));
292 p_id_ptr->push_back(std::move(right_p_id));
297void VectorNet::GetJunctions(
const common::PointENU& center_point,
298 const double obstacle_phi,
301 std::vector<apollo::hdmap::JunctionInfoConstPtr> junctions;
303 center_point, FLAGS_road_distance, &junctions);
304 for (
const auto& junction : junctions) {
305 std::vector<std::vector<double>> one_polyline;
306 std::vector<double> one_p_id{std::numeric_limits<float>::max(),
307 std::numeric_limits<float>::max()};
308 double start_length = 0;
309 GetOnePolyline(junction->junction().polygon().point(), &start_length,
311 &one_polyline, &one_p_id);
313 feature_ptr->push_back(std::move(one_polyline));
314 p_id_ptr->push_back(std::move(one_p_id));
319void VectorNet::GetCrosswalks(
const common::PointENU& center_point,
320 const double obstacle_phi,
323 std::vector<apollo::hdmap::CrosswalkInfoConstPtr> crosswalks;
325 center_point, FLAGS_road_distance, &crosswalks);
326 for (
const auto& crosswalk : crosswalks) {
327 std::vector<std::vector<double>> one_polyline;
328 std::vector<double> one_p_id{std::numeric_limits<float>::max(),
329 std::numeric_limits<float>::max()};
330 double start_length = 0;
331 GetOnePolyline(crosswalk->crosswalk().polygon().point(), &start_length,
333 &one_polyline, &one_p_id);
335 feature_ptr->push_back(std::move(one_polyline));
336 p_id_ptr->push_back(std::move(one_p_id));
static PointENU ToPointENU(const double x, const double y, const double z=0)
static const HDMap & BaseMap()
int GetCrosswalks(const apollo::common::PointENU &point, double distance, std::vector< CrosswalkInfoConstPtr > *crosswalks) const
get all crosswalks in certain range
int GetLanes(const apollo::common::PointENU &point, double distance, std::vector< LaneInfoConstPtr > *lanes) const
get all lanes in certain range
LaneInfoConstPtr GetLaneById(const Id &id) const
int GetRoads(const apollo::common::PointENU &point, double distance, std::vector< RoadInfoConstPtr > *roads) const
get all roads in certain range
int GetJunctions(const apollo::common::PointENU &point, double distance, std::vector< JunctionInfoConstPtr > *junctions) const
get all junctions in certain range
bool offline_query(const double obstacle_x, const double obstacle_y, const double obstacle_phi)
bool query(const common::PointENU ¢er_point, const double obstacle_phi, FeatureVector *const feature_ptr, PidVector *const p_id_ptr)
T lerp(const T &x0, const double t0, const T &x1, const double t1, const double t)
Linear interpolation between two points of type T.
Eigen::Vector2d RotateVector2d(const Eigen::Vector2d &v_in, const double theta)
bool SetProtoToASCIIFile(const google::protobuf::Message &message, int file_descriptor)
T bound(const T &x, const T &min, const T &max)
Get bound of value x
std::vector< std::vector< double > > PidVector
std::vector< std::vector< std::vector< double > > > FeatureVector