Apollo 10.0
自动驾驶开放平台
map_xysl.cc 文件参考
#include "gflags/gflags.h"
#include "cyber/common/file.h"
#include "cyber/common/log.h"
#include "modules/common/configs/config_gflags.h"
#include "modules/common/util/string_util.h"
#include "modules/map/hdmap/hdmap_common.h"
#include "modules/map/hdmap/hdmap_impl.h"
#include "modules/map/hdmap/hdmap_util.h"
#include "modules/common_msgs/map_msgs/map_geometry.pb.h"
map_xysl.cc 的引用(Include)关系图:

浏览源代码.

class  apollo::hdmap::MapUtil
 

命名空间

namespace  apollo
 class register implement
 
namespace  apollo::hdmap
 apollo::hdmap
 

宏定义

#define QUIT_IF(CONDITION, RET, LEVEL, MSG, ...)
 
#define GET_ELEMENT_BY_ID(TYPE)
 

函数

 DEFINE_bool (xy_to_sl, false, "calculate xy to sl")
 
 DEFINE_bool (sl_to_xy, false, "calculate sl to xy")
 
 DEFINE_bool (xy_to_lane, false, "calculate xy to lane")
 
 DEFINE_bool (lane_to_lane, false, "calculate lane to lane")
 
 DEFINE_bool (dump_lane_width, false, "dump all lane width info")
 
 DEFINE_string (dump_txt_map, "", "text file name for dumping map")
 
 DEFINE_string (dump_bin_map, "", "binary file name for dumping map")
 
 DEFINE_string (overlap, "", "get overlap information")
 
 DEFINE_string (signal_info, "", "print signal info")
 
 DEFINE_double (x, 0.0, "x")
 
 DEFINE_double (y, 0.0, "y")
 
 DEFINE_string (lane, "", "lane_id")
 
 DEFINE_string (from_lane, "", "from_lane")
 
 DEFINE_string (to_lane, "", "to_lane")
 
 DEFINE_double (s, 0.0, "s")
 
 DEFINE_double (l, 0.0, "l")
 
std::ostream & apollo::hdmap::operator<< (std::ostream &os, const ::google::protobuf::RepeatedPtrField< apollo::hdmap::Id > &ids)
 
int main (int argc, char *argv[])
 

宏定义说明

◆ GET_ELEMENT_BY_ID

#define GET_ELEMENT_BY_ID (   TYPE)
值:
const TYPE##InfoConstPtr Get##TYPE(const std::string &id) { \
auto ret = HDMapUtil::BaseMap().Get##TYPE##ById(MakeMapId(id)); \
AERROR_IF(ret == nullptr) \
<< "failed to find " << #TYPE << " with id: " << id; \
return ret; \
}

在文件 map_xysl.cc70 行定义.

71 { \
72 auto ret = HDMapUtil::BaseMap().Get##TYPE##ById(MakeMapId(id)); \
73 AERROR_IF(ret == nullptr) \
74 << "failed to find " << #TYPE << " with id: " << id; \
75 return ret; \
76 }
apollo::hdmap::Id MakeMapId(const std::string &id)
create a Map ID given a string.
Definition hdmap_util.h:85

◆ QUIT_IF

#define QUIT_IF (   CONDITION,
  RET,
  LEVEL,
  MSG,
  ... 
)
值:
do { \
if (CONDITION) { \
RAW_LOG(LEVEL, MSG, ##__VA_ARGS__); \
return RET; \
} \
} while (0);

在文件 map_xysl.cc50 行定义.

51 { \
52 if (CONDITION) { \
53 RAW_LOG(LEVEL, MSG, ##__VA_ARGS__); \
54 return RET; \
55 } \
56 } while (0);

函数说明

◆ DEFINE_bool() [1/5]

DEFINE_bool ( dump_lane_width  ,
false  ,
"dump all lane width info"   
)

◆ DEFINE_bool() [2/5]

DEFINE_bool ( lane_to_lane  ,
false  ,
"calculate lane to lane"   
)

◆ DEFINE_bool() [3/5]

DEFINE_bool ( sl_to_xy  ,
false  ,
"calculate sl to xy"   
)

◆ DEFINE_bool() [4/5]

DEFINE_bool ( xy_to_lane  ,
false  ,
"calculate xy to lane"   
)

◆ DEFINE_bool() [5/5]

DEFINE_bool ( xy_to_sl  ,
false  ,
"calculate xy to sl"   
)

◆ DEFINE_double() [1/4]

DEFINE_double ( ,
0.  0,
"l"   
)

◆ DEFINE_double() [2/4]

DEFINE_double ( ,
0.  0,
"s"   
)

◆ DEFINE_double() [3/4]

DEFINE_double ( ,
0.  0,
"x"   
)

◆ DEFINE_double() [4/4]

DEFINE_double ( ,
0.  0,
"y"   
)

◆ DEFINE_string() [1/7]

DEFINE_string ( dump_bin_map  ,
""  ,
"binary file name for dumping map"   
)

◆ DEFINE_string() [2/7]

DEFINE_string ( dump_txt_map  ,
""  ,
"text file name for dumping map"   
)

◆ DEFINE_string() [3/7]

DEFINE_string ( from_lane  ,
""  ,
"from_lane"   
)

◆ DEFINE_string() [4/7]

DEFINE_string ( lane  ,
""  ,
"lane_id"   
)

◆ DEFINE_string() [5/7]

DEFINE_string ( overlap  ,
""  ,
"get overlap information"   
)

◆ DEFINE_string() [6/7]

DEFINE_string ( signal_info  ,
""  ,
"print signal info"   
)

◆ DEFINE_string() [7/7]

DEFINE_string ( to_lane  ,
""  ,
"to_lane"   
)

◆ main()

int main ( int  argc,
char *  argv[] 
)

在文件 map_xysl.cc270 行定义.

270 {
271 google::InitGoogleLogging(argv[0]);
272 google::ParseCommandLineFlags(&argc, &argv, true);
273 const std::string map_file = apollo::hdmap::BaseMapFile();
274 bool valid_arg = false;
275
276 apollo::hdmap::MapUtil map_util;
277
278 if (FLAGS_xy_to_sl) {
279 double x = FLAGS_x;
280 double y = FLAGS_y;
281 PointENU point;
282 point.set_x(x);
283 point.set_y(y);
284 point.set_z(0);
285 std::string lane_id;
286 double s = 0.0;
287 double l = 0.0;
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,
291 heading);
292 map_util.PrintLane(lane_id);
293 valid_arg = true;
294 }
295 if (FLAGS_sl_to_xy) {
296 PointENU point;
297 double heading = 0.0;
298 map_util.SLToPoint(map_util.GetLane(FLAGS_lane), FLAGS_s, FLAGS_l, &point,
299 &heading);
300 printf("x[%f] y[%f], heading[%f]\n", point.x(), point.y(), heading);
301 map_util.PrintLane(FLAGS_lane);
302 valid_arg = true;
303 }
304 if (FLAGS_xy_to_lane) {
305 double s = 0.0;
306 double l = 0.0;
307 double heading = 0.0;
308 int ret = map_util.LaneProjection({FLAGS_x, FLAGS_y}, FLAGS_lane, &s, &l,
309 &heading);
310 if (ret != 0) {
311 printf("lane_projection for x[%f], y[%f], lane_id[%s] failed\n", FLAGS_x,
312 FLAGS_y, FLAGS_lane.c_str());
313 return -1;
314 }
315 printf("lane[%s] s[%f], l[%f], heading[%f]\n", FLAGS_lane.c_str(), s, l,
316 heading);
317 map_util.PrintLane(FLAGS_lane);
318 valid_arg = true;
319 }
320 if (FLAGS_lane_to_lane) {
321 PointENU point;
322 double src_heading = 0.0;
323 map_util.SLToPoint(map_util.GetLane(FLAGS_from_lane), FLAGS_s, 0.0, &point,
324 &src_heading);
325 double target_s = 0.0;
326 double target_l = 0.0;
327 double target_heading = 0.0;
328 int ret = map_util.LaneProjection({point.x(), point.y()}, FLAGS_to_lane,
329 &target_s, &target_l, &target_heading);
330 if (ret != 0) {
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());
333 return -1;
334 }
335 printf("lane[%s] s[%f], l[%f], heading[%f]\n", FLAGS_to_lane.c_str(),
336 target_s, target_l, target_heading);
337 map_util.PrintLane(FLAGS_from_lane);
338 map_util.PrintLane(FLAGS_to_lane);
339 valid_arg = true;
340 }
341 if (!FLAGS_lane.empty()) {
342 const auto lane_ptr = map_util.GetLane(FLAGS_lane);
343 if (!lane_ptr) {
344 std::cout << "Could not find lane " << FLAGS_lane << " on map "
345 << map_file;
346 return 0;
347 }
348 map_util.PrintLane(lane_ptr);
349 valid_arg = true;
350 }
351 if (!FLAGS_overlap.empty()) {
352 map_util.PrintOverlap(FLAGS_overlap);
353 valid_arg = true;
354 }
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());
358 valid_arg = true;
359 }
360 if (!FLAGS_dump_txt_map.empty()) {
363 ACHECK(apollo::cyber::common::SetProtoToASCIIFile(map, FLAGS_dump_txt_map));
364 valid_arg = true;
365 }
366 if (!FLAGS_dump_bin_map.empty()) {
369 ACHECK(
370 apollo::cyber::common::SetProtoToBinaryFile(map, FLAGS_dump_bin_map));
371 valid_arg = true;
372 }
373 if (!valid_arg) {
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;
381 std::cout
382 << "usage: --lane_to_lane --from_lane lane_id --s s --to_lane lane_id"
383 << std::endl;
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;
387 }
388 return 0;
389}
int SLToPoint(LaneInfoConstPtr lane_ptr, const double s, const double l, PointENU *point, double *heading) const
Definition map_xysl.cc:114
void Print(const T &t)
Definition map_xysl.cc:96
void PrintLane(const std::string &lane_id)
Definition map_xysl.cc:185
void PrintOverlap(const std::string &overlap_id)
Definition map_xysl.cc:143
int LaneProjection(const apollo::common::math::Vec2d &vec2d, const std::string &lane_id, double *s, double *l, double *heading) const
Definition map_xysl.cc:129
int PointToSL(const PointENU &point, std::string *lane_id, double *s, double *l, double *heading) const
Definition map_xysl.cc:100
#define ACHECK(cond)
Definition log.h:80
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,...
Definition file.cc:132
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 ...
Definition file.cc:111
bool SetProtoToASCIIFile(const google::protobuf::Message &message, int file_descriptor)
Definition file.cc:43
std::string BaseMapFile()
get base map file path from flags.
Definition hdmap_util.cc:47