MRPT  2.0.1
CMetricMapBuilder.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "slam-precomp.h" // Precompiled headers
11 
19 #include <mrpt/system/filesystem.h>
20 
21 using namespace mrpt::slam;
22 using namespace mrpt::maps;
23 using namespace mrpt::io;
24 using namespace mrpt::poses;
25 using namespace mrpt::serialization;
26 
28  : mrpt::system::COutputLogger("CMetricMapBuilder"),
29  options(this->m_min_verbosity_level)
30 {
31  MRPT_LOG_DEBUG("CMetricMapBuilder ctor.");
32 }
33 
35 {
36  MRPT_LOG_DEBUG("CMetricMapBuilder dtor.");
37 }
38 
39 /*---------------------------------------------------------------
40  clear
41 Clear all elements of the maps, and reset localization to (0,0,0deg).
42  ---------------------------------------------------------------*/
44 {
45  MRPT_LOG_DEBUG("CMetricMapBuilder::clear() called.");
46  CSimpleMap dummyMap;
47  CPosePDFGaussian dummyPose;
48 
49  // Initialize with an empty map and pose to (0,0,0)
50  initialize(dummyMap, &dummyPose);
51 }
52 
53 /*---------------------------------------------------------------
54  loadCurrentMapFromFile
55  ---------------------------------------------------------------*/
56 void CMetricMapBuilder::loadCurrentMapFromFile(const std::string& fileName)
57 {
58  CSimpleMap map;
59 
60  // New file??
61  if (mrpt::system::fileExists(fileName))
62  {
64  "[CMetricMapBuilder::loadCurrentMapFromFile] Loading current map "
65  "from '"
66  << fileName << "' ..." << std::endl);
67  CFileGZInputStream f(fileName);
68 
69  // Load from file:
70  archiveFrom(f) >> map;
71  }
72  else
73  { // Is a new file, start with an empty map:
75  "[CMetricMapBuilder::loadCurrentMapFromFile] Loading current map "
76  "from '"
77  << fileName << "' ..." << std::endl);
78  map.clear();
79  }
80 
81  // Initialize the map builder with this map
82  initialize(map);
83 }
84 
85 /*---------------------------------------------------------------
86  saveCurrentMapToFile
87  ---------------------------------------------------------------*/
89  const std::string& fileName, bool compressGZ) const
90 {
91  // get current map:
92  CSimpleMap curmap;
93  getCurrentlyBuiltMap(curmap);
94 
96  "[CMetricMapBuilder::saveCurrentMapToFile] Saving current map to '"
97  << fileName << "' ..." << std::endl);
98 
99  // Save to file:
100  if (compressGZ)
101  {
102  CFileGZOutputStream f(fileName);
103  archiveFrom(f) << curmap;
104  }
105  else
106  {
107  CFileOutputStream f(fileName);
108  archiveFrom(f) << curmap;
109  }
110 }
void saveCurrentMapToFile(const std::string &fileName, bool compressGZ=true) const
Save map (mrpt::maps::CSimpleMap) to a ".simplemap" file.
void clear()
Clear all elements of the maps, and reset localization to (0,0,0deg).
#define MRPT_LOG_DEBUG(_STRING)
Use: MRPT_LOG_DEBUG("message");
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
Definition: CSimpleMap.h:32
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:128
mrpt::system::COutputLogger COutputLogger
#define MRPT_LOG_WARN_STREAM(__CONTENTS)
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT&#39;s CStream, std::istream, std::ostream, std::stringstream.
Definition: CArchive.h:592
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
void loadCurrentMapFromFile(const std::string &fileName)
Load map (mrpt::maps::CSimpleMap) from a ".simplemap" file.
This CStream derived class allow using a file as a write-only, binary stream.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
virtual void getCurrentlyBuiltMap(mrpt::maps::CSimpleMap &out_map) const =0
Fills "out_map" with the set of "poses"-"sensory-frames", thus the so far built map.
~CMetricMapBuilder() override
Destructor.
#define MRPT_LOG_INFO_STREAM(__CONTENTS)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
virtual void initialize(const mrpt::maps::CSimpleMap &initialMap=mrpt::maps::CSimpleMap(), const mrpt::poses::CPosePDF *x0=nullptr)=0
Initialize the method, starting with a known location PDF "x0"(if supplied, set to nullptr to left un...
Transparently opens a compressed "gz" file and reads uncompressed data from it.
Saves data to a file and transparently compress the data using the given compression level...
void clear()
Remove all stored pairs.
Definition: CSimpleMap.cpp:55



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020