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

#include <pyramid_map_matrix_handler.h>

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

Public 成员函数

 PyramidLosslessMapMatrixHandler ()
 
 ~PyramidLosslessMapMatrixHandler ()
 
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.h98 行定义.

构造及析构函数说明

◆ PyramidLosslessMapMatrixHandler()

apollo::localization::msf::pyramid_map::PyramidLosslessMapMatrixHandler::PyramidLosslessMapMatrixHandler ( )

在文件 pyramid_map_matrix_handler.cc1042 行定义.

1042{}

◆ ~PyramidLosslessMapMatrixHandler()

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

在文件 pyramid_map_matrix_handler.cc1044 行定义.

1044{}

成员函数说明

◆ CreateBinary()

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

1149 {
1150 const std::shared_ptr<PyramidMapMatrix> matrix =
1151 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
1152
1153 size_t target_size = GetBinarySize(matrix);
1154 if (buf_size >= target_size) {
1155 unsigned int resolution_num = matrix->GetResolutionNum();
1156 unsigned int ratio = matrix->GetResolutionRatio();
1157 unsigned int rows = matrix->GetRowsSafe();
1158 unsigned int cols = matrix->GetColsSafe();
1159
1160 unsigned int* uint_p =
1161 reinterpret_cast<unsigned int*>(buf); // resolution num
1162 *uint_p = resolution_num;
1163 ++uint_p;
1164 *uint_p = ratio;
1165 ++uint_p;
1166 *uint_p = rows; // rows in first level
1167 ++uint_p;
1168 *uint_p = cols; // cols in first level
1169 ++uint_p;
1170 // buf_size -= sizeof(unsigned int) * 4;
1171
1172 // set has_*
1173 unsigned char* uc_p = reinterpret_cast<unsigned char*>(uint_p);
1174 *uc_p = 0;
1175 ++uc_p;
1176 *uc_p = 0;
1177 ++uc_p;
1178 *uc_p = 0;
1179 ++uc_p;
1180 *uc_p = 0;
1181 if (matrix->HasIntensity()) {
1182 *uc_p |= 1;
1183 }
1184 if (matrix->HasIntensityVar()) {
1185 *uc_p |= 2;
1186 }
1187 if (matrix->HasAltitude()) {
1188 *uc_p |= 4;
1189 }
1190 if (matrix->HasAltitudeVar()) {
1191 *uc_p |= 8;
1192 }
1193 if (matrix->HasGroundAltitude()) {
1194 *uc_p |= 16;
1195 }
1196 if (matrix->HasCount()) {
1197 *uc_p |= 32;
1198 }
1199 if (matrix->HasGroundCount()) {
1200 *uc_p |= 64;
1201 }
1202 ++uc_p;
1203 // buf_size -= sizeof(unsigned char) * 4;
1204
1205 float* float_p = reinterpret_cast<float*>(reinterpret_cast<void*>(uc_p));
1206 for (unsigned int l = 0; l < resolution_num; ++l) {
1207 // unsigned int processed_size = 0;
1208 unsigned int matrix_size =
1209 matrix->GetRowsSafe(l) * matrix->GetColsSafe(l);
1210 if (matrix->HasIntensity()) {
1211 const FloatMatrix* intensity_matrix = matrix->GetIntensityMatrixSafe(l);
1212 memcpy(float_p, (*intensity_matrix)[0], matrix_size * sizeof(float));
1213 float_p += matrix_size;
1214 // processed_size += matrix_size * sizeof(float);
1215 }
1216 if (matrix->HasIntensityVar()) {
1217 const FloatMatrix* intensity_var_matrix =
1218 matrix->GetIntensityVarMatrixSafe(l);
1219 memcpy(float_p, (*intensity_var_matrix)[0],
1220 matrix_size * sizeof(float));
1221 float_p += matrix_size;
1222 // processed_size += matrix_size * sizeof(float);
1223 }
1224 if (matrix->HasAltitude()) {
1225 const FloatMatrix* altitude_matrix = matrix->GetAltitudeMatrixSafe(l);
1226 memcpy(float_p, (*altitude_matrix)[0], matrix_size * sizeof(float));
1227 float_p += matrix_size;
1228 // processed_size += matrix_size * sizeof(float);
1229 }
1230 if (matrix->HasAltitudeVar()) {
1231 const FloatMatrix* altitude_var_matrix =
1232 matrix->GetAltitudeVarMatrixSafe(l);
1233 memcpy(float_p, (*altitude_var_matrix)[0], matrix_size * sizeof(float));
1234 float_p += matrix_size;
1235 // processed_size += matrix_size * sizeof(float);
1236 }
1237 if (matrix->HasGroundAltitude()) {
1238 const FloatMatrix* ground_altitude_matrix =
1239 matrix->GetGroundAltitudeMatrixSafe(l);
1240 memcpy(float_p, (*ground_altitude_matrix)[0],
1241 matrix_size * sizeof(float));
1242 float_p += matrix_size;
1243 // processed_size += matrix_size * sizeof(float);
1244 }
1245
1246 uint_p =
1247 reinterpret_cast<unsigned int*>(reinterpret_cast<void*>(float_p));
1248 if (matrix->HasCount()) {
1249 const UIntMatrix* count_matrix = matrix->GetCountMatrixSafe(l);
1250 memcpy(uint_p, (*count_matrix)[0], matrix_size * sizeof(unsigned int));
1251 uint_p += matrix_size;
1252 // processed_size += matrix_size * sizeof(unsigned int);
1253 }
1254 if (matrix->HasGroundCount()) {
1255 const UIntMatrix* ground_count_matrix =
1256 matrix->GetGroundCountMatrixSafe(l);
1257 memcpy(uint_p, (*ground_count_matrix)[0],
1258 matrix_size * sizeof(unsigned int));
1259 uint_p += matrix_size;
1260 // processed_size += matrix_size * sizeof(unsigned int);
1261 }
1262 float_p = reinterpret_cast<float*>(reinterpret_cast<void*>(uint_p));
1263 // assert(buf_size >= processed_size);
1264 // buf_size -= processed_size;
1265 }
1266
1267 return target_size;
1268 }
1269
1270 return 0;
1271}
virtual size_t GetBinarySize(const std::shared_ptr< BaseMapMatrix > matrix)
Get the binary size of the object.
AlignedMatrix< unsigned int > UIntMatrix

◆ GetBinarySize()

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

1274 {
1275 const std::shared_ptr<PyramidMapMatrix> matrix =
1276 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
1277
1278 unsigned int resolution_num = matrix->GetResolutionNum();
1279 // assert(resolution_num > 0);
1280 if (resolution_num == 0) {
1281 throw "[PyramidLosslessMapMatrixHandler::get_binary_size]"
1282 "resolution_num == 0";
1283 }
1284
1285 // resolution_num and ratio
1286 // rows and cols in first level
1287 // space for has_*
1288 size_t target_size = sizeof(unsigned int) * 2 + sizeof(unsigned int) * 2 +
1289 sizeof(unsigned char) * 4;
1290
1291 for (unsigned int l = 0; l < resolution_num; ++l) {
1292 unsigned int matrix_size = matrix->GetRowsSafe(l) * matrix->GetColsSafe(l);
1293 if (matrix->HasIntensity()) {
1294 target_size += sizeof(float) * matrix_size;
1295 }
1296 if (matrix->HasIntensityVar()) {
1297 target_size += sizeof(float) * matrix_size;
1298 }
1299 if (matrix->HasAltitude()) {
1300 target_size += sizeof(float) * matrix_size;
1301 }
1302 if (matrix->HasAltitudeVar()) {
1303 target_size += sizeof(float) * matrix_size;
1304 }
1305 if (matrix->HasGroundAltitude()) {
1306 target_size += sizeof(float) * matrix_size;
1307 }
1308 if (matrix->HasCount()) {
1309 target_size += sizeof(unsigned int) * matrix_size;
1310 }
1311 if (matrix->HasGroundCount()) {
1312 target_size += sizeof(unsigned int) * matrix_size;
1313 }
1314 }
1315
1316 return target_size;
1317}

◆ LoadBinary()

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

1047 {
1048 std::shared_ptr<PyramidMapMatrix> matrix =
1049 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
1050
1051 size_t binary_size = sizeof(unsigned int) * 4;
1052 const unsigned int* uint_p =
1053 reinterpret_cast<const unsigned int*>(buf); // resolution num
1054 unsigned int resolution_num = *uint_p;
1055 ++uint_p;
1056 unsigned int ratio = *uint_p; // ratio
1057 ++uint_p;
1058 unsigned int rows = *uint_p; // rows in first level
1059 ++uint_p;
1060 unsigned int cols = *uint_p; // cols in first level
1061 ++uint_p;
1062
1063 // set has_*
1064 binary_size += sizeof(unsigned char) * 4;
1065 const unsigned char* uc_p = reinterpret_cast<const unsigned char*>(uint_p);
1066 ++uc_p;
1067 ++uc_p;
1068 ++uc_p;
1069 unsigned char has_flag = *uc_p;
1070 ++uc_p;
1071 bool has_intensity = (has_flag & 1);
1072 bool has_intensity_var = (has_flag & 2);
1073 bool has_altitude = (has_flag & 4);
1074 bool has_altitude_var = (has_flag & 8);
1075 bool has_ground_altitude = (has_flag & 16);
1076 bool has_count = (has_flag & 32);
1077 bool has_ground_count = (has_flag & 64);
1078
1079 // reset or init matrix
1080 if (resolution_num == matrix->GetResolutionNum() &&
1081 ratio == matrix->GetResolutionRatio() && rows == matrix->GetRowsSafe() &&
1082 cols == matrix->GetColsSafe() &&
1083 has_intensity == matrix->HasIntensity() &&
1084 has_intensity_var == matrix->HasIntensityVar() &&
1085 has_altitude == matrix->HasAltitude() &&
1086 has_altitude_var == matrix->HasAltitudeVar() &&
1087 has_ground_altitude == matrix->HasGroundAltitude() &&
1088 has_count == matrix->HasCount() &&
1089 has_ground_count == matrix->HasGroundCount()) {
1090 matrix->Reset();
1091 } else {
1092 matrix->Init(rows, cols, has_intensity, has_intensity_var, has_altitude,
1093 has_altitude_var, has_ground_altitude, has_count,
1094 has_ground_count, resolution_num, ratio);
1095 }
1096
1097 // load matrix
1098 const float* float_p =
1099 reinterpret_cast<const float*>(reinterpret_cast<const void*>(uc_p));
1100 for (unsigned int l = 0; l < resolution_num; ++l) {
1101 unsigned int matrix_size = matrix->GetRowsSafe(l) * matrix->GetColsSafe(l);
1102 if (matrix->HasIntensity()) {
1103 binary_size += sizeof(float) * matrix_size;
1104 matrix->SetIntensityMatrix(float_p, matrix_size, 0, l);
1105 float_p += matrix_size;
1106 }
1107 if (matrix->HasIntensityVar()) {
1108 binary_size += sizeof(float) * matrix_size;
1109 matrix->SetIntensityVarMatrix(float_p, matrix_size, 0, l);
1110 float_p += matrix_size;
1111 }
1112 if (matrix->HasAltitude()) {
1113 binary_size += sizeof(float) * matrix_size;
1114 matrix->SetAltitudeMatrix(float_p, matrix_size, 0, l);
1115 float_p += matrix_size;
1116 }
1117 if (matrix->HasAltitudeVar()) {
1118 binary_size += sizeof(float) * matrix_size;
1119 matrix->SetAltitudeVarMatrix(float_p, matrix_size, 0, l);
1120 float_p += matrix_size;
1121 }
1122 if (matrix->HasGroundAltitude()) {
1123 binary_size += sizeof(float) * matrix_size;
1124 matrix->SetGroundAltitudeMatrix(float_p, matrix_size, 0, l);
1125 float_p += matrix_size;
1126 }
1127
1128 uint_p = reinterpret_cast<const unsigned int*>(
1129 reinterpret_cast<const void*>(float_p));
1130 if (matrix->HasCount()) {
1131 binary_size += sizeof(unsigned int) * matrix_size;
1132 matrix->SetCountMatrix(uint_p, matrix_size, 0, l);
1133 uint_p += matrix_size;
1134 }
1135 if (matrix->HasGroundCount()) {
1136 binary_size += sizeof(unsigned int) * matrix_size;
1137 matrix->SetGroundCountMatrix(uint_p, matrix_size, 0, l);
1138 uint_p += matrix_size;
1139 }
1140 float_p =
1141 reinterpret_cast<const float*>(reinterpret_cast<const void*>(uint_p));
1142 }
1143
1144 return binary_size;
1145}

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