Main MRPT website > C++ reference for MRPT 1.9.9
CTopLCDetector_GridMatching.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "hmtslam-precomp.h" // Precomp header
11 
14 #include <mrpt/system/filesystem.h>
15 
16 using namespace mrpt::slam;
17 using namespace mrpt::hmtslam;
18 using namespace mrpt::utils;
19 using namespace mrpt::poses;
20 using namespace mrpt::obs;
21 using namespace mrpt::maps;
22 
23 CTopLCDetector_GridMatching::CTopLCDetector_GridMatching(CHMTSLAM* hmtslam)
24  : CTopLCDetectorBase(hmtslam)
25 {
26 }
27 
29 /** This method must compute the topological observation model.
30  * \param out_log_lik The output, a log-likelihood.
31  * \return nullptr, or a PDF of the estimated translation between the two areas
32  * (can be a multi-modal PDF).
33  */
35  const THypothesisID& hypID, const CHMHMapNode::Ptr& currentArea,
36  const CHMHMapNode::Ptr& refArea, double& out_log_lik)
37 {
38  // ------------------------------------------------------------------------------
39  // Compute potential map transformations between the areas "areaID" and
40  // "a->first"
41  // For this, we use the grid-to-grid matching method described in the TRO
42  // paper...
43  // ------------------------------------------------------------------------------
44  out_log_lik = 0; // Nothing to modify, for now.
45 
46  CGridMapAligner gridAligner;
48  const CPose2D initEstimate(
49  0, 0, 0); // It's actually ignored by the grid-matching
50 
51  // Use already loaded options:
54  gridAligner.options = o.matchingOptions;
55 
56  CMultiMetricMap::Ptr hMapCur =
57  currentArea->m_annotations.getAs<CMultiMetricMap>(
58  NODE_ANNOTATION_METRIC_MAPS, hypID, false);
59  CMultiMetricMap::Ptr hMapRef =
60  refArea->m_annotations.getAs<CMultiMetricMap>(
61  NODE_ANNOTATION_METRIC_MAPS, hypID, false);
62 
63  ASSERT_(hMapRef->m_gridMaps.size() >= 1)
64  ASSERT_(hMapCur->m_gridMaps.size() >= 1)
65 
66 #if 0
67  {
68  static int i = 0;
69  CFileOutputStream f(format("debug_%05i.hmtslam",++i));
70  f << *m_hmtslam;
71  }
72 #endif
73 
74  gridAligner.options.dumpToConsole();
75 
76  // Do the map align:
77  CPosePDF::Ptr alignRes = gridAligner.Align(
78  hMapCur.get(), // "ref" as seen from "cur"...The order is critical!!!
79  hMapRef.get(), initEstimate, nullptr, &info);
80 
81 #if 0
82  {
83  hMapCur->m_gridMaps[0]->saveAsBitmapFileWithLandmarks("map1.png", info.landmarks_map1.get());
84  hMapRef->m_gridMaps[0]->saveAsBitmapFileWithLandmarks("map2.png", info.landmarks_map2.get());
85  }
86 #endif
87 
88  // Transform the 2D SOG into a 3D SOG:
89  CPose3DPDF::Ptr res = CPose3DPDF::Ptr(CPose3DPDF::createFrom2D(*alignRes));
90 
91 // --------------------
92 // Debug output:
93 // --------------------
94 #if 1
95  const std::string dbg_dir =
96  m_hmtslam->m_options.LOG_OUTPUT_DIR + "/TBI_TESTS";
97  if (!m_hmtslam->m_options.LOG_OUTPUT_DIR.empty())
98  {
100  static int cnt = 0;
101  ++cnt;
102  const std::string filStat =
103  dbg_dir + format(
104  "/state_%05i_test_%i_%i.hmtslam", cnt,
105  (int)currentArea->getID(), (int)refArea->getID());
106  const std::string filRes =
107  dbg_dir + format(
108  "/state_%05i_test_%i_%i_result.txt", cnt,
109  (int)currentArea->getID(), (int)refArea->getID());
110 
111  m_hmtslam->logFmt(
112  mrpt::utils::LVL_DEBUG, "[TLCD_gridmatch] DEBUG: Saving %s\n",
113  filStat.c_str());
114  CFileGZOutputStream f(filStat);
115  this->m_hmtslam->saveState(f);
116 
117  m_hmtslam->logFmt(
118  mrpt::utils::LVL_DEBUG, "[TLCD_gridmatch] DEBUG: Saving %s\n",
119  filRes.c_str());
120  CFileOutputStream f_res(filRes);
121  f_res.printf(
122  "# SOG modes: %i\n",
123  (int)std::dynamic_pointer_cast<CPosePDFSOG>(alignRes)->size());
124  f_res.printf("ICP goodness: ");
125  f_res.printf_vector("%f ", info.icp_goodness_all_sog_modes);
126  f_res.printf("\n");
127  }
128 #endif
129 
130  return res;
131 }
132 
133 /** Hook method for being warned about the insertion of a new poses into the
134  * maps.
135  * This should be independent of hypothesis IDs.
136  */
138  const TPoseID& poseID, const CSensoryFrame* SF)
139 {
140  MRPT_UNUSED_PARAM(poseID);
141  MRPT_UNUSED_PARAM(SF);
142 }
143 
144 // Initialization
146 // Load parameters from configuration source
148  const mrpt::utils::CConfigFileBase& source, const std::string& section)
149 {
150  matchingOptions.loadFromConfigFile(source, section);
151 }
152 
153 // This method must display clearly all the contents of the structure in
154 // textual form, sending it to a CStream.
156  mrpt::utils::CStream& out) const
157 {
158  out.printf(
159  "\n----------- [CTopLCDetector_GridMatching::TOptions] ------------ "
160  "\n\n");
161  matchingOptions.dumpToTextStream(out);
162 }
bool createDirectory(const std::string &dirName)
Creates a directory.
Definition: filesystem.cpp:158
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
A class for aligning two multi-metric maps (with an occupancy grid maps and a points map...
Classes related to the implementation of Hybrid Metric Topological (HMT) SLAM.
mrpt::poses::CPosePDF::Ptr Align(const mrpt::maps::CMetricMap *m1, const mrpt::maps::CMetricMap *m2, const mrpt::poses::CPose2D &grossEst, float *runningTime=nullptr, void *info=nullptr)
The method for aligning a pair of metric maps, aligning only 2D + orientation.
mrpt::slam::CGridMapAligner::TConfigParams matchingOptions
Options for the grid-to-grid matching algorithm.
CTopLCDetector_GridMatching::TOptions TLC_grid_options
Options passed to this TLC constructor.
Definition: CHMTSLAM.h:501
uint64_t TPoseID
An integer number uniquely identifying each robot pose stored in HMT-SLAM.
The ICP algorithm return information.
An implementation of Hybrid Metric Topological SLAM (HMT-SLAM).
Definition: CHMTSLAM.h:65
void dumpToTextStream(mrpt::utils::CStream &out) const override
This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
This class allows loading and storing values and vectors of different types from a configuration text...
int64_t THypothesisID
An integer number uniquely identifying each of the concurrent hypotheses for the robot topological pa...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
std::shared_ptr< CPosePDF > Ptr
Definition: CPosePDF.h:44
std::string LOG_OUTPUT_DIR
[LOGGING] If it is not an empty string (""), a directory with that name will be created and log files...
Definition: CHMTSLAM.h:442
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
This CStream derived class allow using a file as a write-only, binary stream.
mrpt::poses::CPose3DPDF::Ptr computeTopologicalObservationModel(const THypothesisID &hypID, const CHMHMapNode::Ptr &currentArea, const CHMHMapNode::Ptr &refArea, double &out_log_lik)
This method must compute the topological observation model.
virtual int void printf_vector(const char *fmt, const CONTAINER_TYPE &V, char separator=',')
Prints a vector in the format [A,B,C,...] using CStream::printf, and the fmt string for each vector e...
Definition: CStream.h:370
std::shared_ptr< CPose3DPDF > Ptr
Definition: CPose3DPDF.h:45
This namespace contains representation of robot actions and observations.
std::shared_ptr< CMultiMetricMap > Ptr
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:54
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
mrpt::hmtslam::CHMTSLAM::TOptions m_options
The virtual base class for Topological Loop-closure Detectors; used in HMT-SLAM.
#define NODE_ANNOTATION_METRIC_MAPS
GLsizei const GLchar ** string
Definition: glext.h:4101
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
bool saveState(mrpt::utils::CStream &out) const
Save the state of the whole HMT-SLAM framework to some binary stream (e.g.
mrpt::maps::CLandmarksMap::Ptr landmarks_map1
The landmarks of each map (the indices of these landmarks correspond to those in "correspondences") ...
std::vector< double > icp_goodness_all_sog_modes
The ICP goodness of all potential SOG modes at the stage "sog2", thus before the removing of "bad" IC...
#define CFileGZOutputStream
Saves data to a file and transparently compress the data using the given compression level...
Options for a TLC-detector of type gridmap-matching, used from CHMTSLAM.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
#define ASSERT_(f)
void dumpToConsole() const
Just like dumpToTextStream() but sending the text to the console (std::cout)
mrpt::slam::CGridMapAligner::TConfigParams options
mrpt::maps::CLandmarksMap::Ptr landmarks_map2
std::shared_ptr< CHMHMapNode > Ptr
Definition: CHMHMapNode.h:42
GLsizeiptr size
Definition: glext.h:3923
GLuint res
Definition: glext.h:7268
This class stores any customizable set of metric maps.
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &section) override
This method load the options from a ".ini"-like file or memory-stored string list.
void OnNewPose(const TPoseID &poseID, const mrpt::obs::CSensoryFrame *SF)
Hook method for being warned about the insertion of a new poses into the maps.
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
Definition: CStream.cpp:597



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019