Main MRPT website > C++ reference for 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 }
n
GLenum GLsizei n
Definition: glext.h:5074
mrpt::maps::TMapGenericParams::loadFromConfigFile
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.
Definition: metric_map_types.cpp:22
mrpt::maps::TMetricMapInitializer::saveToConfigFile
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.
Definition: TMetricMapInitializer.cpp:51
mrpt::maps::TSetOfMetricMapInitializers::size
size_t size() const
Definition: TMetricMapInitializer.h:105
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
mrpt::maps::TMetricMapInitializer::metricMapClassType
const mrpt::rtti::TRuntimeClassId::Ptr metricMapClassType
Derived classes set this to CLASS_ID(< class >) where < class > is any CMetricMap derived class.
Definition: TMetricMapInitializer.h:74
mrpt::rtti::TRuntimeClassId
A structure that holds runtime class type information.
Definition: CObject.h:30
s
GLdouble s
Definition: glext.h:3676
mrpt::maps::TMetricMapInitializer::dumpToTextStream_map_specific
virtual void dumpToTextStream_map_specific(std::ostream &out) const =0
mrpt::maps::TMapGenericParams::saveToConfigFile
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.
Definition: metric_map_types.cpp:29
mrpt::maps::TSetOfMetricMapInitializers::begin
iterator begin()
Definition: TMetricMapInitializer.h:109
obs-precomp.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::maps::TMetricMapInitializer
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
Definition: TMetricMapInitializer.h:34
mrpt::maps::TMetricMapInitializer::genericMapParams
mrpt::maps::TMapGenericParams genericMapParams
Common params for all maps: These are automatically set in TMetricMapTypesRegistry::factoryMapObjectF...
Definition: TMetricMapInitializer.h:42
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::maps::TMetricMapInitializer::dumpToTextStream
void dumpToTextStream(std::ostream &out) const override
This method should clearly display all the contents of the structure in textual form,...
Definition: TMetricMapInitializer.cpp:59
source
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
CConfigFileBase.h
mrpt::maps::TMetricMapInitializer::Ptr
std::shared_ptr< TMetricMapInitializer > Ptr
Smart pointer to TMetricMapInitializer.
Definition: TMetricMapInitializer.h:38
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::config::CConfigFileBase
This class allows loading and storing values and vectors of different types from a configuration text...
Definition: config/CConfigFileBase.h:44
mrpt::format
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
mrpt::maps::TSetOfMetricMapInitializers::loadFromConfigFile
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.
Definition: TMetricMapInitializer.cpp:69
mrpt::config::CConfigFileBase::read_uint64_t
uint64_t read_uint64_t(const std::string &section, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
Definition: CConfigFileBase.cpp:137
mrpt::maps::TSetOfMetricMapInitializers::saveToConfigFile
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.
Definition: TMetricMapInitializer.cpp:117
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
mrpt::maps::TSetOfMetricMapInitializers::push_back
void push_back(const MAP_DEFINITION &o)
Definition: TMetricMapInitializer.h:99
mrpt::maps::internal::TMetricMapTypesRegistry
Class factory & registry for map classes.
Definition: TMetricMapTypesRegistry.h:31
mrpt::maps::TMetricMapInitializer::loadFromConfigFile_map_specific
virtual void loadFromConfigFile_map_specific(const mrpt::config::CConfigFileBase &source, const std::string &sectionNamePrefix)=0
Load all map-specific params.
string
GLsizei const GLchar ** string
Definition: glext.h:4101
TMetricMapInitializer.h
mrpt::maps
Definition: CBeacon.h:24
CArchive.h
mrpt::maps::TSetOfMetricMapInitializers::dumpToTextStream
void dumpToTextStream(std::ostream &out) const override
This method dumps the options of the multi-metric map AND those of every internal map.
Definition: TMetricMapInitializer.cpp:125
mrpt::maps::TSetOfMetricMapInitializers::end
iterator end()
Definition: TMetricMapInitializer.h:110
mrpt::maps::TMetricMapInitializer::loadFromConfigFile
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &sectionNamePrefix) override
Load all params from a config file/source.
Definition: TMetricMapInitializer.cpp:38
mrpt::config::CLoadableOptions::dumpToTextStream
virtual void dumpToTextStream(std::ostream &out) const
This method should clearly display all the contents of the structure in textual form,...
Definition: CLoadableOptions.cpp:77
mrpt::maps::TSetOfMetricMapInitializers::clear
void clear()
Definition: TMetricMapInitializer.h:113



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST