MRPT  1.9.9
TMetricMapInitializer.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-2019, 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 "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 
52  mrpt::config::CConfigFileBase& target, const std::string& section) const
53 {
54  auto s = section + std::string("_") +
55  std::string(this->metricMapClassType->className);
56  this->genericMapParams.saveToConfigFile(target, s);
57 }
58 
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 auto& allMapKinds = mmr.getAllRegistered();
82  for (const auto& allMapKind : allMapKinds)
83  {
84  // ; Creation of maps:
85  // occupancyGrid_count=<Number of mrpt::maps::COccupancyGridMap2D maps>
86  const std::string sMapName = allMapKind.first;
87 
88  unsigned int n =
89  ini.read_uint64_t(sectionName, sMapName + string("_count"), 0);
90  for (unsigned int i = 0; i < n; i++)
91  {
92  TMetricMapInitializer* mi = mmr.factoryMapDefinition(sMapName);
93  ASSERT_(mi);
94 
95  // Load from sections formatted like this:
96  // [<sectionName>+"_occupancyGrid_##_creationOpts"]
97  // [<sectionName>+"_occupancyGrid_##_insertOpts"]
98  // [<sectionName>+"_occupancyGrid_##_likelihoodOpts"]
99  // ...
100  // ==> Section prefix:
101  const string sMapSectionsPrefix = mrpt::format(
102  "%s_%s_%02u", sectionName.c_str(), sMapName.c_str(), i);
103  mi->loadFromConfigFile(ini, sMapSectionsPrefix);
104 
105  // Add the params to the list:
107  }
108 
109  } // end for each map kind
110 
111  MRPT_END
112 }
113 
115  mrpt::config::CConfigFileBase& target, const std::string& section) const
116 {
117  for (auto& mi : *this) mi->saveToConfigFile(target, section);
118 }
119 
121 {
122  MRPT_START
123  out << "===============================================================\n\n"
124  " Set of internal maps for 'CMultiMetricMap' object\n\n"
125  "=================================================================\n"
126  "Showing next the "
127  << this->size() << " internal maps:\n\n";
128 
129  int i = 0;
130  for (auto it = begin(); it != end(); ++it, i++)
131  {
132  out << mrpt::format(
133  "------- Internal map %u out of %u:\n", i + 1, (int)size());
134  (*it)->dumpToTextStream(out);
135  } // for "it"
136  MRPT_END
137 }
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
#define MRPT_START
Definition: exceptions.h:241
virtual void dumpToTextStream_map_specific(std::ostream &out) const =0
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
GLenum GLsizei n
Definition: glext.h:5136
A structure that holds runtime class type information.
Definition: CObject.h:31
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:3682
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:120
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:4116
void push_back(const MAP_DEFINITION &o)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::vision::TStereoCalibResults out
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. ...
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:245
GLsizei GLsizei GLchar * source
Definition: glext.h:4097
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.
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: dad381fd7 Sun Oct 20 13:36:46 2019 +0200 at dom oct 20 13:40:10 CEST 2019