46 double y_max,
double resolution)
65 const double x_min,
const double x_max,
const double y_min,
66 const double y_max,
const double resolution,
70 x_min, x_max, y_min, y_max, resolution, fill_value);
77 m_gmrf_connectivity = new_connectivity_descriptor;
86 m_insertOptions_common =
87 getCommonInsertOptions();
89 m_average_normreadings_mean = 0;
90 m_average_normreadings_var = 0;
91 m_average_normreadings_count = 0;
107 "[clear] Setting covariance matrix to %ux%u\n",
108 (
unsigned int)(m_size_y * m_size_x),
109 (
unsigned int)(m_size_y * m_size_x));
112 m_insertOptions_common->KF_defaultCellMeanValue,
113 m_insertOptions_common->KF_initialCellStd
119 m_cov.setSize(m_size_y * m_size_x, m_size_y * m_size_x);
122 const double KF_covSigma2 =
123 square(m_insertOptions_common->KF_covSigma);
124 const double res2 =
square(m_resolution);
125 const double std0sqr =
126 square(m_insertOptions_common->KF_initialCellStd);
128 for (
int i = 0; i < m_cov.rows(); i++)
130 int cx1 = (i % m_size_x);
131 int cy1 = (i / m_size_x);
133 for (
int j = i; j < m_cov.cols(); j++)
135 int cx2 = (j % m_size_x);
136 int cy2 = (j / m_size_x);
140 m_cov(i, j) = std0sqr;
146 (res2 * static_cast<double>(
150 m_cov(j, i) = m_cov(i, j);
159 case mrKalmanApproximate:
161 m_hasToRecoverMeanAndCov =
true;
167 "[CRandomFieldGridMap2D::clear] Resetting compressed cov. " 168 "matrix and cells\n");
170 m_insertOptions_common->KF_defaultCellMeanValue,
171 m_insertOptions_common->KF_initialCellStd
178 const signed W = m_insertOptions_common->KF_W_size;
179 const size_t N = m_map.size();
180 const size_t K = 2 * W * (W + 1) + 1;
182 const double KF_covSigma2 =
183 square(m_insertOptions_common->KF_covSigma);
184 const double std0sqr =
185 square(m_insertOptions_common->KF_initialCellStd);
186 const double res2 =
square(m_resolution);
188 m_stackedCov.setSize(N, K);
193 const double* ptr_first_row = &m_stackedCov(0, 0);
195 for (
size_t i = 0; i < N; i++)
197 double* ptr = &m_stackedCov(i, 0);
206 for (Acx = 1; Acx <= W; Acx++)
209 (res2 * static_cast<double>(
214 for (Acy = 1; Acy <= W; Acy++)
215 for (Acx = -W; Acx <= W; Acx++)
219 (res2 * static_cast<double>(
226 memcpy(ptr, ptr_first_row,
sizeof(
double) * K);
231 "[clear] %ux%u cells done in %.03fms\n",
unsigned(m_size_x),
232 unsigned(m_size_y), 1000 * tictac.
Tac());
242 "[clear] Generating Prior based on 'Squared Differences'\n");
244 "[clear] Initial map dimension: %u cells, x=(%.2f,%.2f) " 246 static_cast<unsigned int>(m_map.size()), getXMin(), getXMax(),
247 getYMin(), getYMax());
254 float res_coef = 1.f;
256 if (this->m_insertOptions_common->GMRF_use_occupancy_information)
258 if (!m_insertOptions_common->GMRF_simplemap_file.empty())
262 this->m_insertOptions_common->GMRF_simplemap_file);
269 else if (!m_insertOptions_common->GMRF_gridmap_image_file
274 this->m_insertOptions_common->GMRF_gridmap_image_file,
275 this->m_insertOptions_common->GMRF_gridmap_image_res,
277 this->m_insertOptions_common->GMRF_gridmap_image_cx,
278 this->m_insertOptions_common
279 ->GMRF_gridmap_image_cy));
282 this->getResolution() /
283 this->m_insertOptions_common->GMRF_gridmap_image_res;
288 "Neither `simplemap_file` nor `gridmap_image_file` " 289 "found in config/mission file. Quitting.");
294 "Resizing m_map to match Occupancy Gridmap dimensions");
301 "Occupancy Gridmap dimensions: x=(%.2f,%.2f)m " 306 "Occupancy Gridmap dimensions: %u cells, cx=%i cy=%i\n\n",
307 static_cast<unsigned int>(
311 "New map dimensions: %u cells, x=(%.2f,%.2f) " 313 static_cast<unsigned int>(m_map.size()), getXMin(),
314 getXMax(), getYMin(), getYMax());
316 "New map dimensions: %u cells, cx=%u cy=%u\n",
317 static_cast<unsigned int>(m_map.size()),
318 static_cast<unsigned int>(getSizeX()),
319 static_cast<unsigned int>(getSizeY()));
322 "./obstacle_map_from_MRPT_for_GMRF.png");
326 const size_t nodeCount = m_map.size();
329 const size_t nPriorFactors =
330 (this->getSizeX() - 1) * this->getSizeY() +
336 "[clear] Generating " 338 <<
" prior factors for a map size of N=" << nodeCount << endl);
341 m_gmrf.initialize(nodeCount);
343 m_mrf_factors_activeObs.clear();
344 m_mrf_factors_activeObs.resize(
347 m_mrf_factors_priors.clear();
352 if (!m_gmrf_connectivity &&
353 this->m_insertOptions_common->GMRF_use_occupancy_information)
357 "MRF Map Dimmensions: %u x %u cells \n",
358 static_cast<unsigned int>(m_size_x),
359 static_cast<unsigned int>(m_size_y));
361 "Occupancy map Dimmensions: %i x %i cells \n",
370 size_t cxoj_min, cxoj_max, cyoj_min, cyoj_max, seed_cxo,
372 size_t cxoi_min, cxoi_max, cyoi_min, cyoi_max, objective_cxo,
374 size_t cxo_min, cxo_max, cyo_min,
378 std::multimap<size_t, size_t>
379 cell_interconnections;
383 for (
size_t j = 0; j < nodeCount;
387 cxoj_min = floor(cx * res_coef);
388 cxoj_max = cxoj_min + ceil(res_coef - 1);
389 cyoj_min = floor(cy * res_coef);
390 cyoj_max = cyoj_min + ceil(res_coef - 1);
392 seed_cxo = cxoj_min + ceil(res_coef / 2 - 1);
393 seed_cyo = cyoj_min + ceil(res_coef / 2 - 1);
397 if (m_Ocgridmap.
getCell(seed_cxo, seed_cyo) < 0.5)
405 m_mrf_factors_activeObs[j].push_back(new_obs);
406 m_gmrf.addConstraint(*m_mrf_factors_activeObs[j]
413 for (
int neighbor = 0; neighbor < 2; neighbor++)
419 if (cx >= (m_size_x - 1))
continue;
424 else if (neighbor == 1)
426 if (cy >= (m_size_y - 1))
continue;
432 throw std::runtime_error(
"Shouldn't reach here!");
435 cxoi_min = floor(cxi * res_coef);
436 cxoi_max = cxoi_min + ceil(res_coef - 1);
437 cyoi_min = floor(cyi * res_coef);
438 cyoi_max = cyoi_min + ceil(res_coef - 1);
440 objective_cxo = cxoi_min + ceil(res_coef / 2 - 1);
441 objective_cyo = cyoi_min + ceil(res_coef / 2 - 1);
444 cxo_min = min(cxoj_min, cxoi_min);
445 cxo_max = max(cxoj_max, cxoi_max);
446 cyo_min = min(cyoj_min, cyoi_min);
447 cyo_max = max(cyoj_max, cyoi_max);
451 if (exist_relation_between2cells(
452 &m_Ocgridmap, cxo_min, cxo_max, cyo_min,
453 cyo_max, seed_cxo, seed_cyo, objective_cxo,
460 m_insertOptions_common->GMRF_lambdaPrior;
462 m_mrf_factors_priors.push_back(new_prior);
463 m_gmrf.addConstraint(
464 *m_mrf_factors_priors
468 cell_interconnections.insert(
469 std::pair<size_t, size_t>(j, i));
470 cell_interconnections.insert(
471 std::pair<size_t, size_t>(i, j));
477 if (++cx >= m_size_x)
487 m_gmrf_connectivity.get();
489 if (custom_connectivity !=
nullptr)
491 "[CRandomFieldGridMap2D::clear] Initiating prior " 492 "(using user-supplied connectivity pattern)");
495 "[CRandomFieldGridMap2D::clear] Initiating prior " 496 "(fully connected)");
502 size_t cx = 0, cy = 0;
503 for (
size_t j = 0; j < nodeCount; j++)
509 const size_t c_idx_to_check[2] = {cx, cy};
510 const size_t c_idx_to_check_limits[2] = {
511 m_size_x - 1, m_size_y - 1};
512 const size_t c_neighbor_idx_incr[2] = {1, m_size_x};
516 if (c_idx_to_check[
dir] >= c_idx_to_check_limits[
dir])
519 const size_t i = j + c_neighbor_idx_incr[
dir];
522 double edge_lamdba = .0;
523 if (custom_connectivity !=
nullptr)
525 const bool is_connected =
527 this, cx, cy, cx + (
dir == 0 ? 1 : 0),
528 cy + (
dir == 1 ? 1 : 0), edge_lamdba);
529 if (!is_connected)
continue;
534 m_insertOptions_common->GMRF_lambdaPrior;
539 new_prior.
Lambda = edge_lamdba;
541 m_mrf_factors_priors.push_back(new_prior);
542 m_gmrf.addConstraint(
543 *m_mrf_factors_priors.rbegin());
547 if (++cx >= m_size_x)
556 "[clear] Prior built in " << tictac.
Tac() <<
" s ----------");
558 if (m_rfgm_run_update_upon_clear)
561 updateMapEstimation_GMRF();
567 cerr <<
"MAP TYPE NOT RECOGNIZED... QUITTING" << endl;
593 point.
x - m_insertOptions_common->cutoffRadius * 2,
594 point.
x + m_insertOptions_common->cutoffRadius * 2,
595 point.
y - m_insertOptions_common->cutoffRadius * 2,
596 point.
y + m_insertOptions_common->cutoffRadius * 2, defCell);
600 int Ac_cutoff =
round(m_insertOptions_common->cutoffRadius / m_resolution);
601 unsigned Ac_all = 1 + 2 * Ac_cutoff;
602 double minWinValueAtCutOff = exp(-
square(
603 m_insertOptions_common->cutoffRadius / m_insertOptions_common->sigma));
605 if (m_DM_lastCutOff != m_insertOptions_common->cutoffRadius ||
606 m_DM_gaussWindow.size() !=
square(Ac_all))
609 "[CRandomFieldGridMap2D::insertObservation_KernelDM_DMV] " 610 "Precomputing window %ux%u\n",
614 double std = m_insertOptions_common->sigma;
617 m_DM_gaussWindow.resize(Ac_all * Ac_all);
618 m_DM_lastCutOff = m_insertOptions_common->cutoffRadius;
622 auto it = m_DM_gaussWindow.begin();
623 for (
unsigned cx = 0; cx < Ac_all; cx++)
625 for (
unsigned cy = 0; cy < Ac_all; cy++)
627 dist = m_resolution * sqrt(static_cast<double>(
628 square(Ac_cutoff + 1 - cx) +
629 square(Ac_cutoff + 1 - cy)));
635 "[CRandomFieldGridMap2D::insertObservation_KernelDM_DMV] Done!");
640 const int sensor_cx = x2idx(point.
x);
641 const int sensor_cy = y2idx(point.
y);
643 auto windowIt = m_DM_gaussWindow.begin();
645 for (
int Acx = -Ac_cutoff; Acx <= Ac_cutoff; Acx++)
647 for (
int Acy = -Ac_cutoff; Acy <= Ac_cutoff; ++Acy, ++windowIt)
649 const double windowValue = *windowIt;
651 if (windowValue > minWinValueAtCutOff)
653 cell = cellByIndex(sensor_cx + Acx, sensor_cy + Acy);
656 cell->
dm_mean() += windowValue * normReading;
659 const double cell_var =
660 square(normReading - computeMeanCellValue_DM_DMV(cell));
674 : cutoffRadius(sigma * 3.0),
676 GMRF_simplemap_file(
""),
677 GMRF_gridmap_image_file(
""),
679 GMRF_saturate_min(-
std::numeric_limits<double>::max()),
680 GMRF_saturate_max(
std::numeric_limits<double>::max())
692 "sigma = %f\n", sigma);
694 "cutoffRadius = %f\n", cutoffRadius);
696 "R_min = %f\n", R_min);
698 "R_max = %f\n", R_max);
700 "dm_sigma_omega = %f\n", dm_sigma_omega);
703 "KF_covSigma = %f\n", KF_covSigma);
705 "KF_initialCellStd = %f\n", KF_initialCellStd);
707 "KF_observationModelNoise = %f\n",
708 KF_observationModelNoise);
710 "KF_defaultCellMeanValue = %f\n",
711 KF_defaultCellMeanValue);
713 "KF_W_size = %u\n", (
unsigned)KF_W_size);
716 "GMRF_lambdaPrior = %f\n", GMRF_lambdaPrior);
718 "GMRF_lambdaObs = %f\n", GMRF_lambdaObs);
720 "GMRF_lambdaObsLoss = %f\n", GMRF_lambdaObs);
723 "GMRF_use_occupancy_information = %s\n",
724 GMRF_use_occupancy_information ?
"YES" :
"NO");
726 "GMRF_simplemap_file = %s\n",
727 GMRF_simplemap_file.c_str());
729 "GMRF_gridmap_image_file = %s\n",
730 GMRF_gridmap_image_file.c_str());
732 "GMRF_gridmap_image_res = %f\n",
733 GMRF_gridmap_image_res);
735 "GMRF_gridmap_image_cx = %u\n",
736 static_cast<unsigned int>(GMRF_gridmap_image_cx));
738 "GMRF_gridmap_image_cy = %u\n",
739 static_cast<unsigned int>(GMRF_gridmap_image_cy));
748 const std::string& section)
750 sigma =
iniFile.read_float(section.c_str(),
"sigma", sigma);
752 iniFile.read_float(section.c_str(),
"cutoffRadius", cutoffRadius);
753 R_min =
iniFile.read_float(section.c_str(),
"R_min", R_min);
754 R_max =
iniFile.read_float(section.c_str(),
"R_max", R_max);
758 iniFile.read_float(section.c_str(),
"KF_covSigma", KF_covSigma);
759 KF_initialCellStd =
iniFile.read_float(
760 section.c_str(),
"KF_initialCellStd", KF_initialCellStd);
761 KF_observationModelNoise =
iniFile.read_float(
762 section.c_str(),
"KF_observationModelNoise", KF_observationModelNoise);
763 KF_defaultCellMeanValue =
iniFile.read_float(
764 section.c_str(),
"KF_defaultCellMeanValue", KF_defaultCellMeanValue);
767 GMRF_lambdaPrior =
iniFile.read_float(
768 section.c_str(),
"GMRF_lambdaPrior", GMRF_lambdaPrior);
770 iniFile.read_float(section.c_str(),
"GMRF_lambdaObs", GMRF_lambdaObs);
771 GMRF_lambdaObsLoss =
iniFile.read_float(
772 section.c_str(),
"GMRF_lambdaObsLoss", GMRF_lambdaObsLoss);
774 GMRF_use_occupancy_information =
iniFile.read_bool(
775 section.c_str(),
"GMRF_use_occupancy_information",
false,
false);
776 GMRF_simplemap_file =
777 iniFile.read_string(section.c_str(),
"simplemap_file",
"",
false);
778 GMRF_gridmap_image_file =
779 iniFile.read_string(section.c_str(),
"gridmap_image_file",
"",
false);
780 GMRF_gridmap_image_res =
781 iniFile.read_float(section.c_str(),
"gridmap_image_res", 0.01f,
false);
782 GMRF_gridmap_image_cx =
783 iniFile.read_int(section.c_str(),
"gridmap_image_cx", 0,
false);
784 GMRF_gridmap_image_cy =
785 iniFile.read_int(section.c_str(),
"gridmap_image_cy", 0,
false);
797 img.saveToFile(filName);
810 for (
unsigned int y = 0; y <
m_size_y; y++)
812 for (
unsigned int x = 0; x <
m_size_x; x++)
862 double new_x_min,
double new_x_max,
double new_y_min,
double new_y_max,
863 const TRandomFieldCell& defaultValueNewCells,
double additionalMarginMeters)
874 new_x_min, new_x_max, new_y_min, new_y_max, defaultValueNewCells,
875 additionalMarginMeters);
894 "[CRandomFieldGridMap2D::resize] Resizing from %ux%u to %ux%u " 896 static_cast<unsigned>(old_sizeX),
897 static_cast<unsigned>(old_sizeY),
911 for (i = 0; i < N; i++)
916 bool C1_isFromOldMap =
917 Acx_left <= cx1 && cx1 < (Acx_left + old_sizeX) &&
918 Acy_bottom <= cy1 && cy1 < (Acy_bottom + old_sizeY);
922 for (j = i; j < N; j++)
927 bool C2_isFromOldMap =
928 Acx_left <= cx2 && cx2 < (Acx_left + old_sizeX) &&
929 Acy_bottom <= cy2 && cy2 < (Acy_bottom + old_sizeY);
932 if (C1_isFromOldMap && C2_isFromOldMap)
935 unsigned int idx_c1 =
937 old_sizeX * (cy1 - Acy_bottom));
938 unsigned int idx_c2 =
940 old_sizeX * (cy2 - Acy_bottom));
946 ASSERT_((cx1 - Acx_left) < old_sizeX);
947 ASSERT_((cy1 - Acy_bottom) < old_sizeY);
951 ASSERT_((cx2 - Acx_left) < old_sizeX);
952 ASSERT_((cy2 - Acy_bottom) < old_sizeY);
954 ASSERT_(idx_c1 < old_sizeX * old_sizeY);
955 ASSERT_(idx_c2 < old_sizeX * old_sizeY);
958 printf(
"cx1=%u\n", static_cast<unsigned>(cx1));
959 printf(
"cy1=%u\n", static_cast<unsigned>(cy1));
960 printf(
"cx2=%u\n", static_cast<unsigned>(cx2));
961 printf(
"cy2=%u\n", static_cast<unsigned>(cy2));
964 static_cast<unsigned>(Acx_left));
967 static_cast<unsigned>(Acy_bottom));
970 static_cast<unsigned>(idx_c1));
973 static_cast<unsigned>(idx_c2)););
975 m_cov(i, j) = oldCov(idx_c1, idx_c2);
978 if (i == j)
ASSERT_(idx_c1 == idx_c2);
980 if (i == j &&
m_cov(i, i) < 0)
983 "\ni=%u \nj=%i \ncx1,cy1 = %u,%u \n " 984 "cx2,cy2=%u,%u \nidx_c1=%u \nidx_c2=%u " 985 "\nAcx_left=%u \nAcy_bottom=%u " 987 static_cast<unsigned>(i),
988 static_cast<unsigned>(j),
989 static_cast<unsigned>(cx1),
990 static_cast<unsigned>(cy1),
991 static_cast<unsigned>(cx2),
992 static_cast<unsigned>(cy2),
993 static_cast<unsigned>(idx_c1),
994 static_cast<unsigned>(idx_c2),
995 static_cast<unsigned>(Acx_left),
996 static_cast<unsigned>(Acy_bottom),
997 static_cast<unsigned>(old_sizeX));
1010 for (i = 0; i < N; i++)
1015 bool C1_isFromOldMap =
1016 Acx_left <= cx1 && cx1 < (Acx_left + old_sizeX) &&
1017 Acy_bottom <= cy1 && cy1 < (Acy_bottom + old_sizeY);
1018 for (j = i; j < N; j++)
1023 bool C2_isFromOldMap =
1024 Acx_left <= cx2 && cx2 < (Acx_left + old_sizeX) &&
1025 Acy_bottom <= cy2 && cy2 < (Acy_bottom + old_sizeY);
1030 if (!C1_isFromOldMap || !C2_isFromOldMap)
1041 sqrt(static_cast<double>(
1048 "c(i,i)=%e c(j,j)=%e\n",
m_cov(i, i),
1069 printf(
"[CRandomFieldGridMap2D::resize] Done\n");
1084 "[resize] Resizing from %ux%u to %ux%u (%u cells)\n",
1085 static_cast<unsigned>(old_sizeX),
1086 static_cast<unsigned>(old_sizeY),
1093 const size_t N =
m_map.size();
1094 const size_t K = 2 * W * (W + 1) + 1;
1107 const double std0sqr =
1109 double* ptr = &template_row[0];
1111 const double KF_covSigma2 =
1119 for (Acx = 1; Acx <= W; Acx++)
1121 std0sqr * exp(-0.5 *
1122 (res2 * static_cast<double>(
1127 for (Acy = 1; Acy <= W; Acy++)
1128 for (Acx = -W; Acx <= W; Acx++)
1131 (res2 * static_cast<double>(
1139 for (
size_t i = N - 1; i < N; i--)
1144 const int old_idx_of_i =
1145 (cx - Acx_left) + (cy - Acy_bottom) * old_sizeX;
1155 memcpy(new_row, &template_row[0],
sizeof(
double) * K);
1162 if (old_idx_of_i !=
int(i))
1164 const double* ptr_old = &
m_stackedCov(old_idx_of_i, 0);
1166 memcpy(ptr_new, ptr_old,
sizeof(
double) * K);
1190 resize(point.
x - 1, point.
x + 1, point.
y - 1, point.
y + 1, defCell);
1204 int cellIdx =
xy2idx(point.
x, point.
y);
1209 double yk = normReading - cell->
kf_mean();
1211 m_cov(cellIdx, cellIdx) +
1214 ->KF_observationModelNoise);
1215 double sk_1 = 1.0 / sk;
1218 std::vector<TRandomFieldCell>::iterator it;
1221 MRPT_LOG_DEBUG(
"[insertObservation_KF] Updating mean values...");
1226 for (i = 0, it =
m_map.begin(); it !=
m_map.end(); ++it, ++i)
1228 it->kf_mean() += yk * sk_1 *
m_cov(i, cellIdx);
1236 MRPT_LOG_DEBUG(
"[insertObservation_KF] Updating covariance matrix...");
1240 auto* oldCov = (
double*) malloc(
sizeof(
double) * N * N);
1241 double* oldCov_ptr = oldCov;
1242 for (i = 0; i < N; i++)
1244 memcpy(oldCov_ptr, &
m_cov(i, 0),
sizeof(
double) * N);
1249 "Copy matrix %ux%u: %.06fms\n", (
unsigned)
m_cov.
rows(),
1255 const double* oldCov_row_c = oldCov + cellIdx * N;
1256 for (i = 0; i < N; i++)
1258 const double oldCov_i_c = oldCov[i * N + cellIdx];
1259 const double sk_1_oldCov_i_c = sk_1 * oldCov_i_c;
1261 const double* oldCov_row_i = oldCov + i * N;
1262 for (j = i; j < N; j++)
1265 oldCov_row_i[j] - sk_1_oldCov_i_c * oldCov_row_c[j];
1268 m_cov(i, j) = new_cov_ij;
1269 m_cov(j, i) = new_cov_ij;
1274 if (
m_cov(i, i) < 0)
1277 "Wrong insertion in KF! m_cov(%u,%u) = %.5f",
1278 static_cast<unsigned int>(i),
1279 static_cast<unsigned int>(i),
m_cov(i, i));
1283 m_map[i].kf_std() = sqrt(new_cov_ij);
1300 const std::string& filNamePrefix)
const 1306 fil = filNamePrefix + std::string(
"_mean.png");
1320 "% Grid limits: [x_min x_max y_min y_max]\n");
1331 for (
size_t y = 0; y <
m_size_y; y++)
1332 for (
size_t x = 0; x <
m_size_x; x++)
1345 filNamePrefix + std::string(
"_var.txt"),
1348 filNamePrefix + std::string(
"_confidence.txt"),
1363 for (
size_t i = 0; i <
m_size_y; i++)
1364 for (
size_t j = 0; j <
m_size_x; j++)
1373 filNamePrefix + std::string(
"_cells_std.txt"),
1379 filNamePrefix + std::string(
"_mean_compressed_cov.txt"),
1386 filNamePrefix + std::string(
"_mean_cov.txt"));
1393 filNamePrefix + std::string(
"_cells_std.png"),
1409 for (
size_t i = 0; i <
m_size_y; ++i)
1411 for (
size_t j = 0; j <
m_size_x; ++j, ++idx)
1416 XYZ(idx, 0) =
idx2x(j);
1417 XYZ(idx, 1) =
idx2y(i);
1426 filNamePrefix + std::string(
"_cells_std.txt"),
1429 filNamePrefix + std::string(
"_xyz_and_std.txt"),
1431 "% Columns: GRID_X GRID_Y ESTIMATED_Z " 1432 "STD_DEV_OF_ESTIMATED_Z \n");
1445 const std::string& filName)
const 1449 const double std_times = 3;
1457 FILE* f =
os::fopen(filName.c_str(),
"wt");
1461 f,
"%%-------------------------------------------------------\n");
1462 os::fprintf(f,
"%% File automatically generated using the MRPT method:\n");
1463 os::fprintf(f,
"%%'CRandomFieldGridMap2D::saveAsMatlab3DGraph'\n");
1467 f,
"%% Jose Luis Blanco Claraco, University of Malaga @ 2006-2007\n");
1470 f,
"%%-------------------------------------------------------\n\n");
1472 unsigned int cx, cy;
1473 vector<double> xs, ys;
1557 os::fprintf(f,
"set(S1,'FaceAlpha',0.9,'EdgeAlpha',0.9);\n");
1558 os::fprintf(f,
"set(S2,'FaceAlpha',0.4,'EdgeAlpha',0.4);\n");
1559 os::fprintf(f,
"set(S3,'FaceAlpha',0.2,'EdgeAlpha',0.2);\n");
1562 f,
"set(gca,'PlotBoxAspectRatio',[%f %f %f]);\n",
m_x_max -
m_x_min,
1570 "\nfigure; imagesc(xs,ys,z_mean);axis equal;title('Mean " 1571 "value');colorbar;");
1574 "\nfigure; imagesc(xs,ys,(z_upper-z_mean)/%f);axis equal;title('Std " 1575 "dev of estimated value');colorbar;",
1610 unsigned int cx, cy;
1611 vector<double> xs, ys;
1630 auto obj_m = std::make_shared<opengl::CSetOfTriangles>();
1631 auto obj_v = std::make_shared<opengl::CSetOfTriangles>();
1635 double maxVal_m = 0, minVal_m = 1, AMaxMin_m, maxVal_v = 0,
1636 minVal_v = 1, AMaxMin_v;
1646 minVal_m = min(minVal_m, c);
1647 maxVal_m = max(maxVal_m, c);
1650 minVal_v = min(minVal_v, v);
1651 maxVal_v = max(maxVal_v, v);
1655 AMaxMin_m = maxVal_m - minVal_m;
1656 if (AMaxMin_m == 0) AMaxMin_m = 1;
1657 AMaxMin_v = maxVal_v - minVal_v;
1658 if (AMaxMin_v == 0) AMaxMin_v = 1;
1664 triag.
a(0) = triag.
a(1) = triag.
a(2) = 0xA0;
1673 ASSERT_(cell_x_1y !=
nullptr);
1675 ASSERT_(cell_xy_1 !=
nullptr);
1678 ASSERT_(cell_x_1y_1 !=
nullptr);
1699 double col_xy = c_xy;
1700 double col_x_1y = c_x_1y;
1701 double col_xy_1 = c_xy_1;
1702 double col_x_1y_1 = c_x_1y_1;
1705 triag.
x(0) = xs[cx];
1706 triag.
y(0) = ys[cy];
1708 triag.
x(1) = xs[cx];
1709 triag.
y(1) = ys[cy - 1];
1710 triag.
z(1) = c_xy_1;
1711 triag.
x(2) = xs[cx - 1];
1712 triag.
y(2) = ys[cy - 1];
1713 triag.
z(2) = c_x_1y_1;
1719 obj_m->insertTriangle(triag);
1722 triag.
x(0) = xs[cx];
1723 triag.
y(0) = ys[cy];
1725 triag.
x(1) = xs[cx - 1];
1726 triag.
y(1) = ys[cy - 1];
1727 triag.
z(1) = c_x_1y_1;
1728 triag.
x(2) = xs[cx - 1];
1729 triag.
y(2) = ys[cy];
1730 triag.
z(2) = c_x_1y;
1734 obj_m->insertTriangle(triag);
1750 col_x_1y = v_x_1y / 10;
1752 col_xy_1 = v_xy_1 / 10;
1754 col_x_1y_1 = v_x_1y_1 / 10;
1758 triag.
x(0) = xs[cx];
1759 triag.
y(0) = ys[cy];
1760 triag.
z(0) = c_xy + v_xy;
1761 triag.
x(1) = xs[cx];
1762 triag.
y(1) = ys[cy - 1];
1763 triag.
z(1) = c_xy_1 + v_xy_1;
1764 triag.
x(2) = xs[cx - 1];
1765 triag.
y(2) = ys[cy - 1];
1766 triag.
z(2) = c_x_1y_1 + v_x_1y_1;
1772 obj_v->insertTriangle(triag);
1775 triag.
x(0) = xs[cx];
1776 triag.
y(0) = ys[cy];
1777 triag.
z(0) = c_xy + v_xy;
1778 triag.
x(1) = xs[cx - 1];
1779 triag.
y(1) = ys[cy - 1];
1780 triag.
z(1) = c_x_1y_1 + v_x_1y_1;
1781 triag.
x(2) = xs[cx - 1];
1782 triag.
y(2) = ys[cy];
1783 triag.
z(2) = c_x_1y + v_x_1y;
1789 obj_v->insertTriangle(triag);
1793 meanObj->insert(obj_m);
1794 varObj->insert(obj_v);
1803 auto obj_m = std::make_shared<opengl::CSetOfTriangles>();
1804 auto obj_v = std::make_shared<opengl::CSetOfTriangles>();
1808 double maxVal_m = 0, minVal_m = 1, AMaxMin_m, maxVal_v = 0,
1809 minVal_v = 1, AMaxMin_v;
1819 minVal_m = min(minVal_m, c);
1820 maxVal_m = max(maxVal_m, c);
1823 minVal_v = min(minVal_v, v);
1824 maxVal_v = max(maxVal_v, v);
1828 AMaxMin_m = maxVal_m - minVal_m;
1829 if (AMaxMin_m == 0) AMaxMin_m = 1;
1830 AMaxMin_v = maxVal_v - minVal_v;
1831 if (AMaxMin_v == 0) AMaxMin_v = 1;
1836 triag.
a(0) = triag.
a(1) = triag.
a(2) = 0xA0;
1845 ASSERT_(cell_x_1y !=
nullptr);
1847 ASSERT_(cell_xy_1 !=
nullptr);
1850 ASSERT_(cell_x_1y_1 !=
nullptr);
1871 double col_xy = c_xy;
1872 double col_x_1y = c_x_1y;
1873 double col_xy_1 = c_xy_1;
1874 double col_x_1y_1 = c_x_1y_1;
1877 triag.
x(0) = xs[cx];
1878 triag.
y(0) = ys[cy];
1880 triag.
x(1) = xs[cx];
1881 triag.
y(1) = ys[cy - 1];
1882 triag.
z(1) = c_xy_1;
1883 triag.
x(2) = xs[cx - 1];
1884 triag.
y(2) = ys[cy - 1];
1885 triag.
z(2) = c_x_1y_1;
1891 obj_m->insertTriangle(triag);
1894 triag.
x(0) = xs[cx];
1895 triag.
y(0) = ys[cy];
1897 triag.
x(1) = xs[cx - 1];
1898 triag.
y(1) = ys[cy - 1];
1899 triag.
z(1) = c_x_1y_1;
1900 triag.
x(2) = xs[cx - 1];
1901 triag.
y(2) = ys[cy];
1902 triag.
z(2) = c_x_1y;
1908 obj_m->insertTriangle(triag);
1914 double v_x_1y = min(
1916 double v_xy_1 = min(
1918 double v_x_1y_1 = min(
1924 col_x_1y_1 = v_x_1y_1;
1927 triag.
x(0) = xs[cx];
1928 triag.
y(0) = ys[cy];
1930 triag.
x(1) = xs[cx];
1931 triag.
y(1) = ys[cy - 1];
1932 triag.
z(1) = v_xy_1;
1933 triag.
x(2) = xs[cx - 1];
1934 triag.
y(2) = ys[cy - 1];
1935 triag.
z(2) = v_x_1y_1;
1941 obj_v->insertTriangle(triag);
1944 triag.
x(0) = xs[cx];
1945 triag.
y(0) = ys[cy];
1947 triag.
x(1) = xs[cx - 1];
1948 triag.
y(1) = ys[cy - 1];
1949 triag.
z(1) = v_x_1y_1;
1950 triag.
x(2) = xs[cx - 1];
1951 triag.
y(2) = ys[cy];
1952 triag.
z(2) = v_x_1y;
1958 obj_v->insertTriangle(triag);
1962 meanObj->insert(obj_m);
1963 varObj->insert(obj_v);
1988 const double alpha =
1991 const double r_val =
2003 const double alpha =
2006 const double r_val =
2022 const double x,
const double y,
double& out_predict_response,
2023 double& out_predict_response_variance,
bool do_sensor_normalization,
2028 vector<TInterpQuery> queries;
2029 switch (interp_method)
2033 queries[0].cx =
x2idx(x);
2034 queries[0].cy =
y2idx(y);
2035 queries[0].coef = 1.0;
2046 queries[0].cx =
x2idx(x);
2047 queries[0].cy =
y2idx(y);
2048 queries[0].coef = 1.0;
2067 queries[0].coef = K_1 * (
idx2x(queries[3].cx) - x) *
2068 (
idx2y(queries[3].cy) - y);
2069 queries[1].coef = K_1 * (
idx2x(queries[3].cx) - x) *
2070 (y -
idx2y(queries[0].cy));
2071 queries[2].coef = K_1 * (x -
idx2x(queries[0].cx)) *
2072 (
idx2y(queries[3].cy) - y);
2073 queries[3].coef = K_1 * (x -
idx2x(queries[0].cx)) *
2074 (y -
idx2y(queries[0].cy));
2082 for (
auto& q : queries)
2149 out_predict_response = 0;
2150 out_predict_response_variance = 0;
2151 for (
auto& querie : queries)
2153 out_predict_response += querie.val * querie.coef;
2154 out_predict_response_variance += querie.var * querie.coef;
2158 if (do_sensor_normalization)
2159 out_predict_response =
2161 out_predict_response *
2176 "Inserting KF2: (" << normReading <<
") at Position" << point << endl);
2179 const size_t K = 2 * W * (W + 1) + 1;
2180 const size_t W21 = 2 * W + 1;
2181 const size_t W21sqr = W21 * W21;
2197 point.
x - Aspace, point.
x + Aspace, point.
y - Aspace, point.
y + Aspace,
2203 const size_t N =
m_map.size();
2220 const int cellIdx =
xy2idx(point.
x, point.
y);
2225 double yk = normReading - cell->
kf_mean();
2231 double sk_1 = 1.0 / sk;
2234 MRPT_LOG_DEBUG(
"[insertObservation_KF2] Updating mean values...");
2243 const int cx_c =
x2idx(point.
x);
2244 const int cy_c =
y2idx(point.
y);
2246 const int Acx0 = max(-W, -cx_c);
2247 const int Acy0 = max(-W, -cy_c);
2248 const int Acx1 = min(W,
int(
m_size_x) - 1 - cx_c);
2249 const int Acy1 = min(W,
int(
m_size_y) - 1 - cy_c);
2256 std::vector<int> window_idxs(W21sqr, -1);
2262 for (
int Acy = Acy0; Acy <= 0; Acy++)
2264 int limit_cx = Acy < 0 ? Acx1 : -1;
2266 size_t idx = cx_c + Acx0 +
m_size_x * (cy_c + Acy);
2267 int idx_c_in_idx = -Acy * W21 - Acx0;
2269 int window_idx = Acx0 + W + (Acy + W) * W21;
2271 for (
int Acx = Acx0; Acx <= limit_cx; Acx++)
2274 const double cov_i_c =
m_stackedCov(idx, idx_c_in_idx);
2277 m_map[idx].kf_mean() += yk * sk_1 * cov_i_c;
2280 cross_covs_c_i[window_idx] = cov_i_c;
2281 window_idxs[window_idx++] = idx;
2289 for (
int Acy = 0; Acy <= Acy1; Acy++)
2291 int start_cx = Acy > 0 ? Acx0 : 0;
2293 size_t idx = cx_c + start_cx +
m_size_x * (cy_c + Acy);
2297 (W + 1) + (Acy - 1) * W21 + (start_cx + W);
2301 int window_idx = start_cx + W + (Acy + W) * W21;
2303 for (
int Acx = start_cx; Acx <= Acx1; Acx++)
2305 ASSERT_(idx_i_in_c >= 0 && idx_i_in_c <
int(K));
2308 m_map[idx].kf_mean() += yk * sk_1 * cov_i_c;
2311 cross_covs_c_i[window_idx] = cov_i_c;
2312 window_idxs[window_idx++] = idx;
2327 for (
size_t i = 0; i < W21sqr; i++)
2329 const int idx_i = window_idxs[i];
2330 if (idx_i < 0)
continue;
2336 const double cov_c_i = cross_covs_c_i[i];
2338 for (
size_t j = i; j < W21sqr; j++)
2340 const int idx_j = window_idxs[j];
2341 if (idx_j < 0)
continue;
2347 const int Ax = cx_j - cx_i;
2352 const int Ay = cy_j - cy_i;
2355 const double cov_c_j = cross_covs_c_i[j];
2359 idx_j_in_i = Ax + W + (Ay - 1) * W21 + W + 1;
2364 double& cov_to_change =
m_stackedCov(idx_i, idx_j_in_i);
2365 double Delta_cov = cov_c_j * cov_c_i * sk_1;
2366 if (i == j && cov_to_change < Delta_cov)
2368 "Negative variance value appeared! Please increase the " 2369 "size of the window " 2370 "(W).\n(m_insertOptions_common->KF_covSigma=%f)",
2373 cov_to_change -= Delta_cov;
2391 const size_t N =
m_map.size();
2392 for (
size_t i = 0; i < N; i++)
2404 for (
size_t i = 0; i < N; ++i) out_means[i] =
BASE::m_map[i].kf_mean();
2421 for (
size_t i = 0; i < N; ++i)
2440 for (
size_t i = 0; i < N; ++i)
2442 m_map[i].kf_mean() = in_means[i];
2469 "insertObservation() isn't implemented for selected 'mapType'");
2475 const bool update_map,
const bool time_invariant,
2476 const double reading_stddev)
2494 sensorReading, point, update_map, time_invariant,
2495 reading_stddev == .0
2502 "insertObservation() isn't implemented for selected 'mapType'");
2511 const bool update_map,
const bool time_invariant,
2512 const double reading_information)
2517 const int cellIdx =
xy2idx(point.
x, point.
y);
2525 new_obs.
Lambda = reading_information;
2532 catch (
const std::exception& e)
2534 cerr <<
"Exception while Inserting new Observation: " << e.what()
2554 size_t(
m_map.size()) ==
size_t(x_var.
size()));
2557 for (
size_t j = 0; j <
m_map.size(); j++)
2561 : std::sqrt(x_var[j]);
2562 m_map[j].gmrf_mean() += x_incr[j];
2575 for (
auto ito = obs.begin(); ito != obs.end();)
2577 if (!ito->time_invariant)
2584 if (ito->Lambda < 0)
2587 ito = obs.erase(ito);
2598 size_t cxo_max,
size_t cyo_min,
size_t cyo_max,
const size_t seed_cxo,
2599 const size_t seed_cyo,
const size_t objective_cxo,
2600 const size_t objective_cyo)
2606 cxo_min = max(cxo_min, (
size_t)0);
2607 cxo_max = min(cxo_max, (
size_t)m_Ocgridmap->
getSizeX() - 1);
2608 cyo_min = max(cyo_min, (
size_t)0);
2609 cyo_max = min(cyo_max, (
size_t)m_Ocgridmap->
getSizeY() - 1);
2615 if ((seed_cxo < cxo_min) || (seed_cxo >= cxo_max) || (seed_cyo < cyo_min) ||
2616 (seed_cyo >= cyo_max))
2621 if ((objective_cxo < cxo_min) || (objective_cxo >= cxo_max) ||
2622 (objective_cyo < cyo_min) || (objective_cyo >= cyo_max))
2629 if ((m_Ocgridmap->
getCell(seed_cxo, seed_cyo) < 0.5) !=
2630 (m_Ocgridmap->
getCell(objective_cxo, objective_cyo) < 0.5))
2638 cxo_max - cxo_min + 1, cyo_max - cyo_min + 1);
2645 matExp(seed_cxo - cxo_min, seed_cyo - cyo_min) = 1;
2650 while (seedsOld < seedsNew)
2652 seedsOld = seedsNew;
2654 for (
int col = 0; col < matExp.
cols(); col++)
2656 for (
int row = 0; row < matExp.
rows(); row++)
2659 if (matExp(row, col) == 1)
2661 matExp(row, col) = 2;
2663 for (
int i = -1; i <= 1; i++)
2665 for (
int j = -1; j <= 1; j++)
2668 if ((
int(row) + j >= 0) &&
2669 (
int(row) + j <=
int(matExp.
rows() - 1)) &&
2670 (int(col) + i >= 0) &&
2671 (
int(col) + i <= int(matExp.
cols()) - 1))
2673 if (!((i == 0 && j == 0) ||
2674 !(matExp(row + j, col + i) == 0)))
2678 row + cxo_min, col + cyo_min) <
2682 col + i + cyo_min) < 0.5))
2684 if ((row + j + cxo_min ==
2686 (col + i + cyo_min ==
2693 matExp(row + j, col + i) = 1;
2720 return m_parent->m_map[this->node_id].gmrf_mean() - this->obsValue;
2724 return this->Lambda;
2733 return m_parent->m_map[this->node_id_i].gmrf_mean() -
2734 m_parent->m_map[this->node_id_j].gmrf_mean();
2738 return this->Lambda;
2741 double& dr_dx_i,
double& dr_dx_j)
const
void clear()
Erase all the contents of the map.
#define IMPLEMENTS_VIRTUAL_SERIALIZABLE(class_name, base_class, NS)
This must be inserted as implementation of some required members for virtual CSerializable classes: ...
float getXMax() const
Returns the "x" coordinate of right side of grid map.
double Tac() noexcept
Stops the stopwatch.
Gaussian kernel-based estimator (see discussion in mrpt::maps::CRandomFieldGridMap2D) ...
Parameters for CMetricMap::compute3DMatchingRatio()
std::vector< TRandomFieldCell > m_map
The cells.
void colormap(const TColormap &color_map, const float color_index, float &r, float &g, float &b)
Transform a float number in the range [0,1] into RGB components.
float getYMin() const
Returns the "y" coordinate of top side of grid map.
bool empty() const
Returns size()!=0.
void getMeanAndSTD(mrpt::math::CVectorDouble &out_means, mrpt::math::CVectorDouble &out_STD) const
Return the mean and STD vectors of the full Kalman filter estimate (works for all KF-based methods)...
int y2idx(double y) const
#define MRPT_LOG_DEBUG(_STRING)
Use: MRPT_LOG_DEBUG("message");
double & dm_mean()
[Kernel-methods only] The cumulative weighted readings of this cell
double evaluateResidual() const override
Return the residual/error of this observation.
This class is a "CSerializable" wrapper for "CMatrixDynamic<double>".
double & kf_std()
[KF-methods only] The standard deviation value of this cell
void resize(size_t row, size_t col)
double & dm_mean_w()
[Kernel-methods only] The cumulative weights (concentration = alpha
virtual void saveAsMatlab3DGraph(const std::string &filName) const
Save a matlab ".m" file which represents as 3D surfaces the mean and a given confidence level for the...
void updateEstimation(mrpt::math::CVectorDouble &solved_x_inc, mrpt::math::CVectorDouble *solved_variances=nullptr)
float getResolution() const
Returns the resolution of the grid map.
#define THROW_EXCEPTION(msg)
TInsertionOptionsCommon()
Default values loader.
std::string std::string format(std::string_view fmt, ARGS &&... args)
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
bool enableSaveAs3DObject
(Default=true) If false, calling CMetricMap::getAs3DObject() will have no effects ...
double m_average_normreadings_mean
float KF_defaultCellMeanValue
The default value for the mean of cells' concentration.
int void fclose(FILE *f)
An OS-independent version of fclose.
bool eraseConstraint(const FactorBase &c)
Removes a constraint.
double getInformation() const override
Return the inverse of the variance of this constraint.
const float & x(size_t i) const
void fill(const Scalar &val)
bool exist_relation_between2cells(const mrpt::maps::COccupancyGridMap2D *m_Ocgridmap, size_t cxo_min, size_t cxo_max, size_t cyo_min, size_t cyo_max, const size_t seed_cxo, const size_t seed_cyo, const size_t objective_cxo, const size_t objective_cyo)
Check if two cells of the gridmap (m_map) are connected, based on the provided occupancy gridmap...
Base class for user-supplied objects capable of describing cells connectivity, used to build prior fa...
void insertObservation_GMRF(double normReading, const mrpt::math::TPoint2D &point, const bool update_map, const bool time_invariant, const double reading_information)
The implementation of "insertObservation" for the Gaussian Markov Random Field map model...
A triangle (float coordinates) with RGBA colors (u8) and UV (texture coordinates) for each vertex...
void evalJacobian(double &dr_dx_i, double &dr_dx_j) const override
Returns the derivative of the residual wrt the node values.
std::vector< std::list< TObservationGMRF > > m_mrf_factors_activeObs
Vector with the active observations and their respective Information.
A high-performance stopwatch, with typical resolution of nanoseconds.
mrpt::math::CMatrixD m_cov
The whole covariance matrix, used for the Kalman Filter map representation.
size_type size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
double Lambda
"Information" of the observation (=inverse of the variance)
mrpt::vision::TStereoCalibParams params
Double mean + variance Gaussian kernel-based estimator (see discussion in mrpt::maps::CRandomFieldGri...
TMapRepresentation
The type of map representation to be used, see CRandomFieldGridMap2D for a discussion.
void idx2cxcy(int idx, int &cx, int &cy) const
Transform a global (linear) cell index value into its corresponding (x,y) cell indexes.
void getMeanAndCov(mrpt::math::CVectorDouble &out_means, mrpt::math::CMatrixDouble &out_cov) const
Return the mean and covariance vector of the full Kalman filter estimate (works for all KF-based meth...
bool loadFromBitmapFile(const std::string &file, float resolution, const mrpt::math::TPoint2D &origin=mrpt::math::TPoint2D(std::numeric_limits< double >::max(), std::numeric_limits< double >::max()))
Load the gridmap from a image in a file (the format can be any supported by CImage::loadFromFile).
static Ptr Create(Args &&... args)
TMapGenericParams genericMapParams
Common params to all maps.
double idx2x(int cx) const
Transform a cell index into a coordinate value of the cell central point.
#define MRPT_END_WITH_CLEAN_UP(stuff)
TMapRepresentation getMapType()
Return the type of the random-field grid map, according to parameters passed on construction.
std::vector< TRandomFieldCell > & m_map_castaway_const() const
Used only from logically const method that really need to modify the object.
void evalJacobian(double &dr_dx) const override
Returns the derivative of the residual wrt the node value.
void saveToTextFile(const std::string &file, mrpt::math::TMatrixTextFileFormat fileFormat=mrpt::math::MATRIX_FORMAT_ENG, bool appendMRPTHeader=false, const std::string &userHeader=std::string()) const
Saves the vector/matrix to a file compatible with MATLAB/Octave text format.
void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &outObj) const override
Returns a 3D object representing the map (mean)
double idx2y(int cy) const
double computeMeanCellValue_DM_DMV(const TRandomFieldCell *cell) const
Computes the average cell concentration, or the overall average value if it has never been observed...
virtual bool getEdgeInformation(const CRandomFieldGridMap2D *parent, size_t icx, size_t icy, size_t jcx, size_t jcy, double &out_edge_information)=0
Implement the check of whether node i=(icx,icy) is connected with node j=(jcx,jcy).
void recoverMeanAndCov() const
In the KF2 implementation, takes the auxiliary matrices and from them update the cells' mean and std ...
void internal_dumpToTextStream_common(std::ostream &out) const
See utils::CLoadableOptions.
TMapRepresentation m_mapType
The map representation type of this map, as passed in the constructor.
mrpt::graphs::ScalarFactorGraph m_gmrf
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream, std::istream, std::ostream, std::stringstream.
const uint8_t & a(size_t i) const
void setSize(const double x_min, const double x_max, const double y_min, const double y_max, const double resolution, const TRandomFieldCell *fill_value=nullptr)
Changes the size of the grid, ERASING all previous contents.
void saturate(T &var, const T sat_min, const T sat_max)
Saturate the value of var (the variable gets modified) so it does not get out of [min,max].
std::array< Vertex, 3 > vertices
double getInformation() const override
Return the inverse of the variance of this constraint.
float KF_observationModelNoise
The sensor model noise (in normalized concentration units).
~CRandomFieldGridMap2D() override
Destructor.
#define ASSERT_(f)
Defines an assertion mechanism.
TInsertionOptionsCommon * m_insertOptions_common
Common options to all random-field grid maps: pointer that is set to the derived-class instance of "i...
bool time_invariant
whether the observation will lose weight (lambda) as time goes on (default false) ...
int xy2idx(double x, double y) const
bool saveAsBitmapFile(const std::string &file) const
Saves the gridmap as a graphical file (BMP,PNG,...).
float R_min
Limits for normalization of sensor readings.
virtual void saveAsBitmapFile(const std::string &filName) const
Save the current map as a graphical file (BMP,PNG,...).
This class allows loading and storing values and vectors of different types from a configuration text...
bool isEmpty() const override
Returns true if the map is empty/no observation has been inserted (in this class it always return fal...
This base provides a set of functions for maths stuff.
double & kf_mean()
[KF-methods only] The mean value of this cell
void resize(double new_x_min, double new_x_max, double new_y_min, double new_y_max, const TRandomFieldCell &defaultValueNewCells, double additionalMarginMeters=1.0f) override
Changes the size of the grid, maintaining previous contents.
void updateMapEstimation_GMRF()
solves the minimum quadratic system to determine the new concentration of each cell ...
#define MRPT_LOG_DEBUG_FMT(_FMT_STRING,...)
Use: MRPT_LOG_DEBUG_FMT("i=%u", i);
float getXMin() const
Returns the "x" coordinate of left side of grid map.
The contents of each cell in a CRandomFieldGridMap2D map.
double obsValue
Observation value.
void setMeanAndSTD(mrpt::math::CVectorDouble &out_means, mrpt::math::CVectorDouble &out_STD)
Load the mean and STD vectors of the full Kalman filter estimate (works for all KF-based methods)...
Versatile class for consistent logging and management of output messages.
TRandomFieldCell * cellByPos(double x, double y)
Returns a pointer to the contents of a cell given by its coordinates, or nullptr if it is out of the ...
"Brute-force" Kalman filter (see discussion in mrpt::maps::CRandomFieldGridMap2D) ...
virtual void setSize(const double x_min, const double x_max, const double y_min, const double y_max, const double resolution, const TRandomFieldCell *fill_value=nullptr)
Changes the size of the grid, erasing previous contents.
This namespace contains representation of robot actions and observations.
string iniFile(myDataDir+string("benchmark-options.ini"))
void insertObservation_KernelDM_DMV(double normReading, const mrpt::math::TPoint2D &point, bool is_DMV)
The implementation of "insertObservation" for Achim Lilienthal's map models DM & DM+V.
unsigned int getSizeX() const
Returns the horizontal size of grid map in cells count.
void setFromMatrix(const MAT &m, bool matrix_is_normalized=true)
Set the image from a matrix, interpreted as grayscale intensity values, in the range [0...
virtual ~ConnectivityDescriptor()
double dm_sigma_omega
[DM/DM+V methods] The scaling parameter for the confidence "alpha" values (see the IROS 2009 paper; s...
TRandomFieldCell * cellByIndex(unsigned int cx, unsigned int cy)
Returns a pointer to the contents of a cell given by its cell indexes, or nullptr if it is out of the...
void insertObservation_KF(double normReading, const mrpt::math::TPoint2D &point)
The implementation of "insertObservation" for the (whole) Kalman Filter map model.
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
Use: MRPT_LOG_DEBUG_STREAM("Var=" << value << " foo=" << foo_var);
virtual void getAsBitmapFile(mrpt::img::CImage &out_img) const
Returns an image just as described in saveAsBitmapFile.
size_type rows() const
Number of rows in the matrix.
size_type cols() const
Number of columns in the matrix.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
(see discussion in mrpt::maps::CRandomFieldGridMap2D)
void internal_loadFromConfigFile_common(const mrpt::config::CConfigFileBase &source, const std::string §ion)
See utils::CLoadableOptions.
bool m_hasToRecoverMeanAndCov
Only for the KF2 implementation.
void addConstraint(const UnaryFactorVirtualBase &listOfConstraints)
Insert constraints into the GMRF problem.
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
void setCellsConnectivity(const ConnectivityDescriptor::Ptr &new_connectivity_descriptor)
Sets a custom object to define the connectivity between cells.
return_t square(const num_t x)
Inline function for the square of a number.
fixed floating point 'f'
#define MRPT_LOAD_CONFIG_VAR( variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
double GMRF_saturate_min
(Default:-inf,+inf) Saturate the estimated mean in these limits
A class for storing an occupancy grid map.
This class is a "CSerializable" wrapper for "CMatrixFloat".
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
const float & y(size_t i) const
CRandomFieldGridMap2D represents a 2D grid map where each cell is associated one real-valued property...
double & gmrf_mean()
[GMRF only] The mean value of this cell
Gaussian Markov Random Field, squared differences prior weights between 4 neighboring cells (see disc...
float KF_covSigma
The "sigma" for the initial covariance value between cells (in meters).
Declares a virtual base class for all metric maps storage classes.
bool GMRF_skip_variance
(Default:false) Skip the computation of the variance, just compute the mean
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
mrpt::vision::TStereoCalibResults out
void updateMapEstimation()
Run the method-specific procedure required to ensure that the mean & variances are up-to-date with al...
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const override
The implementation in this class just calls all the corresponding method of the contained metric maps...
const float & z(size_t i) const
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
void internal_clear() override
Erase all the contents of the map.
double m_average_normreadings_var
double dmv_var_mean
[Kernel DM-V only] The cumulative weighted variance of this cell
uint16_t KF_W_size
[mrKalmanApproximate] The size of the window of neighbor cells.
int x2idx(double x) const
Transform a coordinate values into cell indexes.
float getYMax() const
Returns the "y" coordinate of bottom side of grid map.
double computeConfidenceCellValue_DM_DMV(const TRandomFieldCell *cell) const
Computes the confidence of the cell concentration (alpha)
virtual void predictMeasurement(const double x, const double y, double &out_predict_response, double &out_predict_response_variance, bool do_sensor_normalization, const TGridInterpolationMethod interp_method=gimNearest)
Returns the prediction of the measurement at some (x,y) coordinates, and its certainty (in the form o...
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
mrpt::math::CMatrixD m_stackedCov
The compressed band diagonal matrix for the KF2 implementation.
bool saveToFile(const std::string &fileName, int jpeg_quality=95) const
Save the image to a file, whose format is determined from the extension (internally uses OpenCV)...
double evaluateResidual() const override
Return the residual/error of this observation.
double Lambda
"Information" of the observation (=inverse of the variance)
void resize(std::size_t N, bool zeroNewElements=false)
void Tic() noexcept
Starts the stopwatch.
double computeVarCellValue_DM_DMV(const TRandomFieldCell *cell) const
Computes the estimated variance of the cell concentration, or the overall average variance if it has ...
unsigned int getSizeY() const
Returns the vertical size of grid map in cells count.
T saturate_val(const T &value, const T sat_min, const T sat_max)
Like saturate() but it returns the value instead of modifying the variable.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
void insertObservation_KF2(double normReading, const mrpt::math::TPoint2D &point)
The implementation of "insertObservation" for the Efficient Kalman Filter map model.
void loadFromSimpleMap(const mrpt::maps::CSimpleMap &Map)
!
float KF_initialCellStd
The initial standard deviation of each cell's concentration (will be stored both at each cell's struc...
virtual void getAsMatrix(mrpt::math::CMatrixDouble &out_mat) const
Like saveAsBitmapFile(), but returns the data in matrix form (first row in the matrix is the upper (y...
float getCell(int x, int y) const
Read the real valued [0,1] contents of a cell, given its index.
double GMRF_lambdaObsLoss
The loss of information of the observations with each iteration.
A class for storing images as grayscale or RGB bitmaps.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
void insertIndividualReading(const double sensorReading, const mrpt::math::TPoint2D &point, const bool update_map=true, const bool time_invariant=true, const double reading_stddev=.0)
Direct update of the map with a reading in a given position of the map, using the appropriate method ...
float compute3DMatchingRatio(const mrpt::maps::CMetricMap *otherMap, const mrpt::poses::CPose3D &otherMapPose, const TMatchingRatioParams ¶ms) const override
See docs in base class: in this class this always returns 0.
int round(const T value)
Returns the closer integer (int) to x.