Apollo  6.0
Open source self driving car software
base_map.h
Go to the documentation of this file.
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 #pragma once
18 
19 #include <list>
20 #include <set>
21 #include <string>
22 
29 
30 namespace apollo {
31 namespace localization {
32 namespace msf {
33 
35 class BaseMap {
36  public:
38  explicit BaseMap(BaseMapConfig* map_config);
40  virtual ~BaseMap();
41 
43  virtual void InitMapNodeCaches(int cacheL1_size, int cahceL2_size);
44 
46  BaseMapNode* GetMapNode(const MapNodeIndex& index);
50  bool IsMapNodeExist(const MapNodeIndex& index) const;
51 
53  bool SetMapFolderPath(const std::string folder_path);
55  void AddDataset(const std::string dataset_path);
56 
63  virtual void PreloadMapArea(const Eigen::Vector3d& location,
64  const Eigen::Vector3d& trans_diff,
65  unsigned int resolution_id, unsigned int zone_id);
71  virtual bool LoadMapArea(const Eigen::Vector3d& seed_pt3d,
72  unsigned int resolution_id, unsigned int zone_id,
73  int filter_size_x, int filter_size_y);
74 
76  void AttachMapNodePool(BaseMapNodePool* p_map_node_pool);
77 
83  void WriteBinary(FILE* file);
89  void LoadBinary(FILE* file, std::string map_folder_path = "");
90 
92  inline const BaseMapConfig& GetConfig() const { return *map_config_; }
94  inline BaseMapConfig& GetConfig() { return *map_config_; }
95 
96  protected:
98  void LoadMapNodes(std::set<MapNodeIndex>* map_ids);
100  void PreloadMapNodes(std::set<MapNodeIndex>* map_ids);
102  void LoadMapNodeThreadSafety(MapNodeIndex index, bool is_reserved = false);
103 
107  std::list<MapNodeIndex> map_nodes_disk_;
108 
118  std::set<MapNodeIndex> map_preloading_task_index_;
120  boost::recursive_mutex map_load_mutex_;
121 };
122 
123 } // namespace msf
124 } // namespace localization
125 } // namespace apollo
The data structure of the base map.
Definition: base_map.h:35
The data structure of the LRUCache.
Definition: base_map_cache.h:33
BaseMapNodePool * map_node_pool_
The map node memory pool pointer.
Definition: base_map.h:116
BaseMapNode * GetMapNodeSafe(const MapNodeIndex &index)
Return the map node, if it&#39;s not in the cache, safely load it.
The options of the reflectance map.
Definition: base_map_config.h:32
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
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...
virtual ~BaseMap()
The destructor.
void PreloadMapNodes(std::set< MapNodeIndex > *map_ids)
Load map node by index.
BaseMapNode * GetMapNode(const MapNodeIndex &index)
Get the map node, if it&#39;s not in the cache, return false.
boost::recursive_mutex map_load_mutex_
The mutex for preload map node.
Definition: base_map.h:120
std::set< MapNodeIndex > map_preloading_task_index_
Definition: base_map.h:118
MapNodeCache< MapNodeIndex, BaseMapNode >::DestroyFunc destroy_func_lvl1_
Definition: base_map.h:109
void AddDataset(const std::string dataset_path)
Add a dataset path to the map config.
void WriteBinary(FILE *file)
Write all the map nodes to a single binary file stream. It&#39;s for binary streaming or packing...
The memory pool for the data structure of BaseMapNode.
Definition: base_map_pool.h:32
Eigen::Vector3d Vector3d
Definition: frame_transform.h:27
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...
BaseMap(BaseMapConfig *map_config)
The constructor.
void LoadBinary(FILE *file, std::string map_folder_path="")
Load all the map nodes from a single binary file stream. It&#39;s for binary streaming or packing...
BaseMapConfig * map_config_
The map settings.
Definition: base_map.h:105
const BaseMapConfig & GetConfig() const
Get the map config.
Definition: base_map.h:92
std::function< bool(Element *)> DestroyFunc
Definition: base_map_cache.h:35
bool IsMapNodeExist(const MapNodeIndex &index) const
Check if the map node in the cache.
MapNodeCache< MapNodeIndex, BaseMapNode > * map_node_cache_lvl1_
The cache for map node preload.
Definition: base_map.h:112
virtual void InitMapNodeCaches(int cacheL1_size, int cahceL2_size)
Init load threadpool and preload threadpool.
MapNodeCache< MapNodeIndex, BaseMapNode > * map_node_cache_lvl2_
Definition: base_map.h:114
MapNodeCache< MapNodeIndex, BaseMapNode >::DestroyFunc destroy_func_lvl2_
Definition: base_map.h:110
void LoadMapNodeThreadSafety(MapNodeIndex index, bool is_reserved=false)
Load map node by index, thread_safety.
BaseMapConfig & GetConfig()
Get the map config.
Definition: base_map.h:94
void AttachMapNodePool(BaseMapNodePool *p_map_node_pool)
Attach map node pointer.
std::list< MapNodeIndex > map_nodes_disk_
All the map nodes in the Map (in the disk).
Definition: base_map.h:107
bool SetMapFolderPath(const std::string folder_path)
Set the directory of the map.
Definition: base_map_node_index.h:32
The data structure of a Node in the map.
Definition: base_map_node.h:32
void LoadMapNodes(std::set< MapNodeIndex > *map_ids)
Load map node by index.