Apollo 10.0
自动驾驶开放平台
base_map_config.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include <algorithm>
20#include "cyber/common/log.h"
21
22namespace apollo {
23namespace localization {
24namespace msf {
25
26BaseMapConfig::BaseMapConfig(std::string map_version) {
27 map_resolutions_.push_back(0.125); // Resolution: 0.125m in level 2
28 map_node_size_x_ = 1024; // in pixels
29 map_node_size_y_ = 1024; // in pixels
30 map_range_ = Rect2D<double>(0, 0, 1000448.0, 10000384.0); // in meters
31
32 map_version_ = map_version;
33 map_folder_path_ = ".";
34}
35
36bool BaseMapConfig::Save(const std::string file_path) {
37 boost::property_tree::ptree config;
38 CreateXml(&config);
39 boost::property_tree::write_xml(file_path, config);
40 AINFO << "Saved the map configuration to: " << file_path;
41 return true;
42}
43
44bool BaseMapConfig::Load(const std::string file_path) {
45 boost::property_tree::ptree config;
46 boost::property_tree::read_xml(file_path, config);
47
48 std::string map_version = config.get<std::string>("map.map_config.version");
49 if (map_version_ == map_version) {
50 LoadXml(config);
51 AINFO << "Loaded the map configuration from: " << file_path;
52 return true;
53 } else {
54 AERROR << "[Fatal Error] Expect v" << map_version_ << " map, but found v"
55 << map_version << " map.";
56 return false;
57 }
58}
59
60void BaseMapConfig::CreateXml(boost::property_tree::ptree* config) const {
61 config->put("map.map_config.version", map_version_);
62 config->put("map.map_config.node_size.x", map_node_size_x_);
63 config->put("map.map_config.node_size.y", map_node_size_y_);
64 config->put("map.map_config.range.min_x", map_range_.GetMinX());
65 config->put("map.map_config.range.min_y", map_range_.GetMinY());
66 config->put("map.map_config.range.max_x", map_range_.GetMaxX());
67 config->put("map.map_config.range.max_y", map_range_.GetMaxY());
68 config->put("map.map_config.compression", map_is_compression_);
69 config->put("map.map_runtime.map_ground_height_offset",
71 for (size_t i = 0; i < map_resolutions_.size(); ++i) {
72 config->add("map.map_config.resolutions.resolution", map_resolutions_[i]);
73 }
74
75 for (size_t i = 0; i < map_datasets_.size(); ++i) {
76 config->add("map.map_record.datasets.dataset", map_datasets_[i]);
77 }
78}
79
80void BaseMapConfig::LoadXml(const boost::property_tree::ptree& config) {
81 map_resolutions_.clear();
82 map_datasets_.clear();
83 map_node_size_x_ = config.get<unsigned int>("map.map_config.node_size.x");
84 map_node_size_y_ = config.get<unsigned int>("map.map_config.node_size.y");
85 double min_x = config.get<double>("map.map_config.range.min_x");
86 double min_y = config.get<double>("map.map_config.range.min_y");
87 double max_x = config.get<double>("map.map_config.range.max_x");
88 double max_y = config.get<double>("map.map_config.range.max_y");
89 map_range_ = Rect2D<double>(min_x, min_y, max_x, max_y);
90 map_is_compression_ = config.get<bool>("map.map_config.compression");
92 config.get<float>("map.map_runtime.map_ground_height_offset");
93 const auto& resolutions = config.get_child("map.map_config.resolutions");
94 std::for_each(resolutions.begin(), resolutions.end(),
95 [this](const boost::property_tree::ptree::value_type& v) {
96 map_resolutions_.push_back(
97 static_cast<float>(atof(v.second.data().c_str())));
98 AINFO << "Resolution: " << v.second.data();
99 });
100 const auto& datasets = config.get_child("map.map_record.datasets");
101 std::for_each(datasets.begin(), datasets.end(),
102 [this](const boost::property_tree::ptree::value_type& v) {
103 map_datasets_.push_back(v.second.data());
104 AINFO << "Dataset: " << v.second.data();
105 });
106}
107
109 double min_x = 0;
110 double min_y = 0;
111 double max_x = 0;
112 double max_y = 0;
113
114 double max_resolutions = 0.0;
115 for (std::size_t i = 0; i < map_resolutions_.size(); ++i) {
116 if (max_resolutions < map_resolutions_[i]) {
117 max_resolutions = map_resolutions_[i];
118 }
119 }
120
121 int n = 0;
122 while (true) {
123 if (min_x < map_range_.GetMinX()) {
124 break;
125 }
126 ++n;
127 min_x -= n * map_node_size_x_ * max_resolutions;
128 }
129 n = 0;
130 while (true) {
131 if (min_y < map_range_.GetMinY()) {
132 break;
133 }
134 ++n;
135 min_y -= n * map_node_size_y_ * max_resolutions;
136 }
137 n = 0;
138 while (true) {
139 if (max_x > map_range_.GetMaxX()) {
140 break;
141 }
142 ++n;
143 max_x += n * map_node_size_x_ * max_resolutions;
144 }
145 n = 0;
146 while (true) {
147 if (max_y > map_range_.GetMaxY()) {
148 break;
149 }
150 ++n;
151 max_y += n * map_node_size_y_ * max_resolutions;
152 }
153 map_range_ = Rect2D<double>(min_x, min_y, max_x, max_y);
154}
155
157 map_resolutions_.clear();
158 map_resolutions_.push_back(resolution);
159}
160
162 map_resolutions_.clear();
163 map_resolutions_.push_back(0.03125);
164 map_resolutions_.push_back(0.0625);
165 map_resolutions_.push_back(0.125);
166 map_resolutions_.push_back(0.25);
167 map_resolutions_.push_back(0.5);
168 map_resolutions_.push_back(1);
169 map_resolutions_.push_back(2);
170 map_resolutions_.push_back(4);
171 map_resolutions_.push_back(8);
172 map_resolutions_.push_back(16);
173}
174
175} // namespace msf
176} // namespace localization
177} // namespace apollo
std::vector< float > map_resolutions_
The pixel resolutions in the map in meters.
void SetSingleResolutions(float resolution=0.125)
Set single resolutions.
std::vector< std::string > map_datasets_
The datasets that contributed to the map.
bool Load(const std::string file_path)
Load the map option from a XML file.
BaseMapConfig(std::string map_version="0.1")
The constructor gives the default map settings.
std::string map_version_
The version of map.
bool map_is_compression_
Enable the compression.
void ResizeMapRange()
Resize map range by range and resolutions.
float map_ground_height_offset_
Velodyne's height to the ground.
virtual void CreateXml(boost::property_tree::ptree *config) const
Create the XML structure.
std::string map_folder_path_
The map folder path.
void SetMultiResolutions()
Set multi resolutions.
virtual void LoadXml(const boost::property_tree::ptree &config)
Load the map options from a XML structure.
Rect2D< double > map_range_
The minimum and maximum UTM range in the map.
bool Save(const std::string file_path)
Save the map option to a XML file.
unsigned int map_node_size_y_
The map node size in pixels.
unsigned int map_node_size_x_
The map node size in pixels.
T GetMaxY() const
Get the max y of the rectangle.
Definition rect2d.h:88
T GetMaxX() const
Get the max x of the rectangle.
Definition rect2d.h:83
T GetMinX() const
Get the min x of the rectangle.
Definition rect2d.h:73
T GetMinY() const
Get the min y of the rectangle.
Definition rect2d.h:78
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37