Apollo  6.0
Open source self driving car software
lossless_map_matrix.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 <vector>
20 
21 #include "cyber/common/log.h"
24 
25 namespace apollo {
26 namespace localization {
27 namespace msf {
28 
31 #define IDL_CAR_NUM_RESERVED_MAP_LAYER 2U
32 
37  inline void Reset();
39  void AddSample(const float new_altitude, const float new_intensity);
45  unsigned int LoadBinary(unsigned char* buf);
50  unsigned int CreateBinary(unsigned char* buf, unsigned int buf_size) const;
52  unsigned int GetBinarySize() const;
53 
55  float intensity;
59  float altitude;
61  float altitude_var;
63  unsigned int count;
64 };
65 
71  void Reset();
74  void SetValueLayer(double altitude, unsigned char intensity,
75  double altitude_thres = 10.0);
80  void SetValue(double altitude, unsigned char intensity);
84  unsigned int LoadBinary(unsigned char* buf);
89  unsigned int CreateBinary(unsigned char* buf, unsigned int buf_size) const;
91  unsigned int GetBinarySize() const;
92 
96  unsigned int GetLayerId(double altitude) const;
101  void GetValue(std::vector<unsigned char>* values) const;
103  void GetVar(std::vector<float>* vars) const;
105  void GetAlt(std::vector<float>* alts) const;
107  void GetAltVar(std::vector<float>* alt_vars) const;
109  void GetCount(std::vector<unsigned int>* counts) const;
111  inline unsigned char GetValue() const {
112  return static_cast<unsigned char>(map_cells[0].intensity);
113  }
115  inline float GetVar() const { return map_cells[0].intensity_var; }
117  inline float GetAlt() const { return map_cells[0].altitude; }
119  inline float GetAltVar() const { return map_cells[0].altitude_var; }
121  inline unsigned int GetCount() const { return map_cells[0].count; }
124  LosslessMapSingleCell& GetLayer(unsigned int layer_id) {
125  DCHECK_LT(layer_id, layer_num);
126  return map_cells[layer_id];
127  }
130  const LosslessMapSingleCell& GetLayer(unsigned int layer_id) const {
131  DCHECK_LT(layer_id, layer_num);
132  return map_cells[layer_id];
133  }
134 
136  unsigned int layer_num;
141 };
142 
144  public:
147  LosslessMapMatrix(const LosslessMapMatrix& matrix);
148 
149  virtual void Init(const BaseMapConfig* config);
151  virtual void Reset(const BaseMapConfig* config);
152 
153  void Init(unsigned int rows, unsigned int cols);
154  void Reset(unsigned int rows, unsigned int cols);
155 
159  virtual unsigned int LoadBinary(unsigned char* buf);
164  virtual unsigned int CreateBinary(unsigned char* buf,
165  unsigned int buf_size) const;
167  virtual unsigned int GetBinarySize() const;
169  virtual void GetIntensityImg(cv::Mat* intensity_img) const;
170 
172  inline const LosslessMapCell& GetMapCell(unsigned int row,
173  unsigned int col) const {
174  DCHECK_LT(row, rows_);
175  DCHECK_LT(col, cols_);
176  return map_cells_[row * cols_ + col];
177  }
179  inline LosslessMapCell& GetMapCell(unsigned int row, unsigned int col) {
180  DCHECK_LT(row, rows_);
181  DCHECK_LT(col, cols_);
182  return map_cells_[row * cols_ + col];
183  }
184 
185  inline LosslessMapCell* operator[](int row) {
186  return map_cells_ + row * cols_;
187  }
188  inline const LosslessMapCell* operator[](int row) const {
189  return map_cells_ + row * cols_;
190  }
191 
192  protected:
194  unsigned int rows_;
196  unsigned int cols_;
199 };
200 
201 } // namespace msf
202 } // namespace localization
203 } // namespace apollo
unsigned int rows_
The number of rows.
Definition: lossless_map_matrix.h:194
unsigned int GetBinarySize() const
Get the binary size of the object.
float GetVar() const
Get the variance of the intensity of the map cell.
Definition: lossless_map_matrix.h:115
The options of the reflectance map.
Definition: base_map_config.h:32
Definition: lossless_map_matrix.h:33
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
unsigned int CreateBinary(unsigned char *buf, unsigned int buf_size) const
Create the binary. Serialization of the object.
float intensity
The average intensity value.
Definition: lossless_map_matrix.h:55
unsigned int layer_num
The layers of the cell.
Definition: lossless_map_matrix.h:136
The multiple layers of the cell.
Definition: lossless_map_matrix.h:67
const LosslessMapCell & GetMapCell(unsigned int row, unsigned int col) const
Get a map cell.
Definition: lossless_map_matrix.h:172
LosslessMapCell * map_cells_
The matrix data structure.
Definition: lossless_map_matrix.h:198
The data structure of the map cells in a map node.
Definition: base_map_matrix.h:28
Definition: lossless_map_matrix.h:143
unsigned int cols_
The number of columns.
Definition: lossless_map_matrix.h:196
float intensity_var
The variance intensity value.
Definition: lossless_map_matrix.h:57
LosslessMapSingleCell()
The default constructor.
unsigned int LoadBinary(unsigned char *buf)
Load the map cell from a binary chunk.
const LosslessMapSingleCell & GetLayer(unsigned int layer_id) const
Get a perticular layer in the map cell. The layer 0 is the layer includes all the samples...
Definition: lossless_map_matrix.h:130
unsigned int count
The number of samples in the cell.
Definition: lossless_map_matrix.h:63
LosslessMapSingleCell & operator=(const LosslessMapSingleCell &ref)
Overloading the assign operator.
unsigned int GetCount() const
Get the count of the samples in the map cell.
Definition: lossless_map_matrix.h:121
float GetAltVar() const
Get the variance of the altitude of the map cell.
Definition: lossless_map_matrix.h:119
float altitude_var
The variance altitude value of the cell.
Definition: lossless_map_matrix.h:61
#define IDL_CAR_NUM_RESERVED_MAP_LAYER
The first layer (layer 0) includes all the intensities from any layers. Other layers only include the...
Definition: lossless_map_matrix.h:31
bool Init(const char *binary_name)
LosslessMapCell & GetMapCell(unsigned int row, unsigned int col)
Get a map cell.
Definition: lossless_map_matrix.h:179
void AddSample(const float new_altitude, const float new_intensity)
Add a sample.
unsigned char GetValue() const
Get the average intensity of the map cell.
Definition: lossless_map_matrix.h:111
LosslessMapSingleCell & GetLayer(unsigned int layer_id)
Get a particular layer in the map cell. The layer 0 is the layer includes all the samples...
Definition: lossless_map_matrix.h:124
const LosslessMapCell * operator[](int row) const
Definition: lossless_map_matrix.h:188
float altitude
The average altitude of the cell.
Definition: lossless_map_matrix.h:59
float GetAlt() const
Get the average altitude of the map cell.
Definition: lossless_map_matrix.h:117
LosslessMapCell * operator[](int row)
Definition: lossless_map_matrix.h:185