diff --git a/modules/routing/common/routing_gflags.cc b/modules/routing/common/routing_gflags.cc index a4469369dbc4acef6a23335ab4350b15068800ea..8dd6b27f6bd5aa87cdb92c9113b40915e4886320 100644 --- a/modules/routing/common/routing_gflags.cc +++ b/modules/routing/common/routing_gflags.cc @@ -26,8 +26,10 @@ DEFINE_string(route_topic_for_broadcast, "/routing/routing", "the default routing topic"); DEFINE_bool(use_road_id, true, "enable use road id to cut routing result"); -DEFINE_string(graph_dir, "", "the default directory of topology graph data"); -DEFINE_string(graph_file_name, "routing_map.bin", +DEFINE_string(map_dir, "/apollo/modules/map/data", "the default directory of hdmap"); +DEFINE_string(map_file_name, "base_map.txt", "the default file name of hdmap."); +DEFINE_string(graph_dir, "/apollo/modules/map/data", "the default directory of topology graph data"); +DEFINE_string(graph_file_name, "routing_map.txt", "the default file name of topology graph data"); DEFINE_string(rosparam_name_routing_init_status, "/pnc/routing_initialized", diff --git a/modules/routing/common/routing_gflags.h b/modules/routing/common/routing_gflags.h index dff427681509ff807e15427600f5ea462b7ce3f2..0175b45510478978097566120b80fb032b1aa73f 100644 --- a/modules/routing/common/routing_gflags.h +++ b/modules/routing/common/routing_gflags.h @@ -27,6 +27,8 @@ DECLARE_bool(enable_old_routing); DECLARE_string(route_topic_for_broadcast); DECLARE_bool(use_road_id); +DECLARE_string(map_dir); +DECLARE_string(map_file_name); DECLARE_string(graph_dir); DECLARE_string(graph_file_name); diff --git a/modules/routing/common/utils.cc b/modules/routing/common/utils.cc index e6f3c2547121dc1d207c518fe8701d7fb9008961..1f05c03c30935f2e757c3a42321086f1c75f01b9 100644 --- a/modules/routing/common/utils.cc +++ b/modules/routing/common/utils.cc @@ -27,23 +27,6 @@ using ::google::protobuf::io::FileInputStream; using ::google::protobuf::io::ZeroCopyInputStream; using ::google::protobuf::io::CodedInputStream; -bool FileUtils::load_protobuf_data_from_file( - const std::string& file_path, - ::google::protobuf::Message* const proto_data) { - int fd = open(file_path.c_str(), O_RDONLY); - if (fd == -1) { - AERROR << "File %s not found" << file_path.c_str(); - return false; - } - std::unique_ptr raw_input(new FileInputStream(fd)); - std::unique_ptr coded_input( - new CodedInputStream(raw_input.get())); - coded_input->SetTotalBytesLimit(INT_MAX, 536870912); // 0..512M..2G - bool ret = proto_data->ParseFromCodedStream(coded_input.get()); - close(fd); - return ret; -} - bool FileUtils::dump_protobuf_data_to_file( const std::string& file_path, const ::google::protobuf::Message* const proto_data) { diff --git a/modules/routing/common/utils.h b/modules/routing/common/utils.h index 774ee8e0a6507523956c93b68289b7a6e6fbb00c..47ce711e79c1765ff85177132ba1ba0dc92aa11f 100644 --- a/modules/routing/common/utils.h +++ b/modules/routing/common/utils.h @@ -25,9 +25,6 @@ namespace routing { class FileUtils { public: - static bool load_protobuf_data_from_file( - const std::string& file_path, - ::google::protobuf::Message* const proto_data); static bool dump_protobuf_data_to_file( const std::string& file_path, const ::google::protobuf::Message& proto_data); diff --git a/modules/routing/graph/BUILD b/modules/routing/graph/BUILD index fe8b19a213f9386ca48ed9736d721a24e7bf5704..17b39720d8f38c83acab4ba2053c6e20d0e167af 100644 --- a/modules/routing/graph/BUILD +++ b/modules/routing/graph/BUILD @@ -39,6 +39,7 @@ cc_library( "//modules/map/proto:map_proto", "//modules/routing/proto:routing_proto", "//modules/common:common", + "//modules/common/util", "//modules/routing/common" ], ) diff --git a/modules/routing/graph/topo_graph.cc b/modules/routing/graph/topo_graph.cc index f702bd99bc6fd30258394ff225bee937ced26c62..213aee766afb1a69d7d841307e908d0ad14e1a67 100644 --- a/modules/routing/graph/topo_graph.cc +++ b/modules/routing/graph/topo_graph.cc @@ -17,6 +17,7 @@ #include "modules/routing/graph/topo_graph.h" #include "modules/routing/common/utils.h" #include "modules/routing/graph/topo_node.h" +#include "modules/common/util/file.h" namespace apollo { namespace routing { @@ -70,8 +71,8 @@ bool TopoGraph::load_graph(const std::string& file_path) { clear(); ::apollo::routing::Graph graph; - if (!::apollo::routing::FileUtils::load_protobuf_data_from_file(file_path, - &graph)) { + if (!::apollo::common::util::GetProtoFromFile( + file_path, &graph)) { AERROR << "Failed to read topology graph from data."; return false; } diff --git a/modules/routing/topo_creator/BUILD b/modules/routing/topo_creator/BUILD index af0c03fdbc394d4a1e14458ab5834131136a4139..940b10e1a973b73ade0897e6fb49f65bbed88d7a 100644 --- a/modules/routing/topo_creator/BUILD +++ b/modules/routing/topo_creator/BUILD @@ -34,6 +34,7 @@ cc_library( "//modules/routing/proto:routing_proto", "//modules/map/proto:map_proto", "//modules/common:common", + "//modules/common/util", "//modules/routing/common" ], ) diff --git a/modules/routing/topo_creator/graph_creator.cc b/modules/routing/topo_creator/graph_creator.cc index b9bef0d5a85bbda585703094806b63a3a630992c..809f6184e30e50c1b02f65c0c3a2d755e7de2324 100644 --- a/modules/routing/topo_creator/graph_creator.cc +++ b/modules/routing/topo_creator/graph_creator.cc @@ -21,6 +21,7 @@ #include "modules/routing/common/utils.h" #include "modules/routing/topo_creator/edge_creator.h" #include "modules/routing/topo_creator/node_creator.h" +#include "modules/common/util/file.h" namespace apollo { namespace routing { @@ -46,7 +47,7 @@ GraphCreator::GraphCreator(const std::string& base_map_file_path, _dump_topo_file_path(dump_topo_file_path) {} bool GraphCreator::create() { - if (!::apollo::routing::FileUtils::load_protobuf_data_from_file( + if (!::apollo::common::util::GetProtoFromFile( _base_map_file_path, &_pbmap)) { LOG(ERROR) << "Failed to load base map file from " << _base_map_file_path; return false; diff --git a/modules/routing/topo_creator/topo_creator.cc b/modules/routing/topo_creator/topo_creator.cc index fc3d26edbb073646f04d69cee86eb06fd62735d9..ca39297241b347ad1b29212e656b9514dad3fda4 100644 --- a/modules/routing/topo_creator/topo_creator.cc +++ b/modules/routing/topo_creator/topo_creator.cc @@ -21,21 +21,19 @@ #include "modules/routing/topo_creator/graph_creator.h" #include "modules/common/log.h" -DEFINE_string(base_map_dir, "/apollo/modules/map/data", "directory of base map"); -DEFINE_string(base_map_name, "base_map.txt", "file name of base map"); -DEFINE_string(dump_topo_path, "/apollo/modules/map/data/routing_map.bin", "dump path of routing topology file"); - int main(int argc, char **argv) { google::InitGoogleLogging(argv[0]); google::ParseCommandLineFlags(&argc, &argv, true); std::unique_ptr<::apollo::routing::GraphCreator> creator_ptr; creator_ptr.reset(new ::apollo::routing::GraphCreator( - FLAGS_base_map_dir + "/" + FLAGS_base_map_name, - FLAGS_dump_topo_path)); + FLAGS_map_dir + "/" + FLAGS_map_file_name, + FLAGS_graph_dir + "/" + FLAGS_graph_file_name)); if (!creator_ptr->create()) { - AERROR << "Create router topo failed!"; + AERROR << "Create routing topo failed!"; return -1; } + LOG(INFO) << "Create routing topo succesful!"; + LOG(INFO) << FLAGS_graph_dir + "/" + FLAGS_graph_file_name; return 0; }