Apollo 10.0
自动驾驶开放平台
lossless_map_to_lossy_map.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
17#include <boost/filesystem.hpp>
18#include <boost/program_options.hpp>
19
24
31
32namespace apollo {
33namespace localization {
34namespace msf {
35
36MapNodeIndex GetMapIndexFromMapFolder(const std::string& map_folder) {
37 MapNodeIndex index;
38 char buf[100];
39 sscanf(map_folder.c_str(), "/%03u/%05s/%02d/%08u/%08u", &index.resolution_id_,
40 buf, &index.zone_id_, &index.m_, &index.n_);
41 std::string zone = buf;
42 if (zone == "south") {
43 index.zone_id_ = -index.zone_id_;
44 }
45 ADEBUG << index;
46 return index;
47}
48
49bool GetAllMapIndex(const std::string& src_map_folder,
50 const std::string& dst_map_folder,
51 std::list<MapNodeIndex>* buf) {
52 std::string src_map_path = src_map_folder + "/map";
53 std::string dst_map_path = dst_map_folder + "/map";
54 boost::filesystem::path src_map_path_boost(src_map_path);
55 boost::filesystem::path dst_map_path_boost(dst_map_path);
56
57 if (!boost::filesystem::exists(dst_map_path)) {
58 boost::filesystem::create_directory(dst_map_path_boost);
59 }
60
61 // push path of map's index to list
62 buf->clear();
63 // std::deque<std::string> map_bin_path;
64 boost::filesystem::recursive_directory_iterator end_iter;
65 boost::filesystem::recursive_directory_iterator iter(src_map_path_boost);
66 for (; iter != end_iter; ++iter) {
67 if (!boost::filesystem::is_directory(*iter)) {
68 if (iter->path().extension() == "") {
69 // map_bin_path.push_back(iter->path().string());
70 std::string tmp = iter->path().string();
71 tmp = tmp.substr(src_map_path.length(), tmp.length());
72 buf->push_back(GetMapIndexFromMapFolder(tmp));
73 }
74 } else {
75 std::string tmp = iter->path().string();
76 tmp = tmp.substr(src_map_path.length(), tmp.length());
77 tmp = dst_map_path + tmp;
78 boost::filesystem::path p(tmp);
79 if (!boost::filesystem::exists(p)) {
80 boost::filesystem::create_directory(p);
81 }
82 }
83 }
84
85 return true;
86}
87
88} // namespace msf
89} // namespace localization
90} // namespace apollo
91
92int main(int argc, char** argv) {
93 boost::program_options::options_description boost_desc("Allowed options");
94 boost_desc.add_options()("help", "produce help message")(
95 "srcdir", boost::program_options::value<std::string>(),
96 "provide the data base dir")("dstdir",
97 boost::program_options::value<std::string>(),
98 "provide the lossy map destination dir");
99
100 boost::program_options::variables_map boost_args;
101 boost::program_options::store(
102 boost::program_options::parse_command_line(argc, argv, boost_desc),
103 boost_args);
104 boost::program_options::notify(boost_args);
105
106 if (boost_args.count("help") || !boost_args.count("srcdir") ||
107 !boost_args.count("dstdir")) {
108 AERROR << boost_desc;
109 return 0;
110 }
111
112 const std::string src_path = boost_args["srcdir"].as<std::string>();
113 const std::string dst_path = boost_args["dstdir"].as<std::string>();
114 std::string src_map_folder = src_path + "/";
115
116 PyramidMapConfig lossless_config("lossless_map");
117 PyramidMapNodePool lossless_map_node_pool(25, 8);
118 lossless_map_node_pool.Initial(&lossless_config);
119
120 PyramidMap lossless_map(&lossless_config);
121 lossless_map.InitMapNodeCaches(12, 24);
122 lossless_map.AttachMapNodePool(&lossless_map_node_pool);
123 if (!lossless_map.SetMapFolderPath(src_map_folder)) {
124 AERROR << "Reflectance map folder is invalid!";
125 return -1;
126 }
127
128 // create lossy map
129 std::string dst_map_folder = dst_path + "/lossy_map/";
130 if (!boost::filesystem::exists(dst_map_folder)) {
131 boost::filesystem::create_directory(dst_map_folder);
132 }
133
134 std::list<MapNodeIndex> buf;
135 apollo::localization::msf::GetAllMapIndex(src_map_folder, dst_map_folder,
136 &buf);
137 AINFO << "index size: " << buf.size();
138
139 PyramidMapConfig config_transform_lossy("lossless_map");
140 config_transform_lossy.Load(src_map_folder + "config.xml");
141 config_transform_lossy.map_version_ = "lossy_map";
142 config_transform_lossy.Save(dst_map_folder + "config.xml");
143
144 AINFO << "lossy map directory structure has built.";
145
146 PyramidMapNodePool lossy_map_node_pool(25, 8);
147 lossy_map_node_pool.Initial(&config_transform_lossy);
148 PyramidMap lossy_map(&config_transform_lossy);
149 lossy_map.InitMapNodeCaches(12, 24);
150 lossy_map.AttachMapNodePool(&lossy_map_node_pool);
151 if (!lossy_map.SetMapFolderPath(dst_map_folder)) {
152 AINFO << "lossy_map config xml not exist";
153 }
154
155 int index = 0;
156 auto itr = buf.begin();
157 for (; itr != buf.end(); ++itr, ++index) {
158 PyramidMapNode* lossless_node =
159 static_cast<PyramidMapNode*>(lossless_map.GetMapNodeSafe(*itr));
160 if (lossless_node == nullptr) {
161 AWARN << "index: " << index << " is a nullptr pointer!";
162 continue;
163 }
164 PyramidMapMatrix& lossless_matrix =
165 static_cast<PyramidMapMatrix&>(lossless_node->GetMapCellMatrix());
166
167 PyramidMapNode* lossy_node =
168 static_cast<PyramidMapNode*>(lossy_map.GetMapNodeSafe(*itr));
169 PyramidMapMatrix& lossy_matrix =
170 static_cast<PyramidMapMatrix&>(lossy_node->GetMapCellMatrix());
171
172 int rows = lossless_config.map_node_size_y_;
173 int cols = lossless_config.map_node_size_x_;
174 for (int row = 0; row < rows; ++row) {
175 for (int col = 0; col < cols; ++col) {
176 const float* intensity = lossless_matrix.GetIntensitySafe(row, col);
177 const float* intensity_var =
178 lossless_matrix.GetIntensityVarSafe(row, col);
179 const unsigned int* count = lossless_matrix.GetCountSafe(row, col);
180 // Read altitude
181 const float* altitude_avg = lossless_matrix.GetAltitudeSafe(row, col);
182 const float* altitude_var =
183 lossless_matrix.GetAltitudeVarSafe(row, col);
184 const float* altitude_ground =
185 lossless_matrix.GetGroundAltitudeSafe(row, col);
186 const unsigned int* ground_count =
187 lossless_matrix.GetGroundCountSafe(row, col);
188 if (intensity) {
189 lossy_matrix.SetIntensitySafe(*intensity, row, col);
190 }
191 if (intensity_var) {
192 lossy_matrix.SetIntensityVarSafe(*intensity_var, row, col);
193 }
194 if (count) {
195 lossy_matrix.SetCountSafe(*count, row, col);
196 }
197 if (altitude_avg) {
198 lossy_matrix.SetAltitudeSafe(*altitude_avg, row, col);
199 }
200 if (altitude_var) {
201 lossy_matrix.SetAltitudeVarSafe(*altitude_var, row, col);
202 }
203 if (altitude_ground) {
204 lossy_matrix.SetGroundAltitudeSafe(*altitude_ground, row, col);
205 }
206 if (ground_count) {
207 lossy_matrix.SetGroundCountSafe(*ground_count, row, col);
208 }
209 }
210 }
211 lossy_node->SetIsChanged(true);
212 }
213
214 return 0;
215}
unsigned int m_
The map node ID at the northing direction.
unsigned int n_
The map node ID at the easting direction.
unsigned int resolution_id_
The ID of the resolution.
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.
bool Load(const std::string &file_path)
Load the map option from a XML file.
unsigned int map_node_size_x_
The map node size in pixels.
void Initial(const BaseMapConfig *map_config, bool is_fixed_size=true)
Initialize the pool.
const BaseMapMatrix & GetMapCellMatrix() const
Get map cell matrix.
void SetIsChanged(bool is)
Set if the map node data has changed.
bool SetMapFolderPath(const std::string folder_path)
Set the directory of the map.
Definition base_map.cc:106
BaseMapNode * GetMapNodeSafe(const MapNodeIndex &index)
Return the map node, if it's not in the cache, safely load it.
Definition base_map.cc:63
virtual void InitMapNodeCaches(int cacheL1_size, int cahceL2_size)
Definition base_map.cc:40
void AttachMapNodePool(BaseMapNodePool *p_map_node_pool)
Attach map node pointer.
Definition base_map.cc:53
const unsigned int * GetGroundCountSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get a ground count value by check.
const float * GetIntensityVarSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an intensity variance value by check.
const float * GetIntensitySafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an intensity value by check.
void SetGroundAltitudeSafe(float ground_altitude, unsigned int row, unsigned int col, unsigned int level=0)
Set an altitude ground value by check.
const float * GetAltitudeSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an altitude value by check.
void SetAltitudeSafe(float altitude, unsigned int row, unsigned int col, unsigned int level=0)
Set an altitude value by check.
void SetCountSafe(unsigned int count, unsigned int row, unsigned int col, unsigned int level=0)
Set a count value by check.
const unsigned int * GetCountSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get a count value by check.
void SetIntensityVarSafe(float intensity_var, unsigned int row, unsigned int col, unsigned int level=0)
Set an intensity variance value by check.
const float * GetAltitudeVarSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an altitude variance value by check.
const float * GetGroundAltitudeSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an altitude ground value by check.
void SetGroundCountSafe(unsigned int ground_count, unsigned int row, unsigned int col, unsigned int level=0)
Set a ground count value by check.
void SetIntensitySafe(float intensity, unsigned int row, unsigned int col, unsigned int level=0)
Set an intensity value by check.
void SetAltitudeVarSafe(float altitude_var, unsigned int row, unsigned int col, unsigned int level=0)
Set an altitude variance value by check.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
#define AWARN
Definition log.h:43
int main(int argc, char **argv)
bool GetAllMapIndex(const std::string &src_map_folder, const std::string &dst_map_folder, std::list< MapNodeIndex > *buf)
MapNodeIndex GetMapIndexFromMapFolder(const std::string &map_folder)
class register implement
Definition arena_queue.h:37