17#include "gflags/gflags.h"
26#include "modules/common_msgs/map_msgs/map_geometry.pb.h"
32DEFINE_bool(dump_lane_width,
false,
"dump all lane width info");
50#define QUIT_IF(CONDITION, RET, LEVEL, MSG, ...) \
53 RAW_LOG(LEVEL, MSG, ##__VA_ARGS__); \
60 const ::google::protobuf::RepeatedPtrField<apollo::hdmap::Id> &ids) {
61 for (
int i = 0; i < ids.size(); ++i) {
62 os << ids.Get(i).id();
63 if (i != ids.size() - 1) {
70#define GET_ELEMENT_BY_ID(TYPE) \
71 const TYPE##InfoConstPtr Get##TYPE(const std::string &id) { \
72 auto ret = HDMapUtil::BaseMap().Get##TYPE##ById(MakeMapId(id)); \
73 AERROR_IF(ret == nullptr) \
74 << "failed to find " << #TYPE << " with id: " << id; \
82 AERROR_IF(ret ==
nullptr) <<
"failed to find overlap[" << overlap_id <<
"]";
97 std::cout << t.DebugString();
101 double *l,
double *heading)
const {
102 QUIT_IF(lane_id ==
nullptr, -1,
ERROR,
"arg lane id is null");
107 QUIT_IF(ret != 0, -4,
ERROR,
"get_nearest_lane failed with ret[%d]", ret);
109 *lane_id = lane->id().id();
110 *heading = lane->Heading(*s);
115 PointENU *point,
double *heading)
const {
116 QUIT_IF(point ==
nullptr, -1,
ERROR,
"arg point is null");
117 QUIT_IF(heading ==
nullptr, -2,
ERROR,
"arg heading is null");
118 QUIT_IF(lane_ptr ==
nullptr, -3,
ERROR,
"the provided lane_ptr is null");
119 *point = lane_ptr->GetSmoothPoint(s);
120 *heading = lane_ptr->Heading(s);
123 point->set_x(point->
x() + normal_vec.x());
124 point->set_y(point->
y() + normal_vec.y());
130 const std::string &lane_id,
double *s,
double *l,
131 double *heading)
const {
134 QUIT_IF(lane ==
nullptr, -2,
ERROR,
"GetSignal_by_id[%s] failed",
136 bool ret = lane->GetProjection(vec2d, s, l);
137 QUIT_IF(!ret, -3,
ERROR,
"lane[%s] get projection for point[%f, %f] failed",
138 lane_id.c_str(), vec2d.
x(), vec2d.
y());
139 *heading = lane->Heading(*s);
144 const auto *overlap_ptr =
GetOverlap(FLAGS_overlap);
145 if (overlap_ptr ==
nullptr) {
146 AERROR <<
"overlap_ptr is nullptr.";
149 ADEBUG <<
"overlap[" << overlap_ptr->id().id() <<
"] info["
150 << overlap_ptr->overlap().DebugString() <<
"]" << std::endl;
152 for (
const auto &object_info : overlap_ptr->overlap().object()) {
153 if (object_info.has_lane_overlap_info()) {
154 std::cout <<
"Lane : " << object_info.id().id() << std::endl;
155 PrintLane(GetLane(object_info.id().id()));
156 }
else if (object_info.has_signal_overlap_info()) {
157 std::cout <<
"Signal: " << object_info.id().id() << std::endl;
158 Print(GetSignal(object_info.id().id())->signal());
159 }
else if (object_info.has_stop_sign_overlap_info()) {
160 std::cout <<
"StopSign: " << object_info.id().id() << std::endl;
161 Print(GetStopSign(object_info.id().id())->stop_sign());
162 }
else if (object_info.has_crosswalk_overlap_info()) {
163 std::cout <<
"Crosswalk: " << object_info.id().id() << std::endl;
164 Print(GetCrosswalk(object_info.id().id())->crosswalk());
165 }
else if (object_info.has_junction_overlap_info()) {
166 std::cout <<
"Junction: " << object_info.id().id() << std::endl;
167 Print(GetJunction(object_info.id().id())->junction());
168 }
else if (object_info.has_yield_sign_overlap_info()) {
169 std::cout <<
"YieldSign: " << object_info.id().id() << std::endl;
170 Print(GetYieldSign(object_info.id().id())->yield_sign());
171 }
else if (object_info.has_clear_area_overlap_info()) {
172 std::cout <<
"ClearArea: " << object_info.id().id() << std::endl;
173 Print(GetClearArea(object_info.id().id())->clear_area());
174 }
else if (object_info.has_speed_bump_overlap_info()) {
175 std::cout <<
"SpeedBump: " << object_info.id().id() << std::endl;
176 Print(GetSpeedBump(object_info.id().id())->speed_bump());
177 }
else if (object_info.has_parking_space_overlap_info()) {
178 std::cout <<
"ParkingSpace: " << object_info.id().id() << std::endl;
180 std::cout <<
"Unknown overlap type: " << object_info.DebugString();
187 const auto &lane = lane_ptr->lane();
189 double start_heading = 0.0;
190 SLToPoint(lane_ptr, 0, 0, &start_point, &start_heading);
193 double end_heading = 0.0;
194 SLToPoint(lane_ptr, lane_ptr->total_length(), 0, &end_point, &end_heading);
196 double left_width = 0.0;
197 double right_width = 0.0;
198 lane_ptr->GetWidth(FLAGS_s, &left_width, &right_width);
200 std::cout <<
"lane[" << FLAGS_lane << std::fixed <<
"] length["
201 << lane_ptr->total_length() <<
"] type["
202 << Lane_LaneType_Name(lane.type()) <<
"] turn["
203 << Lane_LaneTurn_Name(lane.turn()) <<
"] speed_limit["
204 << lane.speed_limit() <<
"] predecessor[" << lane.predecessor_id()
205 <<
"] successor[" << lane.successor_id() <<
"] left_forward["
206 << lane.left_neighbor_forward_lane_id() <<
"] right_forward["
207 << lane.right_neighbor_forward_lane_id() <<
"] left_reverse["
208 << lane.left_neighbor_reverse_lane_id() <<
"] right_reverse["
209 << lane.right_neighbor_reverse_lane_id() <<
"], "
210 <<
"Left Boundary: [ virtual?:" << std::boolalpha
211 << lane.left_boundary().virtual_() <<
", Type: [";
212 for (
const auto &boundary_type : lane.left_boundary().boundary_type()) {
213 std::cout <<
"s: " << boundary_type.s() <<
"->";
214 for (
const auto t : boundary_type.types()) {
215 std::cout << LaneBoundaryType::Type_Name(
221 std::cout <<
"]; Right Boundary: [ virtual?:" << std::boolalpha
222 << lane.right_boundary().virtual_() <<
", Type: ";
223 for (
const auto &boundary_type : lane.left_boundary().boundary_type()) {
224 std::cout <<
"s: " << boundary_type.s() <<
"->";
225 for (
const auto t : boundary_type.types()) {
226 std::cout << LaneBoundaryType::Type_Name(
231 std::cout <<
"] overlap[" << lane.overlap_id() <<
"];"
232 <<
" start point(x,y,heading):" << start_point.
x() <<
","
233 << start_point.
y() <<
"," << start_heading
234 <<
" end point(x,y,heading):" << end_point.
x() <<
","
235 << end_point.
y() <<
"," << end_heading
236 <<
" left_width:" << left_width <<
" right_width:" << right_width
238 std::cout.unsetf(std::ios_base::fixed);
240 if (FLAGS_dump_lane_width) {
241 const auto sample_left_widthes = lane_ptr->sampled_left_width();
242 std::cout <<
"left width num: " << sample_left_widthes.size()
245 for (
auto w : sample_left_widthes) {
246 std::cout <<
" " << w.second;
247 if (++num % 10 == 0) {
248 std::cout << std::endl;
251 std::cout << std::endl;
253 const auto sample_right_widthes = lane_ptr->sampled_right_width();
254 std::cout <<
"right width num: " << sample_right_widthes.size()
256 for (
auto w : sample_right_widthes) {
257 std::cout <<
" " << w.second;
258 if (++num % 10 == 0) {
259 std::cout << std::endl;
262 std::cout << std::endl;
270int main(
int argc,
char *argv[]) {
271 google::InitGoogleLogging(argv[0]);
272 google::ParseCommandLineFlags(&argc, &argv,
true);
274 bool valid_arg =
false;
278 if (FLAGS_xy_to_sl) {
288 double heading = 0.0;
289 map_util.
PointToSL(point, &lane_id, &s, &l, &heading);
290 printf(
"lane_id[%s], s[%f], l[%f], heading[%f]\n", lane_id.c_str(), s, l,
295 if (FLAGS_sl_to_xy) {
297 double heading = 0.0;
298 map_util.
SLToPoint(map_util.GetLane(FLAGS_lane), FLAGS_s, FLAGS_l, &point,
300 printf(
"x[%f] y[%f], heading[%f]\n", point.
x(), point.
y(), heading);
304 if (FLAGS_xy_to_lane) {
307 double heading = 0.0;
308 int ret = map_util.
LaneProjection({FLAGS_x, FLAGS_y}, FLAGS_lane, &s, &l,
311 printf(
"lane_projection for x[%f], y[%f], lane_id[%s] failed\n", FLAGS_x,
312 FLAGS_y, FLAGS_lane.c_str());
315 printf(
"lane[%s] s[%f], l[%f], heading[%f]\n", FLAGS_lane.c_str(), s, l,
320 if (FLAGS_lane_to_lane) {
322 double src_heading = 0.0;
323 map_util.
SLToPoint(map_util.GetLane(FLAGS_from_lane), FLAGS_s, 0.0, &point,
325 double target_s = 0.0;
326 double target_l = 0.0;
327 double target_heading = 0.0;
329 &target_s, &target_l, &target_heading);
331 printf(
"lane_projection for lane[%s], s[%f] to lane_id[%s] failed\n",
332 FLAGS_from_lane.c_str(), FLAGS_s, FLAGS_to_lane.c_str());
335 printf(
"lane[%s] s[%f], l[%f], heading[%f]\n", FLAGS_to_lane.c_str(),
336 target_s, target_l, target_heading);
341 if (!FLAGS_lane.empty()) {
342 const auto lane_ptr = map_util.GetLane(FLAGS_lane);
344 std::cout <<
"Could not find lane " << FLAGS_lane <<
" on map "
351 if (!FLAGS_overlap.empty()) {
355 if (!FLAGS_signal_info.empty()) {
356 std::cout <<
"Signal: " << FLAGS_signal_info << std::endl;
357 map_util.
Print(map_util.GetSignal(FLAGS_signal_info)->signal());
360 if (!FLAGS_dump_txt_map.empty()) {
366 if (!FLAGS_dump_bin_map.empty()) {
374 std::cout <<
"usage: --map_dir map/file/directory/" << std::endl;
375 std::cout <<
"usage: --base_map_filename map_file_name" << std::endl;
376 std::cout <<
"usage: --dump_txt_map text_map_file" << std::endl;
377 std::cout <<
"usage: --dump_bin_map bin_map_file" << std::endl;
378 std::cout <<
"usage: --xy_to_sl --x x --y y" << std::endl;
379 std::cout <<
"usage: --sl_to_xy --lane lane_id --s s --l l" << std::endl;
380 std::cout <<
"usage: --xy_to_lane --x --y --lane" << std::endl;
382 <<
"usage: --lane_to_lane --from_lane lane_id --s s --to_lane lane_id"
384 std::cout <<
"usage: --lane lane_id" << std::endl;
385 std::cout <<
"usage: --signal_info signal_id" << std::endl;
386 std::cout <<
"usage: --overlap overlap_id" << std::endl;
Implements a class of 2-dimensional vectors.
static Vec2d CreateUnitVec2d(const double angle)
Creates a unit-vector with a given angle to the positive x semi-axis
double y() const
Getter for y component
double x() const
Getter for x component
static const HDMap & BaseMap()
LaneInfoConstPtr GetLaneById(const Id &id) const
int GetNearestLane(const apollo::common::PointENU &point, LaneInfoConstPtr *nearest_lane, double *nearest_s, double *nearest_l) const
get nearest lane from target point,
OverlapInfoConstPtr GetOverlapById(const Id &id) const
GET_ELEMENT_BY_ID(StopSign)
int SLToPoint(LaneInfoConstPtr lane_ptr, const double s, const double l, PointENU *point, double *heading) const
GET_ELEMENT_BY_ID(Signal)
GET_ELEMENT_BY_ID(YieldSign)
const OverlapInfo * GetOverlap(const std::string &overlap_id) const
void PrintLane(LaneInfoConstPtr lane_ptr)
GET_ELEMENT_BY_ID(SpeedBump)
GET_ELEMENT_BY_ID(ClearArea)
GET_ELEMENT_BY_ID(Junction)
void PrintLane(const std::string &lane_id)
GET_ELEMENT_BY_ID(Crosswalk)
void PrintOverlap(const std::string &overlap_id)
int LaneProjection(const apollo::common::math::Vec2d &vec2d, const std::string &lane_id, double *s, double *l, double *heading) const
int PointToSL(const PointENU &point, std::string *lane_id, double *s, double *l, double *heading) const
int main(int argc, char *argv[])
DEFINE_double(x, 0.0, "x")
DEFINE_string(dump_txt_map, "", "text file name for dumping map")
#define QUIT_IF(CONDITION, RET, LEVEL, MSG,...)
DEFINE_bool(xy_to_sl, false, "calculate xy to sl")
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
bool SetProtoToBinaryFile(const google::protobuf::Message &message, const std::string &file_name)
Sets the content of the file specified by the file_name to be the binary representation of the input ...
bool SetProtoToASCIIFile(const google::protobuf::Message &message, int file_descriptor)
apollo::hdmap::Id MakeMapId(const std::string &id)
create a Map ID given a string.
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
std::string BaseMapFile()
get base map file path from flags.
std::ostream & operator<<(std::ostream &os, const ::google::protobuf::RepeatedPtrField< apollo::hdmap::Id > &ids)
Some string util functions.