44 double x_min,
double x_max,
45 double y_min,
double y_max,
50 m_rfgm_run_update_upon_clear(true),
51 m_insertOptions_common( NULL ),
54 m_hasToRecoverMeanAndCov(true),
56 m_average_normreadings_mean(0),
57 m_average_normreadings_var(0),
58 m_average_normreadings_count(0)
79 m_gmrf_connectivity = new_connectivity_descriptor;
88 m_insertOptions_common = getCommonInsertOptions();
90 m_average_normreadings_mean = 0;
91 m_average_normreadings_var = 0;
92 m_average_normreadings_count = 0;
107 MRPT_LOG_DEBUG_FMT(
"[clear] Setting covariance matrix to %ux%u\n",(
unsigned int)(m_size_y*m_size_x),(
unsigned int)(m_size_y*m_size_x));
110 m_insertOptions_common->KF_defaultCellMeanValue,
111 m_insertOptions_common->KF_initialCellStd
117 m_cov.setSize( m_size_y*m_size_x, m_size_y*m_size_x );
121 const double KF_covSigma2 =
square(m_insertOptions_common->KF_covSigma);
122 const double res2 =
square(m_resolution);
123 const double std0sqr =
square( m_insertOptions_common->KF_initialCellStd );
125 for (
size_t i = 0;i<m_cov.getRowCount();i++)
127 int cx1 = ( i % m_size_x );
128 int cy1 = ( i / m_size_x );
130 for (
size_t j = i;j<m_cov.getColCount();j++)
132 int cx2 = ( j % m_size_x );
133 int cy2 = ( j / m_size_x );
137 m_cov(i,j) = std0sqr;
141 m_cov(i,j) = std0sqr * exp( -0.5 * (res2 * static_cast<double>(
square(cx1-cx2) +
square(cy1-cy2)))/KF_covSigma2 );
142 m_cov(j,i) = m_cov(i,j);
151 case mrKalmanApproximate:
153 m_hasToRecoverMeanAndCov =
true;
158 MRPT_LOG_DEBUG(
"[CRandomFieldGridMap2D::clear] Resetting compressed cov. matrix and cells\n");
160 m_insertOptions_common->KF_defaultCellMeanValue,
161 m_insertOptions_common->KF_initialCellStd
168 const signed W = m_insertOptions_common->KF_W_size;
169 const size_t N = m_map.size();
170 const size_t K = 2*W*(W+1)+1;
172 const double KF_covSigma2 =
square(m_insertOptions_common->KF_covSigma);
173 const double std0sqr =
square( m_insertOptions_common->KF_initialCellStd );
174 const double res2 =
square(m_resolution);
176 m_stackedCov.setSize( N, K );
181 const double *ptr_first_row = m_stackedCov.get_unsafe_row(0);
183 for (
size_t i=0;i<N;i++)
185 double *ptr = m_stackedCov.get_unsafe_row(i);
194 for (Acx=1;Acx<=W;Acx++)
195 *ptr++ = std0sqr * exp( -0.5 * (res2 * static_cast<double>(
square(Acx) +
square(Acy)))/KF_covSigma2 );
198 for (Acy=1;Acy<=W;Acy++)
199 for (Acx=-W;Acx<=W;Acx++)
200 *ptr++ = std0sqr * exp( -0.5 * (res2 * static_cast<double>(
square(Acx) +
square(Acy)))/KF_covSigma2 );
205 memcpy( ptr,ptr_first_row,
sizeof(
double)*K );
209 MRPT_LOG_DEBUG_FMT(
"[clear] %ux%u cells done in %.03fms\n",
unsigned(m_size_x),
unsigned(m_size_y),1000*tictac.
Tac());
218 MRPT_LOG_DEBUG(
"[clear] Generating Prior based on 'Squared Differences'\n");
219 MRPT_LOG_DEBUG_FMT(
"[clear] Initial map dimension: %u cells, x=(%.2f,%.2f) y=(%.2f,%.2f)\n", static_cast<unsigned int>(m_map.size()), getXMin(),getXMax(),getYMin(),getYMax());
226 float res_coef = 1.f;
228 if (this->m_insertOptions_common->GMRF_use_occupancy_information)
230 if( !m_insertOptions_common->GMRF_simplemap_file.empty() )
236 res_coef = this->getResolution() / m_Ocgridmap.
getResolution();
238 else if( !m_insertOptions_common->GMRF_gridmap_image_file.empty() )
241 const bool grid_loaded_ok = m_Ocgridmap.
loadFromBitmapFile(this->m_insertOptions_common->GMRF_gridmap_image_file,this->m_insertOptions_common->GMRF_gridmap_image_res,this->m_insertOptions_common->GMRF_gridmap_image_cx,this->m_insertOptions_common->GMRF_gridmap_image_cy);
243 res_coef = this->getResolution() / this->m_insertOptions_common->GMRF_gridmap_image_res;
246 THROW_EXCEPTION(
"Neither `simplemap_file` nor `gridmap_image_file` found in config/mission file. Quitting.");
250 MRPT_LOG_DEBUG(
"Resizing m_map to match Occupancy Gridmap dimensions");
256 MRPT_LOG_DEBUG_FMT(
"New map dimensions: %u cells, x=(%.2f,%.2f) y=(%.2f,%.2f)\n", static_cast<unsigned int>(m_map.size()), getXMin(),getXMax(),getYMin(),getYMax());
257 MRPT_LOG_DEBUG_FMT(
"New map dimensions: %u cells, cx=%u cy=%u\n", static_cast<unsigned int>(m_map.size()), static_cast<unsigned int>(getSizeX()), static_cast<unsigned int>(getSizeY()));
263 const size_t nodeCount = m_map.size();
266 const size_t nPriorFactors = (this->getSizeX() -1) * this->getSizeY() + this->getSizeX() * (this->getSizeY() -1);
268 MRPT_LOG_DEBUG_STREAM(
"[clear] Generating " << nPriorFactors <<
" prior factors for a map size of N=" << nodeCount << endl);
271 m_gmrf.initialize(nodeCount);
273 m_mrf_factors_activeObs.clear();
274 m_mrf_factors_activeObs.resize(nodeCount);
276 m_mrf_factors_priors.clear();
281 if (!m_gmrf_connectivity.present() && this->m_insertOptions_common->GMRF_use_occupancy_information)
284 MRPT_LOG_DEBUG_FMT(
"MRF Map Dimmensions: %u x %u cells \n", static_cast<unsigned int>(m_size_x), static_cast<unsigned int>(m_size_y));
292 size_t cxoj_min, cxoj_max, cyoj_min, cyoj_max, seed_cxo, seed_cyo;
293 size_t cxoi_min, cxoi_max, cyoi_min, cyoi_max, objective_cxo, objective_cyo;
294 size_t cxo_min, cxo_max, cyo_min, cyo_max;
297 std::multimap<size_t, size_t> cell_interconnections;
299 for (
size_t j=0; j<nodeCount; j++)
302 cxoj_min = floor(cx*res_coef);
303 cxoj_max = cxoj_min + ceil(res_coef-1);
304 cyoj_min = floor(cy*res_coef);
305 cyoj_max = cyoj_min + ceil(res_coef-1);
307 seed_cxo = cxoj_min + ceil(res_coef/2-1);
308 seed_cyo = cyoj_min + ceil(res_coef/2-1);
311 if ( m_Ocgridmap.
getCell(seed_cxo,seed_cyo) < 0.5 )
318 m_mrf_factors_activeObs[j].push_back(new_obs);
319 m_gmrf.addConstraint(*m_mrf_factors_activeObs[j].rbegin());
325 for (
int neighbor=0;neighbor<2; neighbor++)
330 if (cx >= (m_size_x - 1))
338 if (cy >= (m_size_y - 1))
346 cxoi_min = floor(cxi*res_coef);
347 cxoi_max = cxoi_min + ceil(res_coef-1);
348 cyoi_min = floor(cyi*res_coef);
349 cyoi_max = cyoi_min + ceil(res_coef-1);
351 objective_cxo = cxoi_min + ceil(res_coef/2-1);
352 objective_cyo = cyoi_min + ceil(res_coef/2-1);
355 cxo_min =
min(cxoj_min, cxoi_min );
356 cxo_max = max(cxoj_max, cxoi_max );
357 cyo_min =
min(cyoj_min, cyoi_min );
358 cyo_max = max(cyoj_max, cyoi_max );
361 if( exist_relation_between2cells(&m_Ocgridmap, cxo_min,cxo_max,cyo_min,cyo_max,seed_cxo,seed_cyo,objective_cxo,objective_cyo))
366 new_prior.
Lambda = m_insertOptions_common->GMRF_lambdaPrior;
368 m_mrf_factors_priors.push_back(new_prior);
369 m_gmrf.addConstraint(*m_mrf_factors_priors.rbegin());
372 cell_interconnections.insert ( std::pair<size_t,size_t>(j,i) );
373 cell_interconnections.insert ( std::pair<size_t,size_t>(i,j) );
389 if (custom_connectivity!=NULL)
390 MRPT_LOG_DEBUG(
"[CRandomFieldGridMap2D::clear] Initiating prior (using user-supplied connectivity pattern)");
391 else MRPT_LOG_DEBUG(
"[CRandomFieldGridMap2D::clear] Initiating prior (fully connected)");
396 size_t cx = 0, cy = 0;
397 for (
size_t j=0; j<nodeCount; j++)
403 const size_t c_idx_to_check[2] = { cx,cy };
404 const size_t c_idx_to_check_limits[2] = { m_size_x - 1,m_size_y - 1 };
405 const size_t c_neighbor_idx_incr[2] = { 1,m_size_x };
407 for (
int dir = 0; dir < 2; dir++)
409 if (c_idx_to_check[dir] >= c_idx_to_check_limits[dir])
412 const size_t i = j + c_neighbor_idx_incr[dir];
416 double edge_lamdba = .0;
417 if (custom_connectivity != NULL)
422 cx + (dir==0 ? 1:0), cy + (dir == 1 ? 1 : 0),
430 edge_lamdba = m_insertOptions_common->GMRF_lambdaPrior;
435 new_prior.
Lambda = edge_lamdba;
437 m_mrf_factors_priors.push_back(new_prior);
438 m_gmrf.addConstraint(*m_mrf_factors_priors.rbegin());
442 if (++cx>=m_size_x) {
451 if (m_rfgm_run_update_upon_clear) {
453 updateMapEstimation_GMRF();
459 cerr <<
"MAP TYPE NOT RECOGNIZED... QUITTING" << endl;
490 resize( point.
x - m_insertOptions_common->cutoffRadius*2,
491 point.
x + m_insertOptions_common->cutoffRadius*2,
492 point.
y - m_insertOptions_common->cutoffRadius*2,
493 point.
y + m_insertOptions_common->cutoffRadius*2,
498 int Ac_cutoff =
round(m_insertOptions_common->cutoffRadius / m_resolution);
499 unsigned Ac_all = 1+2*Ac_cutoff;
500 double minWinValueAtCutOff = exp(-
square(m_insertOptions_common->cutoffRadius/m_insertOptions_common->sigma) );
502 if ( m_DM_lastCutOff!=m_insertOptions_common->cutoffRadius ||
503 m_DM_gaussWindow.size() !=
square(Ac_all) )
505 MRPT_LOG_DEBUG_FMT(
"[CRandomFieldGridMap2D::insertObservation_KernelDM_DMV] Precomputing window %ux%u\n",Ac_all,Ac_all);
508 double std = m_insertOptions_common->sigma;
511 m_DM_gaussWindow.resize(Ac_all*Ac_all);
512 m_DM_lastCutOff=m_insertOptions_common->cutoffRadius;
517 for (
unsigned cx=0;cx<Ac_all;cx++)
519 for (
unsigned cy=0;cy<Ac_all;cy++)
521 dist = m_resolution * sqrt( static_cast<double>(
square( Ac_cutoff+1-cx ) +
square( Ac_cutoff+1-cy ) ) );
522 *(it++) = std::exp( -
square(dist/
std) );
526 MRPT_LOG_DEBUG(
"[CRandomFieldGridMap2D::insertObservation_KernelDM_DMV] Done!");
531 const int sensor_cx = x2idx( point.
x );
532 const int sensor_cy = y2idx( point.
y );
536 for (
int Acx=-Ac_cutoff;Acx<=Ac_cutoff;Acx++)
538 for (
int Acy=-Ac_cutoff;Acy<=Ac_cutoff;++Acy, ++windowIt)
540 const double windowValue = *windowIt;
542 if (windowValue>minWinValueAtCutOff)
544 cell = cellByIndex(sensor_cx+Acx,sensor_cy+Acy);
548 cell->
dm_mean += windowValue * normReading;
551 const double cell_var =
square(normReading - computeMeanCellValue_DM_DMV(cell) );
567 cutoffRadius ( sigma * 3.0 ),
570 dm_sigma_omega ( 0.05 ),
572 KF_covSigma ( 0.35f ),
573 KF_initialCellStd ( 1.0 ),
574 KF_observationModelNoise ( 0 ),
575 KF_defaultCellMeanValue ( 0 ),
578 GMRF_lambdaPrior ( 0.01f ),
579 GMRF_lambdaObs ( 10.0f ),
580 GMRF_lambdaObsLoss ( 0.0f ),
582 GMRF_use_occupancy_information ( false ),
583 GMRF_simplemap_file (
"" ),
584 GMRF_gridmap_image_file (
"" ),
585 GMRF_gridmap_image_res ( 0.01f ),
586 GMRF_gridmap_image_cx ( 0 ),
587 GMRF_gridmap_image_cy ( 0 ),
589 GMRF_saturate_min ( -
std::numeric_limits<double>::max() ),
590 GMRF_saturate_max (
std::numeric_limits<double>::max() ),
591 GMRF_skip_variance (false)
600 out.
printf(
"sigma = %f\n", sigma);
601 out.
printf(
"cutoffRadius = %f\n", cutoffRadius);
602 out.
printf(
"R_min = %f\n", R_min);
603 out.
printf(
"R_max = %f\n", R_max);
604 out.
printf(
"dm_sigma_omega = %f\n", dm_sigma_omega);
606 out.
printf(
"KF_covSigma = %f\n", KF_covSigma);
607 out.
printf(
"KF_initialCellStd = %f\n", KF_initialCellStd);
608 out.
printf(
"KF_observationModelNoise = %f\n", KF_observationModelNoise);
609 out.
printf(
"KF_defaultCellMeanValue = %f\n", KF_defaultCellMeanValue);
610 out.
printf(
"KF_W_size = %u\n", (
unsigned)KF_W_size);
612 out.
printf(
"GMRF_lambdaPrior = %f\n", GMRF_lambdaPrior);
613 out.
printf(
"GMRF_lambdaObs = %f\n", GMRF_lambdaObs);
614 out.
printf(
"GMRF_lambdaObsLoss = %f\n", GMRF_lambdaObs);
616 out.
printf(
"GMRF_use_occupancy_information = %s\n", GMRF_use_occupancy_information ?
"YES":
"NO" );
617 out.
printf(
"GMRF_simplemap_file = %s\n", GMRF_simplemap_file.c_str());
618 out.
printf(
"GMRF_gridmap_image_file = %s\n", GMRF_gridmap_image_file.c_str());
619 out.
printf(
"GMRF_gridmap_image_res = %f\n", GMRF_gridmap_image_res);
620 out.
printf(
"GMRF_gridmap_image_cx = %u\n", static_cast<unsigned int>(GMRF_gridmap_image_cx));
621 out.
printf(
"GMRF_gridmap_image_cy = %u\n", static_cast<unsigned int>(GMRF_gridmap_image_cy));
631 sigma = iniFile.
read_float(section.c_str(),
"sigma",sigma);
632 cutoffRadius = iniFile.
read_float(section.c_str(),
"cutoffRadius",cutoffRadius);
633 R_min = iniFile.
read_float(section.c_str(),
"R_min",R_min);
634 R_max = iniFile.
read_float(section.c_str(),
"R_max",R_max);
637 KF_covSigma = iniFile.
read_float(section.c_str(),
"KF_covSigma",KF_covSigma);
638 KF_initialCellStd = iniFile.
read_float(section.c_str(),
"KF_initialCellStd",KF_initialCellStd);
639 KF_observationModelNoise= iniFile.
read_float(section.c_str(),
"KF_observationModelNoise",KF_observationModelNoise);
640 KF_defaultCellMeanValue = iniFile.
read_float(section.c_str(),
"KF_defaultCellMeanValue",KF_defaultCellMeanValue);
643 GMRF_lambdaPrior = iniFile.
read_float(section.c_str(),
"GMRF_lambdaPrior",GMRF_lambdaPrior);
644 GMRF_lambdaObs = iniFile.
read_float(section.c_str(),
"GMRF_lambdaObs",GMRF_lambdaObs);
645 GMRF_lambdaObsLoss = iniFile.
read_float(section.c_str(),
"GMRF_lambdaObsLoss",GMRF_lambdaObsLoss);
647 GMRF_use_occupancy_information = iniFile.
read_bool(section.c_str(),
"GMRF_use_occupancy_information",
false,
false);
648 GMRF_simplemap_file = iniFile.
read_string(section.c_str(),
"simplemap_file",
"",
false);
649 GMRF_gridmap_image_file = iniFile.
read_string(section.c_str(),
"gridmap_image_file",
"",
false);
650 GMRF_gridmap_image_res = iniFile.
read_float(section.c_str(),
"gridmap_image_res",0.01f,
false);
651 GMRF_gridmap_image_cx = iniFile.
read_int(section.c_str(),
"gridmap_image_cx",0,
false);
652 GMRF_gridmap_image_cy = iniFile.
read_int(section.c_str(),
"gridmap_image_cy",0,
false);
666 img.saveToFile(filName);
727 double new_x_min,
double new_x_max,
double new_y_min,
double new_y_max,
729 double additionalMarginMeters)
756 printf(
"[CRandomFieldGridMap2D::resize] Resizing from %ux%u to %ux%u (%u cells)\n",
757 static_cast<unsigned>(old_sizeX),
758 static_cast<unsigned>(old_sizeY),
763 m_cov.setSize( N,N );
777 bool C1_isFromOldMap = Acx_left<=cx1 && cx1<(Acx_left+old_sizeX) &&
778 Acy_bottom<=cy1 && cy1<(Acy_bottom+old_sizeY);
780 if ( C1_isFromOldMap )
787 bool C2_isFromOldMap = Acx_left<=cx2 && cx2<(Acx_left+old_sizeX) &&
788 Acy_bottom<=cy2 && cy2<(Acy_bottom+old_sizeY);
791 if ( C1_isFromOldMap && C2_isFromOldMap )
794 unsigned int idx_c1 = ( (cx1 - Acx_left) + old_sizeX * (cy1 - Acy_bottom ) );
795 unsigned int idx_c2 = ( (cx2 - Acx_left) + old_sizeX * (cy2 - Acy_bottom ) );
801 ASSERT_( (cx1 - Acx_left )<old_sizeX );
802 ASSERT_( (cy1 - Acy_bottom )<old_sizeY );
806 ASSERT_( (cx2 - Acx_left )<old_sizeX );
807 ASSERT_( (cy2 - Acy_bottom )<old_sizeY );
809 ASSERT_( idx_c1<old_sizeX*old_sizeY );
810 ASSERT_( idx_c2<old_sizeX*old_sizeY );
813 printf(
"cx1=%u\n",static_cast<unsigned>(cx1)); \
814 printf(
"cy1=%u\n",static_cast<unsigned>(cy1)); \
815 printf(
"cx2=%u\n",static_cast<unsigned>(cx2)); \
816 printf(
"cy2=%u\n",static_cast<unsigned>(cy2)); \
817 printf(
"Acx_left=%u\n",static_cast<unsigned>(Acx_left)); \
818 printf(
"Acy_bottom=%u\n",static_cast<unsigned>(Acy_bottom)); \
819 printf(
"idx_c1=%u\n",static_cast<unsigned>(idx_c1)); \
820 printf(
"idx_c2=%u\n",static_cast<unsigned>(idx_c2)); \
823 m_cov(i,j) = oldCov( idx_c1, idx_c2 );
829 if (i==j &&
m_cov(i,i)<0)
831 printf(
"\ni=%u \nj=%i \ncx1,cy1 = %u,%u \n cx2,cy2=%u,%u \nidx_c1=%u \nidx_c2=%u \nAcx_left=%u \nAcy_bottom=%u \nold_sizeX=%u \n",
832 static_cast<unsigned>(i),
833 static_cast<unsigned>(j),
834 static_cast<unsigned>(cx1),
835 static_cast<unsigned>(cy1),
836 static_cast<unsigned>(cx2),
837 static_cast<unsigned>(cy2),
838 static_cast<unsigned>(idx_c1),
839 static_cast<unsigned>(idx_c2),
840 static_cast<unsigned>(Acx_left),
841 static_cast<unsigned>(Acy_bottom),
842 static_cast<unsigned>(old_sizeX)
861 bool C1_isFromOldMap = Acx_left<=cx1 && cx1<(Acx_left+old_sizeX) &&
862 Acy_bottom<=cy1 && cy1<(Acy_bottom+old_sizeY);
868 bool C2_isFromOldMap = Acx_left<=cx2 && cx2<(Acx_left+old_sizeX) &&
869 Acy_bottom<=cy2 && cy2<(Acy_bottom+old_sizeY);
873 if ( !C1_isFromOldMap || !C2_isFromOldMap )
887 printf(
"c(i,i)=%e c(j,j)=%e\n",
m_cov(i,i),
m_cov(j,j));
903 printf(
"[CRandomFieldGridMap2D::resize] Done\n");
917 static_cast<unsigned>(old_sizeX),
918 static_cast<unsigned>(old_sizeY),
925 const size_t N =
m_map.size();
926 const size_t K = 2*W*(W+1)+1;
940 double *ptr = &template_row[0];
949 for (Acx=1;Acx<=W;Acx++)
950 *ptr++ = std0sqr * exp( -0.5 * (res2 * static_cast<double>(
square(Acx) +
square(Acy)))/KF_covSigma2 );
953 for (Acy=1;Acy<=W;Acy++)
954 for (Acx=-W;Acx<=W;Acx++)
955 *ptr++ = std0sqr * exp( -0.5 * (res2 * static_cast<double>(
square(Acx) +
square(Acy)))/KF_covSigma2 );
960 for (
size_t i=N-1;i<N;i--)
965 const size_t old_idx_of_i = (cx-Acx_left) + (cy-Acy_bottom)*old_sizeX;
974 memcpy( new_row,&template_row[0],
sizeof(
double)*K );
982 const double *ptr_old =
m_stackedCov.get_unsafe_row(old_idx_of_i);
984 memcpy( ptr_new,ptr_old,
sizeof(
double)*K );
1028 int cellIdx =
xy2idx( point.
x, point.
y );
1033 double yk = normReading - cell->
kf_mean;
1035 double sk_1 = 1.0 / sk;
1041 MRPT_LOG_DEBUG(
"[insertObservation_KF] Updating mean values...");
1046 for (i=0,it =
m_map.begin();it!=
m_map.end();++it,++i)
1048 it->kf_mean += yk * sk_1 *
m_cov(i,cellIdx);
1054 N =
m_cov.getRowCount();
1056 MRPT_LOG_DEBUG(
"[insertObservation_KF] Updating covariance matrix...");
1060 double *oldCov = (
double*)malloc(
sizeof(
double)*N*N );
1061 double *oldCov_ptr = oldCov;
1064 memcpy( oldCov_ptr,
m_cov.get_unsafe_row(i) ,
sizeof(double)*N );
1072 const double *oldCov_row_c = oldCov+cellIdx*N;
1075 const double oldCov_i_c = oldCov[i*N+cellIdx];
1076 const double sk_1_oldCov_i_c = sk_1 * oldCov_i_c;
1078 const double *oldCov_row_i = oldCov+i*N;
1081 double new_cov_ij = oldCov_row_i[j] - sk_1_oldCov_i_c * oldCov_row_c[j];
1084 m_cov.set_unsafe(i,j, new_cov_ij );
1085 m_cov.set_unsafe(j,i, new_cov_ij );
1091 printf(
"Wrong insertion in KF! m_cov(%u,%u) = %.5f",static_cast<unsigned int>(i),static_cast<unsigned int>(i),
m_cov(i,i));
1095 m_map[ i ].kf_std = sqrt( new_cov_ij );
1130 DIMs.saveToTextFile( filNamePrefix +
std::string(
"_grid_limits.txt"),
MATRIX_FORMAT_FIXED,
false ,
"% Grid limits: [x_min x_max y_min y_max]\n" );
1191 CImage img_cov(STDs,
true);
1209 for (
size_t j=0; j<
m_size_x; ++j,++idx)
1214 XYZ(idx,0) =
idx2x(j);
1215 XYZ(idx,1) =
idx2y(i);
1223 XYZ.saveToTextFile( filNamePrefix +
std::string(
"_xyz_and_std.txt"),
MATRIX_FORMAT_FIXED,
false,
"% Columns: GRID_X GRID_Y ESTIMATED_Z STD_DEV_OF_ESTIMATED_Z \n" );
1239 const double std_times = 3;
1245 FILE *f=
os::fopen( filName.c_str(),
"wt" );
1249 os::fprintf(f,
"%%-------------------------------------------------------\n");
1250 os::fprintf(f,
"%% File automatically generated using the MRPT method:\n");
1251 os::fprintf(f,
"%%'CRandomFieldGridMap2D::saveAsMatlab3DGraph'\n");
1254 os::fprintf(f,
"%% Jose Luis Blanco Claraco, University of Malaga @ 2006-2007\n");
1256 os::fprintf(f,
"%%-------------------------------------------------------\n\n");
1260 vector<double> xs,ys;
1337 os::fprintf(f,
"set(S1,'FaceAlpha',0.9,'EdgeAlpha',0.9);\n");
1338 os::fprintf(f,
"set(S2,'FaceAlpha',0.4,'EdgeAlpha',0.4);\n");
1339 os::fprintf(f,
"set(S3,'FaceAlpha',0.2,'EdgeAlpha',0.2);\n");
1341 os::fprintf(f,
"set(gca,'PlotBoxAspectRatio',[%f %f %f]);\n",
1353 os::fprintf(f,
"\nfigure; imagesc(xs,ys,z_mean);axis equal;title('Mean value');colorbar;");
1354 os::fprintf(f,
"\nfigure; imagesc(xs,ys,(z_upper-z_mean)/%f);axis equal;title('Std dev of estimated value');colorbar;",std_times);
1387 vector<double> xs,ys;
1407 obj_m->enableTransparency(
true);
1409 obj_v->enableTransparency(
true);
1413 double maxVal_m=0, minVal_m=1, AMaxMin_m, maxVal_v=0, minVal_v=1, AMaxMin_v;
1422 minVal_m =
min(minVal_m,
c);
1423 maxVal_m = max(maxVal_m,
c);
1426 minVal_v =
min(minVal_v,
v);
1427 maxVal_v = max(maxVal_v,
v);
1431 AMaxMin_m = maxVal_m - minVal_m;
1432 if (AMaxMin_m==0) AMaxMin_m=1;
1433 AMaxMin_v = maxVal_v - minVal_v;
1434 if (AMaxMin_v==0) AMaxMin_v=1;
1439 triag.
a[0]=triag.
a[1]=triag.
a[2]= 0.75f;
1457 double col_xy = c_xy;
1458 double col_x_1y = c_x_1y;
1459 double col_xy_1 = c_xy_1;
1460 double col_x_1y_1 = c_x_1y_1;
1463 triag.
x[0] = xs[cx]; triag.
y[0] = ys[cy]; triag.
z[0] = c_xy;
1464 triag.
x[1] = xs[cx]; triag.
y[1] = ys[cy-1]; triag.
z[1] = c_xy_1;
1465 triag.
x[2] = xs[cx-1]; triag.
y[2] = ys[cy-1]; triag.
z[2] = c_x_1y_1;
1466 jet2rgb( col_xy,triag.
r[0],triag.
g[0],triag.
b[0] );
1467 jet2rgb( col_xy_1,triag.
r[1],triag.
g[1],triag.
b[1] );
1468 jet2rgb( col_x_1y_1,triag.
r[2],triag.
g[2],triag.
b[2] );
1469 obj_m->insertTriangle( triag );
1472 triag.
x[0] = xs[cx]; triag.
y[0] = ys[cy]; triag.
z[0] = c_xy;
1473 triag.
x[1] = xs[cx-1]; triag.
y[1] = ys[cy-1]; triag.
z[1] = c_x_1y_1;
1474 triag.
x[2] = xs[cx-1]; triag.
y[2] = ys[cy]; triag.
z[2] = c_x_1y;
1475 jet2rgb( col_xy,triag.
r[0],triag.
g[0],triag.
b[0] );
1476 jet2rgb( col_x_1y_1,triag.
r[1],triag.
g[1],triag.
b[1] );
1477 jet2rgb( col_x_1y,triag.
r[2],triag.
g[2],triag.
b[2] );
1478 obj_m->insertTriangle( triag );
1488 col_x_1y = v_x_1y/10;
1489 col_xy_1 = v_xy_1/10;
1490 col_x_1y_1 = v_x_1y_1/10;
1494 triag.
x[0] = xs[cx]; triag.
y[0] = ys[cy]; triag.
z[0] = c_xy + v_xy;
1495 triag.
x[1] = xs[cx]; triag.
y[1] = ys[cy-1]; triag.
z[1] = c_xy_1 + v_xy_1;
1496 triag.
x[2] = xs[cx-1]; triag.
y[2] = ys[cy-1]; triag.
z[2] = c_x_1y_1+ v_x_1y_1;
1497 jet2rgb( col_xy,triag.
r[0],triag.
g[0],triag.
b[0] );
1498 jet2rgb( col_xy_1,triag.
r[1],triag.
g[1],triag.
b[1] );
1499 jet2rgb( col_x_1y_1,triag.
r[2],triag.
g[2],triag.
b[2] );
1500 obj_v->insertTriangle( triag );
1503 triag.
x[0] = xs[cx]; triag.
y[0] = ys[cy]; triag.
z[0] = c_xy + v_xy;
1504 triag.
x[1] = xs[cx-1]; triag.
y[1] = ys[cy-1]; triag.
z[1] = c_x_1y_1+ v_x_1y_1;
1505 triag.
x[2] = xs[cx-1]; triag.
y[2] = ys[cy]; triag.
z[2] = c_x_1y + v_x_1y;
1506 jet2rgb( col_xy,triag.
r[0],triag.
g[0],triag.
b[0] );
1507 jet2rgb( col_x_1y_1,triag.
r[1],triag.
g[1],triag.
b[1] );
1508 jet2rgb( col_x_1y,triag.
r[2],triag.
g[2],triag.
b[2] );
1509 obj_v->insertTriangle( triag );
1513 meanObj->insert( obj_m );
1514 varObj->insert( obj_v );
1524 obj_m->enableTransparency(
true);
1526 obj_v->enableTransparency(
true);
1530 double maxVal_m=0, minVal_m=1, AMaxMin_m, maxVal_v=0, minVal_v=1, AMaxMin_v;
1539 minVal_m =
min(minVal_m,
c);
1540 maxVal_m = max(maxVal_m,
c);
1543 minVal_v =
min(minVal_v,
v);
1544 maxVal_v = max(maxVal_v,
v);
1548 AMaxMin_m = maxVal_m - minVal_m;
1549 if (AMaxMin_m==0) AMaxMin_m=1;
1550 AMaxMin_v = maxVal_v - minVal_v;
1551 if (AMaxMin_v==0) AMaxMin_v=1;
1556 triag.
a[0]=triag.
a[1]=triag.
a[2]= 0.75f;
1574 double col_xy = c_xy;
1575 double col_x_1y = c_x_1y;
1576 double col_xy_1 = c_xy_1;
1577 double col_x_1y_1 = c_x_1y_1;
1580 triag.
x[0] = xs[cx]; triag.
y[0] = ys[cy]; triag.
z[0] = c_xy;
1581 triag.
x[1] = xs[cx]; triag.
y[1] = ys[cy-1]; triag.
z[1] = c_xy_1;
1582 triag.
x[2] = xs[cx-1]; triag.
y[2] = ys[cy-1]; triag.
z[2] = c_x_1y_1;
1583 jet2rgb( col_xy,triag.
r[0],triag.
g[0],triag.
b[0] );
1584 jet2rgb( col_xy_1,triag.
r[1],triag.
g[1],triag.
b[1] );
1585 jet2rgb( col_x_1y_1,triag.
r[2],triag.
g[2],triag.
b[2] );
1587 obj_m->insertTriangle( triag );
1590 triag.
x[0] = xs[cx]; triag.
y[0] = ys[cy]; triag.
z[0] = c_xy;
1591 triag.
x[1] = xs[cx-1]; triag.
y[1] = ys[cy-1]; triag.
z[1] = c_x_1y_1;
1592 triag.
x[2] = xs[cx-1]; triag.
y[2] = ys[cy]; triag.
z[2] = c_x_1y;
1593 jet2rgb( col_xy,triag.
r[0],triag.
g[0],triag.
b[0] );
1594 jet2rgb( col_x_1y_1,triag.
r[1],triag.
g[1],triag.
b[1] );
1595 jet2rgb( col_x_1y,triag.
r[2],triag.
g[2],triag.
b[2] );
1596 obj_m->insertTriangle( triag );
1608 col_x_1y_1 = v_x_1y_1;
1611 triag.
x[0] = xs[cx]; triag.
y[0] = ys[cy]; triag.
z[0] = v_xy;
1612 triag.
x[1] = xs[cx]; triag.
y[1] = ys[cy-1]; triag.
z[1] = v_xy_1;
1613 triag.
x[2] = xs[cx-1]; triag.
y[2] = ys[cy-1]; triag.
z[2] = v_x_1y_1;
1614 jet2rgb( col_xy,triag.
r[0],triag.
g[0],triag.
b[0] );
1615 jet2rgb( col_xy_1,triag.
r[1],triag.
g[1],triag.
b[1] );
1616 jet2rgb( col_x_1y_1,triag.
r[2],triag.
g[2],triag.
b[2] );
1618 obj_v->insertTriangle( triag );
1621 triag.
x[0] = xs[cx]; triag.
y[0] = ys[cy]; triag.
z[0] = v_xy;
1622 triag.
x[1] = xs[cx-1]; triag.
y[1] = ys[cy-1]; triag.
z[1] = v_x_1y_1;
1623 triag.
x[2] = xs[cx-1]; triag.
y[2] = ys[cy]; triag.
z[2] = v_x_1y;
1624 jet2rgb( col_xy,triag.
r[0],triag.
g[0],triag.
b[0] );
1625 jet2rgb( col_x_1y_1,triag.
r[1],triag.
g[1],triag.
b[1] );
1626 jet2rgb( col_x_1y,triag.
r[2],triag.
g[2],triag.
b[2] );
1627 obj_v->insertTriangle( triag );
1632 meanObj->insert( obj_m );
1633 varObj->insert( obj_v );
1686 double &out_predict_response,
1687 double &out_predict_response_variance,
1688 bool do_sensor_normalization,
1694 vector<TInterpQuery> queries;
1695 switch (interp_method)
1699 queries[0].cx =
x2idx(
x);
1700 queries[0].cy =
y2idx(
y);
1701 queries[0].coef = 1.0;
1712 queries[0].cx =
x2idx(
x);
1713 queries[0].cy =
y2idx(
y);
1714 queries[0].coef = 1.0;
1733 queries[0].coef = K_1*(
idx2x(queries[3].cx)-
x)*(
idx2y(queries[3].cy)-
y);
1734 queries[1].coef = K_1*(
idx2x(queries[3].cx)-
x)*(
y-
idx2y(queries[0].cy));
1735 queries[2].coef = K_1*(
x-
idx2x(queries[0].cx))*(
idx2y(queries[3].cy)-
y);
1736 queries[3].coef = K_1*(
x-
idx2x(queries[0].cx))*(
y-
idx2y(queries[0].cy));
1744 for (
size_t i=0;i<queries.size();i++)
1800 out_predict_response = 0;
1801 out_predict_response_variance = 0;
1802 for (
size_t i=0;i<queries.size();i++) {
1803 out_predict_response += queries[i].val * queries[i].coef;
1804 out_predict_response_variance += queries[i].var * queries[i].coef;
1808 if (do_sensor_normalization)
1827 const size_t K = 2*W*(W+1)+1;
1828 const size_t W21 = 2*W+1;
1829 const size_t W21sqr = W21*W21;
1853 const size_t N =
m_map.size();
1870 const int cellIdx =
xy2idx( point.
x, point.
y );
1875 double yk = normReading - cell->
kf_mean;
1882 double sk_1 = 1.0 / sk;
1885 MRPT_LOG_DEBUG(
"[insertObservation_KF2] Updating mean values...");
1894 const int cx_c =
x2idx( point.
x );
1895 const int cy_c =
y2idx( point.
y );
1897 const int Acx0 = max(-W, -cx_c);
1898 const int Acy0 = max(-W, -cy_c);
1908 for (
int Acy=Acy0;Acy<=0;Acy++)
1910 int limit_cx = Acy<0 ? Acx1 : -1;
1912 size_t idx = cx_c+Acx0 +
m_size_x * ( cy_c+Acy );
1913 int idx_c_in_idx = -Acy*W21 - Acx0;
1915 int window_idx = Acx0+W + (Acy+W)*W21;
1917 for (
int Acx=Acx0;Acx<=limit_cx;Acx++)
1923 m_map[idx].kf_mean += yk * sk_1 * cov_i_c;
1926 cross_covs_c_i[window_idx] = cov_i_c;
1927 window_idxs[window_idx++] = idx;
1937 for (
int Acy=0;Acy<=Acy1;Acy++)
1939 int start_cx = Acy>0 ? Acx0 : 0;
1941 size_t idx = cx_c+start_cx +
m_size_x * ( cy_c+Acy );
1944 idx_i_in_c= (W+1) + (Acy-1)*W21+ (start_cx + W);
1947 int window_idx = start_cx+W + (Acy+W)*W21;
1949 for (
int Acx=start_cx;Acx<=Acx1;Acx++)
1951 ASSERT_(idx_i_in_c>=0 && idx_i_in_c<
int(K));
1954 m_map[idx].kf_mean += yk * sk_1 * cov_i_c;
1957 cross_covs_c_i[window_idx] = cov_i_c;
1958 window_idxs[window_idx++] = idx;
1974 for (
size_t i=0;i<W21sqr;i++)
1976 const int idx_i = window_idxs[i];
1977 if (idx_i<0)
continue;
1983 const double cov_c_i = cross_covs_c_i[i];
1985 for (
size_t j=i;j<W21sqr;j++)
1987 const int idx_j = window_idxs[j];
1988 if (idx_j<0)
continue;
1994 const int Ax = cx_j-cx_i;
1997 const int Ay = cy_j-cy_i;
2000 const double cov_c_j = cross_covs_c_i[j];
2004 idx_j_in_i = Ax+W + (Ay-1)*W21 + W+1;
2005 else idx_j_in_i = Ax;
2008 double &cov_to_change =
m_stackedCov(idx_i,idx_j_in_i);
2009 double Delta_cov = cov_c_j * cov_c_i * sk_1;
2010 if (i==j && cov_to_change<Delta_cov)
2013 cov_to_change -= Delta_cov;
2032 const size_t N =
m_map.size();
2033 for (
size_t i=0;i<N;i++)
2044 out_means.resize(N);
2045 for (
size_t i=0;i<N;++i)
2060 out_means.resize(N);
2063 for (
size_t i=0;i<N;++i)
2078 ASSERT_( N ==
size_t(in_means.size()) );
2079 ASSERT_( N ==
size_t(in_std.size()) );
2082 for (
size_t i=0; i<N; ++i)
2084 m_map[i].kf_mean = in_means[i];
2111 THROW_EXCEPTION(
"insertObservation() isn't implemented for selected 'mapType'")
2131 THROW_EXCEPTION(
"insertObservation() isn't implemented for selected 'mapType'")
2142 const bool time_invariant,
2143 const double reading_information)
2148 const int cellIdx =
xy2idx( point.
x, point.
y );
2156 new_obs.
Lambda = reading_information;
2162 }
catch(std::exception e){
2163 cerr <<
"Exception while Inserting new Observation: " << e.what() << endl;
2175 Eigen::VectorXd x_incr, x_var;
2178 ASSERT_(
size_t(
m_map.size()) ==
size_t(x_incr.size()));
2182 for (
size_t j = 0; j<
m_map.size(); j++)
2185 m_map[j].gmrf_mean += x_incr[j];
2195 for (
auto ito = obs.begin(); ito != obs.end(); )
2197 if (!ito->time_invariant) {
2203 if (ito->Lambda < 0)
2206 ito = obs.erase(ito);
2223 const size_t seed_cxo,
2224 const size_t seed_cyo,
2225 const size_t objective_cxo,
2226 const size_t objective_cyo)
2231 cxo_min = max (cxo_min, (
size_t)0);
2232 cxo_max =
min (cxo_max, (
size_t)m_Ocgridmap->
getSizeX()-1);
2233 cyo_min = max (cyo_min, (
size_t)0);
2234 cyo_max =
min (cyo_max, (
size_t)m_Ocgridmap->
getSizeY()-1);
2239 if( (seed_cxo < cxo_min) || (seed_cxo >= cxo_max) || (seed_cyo < cyo_min) || (seed_cyo >= cyo_max) )
2244 if( (objective_cxo < cxo_min) || (objective_cxo >= cxo_max) || (objective_cyo < cyo_min) || (objective_cyo >= cyo_max) )
2251 if ( (m_Ocgridmap->
getCell(seed_cxo,seed_cyo)<0.5) != (m_Ocgridmap->
getCell(objective_cxo,objective_cyo)<0.5) )
2265 matExp(seed_cxo-cxo_min,seed_cyo-cyo_min) = 1;
2270 while (seedsOld < seedsNew)
2272 seedsOld = seedsNew;
2274 for (
size_t col=0; col<matExp.getColCount(); col++)
2276 for (
size_t row=0;
row<matExp.getRowCount();
row++)
2279 if( matExp(
row,col) == 1)
2281 matExp(
row,col) = 2;
2283 for (
int i=-1;i<=1;i++)
2285 for (
int j=-1;j<=1;j++)
2288 if( (
int(
row)+j>=0) && (
int(
row)+j<=
int(matExp.getRowCount()-1)) && (int(col)+i>=0) && (
int(col)+i<=int(matExp.getColCount())-1) )
2290 if( !( (i==0 && j==0) || !(matExp(
row+j,col+i)==0) ))
2293 if ( (m_Ocgridmap->
getCell(
row+cxo_min,col+cyo_min)<0.5) == (m_Ocgridmap->
getCell(
row+j+cxo_min,col+i+cyo_min)<0.5))
2295 if ( (
row+j+cxo_min == objective_cxo) && (col+i+cyo_min == objective_cyo) )
2300 matExp(
row+j,col+i) = 1;
2327 return m_parent->m_map[this->node_id].gmrf_mean - this->obsValue;
2331 return this->Lambda;
2340 return m_parent->m_map[this->node_id_i].gmrf_mean - m_parent->m_map[this->node_id_j].gmrf_mean;
2344 return this->Lambda;
void clear()
Erase all the contents of the map.
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
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.
float R_max
Limits for normalization of sensor readings.
double GMRF_saturate_max
(Default:-inf,+inf) Saturate the estimated mean in these limits
Gaussian kernel-based estimator (see discussion in mrpt::maps::CRandomFieldGridMap2D) ...
Parameters for CMetricMap::compute3DMatchingRatio()
GLclampf GLclampf GLclampf alpha
FILE BASE_IMPEXP * fopen(const char *fileName, const char *mode) MRPT_NO_THROWS
An OS-independent version of fopen.
virtual bool isEmpty() const MRPT_OVERRIDE
Returns true if the map is empty/no observation has been inserted (in this class it always return fal...
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.
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.
double getInformation() const MRPT_OVERRIDE
Return the inverse of the variance of this constraint.
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 BASE_IMPEXP void BASE_IMPEXP fclose(FILE *f)
An OS-independent version of fclose.
bool eraseConstraint(const FactorBase &c)
Removes a constraint. Return true if found and deleted correctly.
A class for storing images as grayscale or RGB bitmaps.
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.
#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)
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
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.
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) MRPT_OVERRIDE
Changes the size of the grid, maintaining previous contents.
TMapRepresentation getMapType()
Return the type of the random-field grid map, according to parameters passed on construction.
void Tic()
Starts the stopwatch.
void idx2cxcy(const int &idx, int &cx, int &cy) const
Transform a global (linear) cell index value into its corresponding (x,y) cell indexes.
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 * dm_mean / dm_mean_w + (1-alpha)...
TRandomFieldCell * cellByPos(double x, double y)
Returns a pointer to the contents of a cell given by its coordinates, or NULL if it is out of the map...
double idx2y(int cy) const
bool BASE_IMPEXP isNaN(float f) MRPT_NO_THROWS
Returns true if the number is NaN.
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.
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...
void evalJacobian(double &dr_dx_i, double &dr_dx_j) const MRPT_OVERRIDE
Returns the derivative of the residual wrt the node values.
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...
virtual void saveAsBitmapFile(const std::string &filName) const
Save the current map as a graphical file (BMP,PNG,...).
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.
#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 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.
float compute3DMatchingRatio(const mrpt::maps::CMetricMap *otherMap, const mrpt::poses::CPose3D &otherMapPose, const TMatchingRatioParams ¶ms) const MRPT_OVERRIDE
See docs in base class: in this class this always returns 0.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
double evaluateResidual() const MRPT_OVERRIDE
Return the residual/error of this observation.
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.
double getInformation() const MRPT_OVERRIDE
Return the inverse of the variance of this constraint.
"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=NULL)
Changes the size of the grid, erasing previous contents.
This namespace contains representation of robot actions and observations.
static CSetOfTrianglesPtr Create()
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()
virtual void getAs3DObject(mrpt::opengl::CSetOfObjectsPtr &outObj) const MRPT_OVERRIDE
Returns a 3D object representing the map (mean)
double GMRF_lambdaObs
The initial information (Lambda) of each observation (this information will decrease with time) ...
#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 NULL if it is out of the ma...
double idx2x(int cx) const
Transform a cell index into a coordinate value of the cell central point.
double evaluateResidual() const MRPT_OVERRIDE
Return the residual/error of this observation.
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.
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.
#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...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void setCellsConnectivity(const ConnectivityDescriptorPtr &new_connectivity_descriptor)
Sets a custom object to define the connectivity between cells.
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...
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 BASE_IMPEXP 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...
stlplus::smart_ptr< ConnectivityDescriptor > ConnectivityDescriptorPtr
virtual void getAsBitmapFile(mrpt::utils::CImage &out_img) const
Returns an image just as described in saveAsBitmapFile.
double m_average_normreadings_var
void evalJacobian(double &dr_dx) const MRPT_OVERRIDE
Returns the derivative of the residual wrt the node value.
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.
void updateEstimation(Eigen::VectorXd &solved_x_inc, Eigen::VectorXd *solved_variances=NULL)
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...
std::vector< int32_t > vector_int
mrpt::math::CMatrixD m_stackedCov
The compressed band diagonal matrix for the KF2 implementation.
double Lambda
"Information" of the observation (=inverse of the variance)
double dm_mean
[Kernel-methods only] The cumulative weighted readings of this cell
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)
virtual void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const MRPT_OVERRIDE
The implementation in this class just calls all the corresponding method of the contained metric maps...
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)
Load the map contents from a CSimpleMap object, erasing all previous content of the 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...
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'
virtual void internal_clear() MRPT_OVERRIDE
Erase all the contents of the map.
static CSetOfObjectsPtr Create()
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 ...