Apollo 10.0
自动驾驶开放平台
base_map_config.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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 <exception>
20#include <iostream>
21
22#include "cyber/common/log.h"
23
24namespace apollo {
25namespace localization {
26namespace msf {
27namespace pyramid_map {
28
29BaseMapConfig::BaseMapConfig(const std::string &map_version) {
30 map_version_ = map_version;
31 coordinate_type_ = "UTM";
32 map_resolutions_.push_back(0.125);
33 map_node_size_x_ = 1024; // in pixels
34 map_node_size_y_ = 1024; // in pixels
35 map_range_ = Rect2D<double>(0, 0, 1000448.0, 10000384.0); // in meters
38 map_folder_path_ = ".";
39}
40
42
43bool BaseMapConfig::Save(const std::string &file_path) {
44 boost::property_tree::ptree config;
45 bool success = CreateXml(&config);
46 if (success) {
47 boost::property_tree::write_xml(file_path, config);
48 AINFO << "Saved the map configuration to: " << file_path;
49 return true;
50 }
51 return false;
52}
53
54bool BaseMapConfig::Load(const std::string &file_path) {
55 boost::property_tree::ptree config;
56 boost::property_tree::read_xml(file_path, config);
57 bool success = LoadXml(config);
58
59 if (success) {
60 AINFO << "Loaded the map configuration from: " << file_path;
61 return true;
62 }
63 return false;
64}
65
66bool BaseMapConfig::CreateXml(boost::property_tree::ptree *config) const {
67 config->put("map.map_config.version", map_version_);
68 config->put("map.map_config.coordnate_type", coordinate_type_);
69 config->put("map.map_config.node_size.x", map_node_size_x_);
70 config->put("map.map_config.node_size.y", map_node_size_y_);
71 config->put("map.map_config.range.min_x", map_range_.GetMinX());
72 config->put("map.map_config.range.min_y", map_range_.GetMinY());
73 config->put("map.map_config.range.max_x", map_range_.GetMaxX());
74 config->put("map.map_config.range.max_y", map_range_.GetMaxY());
75 config->put("map.map_config.compression", map_is_compression_);
76 config->put("map.map_runtime.map_ground_height_offset",
78 for (size_t i = 0; i < map_resolutions_.size(); ++i) {
79 config->add("map.map_config.resolutions.resolution", map_resolutions_[i]);
80 }
81
82 for (size_t i = 0; i < map_datasets_.size(); ++i) {
83 config->add("map.map_record.datasets.dataset", map_datasets_[i]);
84 }
85
86 // added md5 check info
87 std::map<std::string, std::string>::const_iterator iter;
88 for (iter = node_md5_map_.begin(); iter != node_md5_map_.end(); ++iter) {
89 boost::property_tree::ptree child;
90 child.put("path", iter->first);
91 child.put("md5", iter->second);
92 config->add_child("map.check_info.nodes.node", child);
93 }
94
95 return true;
96}
97
98bool BaseMapConfig::LoadXml(const boost::property_tree::ptree &config) {
99 map_resolutions_.clear();
100 map_datasets_.clear();
101 node_md5_map_.clear();
102
103 auto map_version = config.get_optional<std::string>("map.map_config.version");
104 if (map_version) {
105 map_version_ = map_version.get();
106 }
107 auto coordinate_type =
108 config.get_optional<std::string>("map.map_config.coordinate_type");
109 if (coordinate_type) {
110 coordinate_type_ = coordinate_type.get();
111 }
112 auto map_node_size_x =
113 config.get_optional<unsigned int>("map.map_config.node_size.x");
114 if (map_node_size_x) {
115 map_node_size_x_ = map_node_size_x.get();
116 }
117
118 auto map_node_size_y =
119 config.get_optional<unsigned int>("map.map_config.node_size.y");
120 if (map_node_size_y) {
121 map_node_size_y_ = map_node_size_y.get();
122 }
123 double min_x = 0.0;
124 auto tmp_min_x = config.get_optional<double>("map.map_config.range.min_x");
125 if (tmp_min_x) {
126 min_x = tmp_min_x.get();
127 }
128 double min_y = 0.0;
129 auto tmp_min_y = config.get_optional<double>("map.map_config.range.min_y");
130 if (tmp_min_y) {
131 min_y = tmp_min_y.get();
132 }
133 double max_x = 0.0;
134 auto tmp_max_x = config.get_optional<double>("map.map_config.range.max_x");
135 if (tmp_max_x) {
136 max_x = tmp_max_x.get();
137 }
138 double max_y = 0.0;
139 auto tmp_max_y = config.get_optional<double>("map.map_config.range.max_y");
140 if (tmp_max_y) {
141 max_y = tmp_max_y.get();
142 }
143 map_range_ = Rect2D<double>(min_x, min_y, max_x, max_y);
144 auto map_ground_height_offset =
145 config.get_optional<float>("map.map_runtime.map_ground_height_offset");
146 if (map_ground_height_offset) {
147 map_ground_height_offset_ = map_ground_height_offset.get();
148 }
149 auto map_is_compression =
150 config.get_optional<bool>("map.map_config.compression");
151 if (map_is_compression) {
152 map_is_compression_ = map_is_compression.get();
153 }
154
155 auto resolutions = config.get_child_optional("map.map_config.resolutions");
156 if (resolutions) {
157 std::for_each(resolutions->begin(), resolutions->end(),
158 [this](const boost::property_tree::ptree::value_type &v) {
159 map_resolutions_.push_back(
160 static_cast<float>(atof(v.second.data().c_str())));
161 AINFO << "Resolution: " << v.second.data();
162 });
163 } else {
164 return false;
165 }
166
167 auto datasets = config.get_child_optional("map.map_record.datasets");
168 if (datasets) {
169 for (const boost::property_tree::ptree::value_type &v : *datasets) {
170 map_datasets_.push_back(v.second.data());
171 AINFO << "Dataset: " << v.second.data();
172 }
173 }
174
175 // load md5 check info
176 auto nodes = config.get_child_optional("map.check_info.nodes");
177 if (nodes) {
178 for (const boost::property_tree::ptree::value_type &v : *nodes) {
179 const boost::property_tree::ptree &child = v.second;
180 auto path = child.get_optional<std::string>("path");
181 auto md5 = child.get_optional<std::string>("md5");
182 if (!path || !md5) {
183 AERROR << "Lack path or md5.";
184 return false;
185 }
186 node_md5_map_[*path] = *md5;
187 }
188 }
189
190 return true;
191}
192
193void BaseMapConfig::SetMapVersion(const std::string &map_version) {
194 map_version_ = map_version;
195}
196
198 double min_x = 0;
199 double min_y = 0;
200 double max_x = 0;
201 double max_y = 0;
202
203 double max_resolutions =
204 *std::max_element(map_resolutions_.begin(), map_resolutions_.end());
205 int n = 0;
206 while (min_x >= map_range_.GetMinX()) {
207 ++n;
208 min_x -= n * map_node_size_x_ * max_resolutions;
209 }
210 n = 0;
211 while (min_y >= map_range_.GetMinY()) {
212 ++n;
213 min_y -= n * map_node_size_y_ * max_resolutions;
214 }
215 n = 0;
216 while (max_x <= map_range_.GetMaxX()) {
217 ++n;
218 max_x += n * map_node_size_x_ * max_resolutions;
219 }
220 n = 0;
221 while (max_y <= map_range_.GetMaxY()) {
222 ++n;
223 max_y += n * map_node_size_y_ * max_resolutions;
224 }
225 map_range_ = Rect2D<double>(min_x, min_y, max_x, max_y);
226}
227
229 map_resolutions_.clear();
230 map_resolutions_.push_back(resolution);
231}
232
234 map_resolutions_.clear();
235 map_resolutions_.push_back(0.03125);
236 map_resolutions_.push_back(0.0625);
237 map_resolutions_.push_back(0.125);
238 map_resolutions_.push_back(0.25);
239 map_resolutions_.push_back(0.5);
240 map_resolutions_.push_back(1);
241 map_resolutions_.push_back(2);
242 map_resolutions_.push_back(4);
243 map_resolutions_.push_back(8);
244 map_resolutions_.push_back(16);
245}
246
248 const std::map<std::string, std::string> &node_md5_map) {
249 node_md5_map_ = node_md5_map;
250}
251
252void BaseMapConfig::AddNodeMd5(const std::string &node_path,
253 const std::string &md5) {
254 node_md5_map_[node_path] = md5;
255}
256
257void BaseMapConfig::SetMapNodeSize(unsigned int size_x, unsigned int size_y) {
258 map_node_size_x_ = size_x;
259 map_node_size_y_ = size_y;
260}
261
262void BaseMapConfig::SetGroundHeightOffset(float map_ground_height_offset) {
263 map_ground_height_offset_ = map_ground_height_offset;
264}
265
266void BaseMapConfig::SetIsCompression(bool map_is_compression) {
267 map_is_compression_ = map_is_compression;
268}
269
271 if (map_version_ == "lossy_full_alt" || map_version_ == "lossy_map") {
273 }
274
275 if (map_version_ == "0.21" || map_version_ == "lossless_map") {
277 }
278
279 if (map_version_ == "pyramid_lossy_map") {
281 }
282
283 if (map_version_ == "pyramid_lossless_map") {
285 }
286
287 return MapVersion::UNKNOWN;
288}
289
290} // namespace pyramid_map
291} // namespace msf
292} // namespace localization
293} // namespace apollo
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
std::vector< std::string > map_datasets_
The datasets that contributed to 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.
void SetMapNodeSize(unsigned int size_x, unsigned int size_y)
Set map_node_size.
virtual bool CreateXml(boost::property_tree::ptree *config) const
Create the XML structure.
std::vector< float > map_resolutions_
The pixel resolutions in the map in meters.
Rect2D< double > map_range_
The minimum and maximum UTM range in the map.
virtual bool LoadXml(const boost::property_tree::ptree &config)
Load the map options from a XML structure.
void AddNodeMd5(const std::string &node_path, const std::string &md5)
Add a node md5 pair.
bool Load(const std::string &file_path)
Load the map option from a XML file.
float map_ground_height_offset_
Velodyne's height to the ground.
void SetNodeMd5Map(const std::map< std::string, std::string > &node_md5_map)
Set node_md5_map.
void SetGroundHeightOffset(float map_ground_height_offset)
Set map_ground_height_offset.
BaseMapConfig(const std::string &map_version="0.1")
The constructor gives the default map settings.
unsigned int map_node_size_x_
The map node size in pixels.
std::map< std::string, std::string > node_md5_map_
The map structure to store map node file name and its md5.
void ResizeMapRange()
Resize map range by range and resolutions.
void SetSingleResolutions(float resolution=0.125)
Set single resolutions.
void SetMapVersion(const std::string &map_version)
Set map_version.
void SetIsCompression(bool map_is_compression)
Set map_is_compression.
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37