44 return kf1.metric_map->compute3DMatchingRatio(kf2.metric_map.get(), relPose2wrt1, parent->options.mrp);
58 metricmap.push_back(def);
72 "minDistForCorrespondence",
double, mrp.maxDistForCorr,
75 "minMahaDistForCorrespondence",
double, mrp.maxMahaDistForCorr,
80 metricmap.loadFromConfigFile(cfp,
"metricmap");
81 MRPT_TODO(
"Add link to example INI file");
91 MRPT_SAVE_CONFIG_VAR_COMMENT(forceBisectionOnly,
"Force bisection (true) or automatically determine number of partitions(false = default)");
99 metricmap.saveToConfigFile(cfp,
"metricmap");
104 m_last_last_partition_are_new_ones =
false;
106 m_individualFrames.clear();
107 m_individualMaps.clear();
108 m_last_partition.clear();
117 const uint32_t new_id = m_individualMaps.size();
118 const size_t n = new_id + 1;
121 m_individualMaps.push_back(CMultiMetricMap::Create());
122 auto& newMetricMap = m_individualMaps.back();
123 newMetricMap->setListOfMaps(&options.metricmap);
129 m_individualFrames.insert(&robotPose, frame);
134 ASSERT_(m_individualMaps.size() ==
n);
135 ASSERT_(m_individualFrames.size() ==
n);
139 using namespace std::placeholders;
140 switch (options.simil_method)
149 sim_func = m_sim_func;
167 auto pose_i = posePDF_i->getMeanVal();
169 for (
uint32_t j = 0; j < new_id; j++)
171 const auto id_diff = new_id - j;
173 if (id_diff > options.maxKeyFrameDistanceToEval)
185 auto pose_j = posePDF_j->getMeanVal();
188 auto relPose = pose_j - pose_i;
191 const auto s_ij = sim_func(map_i, map_j, relPose);
192 const auto s_ji = sim_func(map_j, map_i, relPose);
193 s_sym = 0.5*(s_ij + s_ji);
195 m_A(i, j) = m_A(j, i) = s_sym;
200 m_A(new_id, new_id) = 0;
206 if (m_last_last_partition_are_new_ones)
209 m_last_partition[m_last_partition.size() - 1].push_back(
n - 1);
214 std::vector<uint32_t> dummyPart;
215 dummyPart.push_back(
n - 1);
216 m_last_partition.emplace_back(dummyPart);
219 m_last_last_partition_are_new_ones =
true;
228 vector<std::vector<uint32_t>>& partitions)
234 m_A, partitions, options.partitionThreshold,
true,
true,
235 !options.forceBisectionOnly,
236 options.minimumNumberElementsEachCluster,
false
239 m_last_partition = partitions;
240 m_last_last_partition_are_new_ones =
false;
247 return m_individualFrames.size();
251 std::vector<uint32_t> indexesToRemove,
bool changeCoordsRef)
255 size_t nOld = m_A.cols();
256 size_t nNew = nOld - indexesToRemove.size();
260 std::sort(indexesToRemove.begin(), indexesToRemove.end());
265 std::vector<uint32_t> indexesToStay;
266 indexesToStay.reserve(nNew);
267 for (i = 0; i < nOld; i++)
270 for (j = 0; !remov && j < indexesToRemove.size(); j++)
272 if (indexesToRemove[j] == i) remov =
true;
275 if (!remov) indexesToStay.push_back(i);
278 ASSERT_(indexesToStay.size() == nNew);
283 for (i = 0; i < nNew; i++)
284 for (j = 0; j < nNew; j++)
285 newA(i, j) = m_A(indexesToStay[i], indexesToStay[j]);
292 m_last_partition.resize(1);
293 m_last_partition[0].resize(nNew);
294 for (i = 0; i < nNew; i++) m_last_partition[0][i] = i;
296 m_last_last_partition_are_new_ones =
false;
300 for (
auto it = indexesToRemove.rbegin(); it != indexesToRemove.rend(); ++it)
302 auto itM = m_individualMaps.begin() + *it;
303 m_individualMaps.erase(itM);
308 for (
auto it = indexesToRemove.rbegin(); it != indexesToRemove.rend(); ++it)
309 m_individualFrames.remove(*it);
317 ASSERT_(m_individualFrames.size() > 0);
318 m_individualFrames.get(0, posePDF, SF);
322 m_individualFrames.changeCoordinatesOrigin(
p);
332 m_individualFrames.changeCoordinatesOrigin(newOrigin);
336 unsigned int newOriginPose)
342 m_individualFrames.get(newOriginPose, pdf, sf);
346 changeCoordinatesOrigin(-
p);
353 const std::map<uint32_t, int64_t>* renameIndexes)
const
356 ASSERT_((
int)m_individualFrames.size() == m_A.cols());
359 objs->insert(gl_grid);
360 int bbminx = std::numeric_limits<int>::max(), bbminy = std::numeric_limits<int>::max();
361 int bbmaxx = -bbminx, bbmaxy = -bbminy;
363 for (
size_t i = 0; i < m_individualFrames.size(); i++)
367 m_individualFrames.get(i, i_pdf, i_sf);
370 i_pdf->getMean(i_mean);
378 mrpt::make_aligned_shared<opengl::CSphere>();
379 i_sph->setRadius(0.02f);
380 i_sph->setColor(0, 0, 1);
383 i_sph->setName(
format(
"%u",
static_cast<unsigned int>(i)));
387 renameIndexes->find(i);
388 ASSERT_(itName != renameIndexes->end());
390 format(
"%lu",
static_cast<unsigned long>(itName->second)));
393 i_sph->enableShowName();
394 i_sph->setPose(i_mean);
399 for (
size_t j = i + 1; j < m_individualFrames.size(); j++)
403 m_individualFrames.get(j, j_pdf, j_sf);
406 j_pdf->getMean(j_mean);
408 float SSO_ij = m_A(i, j);
413 mrpt::make_aligned_shared<opengl::CSimpleLine>();
415 i_mean.
x(), i_mean.
y(), i_mean.z(), j_mean.
x(), j_mean.
y(),
418 lin->setColor(SSO_ij, 0, 1 - SSO_ij, SSO_ij * 0.6);
419 lin->setLineWidth(SSO_ij * 10);
425 gl_grid->setPlaneLimits(bbminx, bbmaxx, bbminy, bbmaxy);
426 gl_grid->setGridFrequency(5);
437 in >> m_individualFrames >> m_individualMaps >> m_A >>
438 m_last_partition >> m_last_last_partition_are_new_ones;
442 std::vector<uint8_t> old_modified_nodes;
443 in >> old_modified_nodes;
456 out << m_individualFrames << m_individualMaps << m_A << m_last_partition
457 << m_last_last_partition_are_new_ones;