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-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 "obs-precomp.h" // Precomp header
11 
14 #include <mrpt/utils/CStream.h>
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::utils::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 
51 /** Dump the options of the metric map in human-readable format */
53 {
54  out.printf(
55  "-------------------------TMetricMapInitializer "
56  "--------------------------\n");
57  out.printf(
58  "================ C++ Class: '%s'\n",
59  this->metricMapClassType->className);
61 
62  // Class-specific:
64 }
65 
66 /*---------------------------------------------------------------
67  TSetOfMetricMapInitializers::loadFromConfigFile
68  ---------------------------------------------------------------*/
70  const mrpt::utils::CConfigFileBase& ini, const std::string& sectionName)
71 {
74 
75  // Delete previous contents:
76  clear();
77 
78  TMetricMapTypesRegistry& mmr = TMetricMapTypesRegistry::Instance();
79 
80  const TMetricMapTypesRegistry::TListRegisteredMaps& allMapKinds =
81  mmr.getAllRegistered();
83  itMapKind = allMapKinds.begin();
84  itMapKind != allMapKinds.end(); ++itMapKind)
85  {
86  // ; Creation of maps:
87  // occupancyGrid_count=<Number of mrpt::maps::COccupancyGridMap2D maps>
88  const std::string sMapName = itMapKind->first;
89 
90  unsigned int n =
91  ini.read_uint64_t(sectionName, sMapName + string("_count"), 0);
92  for (unsigned int i = 0; i < n; i++)
93  {
94  TMetricMapInitializer* mi = mmr.factoryMapDefinition(sMapName);
95  ASSERT_(mi);
96 
97  // Load from sections formatted like this:
98  // [<sectionName>+"_occupancyGrid_##_creationOpts"]
99  // [<sectionName>+"_occupancyGrid_##_insertOpts"]
100  // [<sectionName>+"_occupancyGrid_##_likelihoodOpts"]
101  // ...
102  // ==> Section prefix:
103  const string sMapSectionsPrefix = mrpt::format(
104  "%s_%s_%02u", sectionName.c_str(), sMapName.c_str(), i);
105  mi->loadFromConfigFile(ini, sMapSectionsPrefix);
106 
107  // Add the params to the list:
109  }
110 
111  } // end for each map kind
112 
113  MRPT_END
114 }
115 
116 /*---------------------------------------------------------------
117  TSetOfMetricMapInitializers::dumpToTextStream
118  ---------------------------------------------------------------*/
120  mrpt::utils::CStream& out) const
121 {
122  MRPT_START
123 
124  out.printf(
125  "===================================================================="
126  "\n\n");
127  out.printf(" Set of internal maps for 'CMultiMetricMap' object\n\n");
128  out.printf(
129  "===================================================================="
130  "\n");
131 
132  // Show each map:
133  out.printf("Showing next the %u internal maps:\n\n", (int)size());
134 
135  int i = 0;
136  for (const_iterator it = begin(); it != end(); ++it, i++)
137  {
138  out.printf(
139  "------------------------- Internal map %u out of %u "
140  "--------------------------\n",
141  i + 1, (int)size());
142  (*it)->dumpToTextStream(out);
143  } // for "it"
144 
145  MRPT_END
146 }
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
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.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLenum GLsizei n
Definition: glext.h:5074
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:27
mrpt::maps::TMapGenericParams genericMapParams
Common params for all maps: These are automatically set in TMetricMapTypesRegistry::factoryMapObjectF...
This class allows loading and storing values and vectors of different types from a configuration text...
virtual void loadFromConfigFile_map_specific(const mrpt::utils::CConfigFileBase &source, const std::string &sectionNamePrefix)=0
Load all map-specific params.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
#define MRPT_END
void dumpToTextStream(mrpt::utils::CStream &out) const override
This method dumps the options of the multi-metric map AND those of every internal map...
const mrpt::utils::TRuntimeClassId::Ptr metricMapClassType
Derived classes set this to CLASS_ID(< class >) where < class > is any CMetricMap derived class...
GLsizei const GLchar ** string
Definition: glext.h:4101
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &sectionNamePrefix) override
Load all params from a config file/source.
void loadFromConfigFile(const mrpt::utils::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...
void push_back(const MAP_DEFINITION &o)
#define MRPT_START
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
#define ASSERT_(f)
void dumpToTextStream(mrpt::utils::CStream &out) const override
Dump the options of the metric map in human-readable format.
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &sectionNamePrefix) override
This method load the options from a ".ini"-like file or memory-stored string list.
uint64_t read_uint64_t(const std::string &section, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
A structure that holds runtime class type information.
Definition: CObject.h:31
Class factory & registry for map classes.
std::shared_ptr< TMetricMapInitializer > Ptr
Smart pointer to TMetricMapInitializer.
virtual void dumpToTextStream_map_specific(mrpt::utils::CStream &out) const =0
std::deque< TMetricMapInitializer::Ptr >::const_iterator const_iterator
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