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

#include <pyramid_map_matrix_handler.h>

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

Public 成员函数

 PyramidLossyMapMatrixHandler ()
 
 ~PyramidLossyMapMatrixHandler ()
 
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.h87 行定义.

构造及析构函数说明

◆ PyramidLossyMapMatrixHandler()

apollo::localization::msf::pyramid_map::PyramidLossyMapMatrixHandler::PyramidLossyMapMatrixHandler ( )

在文件 pyramid_map_matrix_handler.cc628 行定义.

628{}

◆ ~PyramidLossyMapMatrixHandler()

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

在文件 pyramid_map_matrix_handler.cc630 行定义.

630{}

成员函数说明

◆ CreateBinary()

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

791 {
792 const std::shared_ptr<PyramidMapMatrix> matrix =
793 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
794
795 size_t target_size = GetBinarySize(matrix);
796 if (buf_size >= target_size) {
797 unsigned int resolution_num = matrix->GetResolutionNum();
798 unsigned int ratio = matrix->GetResolutionRatio();
799 unsigned int rows = matrix->GetRowsSafe();
800 unsigned int cols = matrix->GetColsSafe();
801
802 unsigned int* uint_p =
803 reinterpret_cast<unsigned int*>(buf); // resolution num
804 *uint_p = resolution_num;
805 ++uint_p;
806 *uint_p = ratio;
807 ++uint_p;
808 *uint_p = rows; // rows in first level
809 ++uint_p;
810 *uint_p = cols; // cols in first level
811 ++uint_p;
812 // buf_size -= sizeof(unsigned int) * 4;
813
814 // set has_*
815 unsigned char* uc_p = reinterpret_cast<unsigned char*>(uint_p);
816 *uc_p = 0;
817 ++uc_p;
818 *uc_p = 0;
819 ++uc_p;
820 *uc_p = 0;
821 ++uc_p;
822 *uc_p = 0;
823 if (matrix->HasIntensity()) {
824 *uc_p |= 1;
825 }
826 if (matrix->HasIntensityVar()) {
827 *uc_p |= 2;
828 }
829 if (matrix->HasAltitude()) {
830 *uc_p |= 4;
831 }
832 if (matrix->HasAltitudeVar()) {
833 *uc_p |= 8;
834 }
835 if (matrix->HasGroundAltitude()) {
836 *uc_p |= 16;
837 }
838 if (matrix->HasCount()) {
839 *uc_p |= 32;
840 }
841 if (matrix->HasGroundCount()) {
842 *uc_p |= 64;
843 }
844 ++uc_p;
845 // buf_size -= sizeof(unsigned char) * 4;
846
847 // altitude min
848 float* float_p = reinterpret_cast<float*>(reinterpret_cast<void*>(uc_p));
849 if (matrix->HasAltitude() && matrix->HasCount()) {
850 alt_avg_min_ = 1e8;
851 for (unsigned int y = 0; y < rows; ++y) {
852 for (unsigned int x = 0; x < cols; ++x) {
853 const float* altitude = matrix->GetAltitudeSafe(y, x);
854 const unsigned int* count = matrix->GetCountSafe(y, x);
855 if (*count == 0) {
856 continue;
857 }
858 if (*altitude < alt_avg_min_) {
859 alt_avg_min_ = *altitude;
860 }
861 }
862 }
863 } else {
864 alt_avg_min_ = 0.0;
865 }
866
867 if (matrix->HasGroundAltitude() && matrix->HasGroundCount()) {
868 ground_alt_min_ = 1e8;
869 for (unsigned int y = 0; y < rows; ++y) {
870 for (unsigned int x = 0; x < cols; ++x) {
871 const float* ground_altitude = matrix->GetGroundAltitudeSafe(y, x);
872 const unsigned int* ground_count = matrix->GetGroundCountSafe(y, x);
873 if (*ground_count == 0) {
874 continue;
875 }
876 if (*ground_altitude < ground_alt_min_) {
877 ground_alt_min_ = *ground_altitude;
878 }
879 }
880 }
881 } else {
882 ground_alt_min_ = 0.0;
883 }
884
885 *float_p = alt_avg_min_;
886 ++float_p;
887 *float_p = ground_alt_min_;
888 ++float_p;
889 // buf_size -= sizeof(float)*2;
890
891 uc_p = reinterpret_cast<unsigned char*>(float_p);
892 for (unsigned int l = 0; l < resolution_num; ++l) {
893 // unsigned int processed_size = 0;
894 unsigned int rows = matrix->GetRowsSafe(l);
895 unsigned int cols = matrix->GetColsSafe(l);
896 unsigned int matrix_size = rows * cols;
897
898 if (matrix->HasCount()) {
899 for (unsigned int r = 0; r < rows; ++r) {
900 for (unsigned int c = 0; c < cols; ++c) {
901 const unsigned int* count = matrix->GetCountSafe(r, c, l);
902 uc_p[r * cols + c] = EncodeCount(*count, count_range_);
903 }
904 }
905 uc_p += matrix_size;
906 // processed_size += matrix_size * sizeof(unsigned char);
907 }
908
909 if (matrix->HasGroundCount()) {
910 for (unsigned int r = 0; r < rows; ++r) {
911 for (unsigned int c = 0; c < cols; ++c) {
912 const unsigned int* ground_count =
913 matrix->GetGroundCountSafe(r, c, l);
914 uc_p[r * cols + c] = EncodeCount(*ground_count, count_range_);
915 }
916 }
917 uc_p += matrix_size;
918 // processed_size += matrix_size * sizeof(unsigned char);
919 }
920
921 if (matrix->HasIntensity()) {
922 for (unsigned int r = 0; r < rows; ++r) {
923 for (unsigned int c = 0; c < cols; ++c) {
924 const float* intensity = matrix->GetIntensitySafe(r, c, l);
925 uc_p[r * cols + c] = EncodeIntensity(*intensity);
926 }
927 }
928 uc_p += matrix_size;
929 // processed_size += matrix_size * sizeof(unsigned char);
930 }
931
932 if (matrix->HasIntensityVar()) {
933 unsigned char* p_low = uc_p + matrix_size;
934 unsigned char* p_high = uc_p;
935 for (unsigned int r = 0; r < rows; ++r) {
936 for (unsigned int c = 0; c < cols; ++c) {
937 const float* intensity_var = matrix->GetIntensityVarSafe(r, c, l);
938 uint16_t var = EncodeIntensityVar(*intensity_var);
939 p_high[r * cols + c] = static_cast<unsigned char>(var / 256);
940 p_low[r * cols + c] = static_cast<unsigned char>(var % 256);
941 }
942 }
943 uc_p += 2 * matrix_size;
944 // processed_size += matrix_size * sizeof(uint16_t);
945 }
946
947 if (matrix->HasAltitude()) {
948 unsigned char* p_low = uc_p + matrix_size;
949 unsigned char* p_high = uc_p;
950 for (unsigned int r = 0; r < rows; ++r) {
951 for (unsigned int c = 0; c < cols; ++c) {
952 const float* altitude = matrix->GetAltitudeSafe(r, c, l);
953 uint16_t alt =
955 p_high[r * cols + c] = static_cast<unsigned char>(alt / 256);
956 p_low[r * cols + c] = static_cast<unsigned char>(alt % 256);
957 }
958 }
959 uc_p += 2 * matrix_size;
960 // processed_size += matrix_size * sizeof(uint16_t);
961 }
962 if (matrix->HasAltitudeVar()) {
963 // default 0
964 memset(uc_p, 0, 2 * matrix_size * sizeof(unsigned char));
965 uc_p += 2 * matrix_size;
966 }
967
968 if (matrix->HasGroundAltitude()) {
969 unsigned char* p_low = uc_p + matrix_size;
970 unsigned char* p_high = uc_p;
971 for (unsigned int r = 0; r < rows; ++r) {
972 for (unsigned int c = 0; c < cols; ++c) {
973 const float* ground_altitude =
974 matrix->GetGroundAltitudeSafe(r, c, l);
975 uint16_t alt = EncodeAltitude(*ground_altitude, ground_alt_min_,
977 p_high[r * cols + c] = static_cast<unsigned char>(alt / 256);
978 p_low[r * cols + c] = static_cast<unsigned char>(alt % 256);
979 }
980 }
981 uc_p += 2 * matrix_size;
982 // processed_size += matrix_size * sizeof(uint16_t);
983 }
984
985 // assert(buf_size >= processed_size);
986 // buf_size -= processed_size;
987 }
988
989 return target_size;
990 }
991
992 return 0;
993}
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
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::PyramidLossyMapMatrixHandler::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.cc995 行定义.

996 {
997 const std::shared_ptr<PyramidMapMatrix> matrix =
998 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
999
1000 unsigned int resolution_num = matrix->GetResolutionNum();
1001 // assert(resolution_num > 0);
1002 if (resolution_num == 0) {
1003 throw "[PyramidLossyMapMatrixHandler::get_binary_size] resolution_num == 0";
1004 }
1005
1006 // resolution_num and ratio
1007 // rows and cols in first level
1008 // space for has_*
1009 // altitude min & ground altitude min
1010 size_t target_size = sizeof(unsigned int) * 2 + sizeof(unsigned int) * 2 +
1011 sizeof(unsigned char) * 4 + sizeof(float) * 2;
1012
1013 for (unsigned int l = 0; l < resolution_num; ++l) {
1014 unsigned int matrix_size = matrix->GetRowsSafe(l) * matrix->GetColsSafe(l);
1015 if (matrix->HasCount()) {
1016 target_size += sizeof(unsigned char) * matrix_size;
1017 }
1018 if (matrix->HasGroundCount()) {
1019 target_size += sizeof(unsigned char) * matrix_size;
1020 }
1021 if (matrix->HasIntensity()) {
1022 target_size += sizeof(unsigned char) * matrix_size;
1023 }
1024 if (matrix->HasIntensityVar()) {
1025 target_size += sizeof(uint16_t) * matrix_size;
1026 }
1027 if (matrix->HasAltitude()) {
1028 target_size += sizeof(uint16_t) * matrix_size;
1029 }
1030 if (matrix->HasAltitudeVar()) {
1031 target_size += sizeof(uint16_t) * matrix_size;
1032 }
1033 if (matrix->HasGroundAltitude()) {
1034 target_size += sizeof(uint16_t) * matrix_size;
1035 }
1036 }
1037
1038 return target_size;
1039}

◆ LoadBinary()

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

633 {
634 std::shared_ptr<PyramidMapMatrix> matrix =
635 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
636
637 size_t binary_size = sizeof(unsigned int) * 4;
638 const unsigned int* uint_p =
639 reinterpret_cast<const unsigned int*>(buf); // resolution num
640 unsigned int resolution_num = *uint_p;
641 ++uint_p;
642 unsigned int ratio = *uint_p; // ratio
643 ++uint_p;
644 unsigned int rows = *uint_p; // rows in first level
645 ++uint_p;
646 unsigned int cols = *uint_p; // cols in first level
647 ++uint_p;
648
649 // set has_*
650 binary_size += sizeof(unsigned char) * 4;
651 const unsigned char* uc_p = reinterpret_cast<const unsigned char*>(uint_p);
652 ++uc_p;
653 ++uc_p;
654 ++uc_p;
655 unsigned char has_flag = *uc_p;
656 ++uc_p;
657 bool has_intensity = (has_flag & 1);
658 bool has_intensity_var = (has_flag & 2);
659 bool has_altitude = (has_flag & 4);
660 bool has_altitude_var = (has_flag & 8);
661 bool has_ground_altitude = (has_flag & 16);
662 bool has_count = (has_flag & 32);
663 bool has_ground_count = (has_flag & 64);
664
665 // reset or init matrix
666 if (resolution_num == matrix->GetResolutionNum() &&
667 ratio == matrix->GetResolutionRatio() && rows == matrix->GetRowsSafe() &&
668 cols == matrix->GetColsSafe() &&
669 has_intensity == matrix->HasIntensity() &&
670 has_intensity_var == matrix->HasIntensityVar() &&
671 has_altitude == matrix->HasAltitude() &&
672 has_altitude_var == matrix->HasAltitudeVar() &&
673 has_ground_altitude == matrix->HasGroundAltitude() &&
674 has_count == matrix->HasCount() &&
675 has_ground_count == matrix->HasGroundCount()) {
676 matrix->Reset();
677 } else {
678 matrix->Init(rows, cols, has_intensity, has_intensity_var, has_altitude,
679 has_altitude_var, has_ground_altitude, has_count,
680 has_ground_count, resolution_num, ratio);
681 }
682
683 // alt min & ground alt min
684 binary_size += sizeof(float) * 2;
685 const float* float_p =
686 reinterpret_cast<const float*>(reinterpret_cast<const void*>(uc_p));
687 alt_avg_min_ = *float_p;
688 ++float_p;
689 ground_alt_min_ = *float_p;
690 ++float_p;
691
692 // load matrix
693 uc_p = reinterpret_cast<const unsigned char*>(float_p);
694 for (unsigned int l = 0; l < resolution_num; ++l) {
695 unsigned int rows = matrix->GetRowsSafe(l);
696 unsigned int cols = matrix->GetColsSafe(l);
697 unsigned int matrix_size = matrix->GetRowsSafe(l) * matrix->GetColsSafe(l);
698
699 if (matrix->HasCount()) {
700 binary_size += sizeof(unsigned char) * matrix_size;
701 UIntMatrix* count_matrix = matrix->GetCountMatrixSafe(l);
702 for (unsigned int r = 0; r < rows; ++r) {
703 for (unsigned int c = 0; c < cols; ++c) {
704 DecodeCount(uc_p[r * cols + c], &(*count_matrix)[r][c]);
705 }
706 }
707 uc_p += matrix_size;
708 }
709 if (matrix->HasGroundCount()) {
710 binary_size += sizeof(unsigned char) * matrix_size;
711 UIntMatrix* ground_count_matrix = matrix->GetGroundCountMatrixSafe(l);
712 for (unsigned int r = 0; r < rows; ++r) {
713 for (unsigned int c = 0; c < cols; ++c) {
714 DecodeCount(uc_p[r * cols + c], &(*ground_count_matrix)[r][c]);
715 }
716 }
717 uc_p += matrix_size;
718 }
719
720 if (matrix->HasIntensity()) {
721 binary_size += sizeof(unsigned char) * matrix_size;
722 FloatMatrix* intensity_matrix = matrix->GetIntensityMatrixSafe(l);
723 for (unsigned int r = 0; r < rows; ++r) {
724 for (unsigned int c = 0; c < cols; ++c) {
725 DecodeIntensity(uc_p[r * cols + c], &(*intensity_matrix)[r][c]);
726 }
727 }
728 uc_p += matrix_size;
729 }
730
731 if (matrix->HasIntensityVar()) {
732 binary_size += sizeof(uint16_t) * matrix_size;
733 FloatMatrix* intensity_var_matrix = matrix->GetIntensityVarMatrixSafe(l);
734 const unsigned char* p_low = uc_p + matrix_size;
735 const unsigned char* p_high = uc_p;
736 for (unsigned int r = 0; r < rows; ++r) {
737 for (unsigned int c = 0; c < cols; ++c) {
738 uint16_t var = p_high[r * cols + c];
739 var = static_cast<uint16_t>(var * 256 + p_low[r * cols + c]);
740 DecodeIntensityVar(var, &(*intensity_var_matrix)[r][c]);
741 }
742 }
743 uc_p += 2 * matrix_size;
744 }
745
746 if (matrix->HasAltitude()) {
747 binary_size += sizeof(uint16_t) * matrix_size;
748 FloatMatrix* altitude_matrix = matrix->GetAltitudeMatrixSafe(l);
749 const unsigned char* p_low = uc_p + matrix_size;
750 const unsigned char* p_high = uc_p;
751 for (unsigned int r = 0; r < rows; ++r) {
752 for (unsigned int c = 0; c < cols; ++c) {
753 uint16_t alt = p_high[r * cols + c];
754 alt = static_cast<uint16_t>(alt * 256 + p_low[r * cols + c]);
756 &(*altitude_matrix)[r][c]);
757 }
758 }
759 uc_p += 2 * matrix_size;
760 }
761
762 if (matrix->HasAltitudeVar()) {
763 // skip
764 binary_size += sizeof(uint16_t) * matrix_size;
765 uc_p += 2 * matrix_size;
766 }
767
768 if (matrix->HasGroundAltitude()) {
769 binary_size += sizeof(uint16_t) * matrix_size;
770 FloatMatrix* ground_altitude_matrix =
771 matrix->GetGroundAltitudeMatrixSafe(l);
772 const unsigned char* p_low = uc_p + matrix_size;
773 const unsigned char* p_high = uc_p;
774 for (unsigned int r = 0; r < rows; ++r) {
775 for (unsigned int c = 0; c < cols; ++c) {
776 uint16_t alt = p_high[r * cols + c];
777 alt = static_cast<uint16_t>(alt * 256 + p_low[r * cols + c]);
779 &(*ground_altitude_matrix)[r][c]);
780 }
781 }
782 uc_p += 2 * matrix_size;
783 }
784 }
785
786 return binary_size;
787}
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

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