44 double y_max,
double resolution)
47 m_rfgm_run_update_upon_clear(true),
48 m_insertOptions_common(
nullptr),
51 m_hasToRecoverMeanAndCov(true),
53 m_average_normreadings_mean(0),
54 m_average_normreadings_var(0),
55 m_average_normreadings_count(0)
68 const double x_min,
const double x_max,
const double y_min,
69 const double y_max,
const double resolution,
73 x_min, x_max, y_min, y_max, resolution, fill_value);
80 m_gmrf_connectivity = new_connectivity_descriptor;
89 m_insertOptions_common =
90 getCommonInsertOptions();
92 m_average_normreadings_mean = 0;
93 m_average_normreadings_var = 0;
94 m_average_normreadings_count = 0;
110 "[clear] Setting covariance matrix to %ux%u\n",
111 (
unsigned int)(m_size_y * m_size_x),
112 (
unsigned int)(m_size_y * m_size_x));
115 m_insertOptions_common->KF_defaultCellMeanValue,
116 m_insertOptions_common->KF_initialCellStd
122 m_cov.setSize(m_size_y * m_size_x, m_size_y * m_size_x);
125 const double KF_covSigma2 =
126 square(m_insertOptions_common->KF_covSigma);
127 const double res2 =
square(m_resolution);
128 const double std0sqr =
129 square(m_insertOptions_common->KF_initialCellStd);
131 for (
size_t i = 0; i < m_cov.getRowCount(); i++)
133 int cx1 = (i % m_size_x);
134 int cy1 = (i / m_size_x);
136 for (
size_t j = i; j < m_cov.getColCount(); j++)
138 int cx2 = (j % m_size_x);
139 int cy2 = (j / m_size_x);
143 m_cov(i, j) = std0sqr;
149 exp(-0.5 * (res2 * static_cast<double>(
153 m_cov(j, i) = m_cov(i, j);
162 case mrKalmanApproximate:
164 m_hasToRecoverMeanAndCov =
true;
170 "[CRandomFieldGridMap2D::clear] Resetting compressed cov. " 171 "matrix and cells\n");
173 m_insertOptions_common->KF_defaultCellMeanValue,
174 m_insertOptions_common->KF_initialCellStd
181 const signed W = m_insertOptions_common->KF_W_size;
182 const size_t N = m_map.size();
183 const size_t K = 2 * W * (W + 1) + 1;
185 const double KF_covSigma2 =
186 square(m_insertOptions_common->KF_covSigma);
187 const double std0sqr =
188 square(m_insertOptions_common->KF_initialCellStd);
189 const double res2 =
square(m_resolution);
191 m_stackedCov.setSize(N, K);
196 const double* ptr_first_row = m_stackedCov.get_unsafe_row(0);
198 for (
size_t i = 0; i < N; i++)
200 double* ptr = m_stackedCov.get_unsafe_row(i);
209 for (Acx = 1; Acx <= W; Acx++)
212 exp(-0.5 * (res2 * static_cast<double>(
217 for (Acy = 1; Acy <= W; Acy++)
218 for (Acx = -W; Acx <= W; Acx++)
222 (res2 * static_cast<double>(
229 memcpy(ptr, ptr_first_row,
sizeof(
double) * K);
234 "[clear] %ux%u cells done in %.03fms\n",
unsigned(m_size_x),
235 unsigned(m_size_y), 1000 * tictac.
Tac());
245 "[clear] Generating Prior based on 'Squared Differences'\n");
247 "[clear] Initial map dimension: %u cells, x=(%.2f,%.2f) " 249 static_cast<unsigned int>(m_map.size()), getXMin(), getXMax(),
250 getYMin(), getYMax());
257 float res_coef = 1.f;
259 if (this->m_insertOptions_common->GMRF_use_occupancy_information)
261 if (!m_insertOptions_common->GMRF_simplemap_file.empty())
265 this->m_insertOptions_common->GMRF_simplemap_file) >>
273 !m_insertOptions_common->GMRF_gridmap_image_file.empty())
277 this->m_insertOptions_common->GMRF_gridmap_image_file,
278 this->m_insertOptions_common->GMRF_gridmap_image_res,
279 this->m_insertOptions_common->GMRF_gridmap_image_cx,
280 this->m_insertOptions_common->GMRF_gridmap_image_cy);
283 this->getResolution() /
284 this->m_insertOptions_common->GMRF_gridmap_image_res;
289 "Neither `simplemap_file` nor `gridmap_image_file` " 290 "found in config/mission file. Quitting.");
295 "Resizing m_map to match Occupancy Gridmap dimensions");
302 "Occupancy Gridmap dimensions: x=(%.2f,%.2f)m " 307 "Occupancy Gridmap dimensions: %u cells, cx=%i cy=%i\n\n",
308 static_cast<unsigned int>(
312 "New map dimensions: %u cells, x=(%.2f,%.2f) " 314 static_cast<unsigned int>(m_map.size()), getXMin(),
315 getXMax(), getYMin(), getYMax());
317 "New map dimensions: %u cells, cx=%u cy=%u\n",
318 static_cast<unsigned int>(m_map.size()),
319 static_cast<unsigned int>(getSizeX()),
320 static_cast<unsigned int>(getSizeY()));
323 "./obstacle_map_from_MRPT_for_GMRF.png");
327 const size_t nodeCount = m_map.size();
330 const size_t nPriorFactors =
331 (this->getSizeX() - 1) * this->getSizeY() +
337 "[clear] Generating " 339 <<
" prior factors for a map size of N=" << nodeCount << endl);
342 m_gmrf.initialize(nodeCount);
344 m_mrf_factors_activeObs.clear();
345 m_mrf_factors_activeObs.resize(
348 m_mrf_factors_priors.clear();
353 if (!m_gmrf_connectivity &&
354 this->m_insertOptions_common->GMRF_use_occupancy_information)
358 "MRF Map Dimmensions: %u x %u cells \n",
359 static_cast<unsigned int>(m_size_x),
360 static_cast<unsigned int>(m_size_y));
362 "Occupancy map Dimmensions: %i x %i cells \n",
371 size_t cxoj_min, cxoj_max, cyoj_min, cyoj_max, seed_cxo,
373 size_t cxoi_min, cxoi_max, cyoi_min, cyoi_max, objective_cxo,
375 size_t cxo_min, cxo_max, cyo_min,
379 std::multimap<size_t, size_t>
380 cell_interconnections;
384 for (
size_t j = 0; j < nodeCount;
388 cxoj_min = floor(cx * res_coef);
389 cxoj_max = cxoj_min + ceil(res_coef - 1);
390 cyoj_min = floor(cy * res_coef);
391 cyoj_max = cyoj_min + ceil(res_coef - 1);
393 seed_cxo = cxoj_min + ceil(res_coef / 2 - 1);
394 seed_cyo = cyoj_min + ceil(res_coef / 2 - 1);
398 if (m_Ocgridmap.
getCell(seed_cxo, seed_cyo) < 0.5)
406 m_mrf_factors_activeObs[j].push_back(new_obs);
407 m_gmrf.addConstraint(
408 *m_mrf_factors_activeObs[j]
415 for (
int neighbor = 0; neighbor < 2; neighbor++)
421 if (cx >= (m_size_x - 1))
continue;
429 if (cy >= (m_size_y - 1))
continue;
436 cxoi_min = floor(cxi * res_coef);
437 cxoi_max = cxoi_min + ceil(res_coef - 1);
438 cyoi_min = floor(cyi * res_coef);
439 cyoi_max = cyoi_min + ceil(res_coef - 1);
441 objective_cxo = cxoi_min + ceil(res_coef / 2 - 1);
442 objective_cyo = cyoi_min + ceil(res_coef / 2 - 1);
445 cxo_min =
min(cxoj_min, cxoi_min);
446 cxo_max = max(cxoj_max, cxoi_max);
447 cyo_min =
min(cyoj_min, cyoi_min);
448 cyo_max = max(cyoj_max, cyoi_max);
452 if (exist_relation_between2cells(
453 &m_Ocgridmap, cxo_min, cxo_max, cyo_min,
454 cyo_max, seed_cxo, seed_cyo, objective_cxo,
461 m_insertOptions_common->GMRF_lambdaPrior;
463 m_mrf_factors_priors.push_back(new_prior);
464 m_gmrf.addConstraint(
465 *m_mrf_factors_priors
469 cell_interconnections.insert(
470 std::pair<size_t, size_t>(j, i));
471 cell_interconnections.insert(
472 std::pair<size_t, size_t>(i, j));
478 if (++cx >= m_size_x)
488 m_gmrf_connectivity.get();
490 if (custom_connectivity !=
nullptr)
492 "[CRandomFieldGridMap2D::clear] Initiating prior " 493 "(using user-supplied connectivity pattern)");
496 "[CRandomFieldGridMap2D::clear] Initiating prior " 497 "(fully connected)");
503 size_t cx = 0, cy = 0;
504 for (
size_t j = 0; j < nodeCount; j++)
510 const size_t c_idx_to_check[2] = {cx, cy};
511 const size_t c_idx_to_check_limits[2] = {m_size_x - 1,
513 const size_t c_neighbor_idx_incr[2] = {1, m_size_x};
515 for (
int dir = 0; dir < 2; dir++)
517 if (c_idx_to_check[dir] >= c_idx_to_check_limits[dir])
520 const size_t i = j + c_neighbor_idx_incr[dir];
523 double edge_lamdba = .0;
524 if (custom_connectivity !=
nullptr)
526 const bool is_connected =
528 this, cx, cy, cx + (dir == 0 ? 1 : 0),
529 cy + (dir == 1 ? 1 : 0), edge_lamdba);
530 if (!is_connected)
continue;
535 m_insertOptions_common->GMRF_lambdaPrior;
540 new_prior.
Lambda = edge_lamdba;
542 m_mrf_factors_priors.push_back(new_prior);
543 m_gmrf.addConstraint(
544 *m_mrf_factors_priors.rbegin());
548 if (++cx >= m_size_x)
557 "[clear] Prior built in " << tictac.
Tac() <<
" s ----------");
559 if (m_rfgm_run_update_upon_clear)
562 updateMapEstimation_GMRF();
568 cerr <<
"MAP TYPE NOT RECOGNIZED... QUITTING" << endl;
594 point.
x - m_insertOptions_common->cutoffRadius * 2,
595 point.
x + m_insertOptions_common->cutoffRadius * 2,
596 point.
y - m_insertOptions_common->cutoffRadius * 2,
597 point.
y + m_insertOptions_common->cutoffRadius * 2, defCell);
601 int Ac_cutoff =
round(m_insertOptions_common->cutoffRadius / m_resolution);
602 unsigned Ac_all = 1 + 2 * Ac_cutoff;
603 double minWinValueAtCutOff =
605 m_insertOptions_common->cutoffRadius /
606 m_insertOptions_common->sigma));
608 if (m_DM_lastCutOff != m_insertOptions_common->cutoffRadius ||
609 m_DM_gaussWindow.size() !=
square(Ac_all))
612 "[CRandomFieldGridMap2D::insertObservation_KernelDM_DMV] " 613 "Precomputing window %ux%u\n",
617 double std = m_insertOptions_common->sigma;
620 m_DM_gaussWindow.resize(Ac_all * Ac_all);
621 m_DM_lastCutOff = m_insertOptions_common->cutoffRadius;
626 for (
unsigned cx = 0; cx < Ac_all; cx++)
628 for (
unsigned cy = 0; cy < Ac_all; cy++)
630 dist = m_resolution * sqrt(
632 square(Ac_cutoff + 1 - cx) +
633 square(Ac_cutoff + 1 - cy)));
639 "[CRandomFieldGridMap2D::insertObservation_KernelDM_DMV] Done!");
644 const int sensor_cx = x2idx(point.
x);
645 const int sensor_cy = y2idx(point.
y);
649 for (
int Acx = -Ac_cutoff; Acx <= Ac_cutoff; Acx++)
651 for (
int Acy = -Ac_cutoff; Acy <= Ac_cutoff; ++Acy, ++windowIt)
653 const double windowValue = *windowIt;
655 if (windowValue > minWinValueAtCutOff)
657 cell = cellByIndex(sensor_cx + Acx, sensor_cy + Acy);
661 cell->
dm_mean += windowValue * normReading;
664 const double cell_var =
665 square(normReading - computeMeanCellValue_DM_DMV(cell));
680 cutoffRadius(sigma * 3.0),
687 KF_initialCellStd(1.0),
688 KF_observationModelNoise(0),
689 KF_defaultCellMeanValue(0),
692 GMRF_lambdaPrior(0.01f),
694 GMRF_lambdaObs(10.0f),
698 GMRF_lambdaObsLoss(0.0f),
700 GMRF_use_occupancy_information(false),
701 GMRF_simplemap_file(
""),
702 GMRF_gridmap_image_file(
""),
703 GMRF_gridmap_image_res(0.01f),
704 GMRF_gridmap_image_cx(0),
705 GMRF_gridmap_image_cy(0),
707 GMRF_saturate_min(-
std::numeric_limits<double>::max()),
708 GMRF_saturate_max(
std::numeric_limits<double>::max()),
709 GMRF_skip_variance(false)
719 out.
printf(
"sigma = %f\n", sigma);
720 out.
printf(
"cutoffRadius = %f\n", cutoffRadius);
721 out.
printf(
"R_min = %f\n", R_min);
722 out.
printf(
"R_max = %f\n", R_max);
724 "dm_sigma_omega = %f\n", dm_sigma_omega);
726 out.
printf(
"KF_covSigma = %f\n", KF_covSigma);
728 "KF_initialCellStd = %f\n", KF_initialCellStd);
730 "KF_observationModelNoise = %f\n",
731 KF_observationModelNoise);
733 "KF_defaultCellMeanValue = %f\n",
734 KF_defaultCellMeanValue);
736 "KF_W_size = %u\n", (
unsigned)KF_W_size);
739 "GMRF_lambdaPrior = %f\n", GMRF_lambdaPrior);
741 "GMRF_lambdaObs = %f\n", GMRF_lambdaObs);
743 "GMRF_lambdaObsLoss = %f\n", GMRF_lambdaObs);
746 "GMRF_use_occupancy_information = %s\n",
747 GMRF_use_occupancy_information ?
"YES" :
"NO");
749 "GMRF_simplemap_file = %s\n",
750 GMRF_simplemap_file.c_str());
752 "GMRF_gridmap_image_file = %s\n",
753 GMRF_gridmap_image_file.c_str());
755 "GMRF_gridmap_image_res = %f\n",
756 GMRF_gridmap_image_res);
758 "GMRF_gridmap_image_cx = %u\n",
759 static_cast<unsigned int>(GMRF_gridmap_image_cx));
761 "GMRF_gridmap_image_cy = %u\n",
762 static_cast<unsigned int>(GMRF_gridmap_image_cy));
772 sigma = iniFile.
read_float(section.c_str(),
"sigma", sigma);
774 iniFile.
read_float(section.c_str(),
"cutoffRadius", cutoffRadius);
775 R_min = iniFile.
read_float(section.c_str(),
"R_min", R_min);
776 R_max = iniFile.
read_float(section.c_str(),
"R_max", R_max);
780 iniFile.
read_float(section.c_str(),
"KF_covSigma", KF_covSigma);
782 section.c_str(),
"KF_initialCellStd", KF_initialCellStd);
783 KF_observationModelNoise = iniFile.
read_float(
784 section.c_str(),
"KF_observationModelNoise", KF_observationModelNoise);
786 section.c_str(),
"KF_defaultCellMeanValue", KF_defaultCellMeanValue);
790 section.c_str(),
"GMRF_lambdaPrior", GMRF_lambdaPrior);
792 iniFile.
read_float(section.c_str(),
"GMRF_lambdaObs", GMRF_lambdaObs);
794 section.c_str(),
"GMRF_lambdaObsLoss", GMRF_lambdaObsLoss);
796 GMRF_use_occupancy_information = iniFile.
read_bool(
797 section.c_str(),
"GMRF_use_occupancy_information",
false,
false);
798 GMRF_simplemap_file =
799 iniFile.
read_string(section.c_str(),
"simplemap_file",
"",
false);
800 GMRF_gridmap_image_file =
801 iniFile.
read_string(section.c_str(),
"gridmap_image_file",
"",
false);
802 GMRF_gridmap_image_res =
803 iniFile.
read_float(section.c_str(),
"gridmap_image_res", 0.01f,
false);
804 GMRF_gridmap_image_cx =
805 iniFile.
read_int(section.c_str(),
"gridmap_image_cx", 0,
false);
806 GMRF_gridmap_image_cy =
807 iniFile.
read_int(section.c_str(),
"gridmap_image_cy", 0,
false);
819 img.saveToFile(filName);
884 double new_x_min,
double new_x_max,
double new_y_min,
double new_y_max,
885 const TRandomFieldCell& defaultValueNewCells,
double additionalMarginMeters)
896 new_x_min, new_x_max, new_y_min, new_y_max, defaultValueNewCells,
897 additionalMarginMeters);
916 "[CRandomFieldGridMap2D::resize] Resizing from %ux%u to %ux%u " 918 static_cast<unsigned>(old_sizeX),
919 static_cast<unsigned>(old_sizeY),
933 for (i = 0; i < N; i++)
938 bool C1_isFromOldMap =
939 Acx_left <= cx1 && cx1 < (Acx_left + old_sizeX) &&
940 Acy_bottom <= cy1 && cy1 < (Acy_bottom + old_sizeY);
944 for (j = i; j < N; j++)
949 bool C2_isFromOldMap =
950 Acx_left <= cx2 && cx2 < (Acx_left + old_sizeX) &&
951 Acy_bottom <= cy2 && cy2 < (Acy_bottom + old_sizeY);
954 if (C1_isFromOldMap && C2_isFromOldMap)
957 unsigned int idx_c1 =
959 old_sizeX * (cy1 - Acy_bottom));
960 unsigned int idx_c2 =
962 old_sizeX * (cy2 - Acy_bottom));
968 ASSERT_((cx1 - Acx_left) < old_sizeX);
969 ASSERT_((cy1 - Acy_bottom) < old_sizeY);
973 ASSERT_((cx2 - Acx_left) < old_sizeX);
974 ASSERT_((cy2 - Acy_bottom) < old_sizeY);
976 ASSERT_(idx_c1 < old_sizeX * old_sizeY);
977 ASSERT_(idx_c2 < old_sizeX * old_sizeY);
980 printf(
"cx1=%u\n", static_cast<unsigned>(cx1));
981 printf(
"cy1=%u\n", static_cast<unsigned>(cy1));
982 printf(
"cx2=%u\n", static_cast<unsigned>(cx2));
983 printf(
"cy2=%u\n", static_cast<unsigned>(cy2));
986 static_cast<unsigned>(Acx_left));
989 static_cast<unsigned>(Acy_bottom));
992 static_cast<unsigned>(idx_c1));
995 static_cast<unsigned>(idx_c2)););
997 m_cov(i, j) = oldCov(idx_c1, idx_c2);
1000 if (i == j)
ASSERT_(idx_c1 == idx_c2);
1002 if (i == j &&
m_cov(i, i) < 0)
1005 "\ni=%u \nj=%i \ncx1,cy1 = %u,%u \n " 1006 "cx2,cy2=%u,%u \nidx_c1=%u \nidx_c2=%u " 1007 "\nAcx_left=%u \nAcy_bottom=%u " 1008 "\nold_sizeX=%u \n",
1009 static_cast<unsigned>(i),
1010 static_cast<unsigned>(j),
1011 static_cast<unsigned>(cx1),
1012 static_cast<unsigned>(cy1),
1013 static_cast<unsigned>(cx2),
1014 static_cast<unsigned>(cy2),
1015 static_cast<unsigned>(idx_c1),
1016 static_cast<unsigned>(idx_c2),
1017 static_cast<unsigned>(Acx_left),
1018 static_cast<unsigned>(Acy_bottom),
1019 static_cast<unsigned>(old_sizeX));
1032 for (i = 0; i < N; i++)
1037 bool C1_isFromOldMap =
1038 Acx_left <= cx1 && cx1 < (Acx_left + old_sizeX) &&
1039 Acy_bottom <= cy1 && cy1 < (Acy_bottom + old_sizeY);
1040 for (j = i; j < N; j++)
1045 bool C2_isFromOldMap =
1046 Acx_left <= cx2 && cx2 < (Acx_left + old_sizeX) &&
1047 Acy_bottom <= cy2 && cy2 < (Acy_bottom + old_sizeY);
1052 if (!C1_isFromOldMap || !C2_isFromOldMap)
1065 static_cast<double>(
1072 "c(i,i)=%e c(j,j)=%e\n",
m_cov(i, i),
1093 printf(
"[CRandomFieldGridMap2D::resize] Done\n");
1108 "[resize] Resizing from %ux%u to %ux%u (%u cells)\n",
1109 static_cast<unsigned>(old_sizeX),
1110 static_cast<unsigned>(old_sizeY),
1117 const size_t N =
m_map.size();
1118 const size_t K = 2 * W * (W + 1) + 1;
1131 const double std0sqr =
1133 double* ptr = &template_row[0];
1135 const double KF_covSigma2 =
1143 for (Acx = 1; Acx <= W; Acx++)
1146 exp(-0.5 * (res2 * static_cast<double>(
1151 for (Acy = 1; Acy <= W; Acy++)
1152 for (Acx = -W; Acx <= W; Acx++)
1155 exp(-0.5 * (res2 * static_cast<double>(
1162 for (
size_t i = N - 1; i < N;
1168 const size_t old_idx_of_i =
1169 (cx - Acx_left) + (cy - Acy_bottom) * old_sizeX;
1179 memcpy(new_row, &template_row[0],
sizeof(
double) * K);
1186 if (old_idx_of_i != i)
1188 const double* ptr_old =
1191 memcpy(ptr_new, ptr_old,
sizeof(
double) * K);
1215 resize(point.
x - 1, point.
x + 1, point.
y - 1, point.
y + 1, defCell);
1229 int cellIdx =
xy2idx(point.
x, point.
y);
1234 double yk = normReading - cell->
kf_mean;
1236 m_cov(cellIdx, cellIdx) +
1239 ->KF_observationModelNoise);
1240 double sk_1 = 1.0 / sk;
1246 MRPT_LOG_DEBUG(
"[insertObservation_KF] Updating mean values...");
1251 for (i = 0, it =
m_map.begin(); it !=
m_map.end(); ++it, ++i)
1253 it->kf_mean += yk * sk_1 *
m_cov(i, cellIdx);
1259 N =
m_cov.getRowCount();
1261 MRPT_LOG_DEBUG(
"[insertObservation_KF] Updating covariance matrix...");
1265 double* oldCov = (
double*) malloc(
sizeof(
double) * N * N);
1266 double* oldCov_ptr = oldCov;
1267 for (i = 0; i < N; i++)
1269 memcpy(oldCov_ptr,
m_cov.get_unsafe_row(i),
sizeof(double) * N);
1274 "Copy matrix %ux%u: %.06fms\n", (
unsigned)
m_cov.getRowCount(),
1275 (unsigned)
m_cov.getColCount(), tictac.
Tac() * 1000);
1280 const double* oldCov_row_c = oldCov + cellIdx * N;
1281 for (i = 0; i < N; i++)
1283 const double oldCov_i_c = oldCov[i * N + cellIdx];
1284 const double sk_1_oldCov_i_c = sk_1 * oldCov_i_c;
1286 const double* oldCov_row_i = oldCov + i * N;
1287 for (j = i; j < N; j++)
1290 oldCov_row_i[j] - sk_1_oldCov_i_c * oldCov_row_c[j];
1293 m_cov.set_unsafe(i, j, new_cov_ij);
1294 m_cov.set_unsafe(j, i, new_cov_ij);
1299 if (
m_cov(i, i) < 0)
1302 "Wrong insertion in KF! m_cov(%u,%u) = %.5f",
1303 static_cast<unsigned int>(i),
1304 static_cast<unsigned int>(i),
m_cov(i, i));
1308 m_map[i].kf_std = sqrt(new_cov_ij);
1342 DIMs.saveToTextFile(
1345 "% Grid limits: [x_min x_max y_min y_max]\n");
1365 all_means.saveToTextFile(
1369 all_vars.saveToTextFile(
1372 all_confs.saveToTextFile(
1388 for (
size_t i = 0; i <
m_size_y; i++)
1389 for (
size_t j = 0; j <
m_size_x; j++)
1395 MEAN.saveToTextFile(
1397 STDs.saveToTextFile(
1404 filNamePrefix +
std::string(
"_mean_compressed_cov.txt"),
1410 m_cov.saveToTextFile(
1416 CImage img_cov(STDs,
true);
1434 for (
size_t i = 0; i <
m_size_y; ++i)
1436 for (
size_t j = 0; j <
m_size_x; ++j, ++idx)
1441 XYZ(idx, 0) =
idx2x(j);
1442 XYZ(idx, 1) =
idx2y(i);
1448 MEAN.saveToTextFile(
1450 STDs.saveToTextFile(
1456 "% Columns: GRID_X GRID_Y ESTIMATED_Z " 1457 "STD_DEV_OF_ESTIMATED_Z \n");
1474 const double std_times = 3;
1482 FILE* f =
os::fopen(filName.c_str(),
"wt");
1486 f,
"%%-------------------------------------------------------\n");
1487 os::fprintf(f,
"%% File automatically generated using the MRPT method:\n");
1488 os::fprintf(f,
"%%'CRandomFieldGridMap2D::saveAsMatlab3DGraph'\n");
1492 f,
"%% Jose Luis Blanco Claraco, University of Malaga @ 2006-2007\n");
1495 f,
"%%-------------------------------------------------------\n\n");
1497 unsigned int cx, cy;
1498 vector<double> xs, ys;
1580 os::fprintf(f,
"set(S1,'FaceAlpha',0.9,'EdgeAlpha',0.9);\n");
1581 os::fprintf(f,
"set(S2,'FaceAlpha',0.4,'EdgeAlpha',0.4);\n");
1582 os::fprintf(f,
"set(S3,'FaceAlpha',0.2,'EdgeAlpha',0.2);\n");
1585 f,
"set(gca,'PlotBoxAspectRatio',[%f %f %f]);\n",
m_x_max -
m_x_min,
1593 "\nfigure; imagesc(xs,ys,z_mean);axis equal;title('Mean " 1594 "value');colorbar;");
1597 "\nfigure; imagesc(xs,ys,(z_upper-z_mean)/%f);axis equal;title('Std " 1598 "dev of estimated value');colorbar;",
1616 mrpt::make_aligned_shared<mrpt::opengl::CSetOfObjects>();
1633 unsigned int cx, cy;
1634 vector<double> xs, ys;
1654 mrpt::make_aligned_shared<opengl::CSetOfTriangles>();
1655 obj_m->enableTransparency(
true);
1657 mrpt::make_aligned_shared<opengl::CSetOfTriangles>();
1658 obj_v->enableTransparency(
true);
1662 double maxVal_m = 0, minVal_m = 1, AMaxMin_m, maxVal_v = 0,
1663 minVal_v = 1, AMaxMin_v;
1673 minVal_m =
min(minVal_m,
c);
1674 maxVal_m = max(maxVal_m,
c);
1677 minVal_v =
min(minVal_v,
v);
1678 maxVal_v = max(maxVal_v,
v);
1682 AMaxMin_m = maxVal_m - minVal_m;
1683 if (AMaxMin_m == 0) AMaxMin_m = 1;
1684 AMaxMin_v = maxVal_v - minVal_v;
1685 if (AMaxMin_v == 0) AMaxMin_v = 1;
1690 triag.
a[0] = triag.
a[1] = triag.
a[2] =
1700 ASSERT_(cell_x_1y !=
nullptr);
1702 ASSERT_(cell_xy_1 !=
nullptr);
1705 ASSERT_(cell_x_1y_1 !=
nullptr);
1726 double col_xy = c_xy;
1727 double col_x_1y = c_x_1y;
1728 double col_xy_1 = c_xy_1;
1729 double col_x_1y_1 = c_x_1y_1;
1732 triag.
x[0] = xs[cx];
1733 triag.
y[0] = ys[cy];
1735 triag.
x[1] = xs[cx];
1736 triag.
y[1] = ys[cy - 1];
1737 triag.
z[1] = c_xy_1;
1738 triag.
x[2] = xs[cx - 1];
1739 triag.
y[2] = ys[cy - 1];
1740 triag.
z[2] = c_x_1y_1;
1741 jet2rgb(col_xy, triag.
r[0], triag.
g[0], triag.
b[0]);
1742 jet2rgb(col_xy_1, triag.
r[1], triag.
g[1], triag.
b[1]);
1743 jet2rgb(col_x_1y_1, triag.
r[2], triag.
g[2], triag.
b[2]);
1744 obj_m->insertTriangle(triag);
1747 triag.
x[0] = xs[cx];
1748 triag.
y[0] = ys[cy];
1750 triag.
x[1] = xs[cx - 1];
1751 triag.
y[1] = ys[cy - 1];
1752 triag.
z[1] = c_x_1y_1;
1753 triag.
x[2] = xs[cx - 1];
1754 triag.
y[2] = ys[cy];
1755 triag.
z[2] = c_x_1y;
1756 jet2rgb(col_xy, triag.
r[0], triag.
g[0], triag.
b[0]);
1757 jet2rgb(col_x_1y_1, triag.
r[1], triag.
g[1], triag.
b[1]);
1758 jet2rgb(col_x_1y, triag.
r[2], triag.
g[2], triag.
b[2]);
1759 obj_m->insertTriangle(triag);
1774 col_x_1y = v_x_1y / 10;
1776 col_xy_1 = v_xy_1 / 10;
1778 col_x_1y_1 = v_x_1y_1 / 10;
1782 triag.
x[0] = xs[cx];
1783 triag.
y[0] = ys[cy];
1784 triag.
z[0] = c_xy + v_xy;
1785 triag.
x[1] = xs[cx];
1786 triag.
y[1] = ys[cy - 1];
1787 triag.
z[1] = c_xy_1 + v_xy_1;
1788 triag.
x[2] = xs[cx - 1];
1789 triag.
y[2] = ys[cy - 1];
1790 triag.
z[2] = c_x_1y_1 + v_x_1y_1;
1791 jet2rgb(col_xy, triag.
r[0], triag.
g[0], triag.
b[0]);
1792 jet2rgb(col_xy_1, triag.
r[1], triag.
g[1], triag.
b[1]);
1793 jet2rgb(col_x_1y_1, triag.
r[2], triag.
g[2], triag.
b[2]);
1794 obj_v->insertTriangle(triag);
1797 triag.
x[0] = xs[cx];
1798 triag.
y[0] = ys[cy];
1799 triag.
z[0] = c_xy + v_xy;
1800 triag.
x[1] = xs[cx - 1];
1801 triag.
y[1] = ys[cy - 1];
1802 triag.
z[1] = c_x_1y_1 + v_x_1y_1;
1803 triag.
x[2] = xs[cx - 1];
1804 triag.
y[2] = ys[cy];
1805 triag.
z[2] = c_x_1y + v_x_1y;
1806 jet2rgb(col_xy, triag.
r[0], triag.
g[0], triag.
b[0]);
1807 jet2rgb(col_x_1y_1, triag.
r[1], triag.
g[1], triag.
b[1]);
1808 jet2rgb(col_x_1y, triag.
r[2], triag.
g[2], triag.
b[2]);
1809 obj_v->insertTriangle(triag);
1813 meanObj->insert(obj_m);
1814 varObj->insert(obj_v);
1824 mrpt::make_aligned_shared<opengl::CSetOfTriangles>();
1825 obj_m->enableTransparency(
true);
1827 mrpt::make_aligned_shared<opengl::CSetOfTriangles>();
1828 obj_v->enableTransparency(
true);
1832 double maxVal_m = 0, minVal_m = 1, AMaxMin_m, maxVal_v = 0,
1833 minVal_v = 1, AMaxMin_v;
1843 minVal_m =
min(minVal_m,
c);
1844 maxVal_m = max(maxVal_m,
c);
1847 minVal_v =
min(minVal_v,
v);
1848 maxVal_v = max(maxVal_v,
v);
1852 AMaxMin_m = maxVal_m - minVal_m;
1853 if (AMaxMin_m == 0) AMaxMin_m = 1;
1854 AMaxMin_v = maxVal_v - minVal_v;
1855 if (AMaxMin_v == 0) AMaxMin_v = 1;
1860 triag.
a[0] = triag.
a[1] = triag.
a[2] =
1870 ASSERT_(cell_x_1y !=
nullptr);
1872 ASSERT_(cell_xy_1 !=
nullptr);
1875 ASSERT_(cell_x_1y_1 !=
nullptr);
1896 double col_xy = c_xy;
1897 double col_x_1y = c_x_1y;
1898 double col_xy_1 = c_xy_1;
1899 double col_x_1y_1 = c_x_1y_1;
1902 triag.
x[0] = xs[cx];
1903 triag.
y[0] = ys[cy];
1905 triag.
x[1] = xs[cx];
1906 triag.
y[1] = ys[cy - 1];
1907 triag.
z[1] = c_xy_1;
1908 triag.
x[2] = xs[cx - 1];
1909 triag.
y[2] = ys[cy - 1];
1910 triag.
z[2] = c_x_1y_1;
1911 jet2rgb(col_xy, triag.
r[0], triag.
g[0], triag.
b[0]);
1912 jet2rgb(col_xy_1, triag.
r[1], triag.
g[1], triag.
b[1]);
1913 jet2rgb(col_x_1y_1, triag.
r[2], triag.
g[2], triag.
b[2]);
1915 obj_m->insertTriangle(triag);
1918 triag.
x[0] = xs[cx];
1919 triag.
y[0] = ys[cy];
1921 triag.
x[1] = xs[cx - 1];
1922 triag.
y[1] = ys[cy - 1];
1923 triag.
z[1] = c_x_1y_1;
1924 triag.
x[2] = xs[cx - 1];
1925 triag.
y[2] = ys[cy];
1926 triag.
z[2] = c_x_1y;
1927 jet2rgb(col_xy, triag.
r[0], triag.
g[0], triag.
b[0]);
1928 jet2rgb(col_x_1y_1, triag.
r[1], triag.
g[1], triag.
b[1]);
1929 jet2rgb(col_x_1y, triag.
r[2], triag.
g[2], triag.
b[2]);
1930 obj_m->insertTriangle(triag);
1936 double v_x_1y =
min(
1938 double v_xy_1 =
min(
1940 double v_x_1y_1 =
min(
1946 col_x_1y_1 = v_x_1y_1;
1949 triag.
x[0] = xs[cx];
1950 triag.
y[0] = ys[cy];
1952 triag.
x[1] = xs[cx];
1953 triag.
y[1] = ys[cy - 1];
1954 triag.
z[1] = v_xy_1;
1955 triag.
x[2] = xs[cx - 1];
1956 triag.
y[2] = ys[cy - 1];
1957 triag.
z[2] = v_x_1y_1;
1958 jet2rgb(col_xy, triag.
r[0], triag.
g[0], triag.
b[0]);
1959 jet2rgb(col_xy_1, triag.
r[1], triag.
g[1], triag.
b[1]);
1960 jet2rgb(col_x_1y_1, triag.
r[2], triag.
g[2], triag.
b[2]);
1962 obj_v->insertTriangle(triag);
1965 triag.
x[0] = xs[cx];
1966 triag.
y[0] = ys[cy];
1968 triag.
x[1] = xs[cx - 1];
1969 triag.
y[1] = ys[cy - 1];
1970 triag.
z[1] = v_x_1y_1;
1971 triag.
x[2] = xs[cx - 1];
1972 triag.
y[2] = ys[cy];
1973 triag.
z[2] = v_x_1y;
1974 jet2rgb(col_xy, triag.
r[0], triag.
g[0], triag.
b[0]);
1975 jet2rgb(col_x_1y_1, triag.
r[1], triag.
g[1], triag.
b[1]);
1976 jet2rgb(col_x_1y, triag.
r[2], triag.
g[2], triag.
b[2]);
1977 obj_v->insertTriangle(triag);
1981 meanObj->insert(obj_m);
1982 varObj->insert(obj_v);
2008 const double alpha =
2012 const double r_val =
2024 const double alpha =
2028 const double r_val =
2044 const double x,
const double y,
double& out_predict_response,
2045 double& out_predict_response_variance,
bool do_sensor_normalization,
2050 vector<TInterpQuery> queries;
2051 switch (interp_method)
2055 queries[0].cx =
x2idx(
x);
2056 queries[0].cy =
y2idx(
y);
2057 queries[0].coef = 1.0;
2068 queries[0].cx =
x2idx(
x);
2069 queries[0].cy =
y2idx(
y);
2070 queries[0].coef = 1.0;
2089 queries[0].coef = K_1 * (
idx2x(queries[3].cx) -
x) *
2090 (
idx2y(queries[3].cy) -
y);
2091 queries[1].coef = K_1 * (
idx2x(queries[3].cx) -
x) *
2092 (
y -
idx2y(queries[0].cy));
2093 queries[2].coef = K_1 * (
x -
idx2x(queries[0].cx)) *
2094 (
idx2y(queries[3].cy) -
y);
2095 queries[3].coef = K_1 * (
x -
idx2x(queries[0].cx)) *
2096 (
y -
idx2y(queries[0].cy));
2104 for (
size_t i = 0; i < queries.size(); i++)
2173 out_predict_response = 0;
2174 out_predict_response_variance = 0;
2175 for (
size_t i = 0; i < queries.size(); i++)
2177 out_predict_response += queries[i].val * queries[i].coef;
2178 out_predict_response_variance += queries[i].var * queries[i].coef;
2182 if (do_sensor_normalization)
2183 out_predict_response =
2185 out_predict_response *
2200 "Inserting KF2: (" << normReading <<
") at Position" << point << endl);
2203 const size_t K = 2 * W * (W + 1) + 1;
2204 const size_t W21 = 2 * W + 1;
2205 const size_t W21sqr = W21 * W21;
2221 point.
x - Aspace, point.
x + Aspace, point.
y - Aspace, point.
y + Aspace,
2227 const size_t N =
m_map.size();
2244 const int cellIdx =
xy2idx(point.
x, point.
y);
2249 double yk = normReading - cell->
kf_mean;
2255 double sk_1 = 1.0 / sk;
2258 MRPT_LOG_DEBUG(
"[insertObservation_KF2] Updating mean values...");
2267 const int cx_c =
x2idx(point.
x);
2268 const int cy_c =
y2idx(point.
y);
2270 const int Acx0 = max(-W, -cx_c);
2271 const int Acy0 = max(-W, -cy_c);
2272 const int Acx1 =
min(W,
int(
m_size_x) - 1 - cx_c);
2273 const int Acy1 =
min(W,
int(
m_size_y) - 1 - cy_c);
2286 for (
int Acy = Acy0; Acy <= 0; Acy++)
2288 int limit_cx = Acy < 0 ? Acx1 : -1;
2290 size_t idx = cx_c + Acx0 +
m_size_x * (cy_c + Acy);
2291 int idx_c_in_idx = -Acy * W21 - Acx0;
2293 int window_idx = Acx0 + W + (Acy + W) * W21;
2295 for (
int Acx = Acx0; Acx <= limit_cx; Acx++)
2298 const double cov_i_c =
m_stackedCov(idx, idx_c_in_idx);
2301 m_map[idx].kf_mean += yk * sk_1 * cov_i_c;
2304 cross_covs_c_i[window_idx] = cov_i_c;
2305 window_idxs[window_idx++] = idx;
2313 for (
int Acy = 0; Acy <= Acy1; Acy++)
2315 int start_cx = Acy > 0 ? Acx0 : 0;
2317 size_t idx = cx_c + start_cx +
m_size_x * (cy_c + Acy);
2321 (W + 1) + (Acy - 1) * W21 + (start_cx + W);
2325 int window_idx = start_cx + W + (Acy + W) * W21;
2327 for (
int Acx = start_cx; Acx <= Acx1; Acx++)
2329 ASSERT_(idx_i_in_c >= 0 && idx_i_in_c <
int(K));
2332 m_map[idx].kf_mean += yk * sk_1 * cov_i_c;
2335 cross_covs_c_i[window_idx] = cov_i_c;
2336 window_idxs[window_idx++] = idx;
2351 for (
size_t i = 0; i < W21sqr; i++)
2353 const int idx_i = window_idxs[i];
2354 if (idx_i < 0)
continue;
2360 const double cov_c_i = cross_covs_c_i[i];
2362 for (
size_t j = i; j < W21sqr; j++)
2364 const int idx_j = window_idxs[j];
2365 if (idx_j < 0)
continue;
2371 const int Ax = cx_j - cx_i;
2376 const int Ay = cy_j - cy_i;
2379 const double cov_c_j = cross_covs_c_i[j];
2383 idx_j_in_i = Ax + W + (Ay - 1) * W21 + W + 1;
2388 double& cov_to_change =
m_stackedCov(idx_i, idx_j_in_i);
2389 double Delta_cov = cov_c_j * cov_c_i * sk_1;
2390 if (i == j && cov_to_change < Delta_cov)
2392 "Negative variance value appeared! Please increase the " 2393 "size of the window " 2394 "(W).\n(m_insertOptions_common->KF_covSigma=%f)",
2397 cov_to_change -= Delta_cov;
2415 const size_t N =
m_map.size();
2416 for (
size_t i = 0; i < N; i++)
2427 out_means.resize(N);
2428 for (
size_t i = 0; i < N; ++i) out_means[i] =
BASE::m_map[i].kf_mean;
2441 out_means.resize(N);
2444 for (
size_t i = 0; i < N; ++i)
2459 ASSERT_(N ==
size_t(in_means.size()));
2460 ASSERT_(N ==
size_t(in_std.size()));
2463 for (
size_t i = 0; i < N; ++i)
2465 m_map[i].kf_mean = in_means[i];
2492 "insertObservation() isn't implemented for selected 'mapType'")
2498 const bool update_map,
const bool time_invariant,
2499 const double reading_stddev)
2517 sensorReading, point, update_map, time_invariant,
2518 reading_stddev == .0
2525 "insertObservation() isn't implemented for selected 'mapType'")
2534 const bool update_map,
const bool time_invariant,
2535 const double reading_information)
2540 const int cellIdx =
xy2idx(point.
x, point.
y);
2548 new_obs.
Lambda = reading_information;
2555 catch (std::exception e)
2557 cerr <<
"Exception while Inserting new Observation: " << e.what()
2570 Eigen::VectorXd x_incr, x_var;
2574 ASSERT_(
size_t(
m_map.size()) ==
size_t(x_incr.size()));
2577 size_t(
m_map.size()) ==
size_t(x_var.size()));
2580 for (
size_t j = 0; j <
m_map.size(); j++)
2584 : std::sqrt(x_var[j]);
2585 m_map[j].gmrf_mean += x_incr[j];
2598 for (
auto ito = obs.begin(); ito != obs.end();)
2600 if (!ito->time_invariant)
2607 if (ito->Lambda < 0)
2610 ito = obs.erase(ito);
2621 size_t cxo_max,
size_t cyo_min,
size_t cyo_max,
const size_t seed_cxo,
2622 const size_t seed_cyo,
const size_t objective_cxo,
2623 const size_t objective_cyo)
2629 cxo_min = max(cxo_min, (
size_t)0);
2630 cxo_max =
min(cxo_max, (
size_t)m_Ocgridmap->
getSizeX() - 1);
2631 cyo_min = max(cyo_min, (
size_t)0);
2632 cyo_max =
min(cyo_max, (
size_t)m_Ocgridmap->
getSizeY() - 1);
2638 if ((seed_cxo < cxo_min) || (seed_cxo >= cxo_max) || (seed_cyo < cyo_min) ||
2639 (seed_cyo >= cyo_max))
2644 if ((objective_cxo < cxo_min) || (objective_cxo >= cxo_max) ||
2645 (objective_cyo < cyo_min) || (objective_cyo >= cyo_max))
2652 if ((m_Ocgridmap->
getCell(seed_cxo, seed_cyo) < 0.5) !=
2653 (m_Ocgridmap->
getCell(objective_cxo, objective_cyo) < 0.5))
2661 cxo_max - cxo_min + 1, cyo_max - cyo_min + 1);
2668 matExp(seed_cxo - cxo_min, seed_cyo - cyo_min) = 1;
2673 while (seedsOld < seedsNew)
2675 seedsOld = seedsNew;
2677 for (
size_t col = 0; col < matExp.getColCount(); col++)
2679 for (
size_t row = 0;
row < matExp.getRowCount();
row++)
2682 if (matExp(
row, col) == 1)
2684 matExp(
row, col) = 2;
2686 for (
int i = -1; i <= 1; i++)
2688 for (
int j = -1; j <= 1; j++)
2691 if ((
int(
row) + j >= 0) &&
2693 int(matExp.getRowCount() - 1)) &&
2694 (int(col) + i >= 0) &&
2695 (
int(col) + i <= int(matExp.getColCount()) - 1))
2697 if (!((i == 0 && j == 0) ||
2698 !(matExp(
row + j, col + i) == 0)))
2702 row + cxo_min, col + cyo_min) <
2706 col + i + cyo_min) < 0.5))
2708 if ((
row + j + cxo_min ==
2710 (col + i + cyo_min ==
2717 matExp(
row + j, col + i) = 1;
2747 return m_parent->m_map[this->node_id].gmrf_mean - this->obsValue;
2751 return this->Lambda;
2760 return m_parent->m_map[this->node_id_i].gmrf_mean -
2761 m_parent->m_map[this->node_id_j].gmrf_mean;
2765 return this->Lambda;
2768 double& dr_dx_i,
double& dr_dx_j)
const void clear()
Erase all the contents of the map.
float getXMax() const
Returns the "x" coordinate of right side of grid map.
std::vector< TRandomFieldCell > & m_map_castaway_const() const
Used only from logically const method that really need to modify the object.
Gaussian kernel-based estimator (see discussion in mrpt::maps::CRandomFieldGridMap2D) ...
Parameters for CMetricMap::compute3DMatchingRatio()
GLclampf GLclampf GLclampf alpha
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)...
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
double evaluateResidual() const override
Return the residual/error of this observation.
This class is a "CSerializable" wrapper for "CMatrixTemplateNumeric<double>".
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...
EIGEN_STRONG_INLINE void fill(const Scalar v)
float getResolution() const
Returns the resolution of the grid map.
#define MRPT_END_WITH_CLEAN_UP(stuff)
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
TInsertionOptionsCommon()
Default values loader.
int xy2idx(double x, double y) const
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.
A class for storing images as grayscale or RGB bitmaps.
double getInformation() const override
Return the inverse of the variance of this constraint.
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...
#define THROW_EXCEPTION(msg)
GLdouble GLdouble GLdouble GLdouble q
#define MRPT_LOG_DEBUG_FMT(_FMT_STRING,...)
int x2idx(double x) const
Transform a coordinate values into cell indexes.
void evalJacobian(double &dr_dx_i, double &dr_dx_j) const override
Returns the derivative of the residual wrt the node values.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
std::vector< std::list< TObservationGMRF > > m_mrf_factors_activeObs
Vector with the active observations and their respective Information.
mrpt::math::CMatrixD m_cov
The whole covariance matrix, used for the Kalman Filter map representation.
void internal_loadFromConfigFile_common(const mrpt::utils::CConfigFileBase &source, const std::string §ion)
See utils::CLoadableOptions.
void internal_dumpToTextStream_common(mrpt::utils::CStream &out) const
See utils::CLoadableOptions.
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
double Lambda
"Information" of the observation (=inverse of the variance)
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
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 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...
double gmrf_mean
[GMRF only] The mean value of this cell
TMapGenericParams genericMapParams
Common params to all maps.
std::shared_ptr< CSetOfTriangles > Ptr
TMapRepresentation getMapType()
Return the type of the random-field grid map, according to parameters passed on construction.
void Tic()
Starts the stopwatch.
void evalJacobian(double &dr_dx) const override
Returns the derivative of the residual wrt the node value.
void idx2cxcy(const int &idx, int &cx, int &cy) const
Transform a global (linear) cell index value into its corresponding (x,y) cell indexes.
virtual void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &outObj) const override
Returns a 3D object representing the map (mean)
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 ...
This class allows loading and storing values and vectors of different types from a configuration text...
T square(const T x)
Inline function for the square of a number.
int y2idx(double y) const
TMapRepresentation m_mapType
The map representation type of this map, as passed in the constructor.
mrpt::graphs::ScalarFactorGraph m_gmrf
virtual ~CRandomFieldGridMap2D()
Destructor.
double dm_mean_w
[Kernel-methods only] The cumulative weights (concentration = alpha
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 ...
double idx2y(int cy) const
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
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.
double getInformation() const override
Return the inverse of the variance of this constraint.
float KF_observationModelNoise
The sensor model noise (in normalized concentration units).
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) ...
bool saveAsBitmapFile(const std::string &file) const
Saves the gridmap as a graphical file (BMP,PNG,...).
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
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,...).
virtual 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.
A 2D grid of dynamic size which stores any kind of data at each cell.
virtual 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 ...
double kf_mean
[KF-methods only] The mean value of this cell
float getXMin() const
Returns the "x" coordinate of left side of grid map.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
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)...
bool loadFromBitmapFile(const std::string &file, float resolution, float xCentralPixel=-1, float yCentralPixel=-1)
Load the gridmap from a image in a file (the format can be any supported by CImage::loadFromFile).
std::vector< TRandomFieldCell > m_map
The cells.
This class implements a high-performance stopwatch.
"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.
std::shared_ptr< CSetOfObjects > Ptr
This namespace contains representation of robot actions and observations.
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
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.
virtual ~ConnectivityDescriptor()
#define MRPT_LOG_DEBUG(_STRING)
double dm_sigma_omega
[DM/DM+V methods] The scaling parameter for the confidence "alpha" values (see the IROS 2009 paper; s...
void insertObservation_KF(double normReading, const mrpt::math::TPoint2D &point)
The implementation of "insertObservation" for the (whole) Kalman Filter map model.
GLsizei const GLchar ** string
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...
double idx2x(int cx) const
Transform a cell index into a coordinate value of the cell central point.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
(see discussion in mrpt::maps::CRandomFieldGridMap2D)
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.
double GMRF_saturate_min
(Default:-inf,+inf) Saturate the estimated mean in these limits
void setFromMatrix(const Eigen::MatrixBase< Derived > &m, bool matrix_is_normalized=true)
Set the image from a matrix, interpreted as grayscale intensity values, in the range [0...
A class for storing an occupancy grid map.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CRandomFieldGridMap2D represents a 2D grid map where each cell is associated one real-valued property...
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).
void updateMapEstimation()
Run the method-specific procedure required to ensure that the mean & variances are up-to-date with al...
virtual void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const override
The implementation in this class just calls all the corresponding method of the contained metric maps...
T square(const T x)
Inline function for the square of a number.
GLenum GLenum GLvoid * row
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].
void jet2rgb(const float color_index, float &r, float &g, float &b)
Computes the RGB color components (range [0,1]) for the corresponding color index in the range [0...
virtual void internal_clear() override
Erase all the contents of the map.
virtual void getAsBitmapFile(mrpt::utils::CImage &out_img) const
Returns an image just as described in saveAsBitmapFile.
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.
double Tac()
Stops the stopwatch.
int round(const T value)
Returns the closer integer (int) to x.
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)...
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.
std::shared_ptr< ConnectivityDescriptor > Ptr
std::vector< int32_t > vector_int
mrpt::math::CMatrixD m_stackedCov
The compressed band diagonal matrix for the KF2 implementation.
double evaluateResidual() const override
Return the residual/error of this observation.
double Lambda
"Information" of the observation (=inverse of the variance)
double dm_mean
[Kernel-methods only] The cumulative weighted readings of this cell
#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 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.
This class is a "CSerializable" wrapper for "CMatrixFloat".
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
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)
!
GLenum const GLfloat * params
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...
void updateEstimation(Eigen::VectorXd &solved_x_inc, Eigen::VectorXd *solved_variances=nullptr)
float getCell(int x, int y) const
Read the real valued [0,1] contents of a cell, given its index.
double kf_std
[KF-methods only] The standard deviation value of this cell
double GMRF_lambdaObsLoss
The loss of information of the observations with each iteration.
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
fixed floating point 'f'
#define IMPLEMENTS_VIRTUAL_SERIALIZABLE( class_name, base_class_name, NameSpace)
This must be inserted as implementation of some required members for virtual CSerializable classes: ...
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.