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

#include <pyramid_map_matrix_handler.h>

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

Public 成员函数

 LosslessMapMatrixHandler ()
 
 ~LosslessMapMatrixHandler ()
 
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::BaseMapMatrixHandler
 BaseMapMatrixHandler ()
 
virtual ~BaseMapMatrixHandler ()
 

详细描述

在文件 pyramid_map_matrix_handler.h76 行定义.

构造及析构函数说明

◆ LosslessMapMatrixHandler()

apollo::localization::msf::pyramid_map::LosslessMapMatrixHandler::LosslessMapMatrixHandler ( )

在文件 pyramid_map_matrix_handler.cc435 行定义.

435{}

◆ ~LosslessMapMatrixHandler()

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

在文件 pyramid_map_matrix_handler.cc437 行定义.

437{}

成员函数说明

◆ CreateBinary()

size_t apollo::localization::msf::pyramid_map::LosslessMapMatrixHandler::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.cc513 行定义.

515 {
516 const std::shared_ptr<PyramidMapMatrix> matrix =
517 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
518
519 size_t target_size = GetBinarySize(matrix);
520 if (buf_size >= target_size) {
521 unsigned int rows = matrix->GetRowsSafe();
522 unsigned int cols = matrix->GetColsSafe();
523
524 unsigned int* uint_p = reinterpret_cast<unsigned int*>(buf);
525 *uint_p = rows;
526 ++uint_p;
527 *uint_p = cols;
528 ++uint_p;
529 // buf_size -= sizeof(unsigned int) * 2;
530 for (unsigned int y = 0; y < rows; y++) {
531 for (unsigned int x = 0; x < cols; x++) {
532 const unsigned int* ground_count = matrix->GetGroundCountSafe(y, x);
533 unsigned int layer_num = 0;
534 if (ground_count != NULL && *ground_count > 0) {
535 layer_num = 2;
536 *uint_p = 2;
537 ++uint_p;
538 } else {
539 layer_num = 1;
540 *uint_p = 1;
541 ++uint_p;
542 }
543
544 // buf_size -= sizeof(unsigned int);
545 for (unsigned int i = 0; i < layer_num; i++) {
546 if (i == 0) { // all points layer
547 const float* intensity = matrix->GetIntensitySafe(y, x);
548 const float* intensity_var = matrix->GetIntensityVarSafe(y, x);
549 const float* altitude = matrix->GetAltitudeSafe(y, x);
550 const float* altitude_var = matrix->GetAltitudeVarSafe(y, x);
551 const unsigned int* count = matrix->GetCountSafe(y, x);
552
553 float* float_p =
554 reinterpret_cast<float*>(reinterpret_cast<void*>(uint_p));
555 *float_p = (intensity != nullptr) ? *intensity : 0.0f;
556 ++float_p;
557 *float_p = (intensity_var != nullptr) ? *intensity_var : 0.0f;
558 ++float_p;
559 *float_p = (altitude != nullptr) ? *altitude : 0.0f;
560 ++float_p;
561 *float_p = (altitude_var != nullptr) ? *altitude_var : 0.0f;
562 ++float_p;
563 uint_p = reinterpret_cast<unsigned int*>(
564 reinterpret_cast<void*>(float_p));
565 *uint_p = (count != nullptr) ? *count : 0;
566 ++uint_p;
567 } else if (i == 1) { // ground points layer
568 const float* ground_altitude = matrix->GetGroundAltitudeSafe(y, x);
569 const unsigned int* ground_count = matrix->GetGroundCountSafe(y, x);
570
571 float* float_p =
572 reinterpret_cast<float*>(reinterpret_cast<void*>(uint_p));
573 *float_p = 0.0f;
574 ++float_p;
575 *float_p = 0.0f;
576 ++float_p;
577 *float_p = (ground_altitude != nullptr) ? *ground_altitude : 0.0f;
578 ++float_p;
579 *float_p = 0.0f;
580 ++float_p;
581 uint_p = reinterpret_cast<unsigned int*>(
582 reinterpret_cast<void*>(float_p));
583 *uint_p = (ground_count != nullptr) ? *ground_count : 0;
584 ++uint_p;
585 }
586
587 // unsigned int processed_size += sizeof(float) * 4 + sizeof(unsigned
588 // int); assert(buf_size >= processed_size); buf_size -=
589 // processed_size;
590 }
591 }
592 }
593
594 return target_size;
595 }
596
597 return 0;
598}
virtual size_t GetBinarySize(const std::shared_ptr< BaseMapMatrix > matrix)
Get the binary size of the object.

◆ GetBinarySize()

size_t apollo::localization::msf::pyramid_map::LosslessMapMatrixHandler::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.cc600 行定义.

601 {
602 const std::shared_ptr<PyramidMapMatrix> matrix =
603 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
604 // assert(matrix->get_resolution_num() > 0);
605 if (matrix->GetResolutionNum() == 0) {
606 throw "[LosslessMapMatrixHandler::get_binary_size]"
607 "matrix->get_resolution_num() == 0";
608 }
609
610 size_t target_size = sizeof(unsigned int) * 2; // rows and cols
611 for (unsigned int y = 0; y < matrix->GetRowsSafe(); y++) {
612 for (unsigned int x = 0; x < matrix->GetColsSafe(); x++) {
613 target_size += sizeof(unsigned int); // layer
614
615 const unsigned int* ground_count = matrix->GetGroundCountSafe(y, x);
616 if (ground_count != NULL && *ground_count > 0) {
617 target_size += (sizeof(float) * 4 + sizeof(unsigned int)) * 2;
618 } else {
619 target_size += sizeof(float) * 4 + sizeof(unsigned int);
620 }
621 }
622 }
623
624 return target_size;
625}

◆ LoadBinary()

size_t apollo::localization::msf::pyramid_map::LosslessMapMatrixHandler::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.cc439 行定义.

440 {
441 std::shared_ptr<PyramidMapMatrix> matrix =
442 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
443
444 size_t binary_size = sizeof(unsigned int) * 2; // rows and cols
445
446 const unsigned int* uint_p = reinterpret_cast<const unsigned int*>(buf);
447 unsigned int rows = *uint_p;
448 ++uint_p;
449 unsigned int cols = *uint_p;
450 ++uint_p;
451
452 // reset or init matrix
453 if ( // matrix->get_resolution_num() == 1 &&
454 // matrix->get_resolution_ratio() == 2 &&
455 rows == matrix->GetRowsSafe() && cols == matrix->GetColsSafe() &&
456 matrix->HasIntensity() && matrix->HasIntensityVar() &&
457 matrix->HasAltitude() && matrix->HasAltitudeVar() &&
458 matrix->HasGroundAltitude() && matrix->HasCount() &&
459 matrix->HasGroundCount()) {
460 matrix->Reset();
461 } else {
462 matrix->Init(rows, cols);
463 }
464
465 // load matrix
466 for (unsigned int y = 0; y < rows; y++) {
467 for (unsigned int x = 0; x < cols; x++) {
468 binary_size += sizeof(unsigned int); // layer
469
470 unsigned int size = *uint_p;
471 ++uint_p;
472
473 for (unsigned int i = 0; i < size; i++) {
474 if (i == 0) { // all points layer
475 binary_size += sizeof(float) * 4 + sizeof(unsigned int);
476
477 const float* float_p = reinterpret_cast<const float*>(
478 reinterpret_cast<const void*>(uint_p));
479 matrix->SetIntensitySafe(*float_p, y, x);
480 ++float_p;
481 matrix->SetIntensityVarSafe(*float_p, y, x);
482 ++float_p;
483 matrix->SetAltitudeSafe(*float_p, y, x);
484 ++float_p;
485 matrix->SetAltitudeVarSafe(*float_p, y, x);
486 ++float_p;
487 uint_p = reinterpret_cast<const unsigned int*>(
488 reinterpret_cast<const void*>(float_p));
489 matrix->SetCountSafe(*uint_p, y, x);
490 ++uint_p;
491 } else if (i == 1) { // ground points layer
492 binary_size += sizeof(float) * 4 + sizeof(unsigned int);
493
494 const float* float_p = reinterpret_cast<const float*>(
495 reinterpret_cast<const void*>(uint_p));
496 ++float_p;
497 ++float_p;
498 matrix->SetGroundAltitudeSafe(*float_p, y, x);
499 ++float_p;
500 ++float_p;
501 uint_p = reinterpret_cast<const unsigned int*>(
502 reinterpret_cast<const void*>(float_p));
503 matrix->SetGroundCountSafe(*uint_p, y, x);
504 ++uint_p;
505 }
506 }
507 }
508 }
509
510 return binary_size;
511}

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