Load the map cell from a binary chunk.
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);
640 unsigned int resolution_num = *uint_p;
641 ++uint_p;
642 unsigned int ratio = *uint_p;
643 ++uint_p;
644 unsigned int rows = *uint_p;
645 ++uint_p;
646 unsigned int cols = *uint_p;
647 ++uint_p;
648
649
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
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
684 binary_size += sizeof(float) * 2;
685 const float* float_p =
686 reinterpret_cast<const float*>(reinterpret_cast<const void*>(uc_p));
688 ++float_p;
690 ++float_p;
691
692
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) {
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]);
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
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;
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 DecodeIntensityVar(uint16_t data, float *var) const
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< float > FloatMatrix
AlignedMatrix< unsigned int > UIntMatrix