Apollo 10.0
自动驾驶开放平台
apollo::localization::msf::pyramid_map::LossyMapFullAltMatrixHandler类 参考

#include <pyramid_map_matrix_handler.h>

类 apollo::localization::msf::pyramid_map::LossyMapFullAltMatrixHandler 继承关系图:
apollo::localization::msf::pyramid_map::LossyMapFullAltMatrixHandler 的协作图:

Public 成员函数

 LossyMapFullAltMatrixHandler ()
 
 ~LossyMapFullAltMatrixHandler ()
 
virtual size_t LoadBinary (const unsigned char *buf, std::shared_ptr< BaseMapMatrix > matrix)
 Load the map cell from a binary chunk.
 
virtual size_t CreateBinary (const std::shared_ptr< BaseMapMatrix > matrix, unsigned char *buf, size_t buf_size)
 Create the binary.
 
virtual size_t GetBinarySize (const std::shared_ptr< BaseMapMatrix > matrix)
 Get the binary size of the object.
 
- Public 成员函数 继承自 apollo::localization::msf::pyramid_map::LossyMapMatrixHandler
 LossyMapMatrixHandler ()
 
virtual ~LossyMapMatrixHandler ()
 
- Public 成员函数 继承自 apollo::localization::msf::pyramid_map::BaseMapMatrixHandler
 BaseMapMatrixHandler ()
 
virtual ~BaseMapMatrixHandler ()
 

额外继承的成员函数

- Protected 成员函数 继承自 apollo::localization::msf::pyramid_map::LossyMapMatrixHandler
virtual unsigned char EncodeIntensity (float intensity) const
 
virtual void DecodeIntensity (unsigned char data, float *intensity) const
 
virtual uint16_t EncodeIntensityVar (float var) const
 
virtual void DecodeIntensityVar (uint16_t data, float *var) const
 
virtual uint16_t EncodeAltitude (float altitude, float min_altitude, float altitude_interval) const
 
virtual void DecodeAltitude (uint16_t data, float min_altitude, float altitude_interval, float *altitude) const
 
virtual unsigned char EncodeCount (unsigned int count, unsigned int count_range) const
 
virtual void DecodeCount (unsigned char data, unsigned int *count) const
 
- Protected 属性 继承自 apollo::localization::msf::pyramid_map::LossyMapMatrixHandler
const unsigned int var_range_ = 1023
 
const unsigned int var_ratio_ = 4
 
const unsigned int count_range_ = 2
 
const float ground_alt_interval_ = 0.04f
 
const float alt_avg_interval_ = 0.04f
 
float alt_avg_min_ = 0.0f
 
float ground_alt_min_ = 0.0f
 
float alt_avg_max_ = 0.0f
 
float ground_alt_max_ = 0.0f
 

详细描述

在文件 pyramid_map_matrix_handler.h64 行定义.

构造及析构函数说明

◆ LossyMapFullAltMatrixHandler()

apollo::localization::msf::pyramid_map::LossyMapFullAltMatrixHandler::LossyMapFullAltMatrixHandler ( )

在文件 pyramid_map_matrix_handler.cc138 行定义.

138{}

◆ ~LossyMapFullAltMatrixHandler()

apollo::localization::msf::pyramid_map::LossyMapFullAltMatrixHandler::~LossyMapFullAltMatrixHandler ( )

在文件 pyramid_map_matrix_handler.cc140 行定义.

140{}

成员函数说明

◆ CreateBinary()

size_t apollo::localization::msf::pyramid_map::LossyMapFullAltMatrixHandler::CreateBinary ( const std::shared_ptr< BaseMapMatrix matrix,
unsigned char *  buf,
size_t  buf_size 
)
virtual

Create the binary.

Serialization of the object.

参数
<buf,buf_size>The buffer and its size.
<return>The required or the used size of is returned.

实现了 apollo::localization::msf::pyramid_map::BaseMapMatrixHandler.

在文件 pyramid_map_matrix_handler.cc256 行定义.

258 {
259 const std::shared_ptr<PyramidMapMatrix> matrix =
260 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
261
262 size_t target_size = GetBinarySize(matrix);
263 if (buf_size >= target_size) {
264 unsigned int rows = matrix->GetRowsSafe();
265 unsigned int cols = matrix->GetColsSafe();
266 unsigned int matrix_size = rows * cols;
267
268 unsigned int* uint_p = reinterpret_cast<unsigned int*>(buf);
269 *uint_p = rows;
270 ++uint_p;
271 *uint_p = cols;
272 ++uint_p;
273 // buf_size -= sizeof(unsigned int) * 2;
274
275 float* float_p = reinterpret_cast<float*>(reinterpret_cast<void*>(uint_p));
276 if (matrix->HasAltitude() && matrix->HasCount()) {
277 alt_avg_min_ = 1e8;
278 alt_avg_max_ = -1e8;
279 for (unsigned int y = 0; y < rows; ++y) {
280 for (unsigned int x = 0; x < cols; ++x) {
281 const float* altitude = matrix->GetAltitudeSafe(y, x);
282 const unsigned int* count = matrix->GetCountSafe(y, x);
283 if (*count == 0) {
284 continue;
285 }
286
287 if (*altitude < alt_avg_min_) {
288 alt_avg_min_ = *altitude;
289 }
290 if (*altitude > alt_avg_max_) {
291 alt_avg_max_ = *altitude;
292 }
293 }
294 }
295 } else {
296 alt_avg_min_ = 0.0;
297 alt_avg_max_ = 0.0;
298 }
299
300 if (matrix->HasGroundAltitude() && matrix->HasGroundCount()) {
301 ground_alt_min_ = 1e8;
302 ground_alt_max_ = -1e8;
303 for (unsigned int y = 0; y < rows; ++y) {
304 for (unsigned int x = 0; x < cols; ++x) {
305 const float* ground_altitude = matrix->GetGroundAltitudeSafe(y, x);
306 const unsigned int* ground_count = matrix->GetGroundCountSafe(y, x);
307 if (*ground_count == 0) {
308 continue;
309 }
310 if (*ground_altitude < ground_alt_min_) {
311 ground_alt_min_ = *ground_altitude;
312 }
313 if (*ground_altitude > ground_alt_max_) {
314 ground_alt_max_ = *ground_altitude;
315 }
316 }
317 }
318 } else {
319 ground_alt_min_ = 0.0;
320 ground_alt_max_ = 0.0;
321 }
322
323 *float_p = alt_avg_min_;
324 ++float_p;
325 *float_p = alt_avg_max_;
326 ++float_p;
327 *float_p = ground_alt_min_;
328 ++float_p;
329 *float_p = ground_alt_max_;
330 ++float_p;
331 // buf_size -= sizeof(float) * 4;
332
333 unsigned char* uc_p = reinterpret_cast<unsigned char*>(float_p);
334 // unsigned int processed_size = 0;
335
336 // count
337 for (unsigned int r = 0; r < rows; ++r) {
338 for (unsigned int c = 0; c < cols; ++c) {
339 const unsigned int* count = matrix->GetCountSafe(r, c);
340 unsigned int ct = (count != nullptr) ? *count : 0;
341 uc_p[r * cols + c] = EncodeCount(ct, count_range_);
342 }
343 }
344 uc_p += matrix_size;
345 // processed_size += matrix_size * sizeof(unsigned char);
346
347 // intensity
348 for (unsigned int r = 0; r < rows; ++r) {
349 for (unsigned int c = 0; c < cols; ++c) {
350 const float* intensity =
351 static_cast<const float*>(matrix->GetIntensitySafe(r, c));
352 float ity = (intensity != nullptr) ? *intensity : 0.0f;
353 uc_p[r * cols + c] = EncodeIntensity(ity);
354 }
355 }
356 uc_p += matrix_size;
357 // processed_size += matrix_size * sizeof(unsigned char);
358
359 // intensiy
360 unsigned char* p_low = uc_p + matrix_size;
361 unsigned char* p_high = uc_p;
362 for (unsigned int r = 0; r < rows; ++r) {
363 for (unsigned int c = 0; c < cols; ++c) {
364 const float* intensity_var =
365 static_cast<const float*>(matrix->GetIntensityVarSafe(r, c));
366 float iv = (intensity_var != nullptr) ? *intensity_var : 0.0f;
367 uint16_t var = EncodeIntensityVar(iv);
368 p_high[r * cols + c] = static_cast<uint8_t>(var / 256);
369 p_low[r * cols + c] = static_cast<uint8_t>(var % 256);
370 }
371 }
372 uc_p += 2 * matrix_size;
373 // processed_size += matrix_size * sizeof(uint16_t);
374
375 // altitude
376 p_low = uc_p + matrix_size;
377 p_high = uc_p;
378 for (unsigned int r = 0; r < rows; ++r) {
379 for (unsigned int c = 0; c < cols; ++c) {
380 const float* altitude = matrix->GetAltitudeSafe(r, c);
381 float a = (altitude != nullptr) ? *altitude : 0.0f;
383 p_high[r * cols + c] = static_cast<unsigned char>(alt / 256);
384 p_low[r * cols + c] = static_cast<unsigned char>(alt % 256);
385 }
386 }
387 uc_p += 2 * matrix_size;
388 // processed_size += matrix_size * sizeof(uint16_t);
389
390 // ground altitude
391 p_low = uc_p + matrix_size;
392 p_high = uc_p;
393 for (unsigned int r = 0; r < rows; ++r) {
394 for (unsigned int c = 0; c < cols; ++c) {
395 const float* ground_altitude = matrix->GetGroundAltitudeSafe(r, c);
396 float ga = (ground_altitude != nullptr) ? *ground_altitude : 0.0f;
397 uint16_t alt =
399 p_high[r * cols + c] = static_cast<unsigned char>(alt / 256);
400 p_low[r * cols + c] = static_cast<unsigned char>(alt % 256);
401 }
402 }
403 uc_p += 2 * matrix_size;
404 // processed_size += matrix_size * sizeof(uint16_t);
405
406 // assert(buf_size >= processed_size);
407 // buf_size -= processed_size;
408 return target_size;
409 }
410
411 return 0;
412}
virtual size_t GetBinarySize(const std::shared_ptr< BaseMapMatrix > matrix)
Get the binary size of the object.
virtual unsigned char EncodeCount(unsigned int count, unsigned int count_range) const
virtual uint16_t EncodeAltitude(float altitude, float min_altitude, float altitude_interval) const

◆ GetBinarySize()

size_t apollo::localization::msf::pyramid_map::LossyMapFullAltMatrixHandler::GetBinarySize ( const std::shared_ptr< BaseMapMatrix matrix)
virtual

Get the binary size of the object.

实现了 apollo::localization::msf::pyramid_map::BaseMapMatrixHandler.

在文件 pyramid_map_matrix_handler.cc414 行定义.

415 {
416 const std::shared_ptr<PyramidMapMatrix> matrix =
417 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
418 // assert(matrix->get_resolution_num() > 0);
419 if (matrix->GetResolutionNum() == 0) {
420 throw "[LossyMapFullAltMatrixHandler::get_binary_size]"
421 "matrix->get_resolution_num() == 0";
422 }
423
424 // rows and cols
425 // altitude min max & ground altitude min max
426 size_t target_size = sizeof(unsigned int) * 2 + sizeof(float) * 4;
427 // count, intensity, intensity_var, altitude_avg, altitude_ground
428 target_size += matrix->GetRowsSafe() * matrix->GetColsSafe() *
429 (sizeof(unsigned char) + sizeof(unsigned char) +
430 sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t));
431 return target_size;
432}

◆ LoadBinary()

size_t apollo::localization::msf::pyramid_map::LossyMapFullAltMatrixHandler::LoadBinary ( const unsigned char *  buf,
std::shared_ptr< BaseMapMatrix matrix 
)
virtual

Load the map cell from a binary chunk.

参数
<return>The size read (the real size of object).

实现了 apollo::localization::msf::pyramid_map::BaseMapMatrixHandler.

在文件 pyramid_map_matrix_handler.cc142 行定义.

143 {
144 std::shared_ptr<PyramidMapMatrix> matrix =
145 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
146
147 size_t binary_size = sizeof(unsigned int) * 2;
148 const unsigned int* uint_p = reinterpret_cast<const unsigned int*>(buf);
149 unsigned int rows = *uint_p; // rows in first level
150 ++uint_p;
151 unsigned int cols = *uint_p; // cols in first level
152 ++uint_p;
153
154 // reset or init matrix
155 if ( // matrix->get_resolution_num() == 1 &&
156 // matrix->get_resolution_ratio() == 2 &&
157 rows == matrix->GetRows() && cols == matrix->GetCols() &&
158 matrix->HasIntensity() && matrix->HasIntensityVar() &&
159 matrix->HasAltitude() && matrix->HasGroundAltitude() &&
160 matrix->HasCount()) {
161 matrix->Reset();
162 } else {
163 matrix->Init(rows, cols, true, true, true, false, true, true, false);
164 }
165
166 // alt min max & ground alt min max
167 binary_size += sizeof(float) * 4;
168 const float* float_p =
169 reinterpret_cast<const float*>(reinterpret_cast<const void*>(uint_p));
170 alt_avg_min_ = *float_p;
171 ++float_p;
172 alt_avg_max_ = *float_p;
173 ++float_p;
174 ground_alt_min_ = *float_p;
175 ++float_p;
176 ground_alt_max_ = *float_p;
177 ++float_p;
178
179 // load matrix
180 const unsigned char* uc_p = reinterpret_cast<const unsigned char*>(float_p);
181 unsigned int matrix_size = rows * cols;
182
183 if (matrix->HasCount()) {
184 binary_size += sizeof(unsigned char) * matrix_size;
185 UIntMatrix* count_matrix = matrix->GetCountMatrixSafe();
186 for (unsigned int r = 0; r < rows; ++r) {
187 for (unsigned int c = 0; c < cols; ++c) {
188 DecodeCount(uc_p[r * cols + c], &(*count_matrix)[r][c]);
189 }
190 }
191 uc_p += matrix_size;
192 }
193
194 if (matrix->HasIntensity()) {
195 binary_size += sizeof(unsigned char) * matrix_size;
196 FloatMatrix* intensity_matrix = matrix->GetIntensityMatrixSafe();
197 for (unsigned int r = 0; r < rows; ++r) {
198 for (unsigned int c = 0; c < cols; ++c) {
199 DecodeIntensity(uc_p[r * cols + c], &(*intensity_matrix)[r][c]);
200 }
201 }
202 uc_p += matrix_size;
203 }
204
205 if (matrix->HasIntensityVar()) {
206 binary_size += sizeof(uint16_t) * matrix_size;
207 FloatMatrix* intensity_var_matrix = matrix->GetIntensityVarMatrixSafe();
208 const unsigned char* p_low = uc_p + matrix_size;
209 const unsigned char* p_high = uc_p;
210 for (unsigned int r = 0; r < rows; ++r) {
211 for (unsigned int c = 0; c < cols; ++c) {
212 unsigned int var = static_cast<unsigned int>(p_high[r * cols + c]);
213 var = var * 256u + static_cast<unsigned int>(p_low[r * cols + c]);
214 DecodeIntensityVar(static_cast<uint16_t>(var),
215 &(*intensity_var_matrix)[r][c]);
216 }
217 }
218 uc_p += 2 * matrix_size;
219 }
220
221 if (matrix->HasAltitude()) {
222 binary_size += sizeof(uint16_t) * matrix_size;
223 FloatMatrix* altitude_matrix = matrix->GetAltitudeMatrixSafe();
224 const unsigned char* p_low = uc_p + matrix_size;
225 const unsigned char* p_high = uc_p;
226 for (unsigned int r = 0; r < rows; ++r) {
227 for (unsigned int c = 0; c < cols; ++c) {
228 unsigned int alt = static_cast<unsigned int>(p_high[r * cols + c]);
229 alt = alt * 256u + static_cast<unsigned int>(p_low[r * cols + c]);
230 DecodeAltitude(static_cast<uint16_t>(alt), alt_avg_min_,
231 alt_avg_interval_, &(*altitude_matrix)[r][c]);
232 }
233 }
234 uc_p += 2 * matrix_size;
235 }
236
237 if (matrix->HasGroundAltitude()) {
238 binary_size += sizeof(uint16_t) * matrix_size;
239 FloatMatrix* ground_altitude_matrix = matrix->GetGroundAltitudeMatrixSafe();
240 const unsigned char* p_low = uc_p + matrix_size;
241 const unsigned char* p_high = uc_p;
242 for (unsigned int r = 0; r < rows; ++r) {
243 for (unsigned int c = 0; c < cols; ++c) {
244 unsigned int alt = static_cast<unsigned int>(p_high[r * cols + c]);
245 alt = alt * 256u + static_cast<unsigned int>(p_low[r * cols + c]);
246 DecodeAltitude(static_cast<uint16_t>(alt), ground_alt_min_,
247 ground_alt_interval_, &(*ground_altitude_matrix)[r][c]);
248 }
249 }
250 uc_p += 2 * matrix_size;
251 }
252
253 return binary_size;
254}
virtual void DecodeIntensity(unsigned char data, float *intensity) const
virtual void DecodeAltitude(uint16_t data, float min_altitude, float altitude_interval, float *altitude) const
virtual void DecodeCount(unsigned char data, unsigned int *count) const
AlignedMatrix< unsigned int > UIntMatrix

该类的文档由以下文件生成: