MRPT  1.9.9
TMetricMapInitializer.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-2018, 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 "obs-precomp.h" // Precomp header
11 
15 
16 using namespace std;
17 using namespace mrpt;
18 using namespace mrpt::maps;
19 
20 /** Looks up in the registry of known map types and call the corresponding
21  * `<metric_map_class>::MapDefinition()`. */
22 TMetricMapInitializer* TMetricMapInitializer::factory(
23  const std::string& mapClassName)
24 {
26  TMetricMapTypesRegistry& mmr = TMetricMapTypesRegistry::Instance();
27  return mmr.factoryMapDefinition(mapClassName);
28 }
29 
30 TMetricMapInitializer::TMetricMapInitializer(
31  const mrpt::rtti::TRuntimeClassId* classID)
32  : metricMapClassType(classID)
33 {
34 }
35 
36 /** Load all params from a config file/source. For examples and format, read the
37  * docs of mrpt::maps::CMultiMetricMap */
40  const std::string& sectionNamePrefix)
41 {
42  // Common:
43  const std::string sctCreat =
44  sectionNamePrefix + std::string("_creationOpts");
45  this->genericMapParams.loadFromConfigFile(source, sctCreat);
46 
47  // Class-specific:
48  this->loadFromConfigFile_map_specific(source, sectionNamePrefix);
49 }
50 
53  const std::string& section) const
54 {
55  auto s = section + std::string("_") + std::string(this->metricMapClassType->className);
56  this->genericMapParams.saveToConfigFile(target, s);
57 }
58 
59 void TMetricMapInitializer::dumpToTextStream(std::ostream& out) const
60 {
61  out << "-----------------TMetricMapInitializer --------------------\n";
62  out << "================ C++ Class: '"
63  << this->metricMapClassType->className << "'\n";
65  // Class-specific:
67 }
68 
70  const mrpt::config::CConfigFileBase& ini, const std::string& sectionName)
71 {
73 
75 
76  // Delete previous contents:
77  clear();
78 
79  TMetricMapTypesRegistry& mmr = TMetricMapTypesRegistry::Instance();
80 
81  const TMetricMapTypesRegistry::TListRegisteredMaps& allMapKinds =
82  mmr.getAllRegistered();
84  itMapKind = allMapKinds.begin();
85  itMapKind != allMapKinds.end(); ++itMapKind)
86  {
87  // ; Creation of maps:
88  // occupancyGrid_count=<Number of mrpt::maps::COccupancyGridMap2D maps>
89  const std::string sMapName = itMapKind->first;
90 
91  unsigned int n =
92  ini.read_uint64_t(sectionName, sMapName + string("_count"), 0);
93  for (unsigned int i = 0; i < n; i++)
94  {
95  TMetricMapInitializer* mi = mmr.factoryMapDefinition(sMapName);
96  ASSERT_(mi);
97 
98  // Load from sections formatted like this:
99  // [<sectionName>+"_occupancyGrid_##_creationOpts"]
100  // [<sectionName>+"_occupancyGrid_##_insertOpts"]
101  // [<sectionName>+"_occupancyGrid_##_likelihoodOpts"]
102  // ...
103  // ==> Section prefix:
104  const string sMapSectionsPrefix = mrpt::format(
105  "%s_%s_%02u", sectionName.c_str(), sMapName.c_str(), i);
106  mi->loadFromConfigFile(ini, sMapSectionsPrefix);
107 
108  // Add the params to the list:
110  }
111 
112  } // end for each map kind
113 
114  MRPT_END
115 }
116 
119  const std::string& section) const
120 {
121  for (auto & mi : *this)
122  mi->saveToConfigFile(target, section);
123 }
124 
126 {
127  MRPT_START
128  out << "===============================================================\n\n"
129  " Set of internal maps for 'CMultiMetricMap' object\n\n"
130  "=================================================================\n"
131  // Show each map:
132  "Showing next the "
133  << this->size() << " internal maps:\n\n";
134 
135  int i = 0;
136  for (auto it = begin(); it != end(); ++it, i++)
137  {
138  out << mrpt::format(
139  "------- Internal map %u out of %u:\n", i + 1, (int)size());
140  (*it)->dumpToTextStream(out);
141  } // for "it"
142  MRPT_END
143 }
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
#define MRPT_START
Definition: exceptions.h:262
virtual void dumpToTextStream_map_specific(std::ostream &out) const =0
GLenum GLsizei n
Definition: glext.h:5074
A structure that holds runtime class type information.
Definition: CObject.h:30
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &sectionNamePrefix) override
This method load the options from a ".ini"-like file or memory-stored string list.
STL namespace.
void saveToConfigFile(mrpt::config::CConfigFileBase &target, const std::string &section) const override
This method saves the options to a ".ini"-like file or memory-stored string list. ...
GLdouble s
Definition: glext.h:3676
mrpt::maps::TMapGenericParams genericMapParams
Common params for all maps: These are automatically set in TMetricMapTypesRegistry::factoryMapObjectF...
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
This class allows loading and storing values and vectors of different types from a configuration text...
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &sectionName) override
Loads the configuration for the set of internal maps from a textual definition in an INI-like file...
uint64_t read_uint64_t(const std::string &section, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
void dumpToTextStream(std::ostream &out) const override
This method dumps the options of the multi-metric map AND those of every internal map...
virtual void dumpToTextStream(std::ostream &out) const
This method should clearly display all the contents of the structure in textual form, sending it to a std::ostream.
GLsizei const GLchar ** string
Definition: glext.h:4101
void push_back(const MAP_DEFINITION &o)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void saveToConfigFile(mrpt::config::CConfigFileBase &target, const std::string &section) const override
This method saves the options to a ".ini"-like file or memory-stored string list. ...
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
const mrpt::rtti::TRuntimeClassId::Ptr metricMapClassType
Derived classes set this to CLASS_ID(< class >) where < class > is any CMetricMap derived class...
#define MRPT_END
Definition: exceptions.h:266
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
Class factory & registry for map classes.
virtual void loadFromConfigFile_map_specific(const mrpt::config::CConfigFileBase &source, const std::string &sectionNamePrefix)=0
Load all map-specific params.
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &sectionNamePrefix) override
Load all params from a config file/source.
const Scalar * const_iterator
Definition: eigen_plugins.h:27
void dumpToTextStream(std::ostream &out) const override
This method should clearly display all the contents of the structure in textual form, sending it to a std::ostream.
void saveToConfigFile(mrpt::config::CConfigFileBase &target, const std::string &section) const override
This method saves the options to a ".ini"-like file or memory-stored string list. ...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020