143 const unsigned char* buf, std::shared_ptr<BaseMapMatrix> base_matrix) {
144 std::shared_ptr<PyramidMapMatrix> matrix =
145 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
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;
151 unsigned int cols = *uint_p;
157 rows == matrix->GetRows() && cols == matrix->GetCols() &&
158 matrix->HasIntensity() && matrix->HasIntensityVar() &&
159 matrix->HasAltitude() && matrix->HasGroundAltitude() &&
160 matrix->HasCount()) {
163 matrix->Init(rows, cols,
true,
true,
true,
false,
true,
true,
false);
167 binary_size +=
sizeof(float) * 4;
168 const float* float_p =
169 reinterpret_cast<const float*
>(
reinterpret_cast<const void*
>(uint_p));
180 const unsigned char* uc_p =
reinterpret_cast<const unsigned char*
>(float_p);
181 unsigned int matrix_size = rows * cols;
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]);
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) {
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]);
215 &(*intensity_var_matrix)[r][c]);
218 uc_p += 2 * matrix_size;
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]);
234 uc_p += 2 * matrix_size;
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]);
250 uc_p += 2 * matrix_size;
257 const std::shared_ptr<BaseMapMatrix> base_matrix,
unsigned char* buf,
259 const std::shared_ptr<PyramidMapMatrix> matrix =
260 std::dynamic_pointer_cast<PyramidMapMatrix>(base_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;
268 unsigned int* uint_p =
reinterpret_cast<unsigned int*
>(buf);
275 float* float_p =
reinterpret_cast<float*
>(
reinterpret_cast<void*
>(uint_p));
276 if (matrix->HasAltitude() && matrix->HasCount()) {
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);
300 if (matrix->HasGroundAltitude() && matrix->HasGroundCount()) {
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) {
333 unsigned char* uc_p =
reinterpret_cast<unsigned char*
>(float_p);
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;
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;
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;
368 p_high[r * cols + c] =
static_cast<uint8_t
>(var / 256);
369 p_low[r * cols + c] =
static_cast<uint8_t
>(var % 256);
372 uc_p += 2 * matrix_size;
376 p_low = uc_p + matrix_size;
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);
387 uc_p += 2 * matrix_size;
391 p_low = uc_p + matrix_size;
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;
399 p_high[r * cols + c] =
static_cast<unsigned char>(alt / 256);
400 p_low[r * cols + c] =
static_cast<unsigned char>(alt % 256);
403 uc_p += 2 * matrix_size;
440 const unsigned char* buf, std::shared_ptr<BaseMapMatrix> base_matrix) {
441 std::shared_ptr<PyramidMapMatrix> matrix =
442 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
444 size_t binary_size =
sizeof(
unsigned int) * 2;
446 const unsigned int* uint_p =
reinterpret_cast<const unsigned int*
>(buf);
447 unsigned int rows = *uint_p;
449 unsigned int cols = *uint_p;
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()) {
462 matrix->Init(rows, cols);
466 for (
unsigned int y = 0; y < rows; y++) {
467 for (
unsigned int x = 0; x < cols; x++) {
468 binary_size +=
sizeof(
unsigned int);
470 unsigned int size = *uint_p;
473 for (
unsigned int i = 0; i < size; i++) {
475 binary_size +=
sizeof(float) * 4 +
sizeof(
unsigned int);
477 const float* float_p =
reinterpret_cast<const float*
>(
478 reinterpret_cast<const void*
>(uint_p));
479 matrix->SetIntensitySafe(*float_p, y, x);
481 matrix->SetIntensityVarSafe(*float_p, y, x);
483 matrix->SetAltitudeSafe(*float_p, y, x);
485 matrix->SetAltitudeVarSafe(*float_p, y, x);
487 uint_p =
reinterpret_cast<const unsigned int*
>(
488 reinterpret_cast<const void*
>(float_p));
489 matrix->SetCountSafe(*uint_p, y, x);
492 binary_size +=
sizeof(float) * 4 +
sizeof(
unsigned int);
494 const float* float_p =
reinterpret_cast<const float*
>(
495 reinterpret_cast<const void*
>(uint_p));
498 matrix->SetGroundAltitudeSafe(*float_p, y, x);
501 uint_p =
reinterpret_cast<const unsigned int*
>(
502 reinterpret_cast<const void*
>(float_p));
503 matrix->SetGroundCountSafe(*uint_p, y, x);
514 const std::shared_ptr<BaseMapMatrix> base_matrix,
unsigned char* buf,
516 const std::shared_ptr<PyramidMapMatrix> matrix =
517 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
520 if (buf_size >= target_size) {
521 unsigned int rows = matrix->GetRowsSafe();
522 unsigned int cols = matrix->GetColsSafe();
524 unsigned int* uint_p =
reinterpret_cast<unsigned int*
>(buf);
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) {
545 for (
unsigned int i = 0; i < layer_num; i++) {
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);
554 reinterpret_cast<float*
>(
reinterpret_cast<void*
>(uint_p));
555 *float_p = (intensity !=
nullptr) ? *intensity : 0.0f;
557 *float_p = (intensity_var !=
nullptr) ? *intensity_var : 0.0f;
559 *float_p = (altitude !=
nullptr) ? *altitude : 0.0f;
561 *float_p = (altitude_var !=
nullptr) ? *altitude_var : 0.0f;
563 uint_p =
reinterpret_cast<unsigned int*
>(
564 reinterpret_cast<void*
>(float_p));
565 *uint_p = (count !=
nullptr) ? *count : 0;
568 const float* ground_altitude = matrix->GetGroundAltitudeSafe(y, x);
569 const unsigned int* ground_count = matrix->GetGroundCountSafe(y, x);
572 reinterpret_cast<float*
>(
reinterpret_cast<void*
>(uint_p));
577 *float_p = (ground_altitude !=
nullptr) ? *ground_altitude : 0.0f;
581 uint_p =
reinterpret_cast<unsigned int*
>(
582 reinterpret_cast<void*
>(float_p));
583 *uint_p = (ground_count !=
nullptr) ? *ground_count : 0;
633 const unsigned char* buf, std::shared_ptr<BaseMapMatrix> base_matrix) {
634 std::shared_ptr<PyramidMapMatrix> matrix =
635 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
637 size_t binary_size =
sizeof(
unsigned int) * 4;
638 const unsigned int* uint_p =
639 reinterpret_cast<const unsigned int*
>(buf);
640 unsigned int resolution_num = *uint_p;
642 unsigned int ratio = *uint_p;
644 unsigned int rows = *uint_p;
646 unsigned int cols = *uint_p;
650 binary_size +=
sizeof(
unsigned char) * 4;
651 const unsigned char* uc_p =
reinterpret_cast<const unsigned char*
>(uint_p);
655 unsigned char has_flag = *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);
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()) {
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);
684 binary_size +=
sizeof(float) * 2;
685 const float* float_p =
686 reinterpret_cast<const float*
>(
reinterpret_cast<const void*
>(uc_p));
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);
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]);
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]);
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) {
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]);
743 uc_p += 2 * matrix_size;
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]);
759 uc_p += 2 * matrix_size;
762 if (matrix->HasAltitudeVar()) {
764 binary_size +=
sizeof(uint16_t) * matrix_size;
765 uc_p += 2 * matrix_size;
768 if (matrix->HasGroundAltitude()) {
769 binary_size +=
sizeof(uint16_t) * matrix_size;
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]);
782 uc_p += 2 * matrix_size;
790 const std::shared_ptr<BaseMapMatrix> base_matrix,
unsigned char* buf,
792 const std::shared_ptr<PyramidMapMatrix> matrix =
793 std::dynamic_pointer_cast<PyramidMapMatrix>(base_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();
802 unsigned int* uint_p =
803 reinterpret_cast<unsigned int*
>(buf);
804 *uint_p = resolution_num;
815 unsigned char* uc_p =
reinterpret_cast<unsigned char*
>(uint_p);
823 if (matrix->HasIntensity()) {
826 if (matrix->HasIntensityVar()) {
829 if (matrix->HasAltitude()) {
832 if (matrix->HasAltitudeVar()) {
835 if (matrix->HasGroundAltitude()) {
838 if (matrix->HasCount()) {
841 if (matrix->HasGroundCount()) {
848 float* float_p =
reinterpret_cast<float*
>(
reinterpret_cast<void*
>(uc_p));
849 if (matrix->HasAltitude() && matrix->HasCount()) {
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);
867 if (matrix->HasGroundAltitude() && matrix->HasGroundCount()) {
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) {
891 uc_p =
reinterpret_cast<unsigned char*
>(float_p);
892 for (
unsigned int l = 0; l < resolution_num; ++l) {
894 unsigned int rows = matrix->GetRowsSafe(l);
895 unsigned int cols = matrix->GetColsSafe(l);
896 unsigned int matrix_size = rows * cols;
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);
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);
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);
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);
939 p_high[r * cols + c] =
static_cast<unsigned char>(var / 256);
940 p_low[r * cols + c] =
static_cast<unsigned char>(var % 256);
943 uc_p += 2 * matrix_size;
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);
955 p_high[r * cols + c] =
static_cast<unsigned char>(alt / 256);
956 p_low[r * cols + c] =
static_cast<unsigned char>(alt % 256);
959 uc_p += 2 * matrix_size;
962 if (matrix->HasAltitudeVar()) {
964 memset(uc_p, 0, 2 * matrix_size *
sizeof(
unsigned char));
965 uc_p += 2 * matrix_size;
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);
977 p_high[r * cols + c] =
static_cast<unsigned char>(alt / 256);
978 p_low[r * cols + c] =
static_cast<unsigned char>(alt % 256);
981 uc_p += 2 * matrix_size;
996 const std::shared_ptr<BaseMapMatrix> base_matrix) {
997 const std::shared_ptr<PyramidMapMatrix> matrix =
998 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
1000 unsigned int resolution_num = matrix->GetResolutionNum();
1002 if (resolution_num == 0) {
1003 throw "[PyramidLossyMapMatrixHandler::get_binary_size] resolution_num == 0";
1010 size_t target_size =
sizeof(
unsigned int) * 2 +
sizeof(
unsigned int) * 2 +
1011 sizeof(
unsigned char) * 4 +
sizeof(
float) * 2;
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;
1018 if (matrix->HasGroundCount()) {
1019 target_size +=
sizeof(
unsigned char) * matrix_size;
1021 if (matrix->HasIntensity()) {
1022 target_size +=
sizeof(
unsigned char) * matrix_size;
1024 if (matrix->HasIntensityVar()) {
1025 target_size +=
sizeof(uint16_t) * matrix_size;
1027 if (matrix->HasAltitude()) {
1028 target_size +=
sizeof(uint16_t) * matrix_size;
1030 if (matrix->HasAltitudeVar()) {
1031 target_size +=
sizeof(uint16_t) * matrix_size;
1033 if (matrix->HasGroundAltitude()) {
1034 target_size +=
sizeof(uint16_t) * matrix_size;
1047 const unsigned char* buf, std::shared_ptr<BaseMapMatrix> base_matrix) {
1048 std::shared_ptr<PyramidMapMatrix> matrix =
1049 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
1051 size_t binary_size =
sizeof(
unsigned int) * 4;
1052 const unsigned int* uint_p =
1053 reinterpret_cast<const unsigned int*
>(buf);
1054 unsigned int resolution_num = *uint_p;
1056 unsigned int ratio = *uint_p;
1058 unsigned int rows = *uint_p;
1060 unsigned int cols = *uint_p;
1064 binary_size +=
sizeof(
unsigned char) * 4;
1065 const unsigned char* uc_p =
reinterpret_cast<const unsigned char*
>(uint_p);
1069 unsigned char has_flag = *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);
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()) {
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);
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;
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;
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;
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;
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;
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;
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;
1141 reinterpret_cast<const float*
>(
reinterpret_cast<const void*
>(uint_p));
1148 const std::shared_ptr<BaseMapMatrix> base_matrix,
unsigned char* buf,
1150 const std::shared_ptr<PyramidMapMatrix> matrix =
1151 std::dynamic_pointer_cast<PyramidMapMatrix>(base_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();
1160 unsigned int* uint_p =
1161 reinterpret_cast<unsigned int*
>(buf);
1162 *uint_p = resolution_num;
1173 unsigned char* uc_p =
reinterpret_cast<unsigned char*
>(uint_p);
1181 if (matrix->HasIntensity()) {
1184 if (matrix->HasIntensityVar()) {
1187 if (matrix->HasAltitude()) {
1190 if (matrix->HasAltitudeVar()) {
1193 if (matrix->HasGroundAltitude()) {
1196 if (matrix->HasCount()) {
1199 if (matrix->HasGroundCount()) {
1205 float* float_p =
reinterpret_cast<float*
>(
reinterpret_cast<void*
>(uc_p));
1206 for (
unsigned int l = 0; l < resolution_num; ++l) {
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;
1216 if (matrix->HasIntensityVar()) {
1218 matrix->GetIntensityVarMatrixSafe(l);
1219 memcpy(float_p, (*intensity_var_matrix)[0],
1220 matrix_size *
sizeof(
float));
1221 float_p += matrix_size;
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;
1230 if (matrix->HasAltitudeVar()) {
1232 matrix->GetAltitudeVarMatrixSafe(l);
1233 memcpy(float_p, (*altitude_var_matrix)[0], matrix_size *
sizeof(
float));
1234 float_p += matrix_size;
1237 if (matrix->HasGroundAltitude()) {
1239 matrix->GetGroundAltitudeMatrixSafe(l);
1240 memcpy(float_p, (*ground_altitude_matrix)[0],
1241 matrix_size *
sizeof(
float));
1242 float_p += matrix_size;
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;
1254 if (matrix->HasGroundCount()) {
1256 matrix->GetGroundCountMatrixSafe(l);
1257 memcpy(uint_p, (*ground_count_matrix)[0],
1258 matrix_size *
sizeof(
unsigned int));
1259 uint_p += matrix_size;
1262 float_p =
reinterpret_cast<float*
>(
reinterpret_cast<void*
>(uint_p));
1274 const std::shared_ptr<BaseMapMatrix> base_matrix) {
1275 const std::shared_ptr<PyramidMapMatrix> matrix =
1276 std::dynamic_pointer_cast<PyramidMapMatrix>(base_matrix);
1278 unsigned int resolution_num = matrix->GetResolutionNum();
1280 if (resolution_num == 0) {
1281 throw "[PyramidLosslessMapMatrixHandler::get_binary_size]"
1282 "resolution_num == 0";
1288 size_t target_size =
sizeof(
unsigned int) * 2 +
sizeof(
unsigned int) * 2 +
1289 sizeof(
unsigned char) * 4;
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;
1296 if (matrix->HasIntensityVar()) {
1297 target_size +=
sizeof(float) * matrix_size;
1299 if (matrix->HasAltitude()) {
1300 target_size +=
sizeof(float) * matrix_size;
1302 if (matrix->HasAltitudeVar()) {
1303 target_size +=
sizeof(float) * matrix_size;
1305 if (matrix->HasGroundAltitude()) {
1306 target_size +=
sizeof(float) * matrix_size;
1308 if (matrix->HasCount()) {
1309 target_size +=
sizeof(
unsigned int) * matrix_size;
1311 if (matrix->HasGroundCount()) {
1312 target_size +=
sizeof(
unsigned int) * matrix_size;