43 : m_parent(parent), m_log_w_metric_history()
47 m_accumRobotMovementIsValid =
false;
53 CLocalMetricHypothesis::~CLocalMetricHypothesis() { m_poseParticles.clearParticles(); }
61 void CLocalMetricHypothesis::getAs3DScene(
71 mrpt::make_aligned_shared<opengl::CGridPlaneXY>(
72 -100, 100, -100, 100, 0, 5);
73 obj->setColor(0.4, 0.4, 0.4);
82 std::map<TPoseID, CPose3DPDFParticles> lstPoses;
84 getPathParticles(lstPoses);
90 std::lock_guard<std::mutex> lock(m_parent->m_map_cs);
93 n != m_neighbors.end(); ++
n)
99 if (node->m_annotations.getElemental(
102 lstPoses[poseID_origin].getMean(originPose);
105 corner->setPose(originPose);
106 objs->insert(corner);
113 const CPose3D meanCurPose = lstPoses[m_currentRobotPose].getMeanVal();
116 cam->setZoomDistance(85);
117 cam->setAzimuthDegrees(45 +
RAD2DEG(meanCurPose.
yaw()));
118 cam->setElevationDegrees(45);
119 cam->setPointingAt(meanCurPose);
123 map<CHMHMapNode::TNodeID, CPoint3D>
125 map<CHMHMapNode::TNodeID, int> areas_howmany;
127 for (it = lstPoses.begin(); it != lstPoses.end(); it++)
130 mrpt::make_aligned_shared<opengl::CEllipsoid>();
132 if (m_nodeIDmemberships.find(it->first)->second ==
133 m_nodeIDmemberships.find(m_currentRobotPose)->second)
134 ellip->setColor(0, 0, 1);
136 ellip->setColor(1, 0, 0);
145 pdf.
mean.z() + 0.005);
153 pdf.
cov(2, 2) < 1e-4f)
156 ellip->setCovMatrix(C);
158 ellip->enableDrawSolid3D(
false);
161 ellip->setName(
format(
"P%u", (
unsigned int)it->first));
162 ellip->enableShowName();
170 0, 0, 0, 0.20f, 0, 0, 0.25f, 0.005f, 0.02f);
171 obj->setColor(1, 0, 0);
177 if (it->first == m_currentRobotPose)
181 robot->setPose(pdf.
mean);
190 m_nodeIDmemberships.find(it->first);
191 ASSERT_(itAreaId != m_nodeIDmemberships.end());
193 areas_howmany[areaId]++;
194 areas_mean[areaId].x_incr(pdf.
mean.
x());
195 areas_mean[areaId].y_incr(pdf.
mean.
y());
196 areas_mean[areaId].z_incr(pdf.
mean.z());
203 ASSERT_(areas_howmany.size() == areas_mean.size());
204 for (itMeans = areas_mean.begin(), itHowMany = areas_howmany.begin();
205 itMeans != areas_mean.end(); itMeans++, itHowMany++)
207 ASSERT_(itHowMany->second > 0);
209 float f = 1.0f / itHowMany->second;
210 itMeans->second *= f;
216 for (it = lstPoses.begin(); it != lstPoses.end(); it++)
218 if (it->first != m_currentRobotPose)
221 areas_mean[m_nodeIDmemberships.find(it->first)->second]);
222 areaPnt.z_incr(m_parent->m_options.VIEW3D_AREA_SPHERES_HEIGHT);
229 mrpt::make_aligned_shared<opengl::CSimpleLine>();
230 line->setColor(0.8, 0.8, 0.8, 0.3);
231 line->setLineWidth(2);
235 areaPnt.y(), areaPnt.z());
288 std::lock_guard<std::mutex> lock(
291 for (itMeans = areas_mean.begin(); itMeans != areas_mean.end();
295 mrpt::make_aligned_shared<opengl::CSphere>();
297 if (itMeans->first ==
298 m_nodeIDmemberships.find(m_currentRobotPose)->second)
300 sphere->setColor(0.1, 0.1, 0.7);
304 sphere->setColor(0.7, 0, 0);
308 itMeans->second.x(), itMeans->second.y(),
309 itMeans->second.z() +
310 m_parent->m_options.VIEW3D_AREA_SPHERES_HEIGHT);
312 sphere->setRadius(m_parent->m_options.VIEW3D_AREA_SPHERES_RADIUS);
315 objs->insert(sphere);
319 txt->setColor(1, 1, 1);
322 m_parent->m_map.getNodeByID(itMeans->first);
326 itMeans->second.x(), itMeans->second.y(),
327 itMeans->second.z() +
328 m_parent->m_options.VIEW3D_AREA_SPHERES_HEIGHT);
331 txt->setString(
format(
"%li", (
long int)node->getID()));
341 std::lock_guard<std::mutex> lock(m_parent->m_map_cs);
343 for (itMeans = areas_mean.begin(); itMeans != areas_mean.end();
348 m_parent->m_map.getNodeByID(srcAreaID);
352 srcArea->getArcs(lstArcs);
354 a != lstArcs.end(); ++
a)
357 if ((*a)->getNodeFrom() == srcAreaID)
360 trgAreaPoseIt = areas_mean.find((*a)->getNodeTo());
361 if (trgAreaPoseIt != areas_mean.end())
365 mrpt::make_aligned_shared<opengl::CSimpleLine>();
366 line->setColor(0.8, 0.8, 0);
367 line->setLineWidth(3);
370 areas_mean[srcAreaID].
x(),
371 areas_mean[srcAreaID].
y(),
372 areas_mean[srcAreaID].
z() +
373 m_parent->m_options.VIEW3D_AREA_SPHERES_HEIGHT,
374 trgAreaPoseIt->second.x(),
375 trgAreaPoseIt->second.y(),
376 trgAreaPoseIt->second.z() +
377 m_parent->m_options.VIEW3D_AREA_SPHERES_HEIGHT);
400 std::map<TPoseID, CPose3DPDFParticles> parts;
401 getPathParticles(parts);
405 for (it = parts.begin(); it != parts.end(); it++)
406 it->second.getMean(outList[it->first]);
414 void CLocalMetricHypothesis::getPathParticles(
415 std::map<TPoseID, CPose3DPDFParticles>& outList)
const 421 if (m_poseParticles.m_particles.empty())
return;
425 m_poseParticles.m_particles.begin()->d->robotPoses.begin();
426 itPoseID != m_poseParticles.m_particles.begin()->d->robotPoses.end(); ++itPoseID)
431 for (it = m_poseParticles.m_particles.begin(), itP = auxPDF.m_particles.begin();
432 it != m_poseParticles.m_particles.end(); it++, itP++)
434 itP->log_w = it->log_w;
435 *itP->d = it->d->robotPoses.find(itPoseID->first)->second;
439 outList[itPoseID->first] = auxPDF;
448 void CLocalMetricHypothesis::getPoseParticles(
453 ASSERT_(!m_poseParticles.m_particles.empty());
458 for (it = m_poseParticles.m_particles.begin(), itP = outPDF.
m_particles.begin();
459 it != m_poseParticles.m_particles.end(); it++, itP++)
461 itP->log_w = it->log_w;
463 it->d->robotPoses.find(poseID);
464 ASSERT_(itPose != it->d->robotPoses.end());
465 *itP->d = itPose->second;
474 void CLocalMetricHypothesis::clearRobotPoses()
476 m_poseParticles.clearParticles();
477 m_poseParticles.m_particles.resize(m_parent->m_options.pf_options.sampleSize);
479 it != m_poseParticles.m_particles.end(); ++it)
485 &m_parent->m_options.defaultMapsInitializers));
488 it->d->robotPoses.clear();
495 const CPose3D* CLocalMetricHypothesis::getCurrentPose(
496 const size_t& particleIdx)
const 498 if (particleIdx >= m_poseParticles.m_particles.size())
502 m_poseParticles.m_particles[particleIdx].d->robotPoses.find(m_currentRobotPose);
503 ASSERT_(it != m_poseParticles.m_particles[particleIdx].d->robotPoses.end());
510 CPose3D* CLocalMetricHypothesis::getCurrentPose(
const size_t& particleIdx)
512 if (particleIdx >= m_poseParticles.m_particles.size())
516 m_poseParticles.m_particles[particleIdx].d->robotPoses.find(m_currentRobotPose);
517 ASSERT_(it != m_poseParticles.m_particles[particleIdx].d->robotPoses.end());
524 void CLocalMetricHypothesis::getRelativePose(
535 for (it = m_poseParticles.m_particles.begin(), itP = outPDF.
m_particles.begin();
536 it != m_poseParticles.m_particles.end(); it++, itP++)
538 itP->log_w = it->log_w;
541 it->d->robotPoses.find(reference);
543 it->d->robotPoses.find(pose);
545 ASSERT_(srcPose != it->d->robotPoses.end())
546 ASSERT_(trgPose != it->d->robotPoses.end())
548 *itP->d = trgPose->second - srcPose->second;
557 void CLocalMetricHypothesis::changeCoordinateOrigin(
const TPoseID& newOrigin)
564 for (it = m_poseParticles.m_particles.begin(), itOrgPDF = originPDF.m_particles.begin();
565 it != m_poseParticles.m_particles.end(); it++, itOrgPDF++)
568 it->d->robotPoses.find(newOrigin);
569 ASSERT_(refPoseIt != it->d->robotPoses.end())
570 const CPose3D& refPose = refPoseIt->second;
573 *itOrgPDF->d = refPose;
574 itOrgPDF->log_w = it->log_w;
580 if (itP != refPoseIt) itP->second = itP->second - refPose;
583 refPoseIt->second.setFromValues(0, 0, 0);
591 std::lock_guard<std::mutex> locker(m_robotPosesGraph.lock);
593 CSimpleMap* SFseq = m_robotPosesGraph.partitioner.getSequenceOfFrames();
595 m_robotPosesGraph.idx2pose.begin();
596 it != m_robotPosesGraph.idx2pose.end(); ++it)
600 SFseq->
get(it->first, pdf, sf);
606 getPoseParticles(it->second, *pdfParts);
614 void CLocalMetricHypothesis::rebuildMetricMaps()
617 it != m_poseParticles.m_particles.end(); ++it)
619 it->d->metricMaps.clear();
630 m_SFs.find(itP->first);
632 SFit->second.insertObservationsInto(
633 &it->d->metricMaps, &itP->second);
651 void CLocalMetricHypothesis::removeAreaFromLMH(
659 if (itNeig != m_neighbors.end()) m_neighbors.erase(itNeig);
665 m_nodeIDmemberships.begin();
666 it != m_nodeIDmemberships.end(); ++it)
667 if (it->second == areaID) lstPoseIDs.
insert(it->first);
675 updateAreaFromLMH(areaID,
true);
681 it != lstPoseIDs.end(); ++it)
683 p != m_poseParticles.m_particles.end(); ++
p)
684 p->d->robotPoses.erase(
p->d->robotPoses.find(*it));
692 ASSERT_(m_log_w_metric_history.size() == m_poseParticles.m_particles.size());
694 for (ws_it = m_log_w_metric_history.begin(),
p = m_poseParticles.m_particles.begin();
695 p != m_poseParticles.m_particles.end(); ++
p, ++ws_it)
698 it != lstPoseIDs.end(); ++it)
701 if (itW != ws_it->end())
705 p->log_w -= itW->second;
717 std::lock_guard<std::mutex> locker(m_robotPosesGraph.lock);
720 indexesToRemove.reserve(lstPoseIDs.size());
723 m_robotPosesGraph.idx2pose.begin();
724 it != m_robotPosesGraph.idx2pose.end();)
726 if (lstPoseIDs.
find(it->second) != lstPoseIDs.end())
728 indexesToRemove.push_back(it->first);
734 m_robotPosesGraph.idx2pose.erase(it);
741 m_robotPosesGraph.partitioner.removeSetOfNodes(indexesToRemove);
746 map<uint32_t, TPoseID> newList;
748 i = m_robotPosesGraph.idx2pose.begin();
749 i != m_robotPosesGraph.idx2pose.end(); ++i, idx++)
750 newList[idx] = i->second;
751 m_robotPosesGraph.idx2pose = newList;
763 it != lstPoseIDs.end(); ++it)
764 m_nodeIDmemberships.erase(m_nodeIDmemberships.find(*it));
766 double out_max_log_w;
767 m_poseParticles.normalizeWeights(&out_max_log_w);
775 unsigned int CLocalMetricHypothesis::TRobotPosesPartitioning::pose2idx(
779 it != idx2pose.end(); ++it)
780 if (it->second ==
id)
return it->first;
790 void CLocalMetricHypothesis::updateAreaFromLMH(
797 m_nodeIDmemberships.begin();
798 it != m_nodeIDmemberships.end(); ++it)
799 if (it->second == areaID) lstPoseIDs.
insert(it->first);
805 std::lock_guard<std::mutex>(m_parent->m_map_cs);
806 node = m_parent->m_map.getNodeByID(areaID);
808 ASSERT_(node->m_hypotheses.has(m_ID));
813 node->m_annotations.getElemental(
826 posesGraph = mrpt::make_aligned_shared<CRobotPosesGraph>();
827 node->m_annotations.setMemoryReference(
839 bool pdfOrigin_ok =
false;
841 it != lstPoseIDs.end(); ++it)
843 TPoseInfo& poseInfo = (*posesGraph)[*it];
844 getPoseParticles(*it, poseInfo.
pdf);
847 if (*it == poseID_origin)
853 if (*it != m_currentRobotPose)
868 poseInfo.
sf = itSF->second;
876 pdfOrigin.
inverse(pdfOriginInv);
878 it != posesGraph->end(); ++it)
881 ASSERT_(it->second.pdf.size() == pdfOriginInv.
size());
882 for (pdfIt = it->second.pdf.m_particles.begin(),
884 orgIt != pdfOriginInv.
m_particles.end(); orgIt++, pdfIt++)
885 *pdfIt->d = *orgIt->d + *pdfIt->d;
894 posesGraph->insertIntoMetricMap(*metricMap);
903 st <<
"LIST OF POSES IN LMH";
904 st <<
"====================";
909 it != m_neighbors.end(); ++it)
920 m_nodeIDmemberships.find(it->first);
923 " ID: %i \t AREA: %i \t %.03f,%.03f,%.03fdeg", (
int)it->first,
924 (
int)area->second, it->second.x(), it->second.y(),
933 void CLocalMetricHypothesis::readFromStream(
940 in >> m_ID >> m_currentRobotPose >> m_neighbors >>
941 m_nodeIDmemberships >> m_SFs >> m_posesPendingAddPartitioner >>
942 m_areasPendingTBI >> m_log_w >> m_log_w_metric_history >>
943 m_robotPosesGraph.partitioner >> m_robotPosesGraph.idx2pose;
946 m_poseParticles.readParticlesFromStream(
in);
959 void CLocalMetricHypothesis::writeToStream(
966 out << m_ID << m_currentRobotPose << m_neighbors << m_nodeIDmemberships
967 << m_SFs << m_posesPendingAddPartitioner << m_areasPendingTBI
968 << m_log_w << m_log_w_metric_history
969 << m_robotPosesGraph.partitioner << m_robotPosesGraph.idx2pose;
972 m_poseParticles.writeParticlesToStream(out);
985 in >> metricMaps >> robotPoses;
998 void CLSLAMParticleData::writeToStream(
1005 out << metricMaps << robotPoses;
void clear()
Erase all the contents of the map.
std::shared_ptr< CRobotPosesGraph > Ptr
double x() const
Common members of all points & poses classes.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
CPose3D mean
The mean value.
std::vector< uint32_t > vector_uint
void copyFrom(const CPose3DPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Classes related to the implementation of Hybrid Metric Topological (HMT) SLAM.
std::shared_ptr< CCamera > Ptr
void moveFrom(CSensoryFrame &sf)
Copies all the observation from another object, then erase them from the origin object (this method i...
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
#define MRPT_CHECK_NORMAL_NUMBER(val)
#define THROW_EXCEPTION(msg)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
mrpt::poses::CPose3DPDFParticles pdf
The robot pose PDF.
double pitch() const
Get the PITCH angle (in radians)
double yaw() const
Get the YAW angle (in radians)
std::shared_ptr< CPose3DPDFParticles > Ptr
const Scalar * const_iterator
uint64_t TPoseID
An integer number uniquely identifying each robot pose stored in HMT-SLAM.
GLsizei GLsizei GLuint * obj
An implementation of Hybrid Metric Topological SLAM (HMT-SLAM).
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
A class for storing a list of text lines.
CParticleList m_particles
The array of particles.
This base provides a set of functions for maths stuff.
mrpt::aligned_containers< TPoseID, mrpt::poses::CPose3D >::map_t TMapPoseID2Pose3D
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
static Ptr Create(Args &&... args)
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
void clear()
Clear the whole list.
std::shared_ptr< CPose3DPDF > Ptr
std::shared_ptr< CSetOfObjects > Ptr
This namespace contains representation of robot actions and observations.
std::shared_ptr< CMultiMetricMap > Ptr
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
std::shared_ptr< CSensoryFrame > Ptr
size_t size() const
Get the m_particles count (equivalent to "particlesCount")
Auxiliary class used in mrpt::slam::CLocalMetricHypothesis for HMT-SLAM; this class stores a set of r...
void get(size_t index, mrpt::poses::CPose3DPDF::Ptr &out_posePDF, mrpt::obs::CSensoryFrame::Ptr &out_SF) const
Access to the i'th pair, first one is index '0'.
This class is used in HMT-SLAM to represent each of the Local Metric Hypotheses (LMHs).
#define NODE_ANNOTATION_METRIC_MAPS
A class used to store a 3D point.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
double roll() const
Get the ROLL angle (in radians)
CSetOfObjects::Ptr RobotPioneer()
Returns a representation of a Pioneer II mobile base.
Auxiliary class used in mrpt::slam::CLocalMetricHypothesis for HMT-SLAM; this class keeps the data re...
std::shared_ptr< CSerializable > Ptr
void copyFrom(const CPose3DPDF &o) override
Copy operator, translating if necesary (for example, between m_particles and gaussian representations...
mrpt::math::CMatrixDouble66 cov
The 6x6 covariance matrix.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void resetDeterministic(const CPose3D &location, size_t particlesCount=0)
Reset the PDF to a single point: All m_particles will be set exactly to the supplied pose...
CSetOfObjects::Ptr CornerXYZ(float scale=1.0)
Returns three arrows representing a X,Y,Z 3D corner.
mrpt::obs::CSensoryFrame sf
The observations.
The namespace for 3D scene representation and rendering.
#define NODE_ANNOTATION_REF_POSEID
Declares a class that represents a Probability Density function (PDF) of a 3D pose ...
Information kept for each robot pose used in CRobotPosesGraph.
std::shared_ptr< CHMHMapNode > Ptr
void inverse(CPose3DPDF &o) const override
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
std::shared_ptr< CText > Ptr
This class stores any customizable set of metric maps.
#define NODE_ANNOTATION_POSES_GRAPH
std::list< T >::iterator find(const T &i)
std::shared_ptr< CSimpleLine > Ptr
std::shared_ptr< CSphere > Ptr
GLubyte GLubyte GLubyte a
A class for storing a sequence of arcs (a path).
std::shared_ptr< CGridPlaneXY > Ptr
Declares a class that represents a Probability Density function (PDF) of a 3D pose.
mrpt::utils::TNodeID TNodeID
The type of the IDs of nodes.
std::shared_ptr< CEllipsoid > Ptr
std::shared_ptr< CArrow > Ptr