Main MRPT website > C++ reference for MRPT 1.5.7
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 
21 /** Looks up in the registry of known map types and call the corresponding `<metric_map_class>::MapDefinition()`. */
22 TMetricMapInitializer* TMetricMapInitializer::factory(const std::string &mapClassName)
23 {
25  TMetricMapTypesRegistry & mmr = TMetricMapTypesRegistry::Instance();
26  return mmr.factoryMapDefinition(mapClassName);
27 }
28 
29 TMetricMapInitializer::TMetricMapInitializer(const mrpt::utils::TRuntimeClassId* classID ) :
30  metricMapClassType(classID)
31 {
32 }
33 
34 /** Load all params from a config file/source. For examples and format, read the docs of mrpt::maps::CMultiMetricMap */
36 {
37  // Common:
38  const std::string sctCreat = sectionNamePrefix + std::string("_creationOpts");
39  this->genericMapParams.loadFromConfigFile(source,sctCreat);
40 
41  // Class-specific:
42  this->loadFromConfigFile_map_specific(source,sectionNamePrefix);
43 }
44 
45 /** Dump the options of the metric map in human-readable format */
47 {
48  out.printf("-------------------------TMetricMapInitializer --------------------------\n");
49  out.printf("================ C++ Class: '%s'\n", this->metricMapClassType->className);
51 
52  // Class-specific:
54 }
55 
56 /*---------------------------------------------------------------
57  TSetOfMetricMapInitializers::loadFromConfigFile
58  ---------------------------------------------------------------*/
61  const std::string &sectionName )
62 {
65 
66  // Delete previous contents:
67  clear();
68 
69  TMetricMapTypesRegistry & mmr = TMetricMapTypesRegistry::Instance();
70 
71  const TMetricMapTypesRegistry::TListRegisteredMaps & allMapKinds = mmr.getAllRegistered();
72  for (TMetricMapTypesRegistry::TListRegisteredMaps::const_iterator itMapKind=allMapKinds.begin();itMapKind!=allMapKinds.end();++itMapKind)
73  {
74  // ; Creation of maps:
75  // occupancyGrid_count=<Number of mrpt::maps::COccupancyGridMap2D maps>
76  const std::string sMapName = itMapKind->first;
77 
78  unsigned int n = ini.read_uint64_t(sectionName,sMapName+string("_count"),0);
79  for (unsigned int i=0;i<n;i++)
80  {
81  TMetricMapInitializer *mi = mmr.factoryMapDefinition(sMapName);
82  ASSERT_(mi);
83 
84  // Load from sections formatted like this:
85  // [<sectionName>+"_occupancyGrid_##_creationOpts"]
86  // [<sectionName>+"_occupancyGrid_##_insertOpts"]
87  // [<sectionName>+"_occupancyGrid_##_likelihoodOpts"]
88  // ...
89  // ==> Section prefix:
90  const string sMapSectionsPrefix = mrpt::format("%s_%s_%02u",sectionName.c_str(),sMapName.c_str(),i);
91  mi->loadFromConfigFile(ini,sMapSectionsPrefix);
92 
93  // Add the params to the list:
95  }
96 
97  }// end for each map kind
98 
99  MRPT_END
100 }
101 
102 /*---------------------------------------------------------------
103  TSetOfMetricMapInitializers::dumpToTextStream
104  ---------------------------------------------------------------*/
106 {
107  MRPT_START
108 
109  out.printf("====================================================================\n\n");
110  out.printf(" Set of internal maps for 'CMultiMetricMap' object\n\n");
111  out.printf("====================================================================\n");
112 
113  // Show each map:
114  out.printf("Showing next the %u internal maps:\n\n", (int)size());
115 
116  int i=0;
117  for (const_iterator it=begin();it!=end();++it,i++)
118  {
119  out.printf("------------------------- Internal map %u out of %u --------------------------\n",i+1,(int)size());
120  (*it)->dumpToTextStream(out);
121  } // for "it"
122 
123  MRPT_END
124 }
125 
126 
127 
128 
129 
130 
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &sectionNamePrefix) MRPT_OVERRIDE
Load all params from a config file/source.
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &sectionNamePrefix) MRPT_OVERRIDE
This method load the options from a ".ini"-like file or memory-stored string list.
GLenum GLsizei n
Definition: glext.h:4618
const mrpt::utils::TRuntimeClassIdPtr metricMapClassType
Derived classes set this to CLASS_ID(< class >) where < class > is any CMetricMap derived class...
std::deque< TMetricMapInitializerPtr >::const_iterator const_iterator
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:24
std::shared_ptr< TMetricMapInitializer > TMetricMapInitializerPtr
Smart pointer to TMetricMapInitializer.
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.
void dumpToTextStream(mrpt::utils::CStream &out) const MRPT_OVERRIDE
This method dumps the options of the multi-metric map AND those of every internal map...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
#define MRPT_END
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &sectionName) MRPT_OVERRIDE
Loads the configuration for the set of internal maps from a textual definition in an INI-like file...
void dumpToTextStream(mrpt::utils::CStream &out) const MRPT_OVERRIDE
Dump the options of the metric map in human-readable format.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLsizei const GLchar ** string
Definition: glext.h:3919
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:3908
#define ASSERT_(f)
uint64_t read_uint64_t(const std::string &section, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
void dumpToTextStream(mrpt::utils::CStream &out) const MRPT_OVERRIDE
This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
A structure that holds runtime class type information.
Definition: CObject.h:36
Class factory & registry for map classes.
virtual void dumpToTextStream_map_specific(mrpt::utils::CStream &out) const =0
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
Definition: CStream.cpp:507



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019