Apollo  6.0
Open source self driving car software
base_map.h
Go to the documentation of this file.
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 
32 namespace apollo {
33 namespace localization {
34 namespace msf {
35 namespace pyramid_map {
36 
38 class 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:
110  void GetAllMapIndexAndPath();
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
void PreloadMapNodes(std::set< MapNodeIndex > *map_ids)
Load map node by index.
virtual void InitMapNodeCaches(int cacheL1_size, int cahceL2_size)
MapNodeCache< MapNodeIndex, BaseMapNode >::DestroyFunc destroy_func_lvl2_
Definition: base_map.h:128
std::unique_ptr< MapNodeCache< MapNodeIndex, BaseMapNode > > map_node_cache_lvl2_
Definition: base_map.h:134
BaseMapNodePool * map_node_pool_
The map node memory pool pointer.
Definition: base_map.h:136
bool CheckMapStrictly()
Check if map is normal(with map node checking).
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
BaseMapConfig & GetMapConfig()
Get the map config.
Definition: base_map.h:99
std::vector< std::string > all_map_node_md5s_
All the map nodes&#39; md5 in the Map (in the disk).
Definition: base_map.h:147
void AddDataset(const std::string dataset_path)
Add a dataset path to the map config.
Eigen::Vector3d Vector3d
Definition: frame_transform.h:27
const std::vector< std::string > & GetAllMapNodeMd5s() const
Get all map node md5s.
Definition: base_map.h:105
MapNodeIndex GetMapIndexFromMapPath(const std::string &map_path)
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. It will forecasts the nodes by the directi...
bool CheckMap()
Check if map is normal.
BaseMapNode * GetMapNodeSafe(const MapNodeIndex &index)
Return the map node, if it&#39;s not in the cache, safely load it.
bool SetMapFolderPath(const std::string folder_path)
Set the directory of the map.
The memory pool for the data structure of BaseMapNode.
Definition: base_map_pool.h:34
std::function< bool(Element *)> DestroyFunc
Definition: base_map_cache.h:35
BaseMapNode * GetMapNode(const MapNodeIndex &index)
Return the map node, if it&#39;s not in the cache, return false.
std::vector< std::string > all_map_node_paths_
Definition: base_map.h:144
The data structure of a Node in the map.
Definition: base_map_node.h:37
bool IsMapNodeExist(const MapNodeIndex &index)
Check if the map node in the cache.
MapNodeCache< MapNodeIndex, BaseMapNode >::DestroyFunc destroy_func_lvl1_
Definition: base_map.h:127
void CheckAndUpdateCache(std::set< MapNodeIndex > *map_ids)
Check map node in L2 Cache.
BaseMap(BaseMapConfig *config)
The constructor.
std::unique_ptr< MapNodeCache< MapNodeIndex, BaseMapNode > > map_node_cache_lvl1_
The cache for map node preload.
Definition: base_map.h:131
void ComputeMd5ForAllMapNodes()
Compute md5 for all map node file in map.
const std::vector< std::string > & GetAllMapNodePaths() const
Get all map node paths.
Definition: base_map.h:101
The data structure of the base map.
Definition: base_map.h:38
void LoadMapNodes(std::set< MapNodeIndex > *map_ids)
Load map node by index.
boost::recursive_mutex map_load_mutex_
The mutex for preload map node.
Definition: base_map.h:140
The options of the reflectance map.
Definition: base_map_config.h:42
void LoadMapNodeThreadSafety(const MapNodeIndex &index, bool is_reserved=false)
Load map node by index, thread_safety.
std::set< MapNodeIndex > map_preloading_task_index_
Definition: base_map.h:138
Definition: base_map_node_index.h:33
const BaseMapConfig & GetMapConfig() const
Get the map config.
Definition: base_map.h:97
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. If the forecasts are correct in last frame...
BaseMapConfig * map_config_
The map settings.
Definition: base_map.h:125
void AttachMapNodePool(BaseMapNodePool *p_map_node_pool)
Attach map node pointer.
std::vector< MapNodeIndex > all_map_node_indices_
All the map nodes in the Map (in the disk).
Definition: base_map.h:143