Apollo  6.0
Open source self driving car software
base_map_node.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 <string>
20 #include <vector>
21 
26 
27 namespace apollo {
28 namespace localization {
29 namespace msf {
30 
32 class BaseMapNode {
33  public:
35  BaseMapNode(BaseMapMatrix* matrix, CompressionStrategy* strategy);
37  virtual ~BaseMapNode();
38 
40  virtual void Init(const BaseMapConfig* map_config, const MapNodeIndex& index,
41  bool create_map_cells = true);
43  virtual void InitMapMatrix(const BaseMapConfig* map_config);
45  virtual void Finalize();
47  virtual void ResetMapNode();
48 
50  bool Save();
52  bool SaveIntensityImage() const;
54  bool Load();
55  bool Load(const char* filename);
56 
57  // /**@brief Set compression strategy. */
58  // void SetCompressionStrategy(compression::CompressionStrategy* strategy);
60  inline const BaseMapMatrix& GetMapCellMatrix() const { return *map_matrix_; }
61 
63 
65  inline const BaseMapConfig& GetMapConfig() const { return *map_config_; }
67  inline void SetMapNodeIndex(const MapNodeIndex& index) { index_ = index; }
69  inline const MapNodeIndex& GetMapNodeIndex() const { return index_; }
71  inline void SetIsReserved(bool is_reserved) { is_reserved_ = is_reserved; }
73  inline bool GetIsReserved() const { return is_reserved_; }
75  inline bool GetIsChanged() const { return is_changed_; }
77  inline void SetIsChanged(bool is) { is_changed_ = is; }
79  inline bool GetIsReady() const { return data_is_ready_; }
81  // inline const idl::car::core::numerical::Vector2D& GetLeftTopCorner()
82  // const {
83  // return left_top_corner_;
84  // }
85 
86  inline const Eigen::Vector2d& GetLeftTopCorner() const {
87  return left_top_corner_;
88  }
89 
90  inline void SetLeftTopCorner(double x, double y) {
91  // left_top_corner_[0] = x;
92  // left_top_corner_[1] = y;
93 
94  left_top_corner_[0] = x;
95  left_top_corner_[1] = y;
96  }
98  inline float GetMapResolution() const {
100  }
104  // bool GetCoordinate(const idl::car::core::numerical::Vector2D& coordinate,
105  // unsigned int& x, unsigned int& y) const;
106  // bool GetCoordinate(const idl::car::core::numerical::Vector3D& coordinate,
107  // unsigned int& x, unsigned int& y) const;
109  // idl::car::core::numerical::Vector2D GetCoordinate(unsigned int x, unsigned
110  // int y) const;
111 
115  bool GetCoordinate(const Eigen::Vector2d& coordinate, unsigned int* x,
116  unsigned int* y) const;
117  bool GetCoordinate(const Eigen::Vector3d& coordinate, unsigned int* x,
118  unsigned int* y) const;
121  Eigen::Vector2d GetCoordinate(unsigned int x, unsigned int y) const;
122 
123  // static idl::car::core::numerical::Vector2D GetLeftTopCorner(const
124  // BaseMapConfig& option,
125  // const MapNodeIndex&
126  // index);
127  static Eigen::Vector2d GetLeftTopCorner(const BaseMapConfig& option,
128  const MapNodeIndex& index);
129 
130  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
131 
132  protected:
136  virtual unsigned int LoadBinary(FILE* file);
140  virtual unsigned int CreateBinary(FILE* file) const;
142  virtual unsigned int GetBinarySize() const;
146  virtual unsigned int LoadHeaderBinary(unsigned char* buf);
151  virtual unsigned int CreateHeaderBinary(unsigned char* buf,
152  unsigned int buf_size) const;
154  virtual unsigned int GetHeaderBinarySize() const;
158  virtual unsigned int LoadBodyBinary(std::vector<unsigned char>* buf);
163  virtual unsigned int CreateBodyBinary(std::vector<unsigned char>* buf) const;
165  virtual unsigned int GetBodyBinarySize() const;
167  bool SaveIntensityImage(const std::string& path) const;
168 
170  const BaseMapConfig* map_config_ = nullptr;
175  // idl::car::core::numerical::Vector2D left_top_corner_;
180  bool is_reserved_ = false;
182  bool is_changed_ = false;
183  /* *@brief Indicate map node data is ready*/
184  bool data_is_ready_ = false;
187  mutable unsigned int file_body_binary_size_ = 0;
191  float min_altitude_ = 1e6;
192 };
193 
194 } // namespace msf
195 } // namespace localization
196 } // namespace apollo
virtual unsigned int CreateBodyBinary(std::vector< unsigned char > *buf) const
Create the binary body.
void SetMapNodeIndex(const MapNodeIndex &index)
Set the map node index.
Definition: base_map_node.h:67
virtual void Finalize()
call before deconstruction or reset.
virtual void InitMapMatrix(const BaseMapConfig *map_config)
Initialize the map matrix.
CompressionStrategy * compression_strategy_
Definition: base_map_node.h:189
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
BaseMapNode(BaseMapMatrix *matrix, CompressionStrategy *strategy)
Construct a map node.
bool is_changed_
Has the map node been changed.
Definition: base_map_node.h:182
bool GetIsReserved() const
Get if the map node is reserved.
Definition: base_map_node.h:73
bool data_is_ready_
Definition: base_map_node.h:184
Eigen::Vector2d Vector2d
Definition: base_map_fwd.h:36
bool Save()
Save the map node to the disk.
Eigen::Vector3d Vector3d
Definition: frame_transform.h:27
virtual unsigned int CreateBinary(FILE *file) const
Create the binary. Serialization of the object.
const BaseMapConfig & GetMapConfig() const
Get the map settings.
Definition: base_map_node.h:65
virtual unsigned int LoadBinary(FILE *file)
Load the map cell from a binary chunk.
Eigen::Vector2d left_top_corner_
The left top corner of the map node in the global coordinate system.
Definition: base_map_node.h:176
bool GetIsReady() const
Get if the map node data is ready.
Definition: base_map_node.h:79
virtual unsigned int LoadHeaderBinary(unsigned char *buf)
Load the map node header from a binary chunk.
bool GetCoordinate(const Eigen::Vector2d &coordinate, unsigned int *x, unsigned int *y) const
Given the global coordinate, get the local 2D coordinate of the map cell matrix. <return> If global c...
virtual unsigned int GetBodyBinarySize() const
Get the size of the body in bytes.
virtual unsigned int GetHeaderBinarySize() const
Get the size of the header in bytes.
void SetIsReserved(bool is_reserved)
Set if the map node is reserved.
Definition: base_map_node.h:71
std::vector< float > map_resolutions_
The pixel resolutions in the map in meters.
Definition: base_map_config.h:50
virtual void ResetMapNode()
Reset map cells data.
The data structure of the map cells in a map node.
Definition: base_map_matrix.h:28
MapNodeIndex index_
The index of this node.
Definition: base_map_node.h:172
float GetMapResolution() const
Get the resolution of this map nodex.
Definition: base_map_node.h:98
const MapNodeIndex & GetMapNodeIndex() const
Get the map node index.
Definition: base_map_node.h:69
bool is_reserved_
If the node is reserved in map.
Definition: base_map_node.h:180
virtual ~BaseMapNode()
Destruct a map node.
BaseMapMatrix & GetMapCellMatrix()
Definition: base_map_node.h:62
virtual unsigned int GetBinarySize() const
Get the binary size of the object.
bool GetIsChanged() const
Get if the map data has changed.
Definition: base_map_node.h:75
virtual void Init(const BaseMapConfig *map_config, const MapNodeIndex &index, bool create_map_cells=true)
Initialize the map node. Call this function first before use it!
BaseMapMatrix * map_matrix_
The data structure of the map datas, which is a matrix.
Definition: base_map_node.h:178
bool SaveIntensityImage() const
Save intensity image of node.
virtual unsigned int CreateHeaderBinary(unsigned char *buf, unsigned int buf_size) const
Create the binary header.
bool Load()
Load the map node from the disk.
const BaseMapConfig * map_config_
The map settings.
Definition: base_map_node.h:170
virtual unsigned int LoadBodyBinary(std::vector< unsigned char > *buf)
Load the map node body from a binary chunk.
void SetIsChanged(bool is)
Set if the map node data has changed.
Definition: base_map_node.h:77
const BaseMapMatrix & GetMapCellMatrix() const
Set compression strategy.
Definition: base_map_node.h:60
const Eigen::Vector2d & GetLeftTopCorner() const
Get the left top corner of the map node.
Definition: base_map_node.h:86
float min_altitude_
The min altitude of point cloud in the node.
Definition: base_map_node.h:191
Definition: base_map_node_index.h:32
The data structure of a Node in the map.
Definition: base_map_node.h:32
void SetLeftTopCorner(double x, double y)
Definition: base_map_node.h:90
unsigned int file_body_binary_size_
The body binary size in file. It&#39;s useful when reading and writing files.
Definition: base_map_node.h:187
unsigned int resolution_id_
The ID of the resolution. Should be less than BaseMapConfig::map_resolutions_.size().
Definition: base_map_node_index.h:79