23namespace localization {
25namespace pyramid_map {
33 resolution_num_ = map_matrix.resolution_num_;
34 ratio_ = map_matrix.ratio_;
35 rows_mr_ = map_matrix.rows_mr_;
36 cols_mr_ = map_matrix.cols_mr_;
37 ratio_multiplier_ = map_matrix.ratio_multiplier_;
39 intensity_matrixes_ = map_matrix.intensity_matrixes_;
40 intensity_var_matrixes_ = map_matrix.intensity_var_matrixes_;
41 altitude_matrixes_ = map_matrix.altitude_matrixes_;
42 altitude_var_matrixes_ = map_matrix.altitude_var_matrixes_;
43 ground_altitude_matrixes_ = map_matrix.ground_altitude_matrixes_;
44 count_matrixes_ = map_matrix.count_matrixes_;
45 ground_count_matrixes_ = map_matrix.ground_count_matrixes_;
47 has_intensity_ = map_matrix.has_intensity_;
48 has_intensity_var_ = map_matrix.has_intensity_var_;
49 has_altitude_ = map_matrix.has_altitude_;
50 has_altitude_var_ = map_matrix.has_altitude_var_;
51 has_ground_altitude_ = map_matrix.has_ground_altitude_;
52 has_count_ = map_matrix.has_count_;
53 has_ground_count_ = map_matrix.has_ground_count_;
68 for (
unsigned int i = 0; i < resolution_num_; i++) {
74 bool has_intensity,
bool has_intensity_var,
75 bool has_altitude,
bool has_altitude_var,
76 bool has_ground_altitude,
bool has_count,
77 bool has_ground_count,
unsigned int resolution_num,
82 if (resolution_num < 1) {
84 <<
"PyramidMapMatrix: [init] The resolution_num should greater than 0.";
90 AERROR <<
"PyramidMapMatrix: [init] The ratio should greater than 0.";
95 unsigned int rows_tem = rows;
96 unsigned int cols_tem = cols;
97 for (
unsigned int i = 1; i < resolution_num_; ++i) {
98 unsigned int rows_remainder = rows_tem % ratio;
99 unsigned int cols_remainder = cols_tem % ratio;
101 if (rows_remainder != 0 || cols_remainder != 0) {
102 AERROR <<
"PyramidMapMatrix: [init] "
103 <<
"Rows and cols in each level should be divisible by ratio.";
111 resolution_num_ = resolution_num;
114 has_intensity_ = has_intensity;
115 has_intensity_var_ = has_intensity_var;
116 has_altitude_ = has_altitude;
117 has_altitude_var_ = has_altitude_var;
118 has_ground_altitude_ = has_ground_altitude;
119 has_count_ = has_count;
120 has_ground_count_ = has_ground_count;
123 rows_mr_.resize(resolution_num_, 0);
124 cols_mr_.resize(resolution_num_, 0);
127 for (
unsigned int i = 1; i < resolution_num_; ++i) {
128 rows_mr_[i] = rows_mr_[i - 1] / ratio_;
129 cols_mr_[i] = cols_mr_[i - 1] / ratio_;
133 if (has_intensity_) {
134 intensity_matrixes_.resize(resolution_num_);
135 for (
unsigned int i = 0; i < resolution_num_; i++) {
136 intensity_matrixes_[i].Init(rows_mr_[i], cols_mr_[i]);
139 if (has_intensity_var_) {
140 intensity_var_matrixes_.resize(resolution_num_);
141 for (
unsigned int i = 0; i < resolution_num_; i++) {
142 intensity_var_matrixes_[i].Init(rows_mr_[i], cols_mr_[i]);
146 altitude_matrixes_.resize(resolution_num_);
147 for (
unsigned int i = 0; i < resolution_num_; i++) {
148 altitude_matrixes_[i].Init(rows_mr_[i], cols_mr_[i]);
151 if (has_altitude_var_) {
152 altitude_var_matrixes_.resize(resolution_num_);
153 for (
unsigned int i = 0; i < resolution_num_; i++) {
154 altitude_var_matrixes_[i].Init(rows_mr_[i], cols_mr_[i]);
157 if (has_ground_altitude_) {
158 ground_altitude_matrixes_.resize(resolution_num_);
159 for (
unsigned int i = 0; i < resolution_num_; i++) {
160 ground_altitude_matrixes_[i].Init(rows_mr_[i], cols_mr_[i]);
164 count_matrixes_.resize(resolution_num_);
165 for (
unsigned int i = 0; i < resolution_num_; i++) {
166 count_matrixes_[i].Init(rows_mr_[i], cols_mr_[i]);
169 if (has_ground_count_) {
170 ground_count_matrixes_.resize(resolution_num_);
171 for (
unsigned int i = 0; i < resolution_num_; i++) {
172 ground_count_matrixes_[i].Init(rows_mr_[i], cols_mr_[i]);
177 unsigned int size = std::max(rows_mr_[0], cols_mr_[0]);
178 ratio_multiplier_.resize(size, 0);
179 for (
unsigned int i = 0; i < size; ++i) {
180 ratio_multiplier_[i] = i * ratio_;
185 if (level >= resolution_num_) {
186 AERROR <<
"PyramidMapMatrix: [reset] The level id is illegal.";
190 if (has_intensity_) {
191 intensity_matrixes_[level].MakeEmpty();
193 if (has_intensity_var_) {
194 intensity_var_matrixes_[level].MakeEmpty();
197 altitude_matrixes_[level].MakeEmpty();
199 if (has_altitude_var_) {
200 altitude_var_matrixes_[level].MakeEmpty();
202 if (has_ground_altitude_) {
203 ground_altitude_matrixes_[level].MakeEmpty();
206 count_matrixes_[level].MakeEmpty();
208 if (has_ground_count_) {
209 ground_count_matrixes_[level].MakeEmpty();
214 unsigned int level) {
215 if (level >= resolution_num_) {
216 AERROR <<
"PyramidMapMatrix: [ResetCells] The level id is illegal.";
220 unsigned int length = rows_mr_[level] * cols_mr_[level];
221 if (start_id >= length || end_id >= length) {
223 <<
"PyramidMapMatrix: [ResetCell] The start_id or end_id is illegal.";
227 if (has_intensity_) {
228 intensity_matrixes_[level].MakeEmpty(start_id, end_id);
230 if (has_intensity_var_) {
231 intensity_var_matrixes_[level].MakeEmpty(start_id, end_id);
234 altitude_matrixes_[level].MakeEmpty(start_id, end_id);
236 if (has_altitude_var_) {
237 altitude_var_matrixes_[level].MakeEmpty(start_id, end_id);
239 if (has_ground_altitude_) {
240 ground_altitude_matrixes_[level].MakeEmpty(start_id, end_id);
243 count_matrixes_[level].MakeEmpty(start_id, end_id);
245 if (has_ground_count_) {
246 ground_count_matrixes_[level].MakeEmpty(start_id, end_id);
258 has_intensity_ =
false;
259 has_intensity_var_ =
false;
260 has_altitude_ =
false;
261 has_altitude_var_ =
false;
262 has_ground_altitude_ =
false;
264 has_ground_count_ =
false;
268 ratio_multiplier_.clear();
269 intensity_matrixes_.clear();
270 intensity_var_matrixes_.clear();
271 altitude_matrixes_.clear();
272 altitude_var_matrixes_.clear();
273 ground_altitude_matrixes_.clear();
274 count_matrixes_.clear();
275 ground_count_matrixes_.clear();
283 cv::Mat* intensity_img)
const {
284 if (!has_intensity_ || resolution_num_ < 1) {
285 AERROR <<
"PyramidMapMatrix: [GetIntensityImg] No intensity data.";
289 if (level >= resolution_num_) {
290 AERROR <<
"PyramidMapMatrix: [GetIntensityImg] The level id is illegal.";
294 *intensity_img = cv::Mat(cv::Size(cols_mr_[level], rows_mr_[level]), CV_8UC1);
296 for (
unsigned int y = 0; y < rows_mr_[level]; ++y) {
297 for (
unsigned int x = 0; x < cols_mr_[level]; ++x) {
298 if (intensity_matrixes_[level][y][x] < 0) {
299 intensity_img->at<
unsigned char>(y, x) = 0;
300 }
else if (intensity_matrixes_[level][y][x] > 255) {
301 intensity_img->at<
unsigned char>(y, x) = 255;
303 intensity_img->at<
unsigned char>(y, x) =
304 static_cast<unsigned char>(intensity_matrixes_[level][y][x]);
317 cv::Mat* altitude_img)
const {
318 if (!has_altitude_ || resolution_num_ < 1) {
319 AERROR <<
"PyramidMapMatrix: [GetAltitudeImg] No altitude data.";
323 if (level >= resolution_num_) {
324 AERROR <<
"PyramidMapMatrix: [GetAltitudeImg] The level id is illegal.";
329 float max_alt = -1e8;
331 for (
unsigned int y = 0; y < rows_mr_[level]; y++) {
332 for (
unsigned int x = 0; x < cols_mr_[level]; x++) {
333 if (count_matrixes_[level][y][x] > 0) {
334 if (altitude_matrixes_[level][y][x] > max_alt) {
335 max_alt = altitude_matrixes_[level][y][x];
337 if (altitude_matrixes_[level][y][x] < min_alt) {
338 min_alt = altitude_matrixes_[level][y][x];
344 *altitude_img = cv::Mat(cv::Size(cols_mr_[level], rows_mr_[level]), CV_8UC1);
345 for (
unsigned int y = 0; y < rows_mr_[level]; y++) {
346 for (
unsigned int x = 0; x < cols_mr_[level]; x++) {
347 if (count_matrixes_[level][y][x] > 0) {
348 if (altitude_matrixes_[level][y][x] >= max_alt) {
349 altitude_img->at<
unsigned char>(y, x) = 255;
350 }
else if (altitude_matrixes_[level][y][x] <= min_alt) {
351 altitude_img->at<
unsigned char>(y, x) = 0;
353 altitude_img->at<
unsigned char>(y, x) =
static_cast<unsigned char>(
354 (altitude_matrixes_[level][y][x] - min_alt) /
355 (max_alt - min_alt) * 255);
358 altitude_img->at<
unsigned char>(y, x) = 0;
368 AERROR <<
"PyramidMapMatrix: [bottom_up] Has no count.";
372 for (
unsigned int i = 1; i < resolution_num_; ++i) {
373 const unsigned int& row = rows_mr_[i];
374 const unsigned int& col = rows_mr_[i];
375 for (
unsigned int r = 0; r < row; ++r) {
376 for (
unsigned int c = 0; c < col; ++c) {
377 unsigned int& r0 = ratio_multiplier_[r];
378 unsigned int& c0 = ratio_multiplier_[c];
379 for (
unsigned int rl = r0; rl < r0 + ratio_; ++rl) {
380 for (
unsigned int cl = c0; cl < c0 + ratio_; ++cl) {
381 const unsigned int& count = count_matrixes_[i - 1][rl][cl];
383 float* intensity =
nullptr;
384 float* intensity_var =
nullptr;
385 float* altitude =
nullptr;
386 float* altitude_var =
nullptr;
387 float* ground_altitude =
nullptr;
388 unsigned int* count =
nullptr;
389 unsigned int* ground_count =
nullptr;
392 &altitude_var, &ground_altitude, &count,
393 &ground_count, rl, cl, i - 1);
394 MergeCellSafe(intensity, intensity_var, altitude, altitude_var,
395 ground_altitude, count, ground_count, r, c, i);
405 for (
unsigned int i = 1; i < resolution_num_; ++i) {
406 const unsigned int& row = rows_mr_[i];
407 const unsigned int& col = rows_mr_[i];
408 for (
unsigned int r = 0; r < row; ++r) {
409 for (
unsigned int c = 0; c < col; ++c) {
410 unsigned int& r0 = ratio_multiplier_[r];
411 unsigned int& c0 = ratio_multiplier_[c];
412 for (
unsigned int rl = r0; rl < r0 + ratio_; ++rl) {
413 for (
unsigned int cl = c0; cl < c0 + ratio_; ++cl) {
414 const unsigned int& count = count_matrixes_[i - 1][rl][cl];
416 float* intensity =
nullptr;
417 float* intensity_var =
nullptr;
418 float* altitude =
nullptr;
419 unsigned int* count =
nullptr;
423 MergeCellBase(intensity, intensity_var, altitude, count, r, c, i);
435 resolution_num_ = map_matrix.resolution_num_;
436 ratio_ = map_matrix.ratio_;
437 rows_mr_ = map_matrix.rows_mr_;
438 cols_mr_ = map_matrix.cols_mr_;
439 ratio_multiplier_ = map_matrix.ratio_multiplier_;
441 intensity_matrixes_ = map_matrix.intensity_matrixes_;
442 intensity_var_matrixes_ = map_matrix.intensity_var_matrixes_;
443 altitude_matrixes_ = map_matrix.altitude_matrixes_;
444 altitude_var_matrixes_ = map_matrix.altitude_var_matrixes_;
445 ground_altitude_matrixes_ = map_matrix.ground_altitude_matrixes_;
446 count_matrixes_ = map_matrix.count_matrixes_;
447 ground_count_matrixes_ = map_matrix.ground_count_matrixes_;
449 has_intensity_ = map_matrix.has_intensity_;
450 has_intensity_var_ = map_matrix.has_intensity_var_;
451 has_altitude_ = map_matrix.has_altitude_;
452 has_altitude_var_ = map_matrix.has_altitude_var_;
453 has_ground_altitude_ = map_matrix.has_ground_altitude_;
454 has_count_ = map_matrix.has_count_;
455 has_ground_count_ = map_matrix.has_ground_count_;
461 unsigned int level)
const {
462 if (!has_intensity_) {
463 AERROR <<
"PyramidMapMatrix: [GetIntensitySafe] Has no intensity.";
467 if (!CheckLegalityForGetData(row, col, level)) {
468 AERROR <<
"PyramidMapMatrix: [GetIntensitySafe] Params is illegal.";
472 return &intensity_matrixes_[level][row][col];
477 unsigned int level)
const {
478 if (!has_intensity_var_) {
479 AERROR <<
"PyramidMapMatrix: [GetIntensityVarSafe] Has no intensity_var.";
483 if (!CheckLegalityForGetData(row, col, level)) {
484 AERROR <<
"PyramidMapMatrix: [GetIntensityVarSafe] Params is illegal.";
488 return &intensity_var_matrixes_[level][row][col];
493 unsigned int level)
const {
494 if (!has_altitude_) {
495 AERROR <<
"PyramidMapMatrix: [GetAltitudeSafe] Has no altitude.";
499 if (!CheckLegalityForGetData(row, col, level)) {
500 AERROR <<
"PyramidMapMatrix: [GetAltitudeSafe] Params is illegal.";
504 return &altitude_matrixes_[level][row][col];
509 unsigned int level)
const {
510 if (!has_altitude_var_) {
511 AERROR <<
"PyramidMapMatrix: [GetAltitudeVarSafe] Has no altitude_var.";
515 if (!CheckLegalityForGetData(row, col, level)) {
516 AERROR <<
"PyramidMapMatrix: [get_altitude_var] Params is illegal.";
520 return &altitude_var_matrixes_[level][row][col];
525 unsigned int level)
const {
526 if (!has_ground_altitude_) {
528 <<
"PyramidMapMatrix: [GetGroundAltitudeSafe] Has no ground_altitude.";
532 if (!CheckLegalityForGetData(row, col, level)) {
533 AERROR <<
"PyramidMapMatrix: [GetGroundAltitudeSafe] Params is illegal.";
537 return &ground_altitude_matrixes_[level][row][col];
542 unsigned int level)
const {
544 AERROR <<
"PyramidMapMatrix: [GetCountSafe] Has no count.";
548 if (!CheckLegalityForGetData(row, col, level)) {
549 AERROR <<
"PyramidMapMatrix: [GetCountSafe] Params is illegal.";
553 return &count_matrixes_[level][row][col];
557 unsigned int row,
unsigned int col,
unsigned int level)
const {
558 if (!has_ground_count_) {
559 AERROR <<
"PyramidMapMatrix: [GetGroundCountSafe] Has no ground_count.";
563 if (!CheckLegalityForGetData(row, col, level)) {
564 AERROR <<
"PyramidMapMatrix: [GetGroundCountSafe] Params is illegal.";
568 return &ground_count_matrixes_[level][row][col];
572 float** altitude,
float** altitude_var,
573 float** ground_altitude,
574 unsigned int** count,
575 unsigned int** ground_count,
576 unsigned int row,
unsigned int col,
577 unsigned int level) {
578 if (!CheckLegalityForGetData(row, col, level)) {
579 AERROR <<
"PyramidMapMatrix: [GetMapCellSafe] Params is illegal.";
583 if (has_intensity_) {
584 *intensity = &intensity_matrixes_[level][row][col];
587 if (has_intensity_var_) {
588 *intensity_var = &intensity_var_matrixes_[level][row][col];
592 *altitude = &altitude_matrixes_[level][row][col];
595 if (has_altitude_var_) {
596 *altitude_var = &altitude_var_matrixes_[level][row][col];
599 if (has_ground_altitude_) {
600 *ground_altitude = &ground_altitude_matrixes_[level][row][col];
604 *count = &count_matrixes_[level][row][col];
607 if (has_ground_count_) {
608 *ground_count = &ground_count_matrixes_[level][row][col];
613 if (!has_intensity_) {
614 AERROR <<
"PyramidMapMatrix: [GetIntensityMatrixSafe] Has no intensity.";
618 if (level >= resolution_num_) {
619 AERROR <<
"PyramidMapMatrix: [GetIntensityMatrixSafe] The level id is "
624 return &intensity_matrixes_[level];
628 if (!has_intensity_var_) {
629 AERROR <<
"PyramidMapMatrix: [GetIntensityVarMatrixSafe] Has no "
634 if (level >= resolution_num_) {
635 AERROR <<
"PyramidMapMatrix: [GetIntensityVarMatrixSafe] The level id "
640 return &intensity_var_matrixes_[level];
644 if (!has_altitude_) {
645 AERROR <<
"PyramidMapMatrix: [GetAltitudeMatrixSafe] Has no altitude.";
649 if (level >= resolution_num_) {
651 <<
"PyramidMapMatrix: [GetAltitudeMatrixSafe] The level id is illegal.";
655 return &altitude_matrixes_[level];
659 if (!has_altitude_var_) {
661 <<
"PyramidMapMatrix: [GetAltitudeVarMatrixSafe] Has no altitude_var.";
665 if (level >= resolution_num_) {
666 AERROR <<
"PyramidMapMatrix: [GetAltitudeVarMatrixSafe] The level id is "
671 return &altitude_var_matrixes_[level];
675 if (!has_ground_altitude_) {
676 AERROR <<
"PyramidMapMatrix: [GetGroundAltitudeMatrixSafe] Has no "
681 if (level >= resolution_num_) {
682 AERROR <<
"PyramidMapMatrix: [GetGroundAltitudeMatrixSafe] The level id "
687 return &ground_altitude_matrixes_[level];
692 AERROR <<
"PyramidMapMatrix: [GetCountMatrixSafe] Has no count.";
696 if (level >= resolution_num_) {
697 AERROR <<
"PyramidMapMatrix: [GetCountMatrixSafe] The level id is illegal.";
701 return &count_matrixes_[level];
705 if (!has_ground_count_) {
707 <<
"PyramidMapMatrix: [GetGroundCountMatrixSafe] Has no ground_count.";
711 if (level >= resolution_num_) {
712 AERROR <<
"PyramidMapMatrix: [GetGroundCountMatrixSafe] The level id is "
717 return &ground_count_matrixes_[level];
721 unsigned int level)
const {
722 if (!has_intensity_) {
723 AERROR <<
"PyramidMapMatrix: [GetIntensityMatrixSafe] Has no intensity.";
727 if (level >= resolution_num_) {
728 AERROR <<
"PyramidMapMatrix: [GetIntensityMatrixSafe] The level id is "
733 return &intensity_matrixes_[level];
737 unsigned int level)
const {
738 if (!has_intensity_var_) {
739 AERROR <<
"PyramidMapMatrix: [GetIntensityVarMatrixSafe] Has no "
744 if (level >= resolution_num_) {
745 AERROR <<
"PyramidMapMatrix: [GetIntensityVarMatrixSafe] The level id "
750 return &intensity_var_matrixes_[level];
754 unsigned int level)
const {
755 if (!has_altitude_) {
756 AERROR <<
"PyramidMapMatrix: [GetAltitudeMatrixSafe] Has no altitude.";
760 if (level >= resolution_num_) {
762 <<
"PyramidMapMatrix: [GetAltitudeMatrixSafe] The level id is illegal.";
766 return &altitude_matrixes_[level];
770 unsigned int level)
const {
771 if (!has_altitude_var_) {
773 <<
"PyramidMapMatrix: [GetAltitudeVarMatrixSafe] Has no altitude_var.";
777 if (level >= resolution_num_) {
778 AERROR <<
"PyramidMapMatrix: [GetAltitudeVarMatrixSafe] The level id is "
783 return &altitude_var_matrixes_[level];
787 unsigned int level)
const {
788 if (!has_ground_altitude_) {
789 AERROR <<
"PyramidMapMatrix: [GetGroundAltitudeMatrixSafe] Has no "
794 if (level >= resolution_num_) {
795 AERROR <<
"PyramidMapMatrix: [GetGroundAltitudeMatrixSafe] The level id "
800 return &ground_altitude_matrixes_[level];
804 unsigned int level)
const {
806 AERROR <<
"PyramidMapMatrix: [GetCountMatrixSafe] Has no count.";
810 if (level >= resolution_num_) {
811 AERROR <<
"PyramidMapMatrix: [GetCountMatrixSafe] The level id is illegal.";
815 return &count_matrixes_[level];
819 unsigned int level)
const {
820 if (!has_ground_count_) {
822 <<
"PyramidMapMatrix: [GetGroundCountMatrixSafe] Has no ground_count.";
826 if (level >= resolution_num_) {
827 AERROR <<
"PyramidMapMatrix: [GetGroundCountMatrixSafe] The level id is "
832 return &ground_count_matrixes_[level];
836 unsigned int start_index,
837 unsigned int level) {
838 if (!has_intensity_) {
839 AERROR <<
"PyramidMapMatrix: [SetIntensityMatrix] Has no intensity.";
843 if (!CheckLegalityForSetData(level, start_index, size)) {
844 AERROR <<
"PyramidMapMatrix: [SetIntensityMatrix] Params is illegal.";
848 intensity_matrixes_[level].SetData(input, size, start_index);
853 unsigned int start_index,
854 unsigned int level) {
855 if (!has_intensity_var_) {
857 <<
"PyramidMapMatrix: [set_intensity_var_matrix] Has no intensity_var.";
861 if (!CheckLegalityForSetData(level, start_index, size)) {
862 AERROR <<
"PyramidMapMatrix: [set_intensity_var_matrix] Params is illegal.";
866 intensity_var_matrixes_[level].SetData(input, size, start_index);
870 unsigned int start_index,
871 unsigned int level) {
872 if (!has_altitude_) {
873 AERROR <<
"PyramidMapMatrix: [SetAltitudeMatrix] Has no altitude.";
877 if (!CheckLegalityForSetData(level, start_index, size)) {
878 AERROR <<
"PyramidMapMatrix: [SetAltitudeMatrix] Params is illegal.";
882 altitude_matrixes_[level].SetData(input, size, start_index);
887 unsigned int start_index,
888 unsigned int level) {
889 if (!has_altitude_var_) {
890 AERROR <<
"PyramidMapMatrix: [SetAltitudeVarMatrix] Has no altitude_var.";
894 if (!CheckLegalityForSetData(level, start_index, size)) {
895 AERROR <<
"PyramidMapMatrix: [SetAltitudeVarMatrix] Params is illegal.";
899 altitude_var_matrixes_[level].SetData(input, size, start_index);
904 unsigned int start_index,
905 unsigned int level) {
906 if (!has_ground_altitude_) {
907 AERROR <<
"PyramidMapMatrix: [SetGroundAltitudeMatrix] Has no "
912 if (!CheckLegalityForSetData(level, start_index, size)) {
913 AERROR <<
"PyramidMapMatrix: [SetGroundAltitudeMatrix] Params is illegal.";
917 ground_altitude_matrixes_[level].SetData(input, size, start_index);
922 unsigned int start_index,
923 unsigned int level) {
925 AERROR <<
"PyramidMapMatrix: [SetCountMatrix] Has no count.";
929 if (!CheckLegalityForSetData(level, start_index, size)) {
930 AERROR <<
"PyramidMapMatrix: [SetCountMatrix] Params is illegal.";
934 count_matrixes_[level].SetData(input, size, start_index);
939 unsigned int start_index,
940 unsigned int level) {
941 if (!has_ground_count_) {
942 AERROR <<
"PyramidMapMatrix: [SetGroundCountMatrix] Has no ground count.";
946 if (!CheckLegalityForSetData(level, start_index, size)) {
947 AERROR <<
"PyramidMapMatrix: [SetGroundCountMatrix] Params is illegal.";
951 ground_count_matrixes_[level].SetData(input, size, start_index);
958 unsigned int level) {
959 if (source_matrix ==
nullptr) {
960 AERROR <<
"PyramidMapMatrix: [SetFloatMatrixRoi] Source matrix is nullptr.";
966 if (!has_intensity_) {
967 AERROR <<
"PyramidMapMatrix: [SetFloatMatrixRoi] Has no intensity.";
972 if (!has_intensity_var_) {
973 AERROR <<
"PyramidMapMatrix: [SetFloatMatrixRoi] Has no intensity var.";
978 if (!has_altitude_) {
979 AERROR <<
"PyramidMapMatrix: [SetFloatMatrixRoi] Has no altitude.";
984 if (!has_altitude_var_) {
985 AERROR <<
"PyramidMapMatrix: [SetFloatMatrixRoi] Has no altitude var.";
990 if (!has_ground_altitude_) {
992 <<
"PyramidMapMatrix: [SetFloatMatrixRoi] Has no ground altitude.";
998 if (!CheckLegalityForSetDataRoi(
999 level,
static_cast<unsigned int>(source_matrix->
GetRow()),
1000 static_cast<unsigned int>(source_matrix->
GetCol()), source_roi,
1002 AERROR <<
"PyramidMapMatrix: [SetFloatMatrixRoi] Params is illegal.";
1006 const unsigned int& source_roi_min_x = source_roi.
GetMinX();
1007 const unsigned int& source_roi_min_y = source_roi.
GetMinY();
1009 const unsigned int& target_roi_min_x = target_roi.
GetMinX();
1010 const unsigned int& target_roi_min_y = target_roi.
GetMinY();
1011 const unsigned int& target_roi_max_x = target_roi.
GetMaxX();
1012 const unsigned int& target_roi_max_y = target_roi.
GetMaxY();
1015 unsigned int roi_cols = target_roi_max_x - target_roi_min_x + 1;
1017 unsigned int inc = 0;
1018 for (
unsigned int y = target_roi_min_y; y <= target_roi_max_y; ++y) {
1019 unsigned int target_start_index = y * cols_mr_[level] + target_roi_min_x;
1020 unsigned int source_start_index =
1021 (source_roi_min_y + inc) * source_matrix->
GetCol() + source_roi_min_x;
1022 const float* input = (*source_matrix)[0] + source_start_index;
1048 unsigned int type,
unsigned int level) {
1049 if (source_matrix ==
nullptr) {
1050 AERROR <<
"PyramidMapMatrix: [SetUintMatrixRoi] Source matrix is nullptr.";
1057 AERROR <<
"PyramidMapMatrix: [SetUintMatrixRoi] Has no count.";
1062 if (!has_ground_count_) {
1063 AERROR <<
"PyramidMapMatrix: [SetUintMatrixRoi] Has no ground count.";
1069 if (!CheckLegalityForSetDataRoi(
1070 level,
static_cast<unsigned int>(source_matrix->
GetRow()),
1071 static_cast<unsigned int>(source_matrix->
GetCol()), source_roi,
1073 AERROR <<
"PyramidMapMatrix: [SetUintMatrixRoi] Params is illegal.";
1077 const unsigned int& source_roi_min_x = source_roi.
GetMinX();
1078 const unsigned int& source_roi_min_y = source_roi.
GetMinY();
1080 const unsigned int& target_roi_min_x = target_roi.
GetMinX();
1081 const unsigned int& target_roi_min_y = target_roi.
GetMinY();
1082 const unsigned int& target_roi_max_x = target_roi.
GetMaxX();
1083 const unsigned int& target_roi_max_y = target_roi.
GetMaxY();
1085 unsigned int roi_cols = target_roi_max_x - target_roi_min_x + 1;
1087 unsigned int inc = 0;
1088 for (
unsigned int y = target_roi_min_y; y <= target_roi_max_y; ++y) {
1089 unsigned int target_start_index = y * cols_mr_[level] + target_roi_min_x;
1090 unsigned int source_start_index =
1091 (source_roi_min_y + inc) * source_matrix->
GetCol() + source_roi_min_x;
1092 const unsigned int* input = (*source_matrix)[0] + source_start_index;
1107 unsigned int col,
unsigned int level) {
1108 if (!has_intensity_) {
1109 AERROR <<
"PyramidMapMatrix: [SetIntensitySafe] Has no intensity.";
1113 if (!CheckLegalityForGetData(row, col, level)) {
1114 AERROR <<
"PyramidMapMatrix: [SetIntensitySafe] Params is illegal.";
1118 intensity_matrixes_[level][row][col] = intensity;
1122 unsigned int row,
unsigned int col,
1123 unsigned int level) {
1124 if (!has_intensity_var_) {
1125 AERROR <<
"PyramidMapMatrix: [SetIntensityVarSafe] Has no intensity_var.";
1129 if (!CheckLegalityForGetData(row, col, level)) {
1130 AERROR <<
"PyramidMapMatrix: [SetIntensityVarSafe] Params is illegal.";
1134 intensity_var_matrixes_[level][row][col] = intensity_var;
1138 unsigned int col,
unsigned int level) {
1139 if (!has_altitude_) {
1140 AERROR <<
"PyramidMapMatrix: [SetAltitudeSafe] Has no altitude.";
1144 if (!CheckLegalityForGetData(row, col, level)) {
1145 AERROR <<
"PyramidMapMatrix: [SetAltitudeSafe] Params is illegal.";
1149 altitude_matrixes_[level][row][col] = altitude;
1154 unsigned int level) {
1155 if (!has_altitude_var_) {
1156 AERROR <<
"PyramidMapMatrix: [SetAltitudeVarSafe] Has no altitude var.";
1160 if (!CheckLegalityForGetData(row, col, level)) {
1161 AERROR <<
"PyramidMapMatrix: [SetAltitudeVarSafe] Params is illegal.";
1165 altitude_var_matrixes_[level][row][col] = altitude_var;
1169 unsigned int row,
unsigned int col,
1170 unsigned int level) {
1171 if (!has_ground_altitude_) {
1173 <<
"PyramidMapMatrix: [SetGroundAltitudeSafe] Has no ground altitude.";
1177 if (!CheckLegalityForGetData(row, col, level)) {
1178 AERROR <<
"PyramidMapMatrix: [SetGroundAltitudeSafe] Params is illegal.";
1182 ground_altitude_matrixes_[level][row][col] = ground_altitude;
1186 unsigned int col,
unsigned int level) {
1188 AERROR <<
"PyramidMapMatrix: [SetCountSafe] Has no count.";
1192 if (!CheckLegalityForGetData(row, col, level)) {
1193 AERROR <<
"PyramidMapMatrix: [SetCountSafe] Params is illegal.";
1197 count_matrixes_[level][row][col] = count;
1201 unsigned int row,
unsigned int col,
1202 unsigned int level) {
1203 if (!has_ground_count_) {
1204 AERROR <<
"PyramidMapMatrix: [SetGroundCountSafe] Has no ground count.";
1208 if (!CheckLegalityForGetData(row, col, level)) {
1209 AERROR <<
"PyramidMapMatrix: [SetGroundCountSafe] Params is illegal.";
1213 ground_count_matrixes_[level][row][col] = ground_count;
1217 unsigned int row,
unsigned int col,
1218 unsigned int level) {
1219 if (!has_intensity_) {
1220 AERROR <<
"PyramidMapMatrix: [SetValueSafe] Has no intensity.";
1224 if (!has_altitude_) {
1225 AERROR <<
"PyramidMapMatrix: [SetValueSafe] Has no altitude.";
1229 if (!CheckLegalityForGetData(row, col, level)) {
1230 AERROR <<
"PyramidMapMatrix: [SetValueSafe] Params is illegal.";
1234 intensity_matrixes_[level][row][col] = intensity;
1235 altitude_matrixes_[level][row][col] = altitude;
1239 const float* intensity,
const float* intensity_var,
const float* altitude,
1240 const float* altitude_var,
const float* ground_altitude,
1241 const unsigned int* count,
const unsigned int* ground_count,
1242 unsigned int row,
unsigned int col,
unsigned int level) {
1243 if (!CheckLegalityForGetData(row, col, level)) {
1244 AERROR <<
"PyramidMapMatrix: [MergeCellSafe] Params is illegal.";
1248 if (count ==
nullptr || !has_count_) {
1252 unsigned int new_count = count_matrixes_[level][row][col] + *count;
1253 float p0 =
static_cast<float>(count_matrixes_[level][row][col]) /
1254 static_cast<float>(new_count);
1255 float p1 =
static_cast<float>(*count) /
static_cast<float>(new_count);
1257 float intensity_diff = 0.0f;
1258 if (intensity !=
nullptr && has_intensity_) {
1259 intensity_diff = intensity_matrixes_[level][row][col] - *intensity;
1260 intensity_matrixes_[level][row][col] =
1261 intensity_matrixes_[level][row][col] * p0 + *intensity * p1;
1264 if (intensity !=
nullptr && has_intensity_ && intensity_var !=
nullptr &&
1265 has_intensity_var_) {
1266 intensity_var_matrixes_[level][row][col] =
1267 intensity_var_matrixes_[level][row][col] * p0 + *intensity_var * p1 +
1268 intensity_diff * intensity_diff * p0 * p1;
1271 float altitude_diff = 0.0f;
1272 if (altitude !=
nullptr && has_altitude_) {
1273 altitude_diff = altitude_matrixes_[level][row][col] - *altitude;
1274 altitude_matrixes_[level][row][col] =
1275 altitude_matrixes_[level][row][col] * p0 + *altitude * p1;
1278 if (altitude !=
nullptr && has_altitude_ && altitude_var !=
nullptr &&
1279 has_altitude_var_) {
1280 altitude_var_matrixes_[level][row][col] =
1281 altitude_var_matrixes_[level][row][col] * p0 + *altitude_var * p1 +
1282 altitude_diff * altitude_diff * p0 * p1;
1285 count_matrixes_[level][row][col] = new_count;
1288 if (ground_count ==
nullptr || !has_ground_count_) {
1292 unsigned int new_ground_count =
1293 ground_count_matrixes_[level][row][col] + *ground_count;
1294 p0 =
static_cast<float>(ground_count_matrixes_[level][row][col]) /
1295 static_cast<float>(new_ground_count);
1296 p1 =
static_cast<float>(*ground_count) /
static_cast<float>(new_ground_count);
1298 if (ground_altitude !=
nullptr && has_ground_altitude_) {
1299 ground_altitude_matrixes_[level][row][col] =
1300 ground_altitude_matrixes_[level][row][col] * p0 + *ground_altitude * p1;
1303 ground_count_matrixes_[level][row][col] = new_ground_count;
1306bool PyramidMapMatrix::CheckLegalityForGetData(
unsigned int row,
1308 unsigned int level)
const {
1309 if (level >= resolution_num_) {
1310 AERROR <<
"PyramidMapMatrix: [CheckLegalityForGetData] The level id is "
1315 if (row >= rows_mr_[level]) {
1316 AERROR <<
"PyramidMapMatrix: [CheckLegalityForGetData] The row is illegal.";
1320 if (col >= cols_mr_[level]) {
1321 AERROR <<
"PyramidMapMatrix: [CheckLegalityForGetData] The col is illegal.";
1328bool PyramidMapMatrix::CheckLegalityForSetData(
unsigned int level,
1329 unsigned int start_id,
1330 unsigned int size)
const {
1331 if (level >= resolution_num_) {
1332 AERROR <<
"PyramidMapMatrix: [CheckLegalityForSetData] The level id is "
1337 if (start_id + size > rows_mr_[level] * cols_mr_[level]) {
1338 AERROR <<
"PyramidMapMatrix: [CheckLegalityForSetData] The start_id or "
1346bool PyramidMapMatrix::CheckLegalityForSetDataRoi(
1347 unsigned int level,
unsigned int source_matrix_rows,
1348 unsigned int source_matrix_cols,
const Rect2D<unsigned int>& source_roi,
1349 const Rect2D<unsigned int>& target_roi)
const {
1350 if (level >= resolution_num_) {
1351 AERROR <<
"PyramidMapMatrix: [CheckLegalityForSetDataRoi] The level id "
1356 const unsigned int& source_roi_min_x = source_roi.GetMinX();
1357 const unsigned int& source_roi_min_y = source_roi.GetMinY();
1358 const unsigned int& source_roi_max_x = source_roi.GetMaxX();
1359 const unsigned int& source_roi_max_y = source_roi.GetMaxY();
1361 const unsigned int& target_roi_min_x = target_roi.GetMinX();
1362 const unsigned int& target_roi_min_y = target_roi.GetMinY();
1363 const unsigned int& target_roi_max_x = target_roi.GetMaxX();
1364 const unsigned int& target_roi_max_y = target_roi.GetMaxY();
1366 if (source_roi_min_x > source_roi_max_x ||
1367 source_roi_min_y > source_roi_max_y ||
1368 target_roi_min_x > target_roi_max_x ||
1369 target_roi_min_y > target_roi_max_y ||
1370 source_roi_max_x >= source_matrix_cols ||
1371 source_roi_max_y >= source_matrix_rows ||
1372 target_roi_max_x >= cols_mr_[level] ||
1373 target_roi_max_y >= rows_mr_[level] ||
1374 source_roi_max_x - source_roi_min_x !=
1375 target_roi_max_x - target_roi_min_x ||
1376 source_roi_max_y - source_roi_min_y !=
1377 target_roi_max_y - target_roi_min_y) {
1378 AERROR <<
"PyramidMapMatrix: [CheckLegalityForSetDataRoi]"
1379 " The source_roi or target_roi is illegal.";
1387 unsigned int row,
unsigned int col,
1388 unsigned int level) {
1389 if (!CheckLegalityForGetData(row, col, level)) {
1390 AERROR <<
"PyramidMapMatrix: [AddSampleSafe] Params is illegal.";
1395 ++count_matrixes_[level][row][col];
1401 if (has_count_ && has_intensity_) {
1402 v1 = intensity - intensity_matrixes_[level][row][col];
1403 value = v1 /
static_cast<float>(count_matrixes_[level][row][col]);
1404 intensity_matrixes_[level][row][col] += value;
1407 if (has_count_ && has_intensity_ && has_intensity_var_) {
1408 v2 = intensity - intensity_matrixes_[level][row][col];
1409 intensity_var_matrixes_[level][row][col] =
1410 (
static_cast<float>(count_matrixes_[level][row][col] - 1) *
1411 intensity_var_matrixes_[level][row][col] +
1413 static_cast<float>(count_matrixes_[level][row][col]);
1416 if (has_count_ && has_altitude_) {
1417 v1 = altitude - altitude_matrixes_[level][row][col];
1418 value = v1 /
static_cast<float>(count_matrixes_[level][row][col]);
1419 altitude_matrixes_[level][row][col] += value;
1422 if (has_count_ && has_altitude_ && has_altitude_var_) {
1423 v2 = altitude - altitude_matrixes_[level][row][col];
1424 altitude_var_matrixes_[level][row][col] =
1425 (
static_cast<float>(count_matrixes_[level][row][col] - 1) *
1426 altitude_var_matrixes_[level][row][col] +
1428 static_cast<float>(count_matrixes_[level][row][col]);
1433 unsigned int col,
unsigned int level) {
1434 if (!CheckLegalityForGetData(row, col, level)) {
1435 AERROR <<
"PyramidMapMatrix: [AddGroundSample] Params is illegal.";
1439 if (has_ground_count_) {
1440 ++ground_count_matrixes_[level][row][col];
1445 if (has_ground_count_ && has_ground_altitude_) {
1446 v1 = ground_altitude - ground_altitude_matrixes_[level][row][col];
1447 value = v1 /
static_cast<float>(ground_count_matrixes_[level][row][col]);
1448 ground_altitude_matrixes_[level][row][col] += value;
1454 AERROR <<
"PyramidMapMatrix: [ComputeMeanIntensity] Has no count.";
1458 if (!has_intensity_ || resolution_num_ < 1) {
1459 AERROR <<
"PyramidMapMatrix: [ComputeMeanIntensity] No intensity data.";
1463 if (level >= resolution_num_) {
1465 <<
"PyramidMapMatrix: [ComputeMeanIntensity] The level id is illegal.";
1471 for (
unsigned int y = 0; y < rows_mr_[level]; ++y) {
1472 for (
unsigned int x = 0; x < cols_mr_[level]; ++x) {
1473 if (count_matrixes_[level][y][x] > 0) {
1475 double delta = intensity_matrixes_[level][y][x] - avg;
1476 avg += (delta / count);
1486 unsigned int level,
unsigned int new_level) {
1487 if (level >= cells->resolution_num_) {
1488 AERROR <<
"PyramidMapMatrix: [Reduce] The level id is illegal.";
1492 if (new_level >= new_cells.resolution_num_) {
1493 AERROR <<
"PyramidMapMatrix: [Reduce] The new level id is illegal.";
1497 if (cells->rows_mr_[level] != new_cells.rows_mr_[new_level] ||
1498 cells->cols_mr_[level] != new_cells.cols_mr_[new_level]) {
1502 for (
unsigned int r = 0; r < cells->rows_mr_[level]; r++) {
1503 for (
unsigned int c = 0; c < cells->cols_mr_[level]; c++) {
1505 const float* intensity_var =
1509 const float* ground_altitude =
1511 const unsigned int* count = new_cells.
GetCountSafe(r, c, new_level);
1512 const unsigned int* ground_count =
1515 cells->MergeCellSafe(intensity, intensity_var, altitude, altitude_var,
1516 ground_altitude, count, ground_count, r, c, level);
T GetMaxY() const
Get the max y of the rectangle.
T GetMaxX() const
Get the max x of the rectangle.
T GetMinX() const
Get the min x of the rectangle.
T GetMinY() const
Get the min y of the rectangle.
The options of the reflectance map.
unsigned int map_node_size_y_
The map node size in pixels.
unsigned int map_node_size_x_
The map node size in pixels.
bool has_ground_altitude_
unsigned int resolution_num_
unsigned int resolution_ratio_
const unsigned int * GetGroundCountSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get a ground count value by check.
void SetValueSafe(unsigned char intensity, float altitude, unsigned int row, unsigned int col, unsigned int level=0)
Set the several values by check.
virtual bool GetAltitudeImg(cv::Mat *altitude_img) const
get altitude image of node.
void SetUintMatrixRoi(const UIntMatrix *source_matrix, const Rect2D< unsigned int > &source_roi, const Rect2D< unsigned int > &target_roi, unsigned int type, unsigned int level=0)
set unsigned int matrix with a ROI.
PyramidMapMatrix & operator=(const PyramidMapMatrix &map_matrix)
const float * GetIntensityVarSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an intensity variance value by check.
const float * GetIntensitySafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an intensity value by check.
void SetGroundAltitudeSafe(float ground_altitude, unsigned int row, unsigned int col, unsigned int level=0)
Set an altitude ground value by check.
virtual bool GetIntensityImg(cv::Mat *intensity_img) const
get intensity image of node.
void BottomUpSafe()
Propagate the data from fine level to the coarse resolution by check.
void BottomUpBase()
Propagate the data from fine level to the coarse resolution by check.
const float * GetAltitudeSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an altitude value by check.
void SetAltitudeVarMatrix(const float *input, unsigned int size, unsigned int start_index, unsigned int level=0)
void SetIntensityMatrix(const float *input, unsigned int size, unsigned int start_index, unsigned int level=0)
void GetMapCellBase(float **intensity, float **intensity_var, float **altitude, unsigned int **count, unsigned int row, unsigned int col, unsigned int level=0)
Get cell values.
double ComputeMeanIntensity(unsigned int level=0)
Compute mean intensity.
void SetAltitudeSafe(float altitude, unsigned int row, unsigned int col, unsigned int level=0)
Set an altitude value by check.
void SetCountSafe(unsigned int count, unsigned int row, unsigned int col, unsigned int level=0)
Set a count value by check.
void SetGroundCountMatrix(const unsigned int *input, unsigned int size, unsigned int start_index, unsigned int level=0)
void Clear()
Release all memory in PyramidMapMatrix.
void MergeCellBase(const float *intensity, const float *intensity_var, const float *altitude, const unsigned int *count, unsigned int row, unsigned int col, unsigned int level)
Merge the data from another map cell.
const unsigned int * GetCountSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get a count value by check.
void SetIntensityVarSafe(float intensity_var, unsigned int row, unsigned int col, unsigned int level=0)
Set an intensity variance value by check.
const float * GetAltitudeVarSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an altitude variance value by check.
void SetFloatMatrixRoi(const FloatMatrix *source_matrix, const Rect2D< unsigned int > &source_roi, const Rect2D< unsigned int > &target_roi, unsigned int type, unsigned int level=0)
set float matrix with a ROI.
FloatMatrix * GetIntensityVarMatrixSafe(unsigned int level=0)
void SetAltitudeMatrix(const float *input, unsigned int size, unsigned int start_index, unsigned int level=0)
void ResetCell(unsigned int id, unsigned int level=0)
Reset a map cell in a specific resolution level.
static void Reduce(std::shared_ptr< PyramidMapMatrix > cells, const PyramidMapMatrix &new_cells, unsigned int level=0, unsigned int new_level=0)
Combine two PyramidMapMatrix instances (Reduce).
void SetIntensityVarMatrix(const float *input, unsigned int size, unsigned int start_index, unsigned int level=0)
void SetGroundAltitudeMatrix(const float *input, unsigned int size, unsigned int start_index, unsigned int level=0)
UIntMatrix * GetCountMatrixSafe(unsigned int level=0)
virtual void Reset()
Reset map cells data.
FloatMatrix * GetGroundAltitudeMatrixSafe(unsigned int level=0)
const float * GetGroundAltitudeSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an altitude ground value by check.
void AddGroundSample(float ground_altitude, unsigned int row, unsigned int col, unsigned int level=0)
Add ground sample to the map cell.
UIntMatrix * GetGroundCountMatrixSafe(unsigned int level=0)
void AddSampleSafe(float intensity, float altitude, unsigned int row, unsigned int col, unsigned int level)
Add sample to the map cell with check.
void SetGroundCountSafe(unsigned int ground_count, unsigned int row, unsigned int col, unsigned int level=0)
Set a ground count value by check.
void SetIntensitySafe(float intensity, unsigned int row, unsigned int col, unsigned int level=0)
Set an intensity value by check.
void SetCountMatrix(const unsigned int *input, unsigned int size, unsigned int start_index, unsigned int level=0)
virtual void Init(const BaseMapConfig &config)
Initialize the map matrix.
void ResetCells(unsigned int start_id, unsigned int end_id, unsigned int level=0)
Reset map cells data from start_id to end_id in a specific resolution level
FloatMatrix * GetAltitudeVarMatrixSafe(unsigned int level=0)
FloatMatrix * GetIntensityMatrixSafe(unsigned int level=0)
void SetAltitudeVarSafe(float altitude_var, unsigned int row, unsigned int col, unsigned int level=0)
Set an altitude variance value by check.
void GetMapCellSafe(float **intensity, float **intensity_var, float **altitude, float **altitude_var, float **ground_altitude, unsigned int **count, unsigned int **ground_count, unsigned int row, unsigned int col, unsigned int level=0)
Get cell values by check.
FloatMatrix * GetAltitudeMatrixSafe(unsigned int level=0)
void MergeCellSafe(const float *intensity, const float *intensity_var, const float *altitude, const float *altitude_var, const float *ground_altitude, const unsigned int *count, const unsigned int *ground_count, unsigned int row, unsigned int col, unsigned int level)
Merge the data from another map cell by check.