Apollo 10.0
自动驾驶开放平台
base_map.h
浏览该文件的文档.
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#pragma once
17
18#include <map>
19#include <memory>
20#include <set>
21#include <string>
22#include <vector>
23
24#include "cyber/task/task.h"
31
32namespace apollo {
33namespace localization {
34namespace msf {
35namespace pyramid_map {
36
38class BaseMap {
39 public:
41 explicit BaseMap(BaseMapConfig* config);
43 virtual ~BaseMap();
44
45 // @brief Init level 1 and level 2 map node caches. */
46 virtual void InitMapNodeCaches(int cacheL1_size, int cahceL2_size);
47
49 void AttachMapNodePool(BaseMapNodePool* p_map_node_pool);
50
52 BaseMapNode* GetMapNode(const MapNodeIndex& index);
53
56
58 bool IsMapNodeExist(const MapNodeIndex& index);
59
61 bool SetMapFolderPath(const std::string folder_path);
62
64 void AddDataset(const std::string dataset_path);
65
67 void Release();
68
75 virtual void PreloadMapArea(const Eigen::Vector3d& location,
76 const Eigen::Vector3d& trans_diff,
77 unsigned int resolution_id, unsigned int zone_id);
84 virtual bool LoadMapArea(const Eigen::Vector3d& seed_pt3d,
85 unsigned int resolution_id, unsigned int zone_id,
86 int filter_size_x, int filter_size_y);
87
90
92 bool CheckMap();
94 bool CheckMapStrictly();
95
97 inline const BaseMapConfig& GetMapConfig() const { return *map_config_; }
99 inline BaseMapConfig& GetMapConfig() { return *map_config_; }
101 inline const std::vector<std::string>& GetAllMapNodePaths() const {
102 return all_map_node_paths_;
103 }
105 inline const std::vector<std::string>& GetAllMapNodeMd5s() const {
106 return all_map_node_md5s_;
107 }
108
109 protected:
111 MapNodeIndex GetMapIndexFromMapPath(const std::string& map_path);
112
113 protected:
115 void LoadMapNodes(std::set<MapNodeIndex>* map_ids);
117 void PreloadMapNodes(std::set<MapNodeIndex>* map_ids);
119 void LoadMapNodeThreadSafety(const MapNodeIndex& index,
120 bool is_reserved = false);
122 void CheckAndUpdateCache(std::set<MapNodeIndex>* map_ids);
123
126
130 std::unique_ptr<MapNodeCache<MapNodeIndex, BaseMapNode>>
133 std::unique_ptr<MapNodeCache<MapNodeIndex, BaseMapNode>>
138 std::set<MapNodeIndex> map_preloading_task_index_;
140 boost::recursive_mutex map_load_mutex_;
141
143 std::vector<MapNodeIndex> all_map_node_indices_;
144 std::vector<std::string> all_map_node_paths_;
145
147 std::vector<std::string> all_map_node_md5s_;
148};
149
150} // namespace pyramid_map
151} // namespace msf
152} // namespace localization
153} // namespace apollo
std::function< bool(Element *)> DestroyFunc
The memory pool for the data structure of BaseMapNode.
The data structure of a Node in the map.
The data structure of the base map.
Definition base_map.h:38
BaseMapConfig & GetMapConfig()
Get the map config.
Definition base_map.h:99
std::vector< std::string > all_map_node_md5s_
All the map nodes' md5 in the Map (in the disk).
Definition base_map.h:147
bool SetMapFolderPath(const std::string folder_path)
Set the directory of the map.
Definition base_map.cc:106
void PreloadMapNodes(std::set< MapNodeIndex > *map_ids)
Load map node by index.
Definition base_map.cc:181
BaseMapNode * GetMapNodeSafe(const MapNodeIndex &index)
Return the map node, if it's not in the cache, safely load it.
Definition base_map.cc:63
void AddDataset(const std::string dataset_path)
Add a dataset path to the map config.
Definition base_map.cc:117
bool CheckMapStrictly()
Check if map is normal(with map node checking).
Definition base_map.cc:552
BaseMapConfig * map_config_
The map settings.
Definition base_map.h:125
const std::vector< std::string > & GetAllMapNodeMd5s() const
Get all map node md5s.
Definition base_map.h:105
MapNodeCache< MapNodeIndex, BaseMapNode >::DestroyFunc destroy_func_lvl1_
Definition base_map.h:127
void LoadMapNodeThreadSafety(const MapNodeIndex &index, bool is_reserved=false)
Load map node by index, thread_safety.
Definition base_map.cc:228
boost::recursive_mutex map_load_mutex_
The mutex for preload map node.
Definition base_map.h:140
std::vector< MapNodeIndex > all_map_node_indices_
All the map nodes in the Map (in the disk).
Definition base_map.h:143
std::unique_ptr< MapNodeCache< MapNodeIndex, BaseMapNode > > map_node_cache_lvl2_
brief The dynamic map node preloading thread pool pointer.
Definition base_map.h:134
BaseMapNode * GetMapNode(const MapNodeIndex &index)
Return the map node, if it's not in the cache, return false.
Definition base_map.cc:57
virtual void InitMapNodeCaches(int cacheL1_size, int cahceL2_size)
Definition base_map.cc:40
const BaseMapConfig & GetMapConfig() const
Get the map config.
Definition base_map.h:97
std::unique_ptr< MapNodeCache< MapNodeIndex, BaseMapNode > > map_node_cache_lvl1_
The cache for map node preload.
Definition base_map.h:131
MapNodeCache< MapNodeIndex, BaseMapNode >::DestroyFunc destroy_func_lvl2_
Definition base_map.h:128
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.
Definition base_map.cc:394
BaseMapNodePool * map_node_pool_
The map node memory pool pointer.
Definition base_map.h:136
bool CheckMap()
Check if map is normal.
Definition base_map.cc:533
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.
Definition base_map.cc:263
bool IsMapNodeExist(const MapNodeIndex &index)
Check if the map node in the cache.
Definition base_map.cc:99
MapNodeIndex GetMapIndexFromMapPath(const std::string &map_path)
Definition base_map.cc:490
const std::vector< std::string > & GetAllMapNodePaths() const
Get all map node paths.
Definition base_map.h:101
void CheckAndUpdateCache(std::set< MapNodeIndex > *map_ids)
Check map node in L2 Cache.
Definition base_map.cc:164
void AttachMapNodePool(BaseMapNodePool *p_map_node_pool)
Attach map node pointer.
Definition base_map.cc:53
std::vector< std::string > all_map_node_paths_
Definition base_map.h:144
void LoadMapNodes(std::set< MapNodeIndex > *map_ids)
Load map node by index.
Definition base_map.cc:123
void ComputeMd5ForAllMapNodes()
Compute md5 for all map node file in map.
Definition base_map.cc:522
std::set< MapNodeIndex > map_preloading_task_index_
@bried Keep the index of preloading nodes.
Definition base_map.h:138
class register implement
Definition arena_queue.h:37