17#include "absl/strings/match.h"
18#include "gflags/gflags.h"
20#include "modules/common_msgs/map_msgs/map.pb.h"
36 "Points are sampled when the accumulated direction change "
37 "exceeds the threshold");
38DEFINE_int32(downsample_distance, 5,
"downsample rate for a normal path");
40 "downsample rate for a steep turn path");
50static void DownsampleCurve(
Curve* curve) {
51 auto* line_segment = curve->mutable_segment(0)->mutable_line_segment();
52 std::vector<PointENU> points(line_segment->point().begin(),
53 line_segment->point().end());
54 line_segment->clear_point();
60 auto sampled_indices = DownsampleByAngle(points, FLAGS_angle_threshold);
61 std::vector<PointENU> downsampled_points;
62 for (
const size_t index : sampled_indices) {
63 downsampled_points.push_back(points[index]);
68 FLAGS_steep_turn_downsample_distance);
70 for (
const size_t index : sampled_indices) {
71 *line_segment->add_point() = downsampled_points[index];
73 size_t new_size = line_segment->point_size();
74 CHECK_GT(new_size, 1U);
76 AINFO <<
"Lane curve downsampled from " << points.size() <<
" points to "
77 << new_size <<
" points.";
80static void DownsampleMap(
Map* map_pb) {
81 for (
int i = 0; i < map_pb->lane_size(); ++i) {
82 auto* lane = map_pb->mutable_lane(i);
83 lane->clear_left_sample();
84 lane->clear_right_sample();
85 lane->clear_left_road_sample();
86 lane->clear_right_road_sample();
88 AINFO <<
"Downsampling lane " << lane->id().id();
89 DownsampleCurve(lane->mutable_central_curve());
90 DownsampleCurve(lane->mutable_left_boundary()->mutable_curve());
91 DownsampleCurve(lane->mutable_right_boundary()->mutable_curve());
95static void OutputMap(
const Map& map_pb) {
96 std::ofstream map_txt_file(FLAGS_output_dir +
"/sim_map.txt");
97 map_txt_file << map_pb.DebugString();
100 std::ofstream map_bin_file(FLAGS_output_dir +
"/sim_map.bin");
102 map_pb.SerializeToString(&map_str);
103 map_bin_file << map_str;
104 map_bin_file.close();
107int main(int32_t argc,
char** argv) {
108 google::InitGoogleLogging(argv[0]);
109 FLAGS_alsologtostderr =
true;
112 google::ParseCommandLineFlags(&argc, &argv,
true);
116 if (absl::EndsWith(map_file,
".xml")) {
119 ACHECK(GetProtoFromFile(map_file, &map_pb)) <<
"Fail to open: " << map_file;
122 DownsampleMap(&map_pb);
124 AINFO <<
"sim_map generated at:" << FLAGS_output_dir;
static bool LoadData(const std::string &filename, apollo::hdmap::Map *pb_map)
std::vector< size_t > DownsampleByAngle(const Points &points, const double angle_threshold)
Downsample the points on the path according to the angle.
std::vector< size_t > DownsampleByDistance(const Points &points, int downsampleDistance, int steepTurnDownsampleDistance)
Downsample the points on the path based on distance.
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,...
std::string BaseMapFile()
get base map file path from flags.
DEFINE_string(output_dir, "/tmp/", "output map directory")
A map tool to generate a downsampled map to be displayed by dreamview frontend.
int main(int32_t argc, char **argv)
DEFINE_double(angle_threshold, 1./180 *M_PI, "Points are sampled when the accumulated direction change " "exceeds the threshold")
DEFINE_int32(downsample_distance, 5, "downsample rate for a normal path")