26namespace localization {
30 : map_config_(map_config),
31 map_node_cache_lvl1_(nullptr),
32 map_node_cache_lvl2_(nullptr),
33 map_node_pool_(nullptr) {}
49 std::placeholders::_1);
52 std::placeholders::_1);
85 AERROR <<
"GetMapNodeSafe: This node don't exist in cache! ";
86 AERROR <<
"load this node from disk now! index = " << index;
123 typename std::set<MapNodeIndex>::iterator itr = map_ids->begin();
124 while (itr != map_ids->end()) {
130 itr = map_ids->erase(itr);
137 itr = map_ids->begin();
140 while (itr != map_ids->end()) {
145 itr = map_ids->erase(itr);
153 std::vector<std::future<void>> load_futures;
154 itr = map_ids->begin();
155 while (itr != map_ids->end()) {
156 AERROR <<
"Preload map node failed!";
157 load_futures.emplace_back(
162 for (
auto& future : load_futures) {
163 if (future.valid()) {
168 itr = map_ids->begin();
171 while (itr != map_ids->end()) {
173 AINFO <<
"LoadMapNodes: preload missed, load this node in main thread.\n"
177 itr = map_ids->erase(itr);
190 typename std::set<MapNodeIndex>::iterator itr = map_ids->begin();
191 while (itr != map_ids->end()) {
196 itr = map_ids->erase(itr);
203 itr = map_ids->begin();
205 while (itr != map_ids->end()) {
209 if (preloading_itr !=
211 itr = map_ids->erase(itr);
218 std::vector<std::future<void>> preload_futures;
219 itr = map_ids->begin();
220 AINFO <<
"Preload map node size: " << map_ids->size();
221 while (itr != map_ids->end()) {
222 AINFO <<
"Preload map node: " << *itr << std::endl;
226 preload_futures.emplace_back(
238 while (map_node ==
nullptr) {
240 if (map_node ==
nullptr) {
249 if (!map_node->
Load()) {
250 AERROR <<
"Created map node: " << index;
252 AERROR <<
" Loaded map node: " << index;
269 const Eigen::Vector3d& trans_diff,
270 unsigned int resolution_id,
unsigned int zone_id) {
273 int x_direction = trans_diff[0] > 0 ? 1 : -1;
274 int y_direction = trans_diff[1] > 0 ? 1 : -1;
276 std::set<MapNodeIndex> map_ids;
277 float map_pixel_resolution =
280 Eigen::Vector3d pt_top_left;
283 map_pixel_resolution / 2.0f);
286 map_pixel_resolution / 2.0f);
289 *(this->
map_config_), pt_top_left, resolution_id, zone_id);
290 map_ids.insert(map_id);
293 Eigen::Vector3d pt_top_center;
294 pt_top_center[0] = location[0];
295 pt_top_center[1] = pt_top_left[1];
296 pt_top_center[2] = 0;
298 resolution_id, zone_id);
299 map_ids.insert(map_id);
302 Eigen::Vector3d pt_top_right;
305 map_pixel_resolution / 2.0);
306 pt_top_right[1] = pt_top_left[1];
309 resolution_id, zone_id);
310 map_ids.insert(map_id);
313 Eigen::Vector3d pt_middle_left;
314 pt_middle_left[0] = pt_top_left[0];
315 pt_middle_left[1] = location[1];
316 pt_middle_left[2] = 0;
318 resolution_id, zone_id);
319 map_ids.insert(map_id);
323 resolution_id, zone_id);
324 map_ids.insert(map_id);
327 Eigen::Vector3d pt_middle_right;
328 pt_middle_right[0] = pt_top_right[0];
329 pt_middle_right[1] = pt_middle_left[1];
330 pt_middle_right[2] = 0;
332 resolution_id, zone_id);
333 map_ids.insert(map_id);
336 Eigen::Vector3d pt_bottom_left;
337 pt_bottom_left[0] = pt_top_left[0];
340 map_pixel_resolution / 2.0);
341 pt_bottom_left[2] = 0;
343 resolution_id, zone_id);
344 map_ids.insert(map_id);
347 Eigen::Vector3d pt_bottom_center;
348 pt_bottom_center[0] = pt_top_center[0];
349 pt_bottom_center[1] = pt_bottom_left[1];
350 pt_bottom_center[2] = 0;
352 resolution_id, zone_id);
353 map_ids.insert(map_id);
356 Eigen::Vector3d pt_bottom_right;
357 pt_bottom_right[0] = pt_top_right[0];
358 pt_bottom_right[1] = pt_bottom_left[1];
359 pt_bottom_right[2] = 0;
361 resolution_id, zone_id);
362 map_ids.insert(map_id);
364 for (
int i = -1; i < 2; ++i) {
366 pt[0] = location[0] + x_direction * 1.5 *
368 map_pixel_resolution;
369 pt[1] = location[1] +
static_cast<double>(i) *
371 map_pixel_resolution;
374 resolution_id, zone_id);
375 map_ids.insert(map_id);
377 for (
int i = -1; i < 2; ++i) {
379 pt[0] = location[0] +
static_cast<double>(i) *
381 map_pixel_resolution;
382 pt[1] = location[1] + y_direction * 1.5 *
384 map_pixel_resolution;
387 resolution_id, zone_id);
388 map_ids.insert(map_id);
392 pt[0] = location[0] + x_direction * 1.5 *
394 map_pixel_resolution;
395 pt[1] = location[1] + y_direction * 1.5 *
397 map_pixel_resolution;
400 resolution_id, zone_id);
401 map_ids.insert(map_id);
408 unsigned int resolution_id,
unsigned int zone_id,
409 int filter_size_x,
int filter_size_y) {
411 std::set<MapNodeIndex> map_ids;
412 float map_pixel_resolution =
415 Eigen::Vector3d pt_top_left;
416 pt_top_left[0] = seed_pt3d[0] -
418 map_pixel_resolution / 2.0f) -
419 static_cast<float>(filter_size_x / 2) * map_pixel_resolution;
420 pt_top_left[1] = seed_pt3d[1] -
422 map_pixel_resolution / 2.0f) -
423 static_cast<float>(filter_size_y / 2) * map_pixel_resolution;
426 *(this->
map_config_), pt_top_left, resolution_id, zone_id);
427 map_ids.insert(map_id);
430 Eigen::Vector3d pt_top_center;
431 pt_top_center[0] = seed_pt3d[0];
432 pt_top_center[1] = pt_top_left[1];
433 pt_top_center[2] = 0;
435 resolution_id, zone_id);
436 map_ids.insert(map_id);
439 Eigen::Vector3d pt_top_right;
443 map_pixel_resolution / 2.0f) +
444 static_cast<float>(filter_size_x / 2) * map_pixel_resolution;
445 pt_top_right[1] = pt_top_left[1];
448 resolution_id, zone_id);
449 map_ids.insert(map_id);
452 Eigen::Vector3d pt_middle_left;
453 pt_middle_left[0] = pt_top_left[0];
454 pt_middle_left[1] = seed_pt3d[1];
455 pt_middle_left[2] = 0;
457 resolution_id, zone_id);
458 map_ids.insert(map_id);
462 resolution_id, zone_id);
463 map_ids.insert(map_id);
466 Eigen::Vector3d pt_middle_right;
467 pt_middle_right[0] = pt_top_right[0];
468 pt_middle_right[1] = seed_pt3d[1];
469 pt_middle_right[2] = 0;
471 resolution_id, zone_id);
472 map_ids.insert(map_id);
475 Eigen::Vector3d pt_bottom_left;
476 pt_bottom_left[0] = pt_top_left[0];
480 map_pixel_resolution / 2.0f) +
481 static_cast<float>(filter_size_y / 2) * map_pixel_resolution;
482 pt_bottom_left[2] = 0;
484 resolution_id, zone_id);
485 map_ids.insert(map_id);
488 Eigen::Vector3d pt_bottom_center;
489 pt_bottom_center[0] = seed_pt3d[0];
490 pt_bottom_center[1] = pt_bottom_left[1];
491 pt_bottom_center[2] = 0;
493 resolution_id, zone_id);
494 map_ids.insert(map_id);
497 Eigen::Vector3d pt_bottom_right;
498 pt_bottom_right[0] = pt_top_right[0];
499 pt_bottom_right[1] = pt_bottom_left[1];
500 pt_bottom_right[2] = 0;
502 resolution_id, zone_id);
503 map_ids.insert(map_id);
The options of the reflectance map.
std::vector< float > map_resolutions_
The pixel resolutions in the map in meters.
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.
std::string map_folder_path_
The map folder path.
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.
The memory pool for the data structure of BaseMapNode.
BaseMapNode * AllocMapNode()
Get a MapNode object from memory pool.
void FreeMapNode(BaseMapNode *map_node)
Release MapNode object to memory pool.
The data structure of a Node in the map.
virtual void Init(const BaseMapConfig *map_config, const MapNodeIndex &index, bool create_map_cells=true)
Initialize the map node.
bool Load()
Load the map node from the disk.
void SetIsReserved(bool is_reserved)
Set if the map node is reserved.
void AddDataset(const std::string dataset_path)
Add a dataset path to the map config.
virtual bool LoadMapArea(const Eigen::Vector3d &seed_pt3d, unsigned int resolution_id, unsigned int zone_id, int filter_size_x, int filter_size_y)
Load map nodes for the location calculate of this frame.
virtual ~BaseMap()
The destructor.
BaseMapConfig * map_config_
The map settings.
MapNodeCache< MapNodeIndex, BaseMapNode >::DestroyFunc destroy_func_lvl2_
virtual void InitMapNodeCaches(int cacheL1_size, int cahceL2_size)
Init load threadpool and preload threadpool.
void AttachMapNodePool(BaseMapNodePool *p_map_node_pool)
Attach map node pointer.
boost::recursive_mutex map_load_mutex_
The mutex for preload map node.
bool SetMapFolderPath(const std::string folder_path)
Set the directory of the map.
MapNodeCache< MapNodeIndex, BaseMapNode > * map_node_cache_lvl2_
brief The dynamic map node preloading thread pool pointer.
void LoadMapNodes(std::set< MapNodeIndex > *map_ids)
Load map node by index.
std::set< MapNodeIndex > map_preloading_task_index_
@bried Keep the index of preloading nodes.
void PreloadMapNodes(std::set< MapNodeIndex > *map_ids)
Load map node by index.
BaseMapNodePool * map_node_pool_
The map node memory pool pointer.
bool IsMapNodeExist(const MapNodeIndex &index) const
Check if the map node in the cache.
BaseMap(BaseMapConfig *map_config)
The constructor.
BaseMapNode * GetMapNodeSafe(const MapNodeIndex &index)
Return the map node, if it's not in the cache, safely load it.
void LoadMapNodeThreadSafety(MapNodeIndex index, bool is_reserved=false)
Load map node by index, thread_safety.
MapNodeCache< MapNodeIndex, BaseMapNode >::DestroyFunc destroy_func_lvl1_
virtual void PreloadMapArea(const Eigen::Vector3d &location, const Eigen::Vector3d &trans_diff, unsigned int resolution_id, unsigned int zone_id)
Preload map nodes for the next frame location calculation.
MapNodeCache< MapNodeIndex, BaseMapNode > * map_node_cache_lvl1_
The cache for map node preload.
BaseMapNode * GetMapNode(const MapNodeIndex &index)
Get the map node, if it's not in the cache, return false.
The data structure of the LRUCache.
static MapNodeIndex GetMapNodeIndex(const BaseMapConfig &option, const Eigen::Vector3d &coordinate, unsigned int resolution_id, int zone_id)
Construct a map node index, given a global coordinate, eigen version.
static bool IsExists(const std::string &path)
Determine if the file or directory exists.