Main MRPT website > C++ reference for MRPT 1.9.9
CHeightGridMap2D_MRF.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 "maps-precomp.h" // Precomp header
12 #include <mrpt/poses/CPose2D.h>
13 #include <mrpt/poses/CPose3D.h>
14 
15 using namespace mrpt;
16 using namespace mrpt::maps;
17 using namespace mrpt::obs;
18 using namespace mrpt::utils;
19 using namespace mrpt::poses;
20 using namespace std;
21 using namespace mrpt::math;
22 
23 // =========== Begin of Map definition ============
25  "CHeightGridMap2D_MRF,dem_mrf", mrpt::maps::CHeightGridMap2D_MRF)
26 
28  : run_map_estimation_at_ctor(true),
29  min_x(-2),
30  max_x(2),
31  min_y(-2),
32  max_y(2),
33  resolution(0.10f),
34  mapType(mrGMRF_SD)
35 {
36 }
37 
40  const std::string& sectionNamePrefix)
41 {
42  // [<sectionNamePrefix>+"_creationOpts"]
43  const std::string sSectCreation =
44  sectionNamePrefix + string("_creationOpts");
46  run_map_estimation_at_ctor, bool, source, sSectCreation);
47  MRPT_LOAD_CONFIG_VAR(min_x, double, source, sSectCreation);
48  MRPT_LOAD_CONFIG_VAR(max_x, double, source, sSectCreation);
49  MRPT_LOAD_CONFIG_VAR(min_y, double, source, sSectCreation);
50  MRPT_LOAD_CONFIG_VAR(max_y, double, source, sSectCreation);
51  MRPT_LOAD_CONFIG_VAR(resolution, double, source, sSectCreation);
53  sSectCreation, "mapType", mapType);
54 
55  insertionOpts.loadFromConfigFile(
56  source, sectionNamePrefix + string("_insertOpts"));
57 }
58 
60  mrpt::utils::CStream& out) const
61 {
62  out.printf(
63  "MAP TYPE = %s\n",
65  CHeightGridMap2D_MRF::TMapRepresentation>::value2name(mapType)
66  .c_str());
67  LOADABLEOPTS_DUMP_VAR(run_map_estimation_at_ctor, bool);
68  LOADABLEOPTS_DUMP_VAR(min_x, double);
69  LOADABLEOPTS_DUMP_VAR(max_x, double);
70  LOADABLEOPTS_DUMP_VAR(min_y, double);
71  LOADABLEOPTS_DUMP_VAR(max_y, double);
72  LOADABLEOPTS_DUMP_VAR(resolution, double);
73 
74  this->insertionOpts.dumpToTextStream(out);
75 }
76 
79 {
81  *dynamic_cast<const CHeightGridMap2D_MRF::TMapDefinition*>(&_def);
83  def.mapType, def.min_x, def.max_x, def.min_y, def.max_y, def.resolution,
85  obj->insertionOptions = def.insertionOpts;
86  return obj;
87 }
88 // =========== End of Map definition Block =========
89 
91 
92 // Constructor
94  TMapRepresentation mapType, double x_min, double x_max, double y_min,
95  double y_max, double resolution, bool run_first_map_estimation_now)
96  : CRandomFieldGridMap2D(mapType, x_min, x_max, y_min, y_max, resolution),
97  insertionOptions()
98 {
99  m_rfgm_run_update_upon_clear = run_first_map_estimation_now;
100  // Set the grid to initial values (and adjusts the KF covariance matrix!)
101  // Also, calling clear() is mandatory to end initialization of our base
102  // class (read note in CRandomFieldGridMap2D::CRandomFieldGridMap2D)
104 }
105 
107  const double x, const double y, const double z,
109 {
110  const TRandomFieldCell* cell = cellByPos(x, y);
111  if (!cell) return false;
112  this->insertIndividualReading(
113  z, mrpt::math::TPoint2D(x, y), params.update_map_after_insertion,
114  true /*time invariant*/, params.pt_z_std);
115  return true;
116 }
117 double CHeightGridMap2D_MRF::dem_get_resolution() const { return m_resolution; }
118 size_t CHeightGridMap2D_MRF::dem_get_size_x() const { return m_size_x; }
119 size_t CHeightGridMap2D_MRF::dem_get_size_y() const { return m_size_y; }
121  const size_t cx, const size_t cy, double& z_out) const
122 {
123  const TRandomFieldCell* cell = cellByIndex(cx, cy);
124  if (cell && cell->kf_mean)
125  {
126  z_out = cell->kf_mean;
127  return true;
128  }
129  else
130  return false;
131 }
133  const double x, const double y, double& z_out) const
134 {
135  const TRandomFieldCell* cell = cellByPos(x, y);
136  if (cell && cell->kf_mean)
137  {
138  z_out = cell->kf_mean;
139  return true;
140  }
141  else
142  return false;
143 }
144 void CHeightGridMap2D_MRF::dem_update_map() { this->updateMapEstimation(); }
146 {
147  // Just do the generic clear:
149  // Anything else special for this derived class?
150 }
151 
153  const CObservation* obs, const CPose3D* robotPose)
154 {
155  return dem_internal_insertObservation(obs, robotPose);
156 }
157 
158 /*---------------------------------------------------------------
159  computeObservationLikelihood
160  ---------------------------------------------------------------*/
162  const CObservation* obs, const CPose3D& takenFrom)
163 {
164  MRPT_UNUSED_PARAM(obs);
165  MRPT_UNUSED_PARAM(takenFrom);
166  THROW_EXCEPTION("Not implemented yet!");
167 }
168 
169 /*---------------------------------------------------------------
170  Implements the writing to a CStream capability of CSerializable objects
171  ---------------------------------------------------------------*/
173  mrpt::utils::CStream& out, int* version) const
174 {
175  if (version)
176  *version = 0;
177  else
178  {
179  dyngridcommon_writeToStream(out);
180 
181  // To assure compatibility: The size of each cell:
182  uint32_t n = static_cast<uint32_t>(sizeof(TRandomFieldCell));
183  out << n;
184 
185  // Save the map contents:
186  n = static_cast<uint32_t>(m_map.size());
187  out << n;
188 
189 // Save the "m_map": This requires special handling for big endian systems:
190 #if MRPT_IS_BIG_ENDIAN
191  for (uint32_t i = 0; i < n; i++)
192  {
193  out << m_map[i].kf_mean << m_map[i].dm_mean
194  << m_map[i].dmv_var_mean;
195  }
196 #else
197  // Little endian: just write all at once:
198  out.WriteBuffer(&m_map[0], sizeof(m_map[0]) * m_map.size());
199 #endif
200 
201  // Save the insertion options:
202  out << uint8_t(m_mapType) << m_cov << m_stackedCov;
203 
204  out << insertionOptions.sigma << insertionOptions.cutoffRadius
205  << insertionOptions.R_min << insertionOptions.R_max
206  << insertionOptions.KF_covSigma
207  << insertionOptions.KF_initialCellStd
208  << insertionOptions.KF_observationModelNoise
209  << insertionOptions.KF_defaultCellMeanValue
210  << insertionOptions.KF_W_size;
211 
212  out << m_average_normreadings_mean << m_average_normreadings_var
213  << uint64_t(m_average_normreadings_count);
214 
215  out << genericMapParams;
216  }
217 }
218 
219 /*---------------------------------------------------------------
220  Implements the reading from a CStream capability of CSerializable objects
221  ---------------------------------------------------------------*/
223 {
224  switch (version)
225  {
226  case 0:
227  {
228  dyngridcommon_readFromStream(in);
229 
230  // To assure compatibility: The size of each cell:
231  uint32_t n;
232  in >> n;
233 
234  ASSERT_EQUAL_(n, static_cast<uint32_t>(sizeof(TRandomFieldCell)));
235  // Load the map contents:
236  in >> n;
237  m_map.resize(n);
238 
239 // Read the note in writeToStream()
240 #if MRPT_IS_BIG_ENDIAN
241  for (uint32_t i = 0; i < n; i++)
242  in >> m_map[i].kf_mean >> m_map[i].dm_mean >>
243  m_map[i].dmv_var_mean;
244 #else
245  // Little endian: just read all at once:
246  in.ReadBuffer(&m_map[0], sizeof(m_map[0]) * m_map.size());
247 #endif
248 
249  {
250  uint8_t i;
251  in >> i;
252  m_mapType = TMapRepresentation(i);
253 
254  in >> m_cov >> m_stackedCov;
255 
256  in >> insertionOptions.sigma >> insertionOptions.cutoffRadius >>
257  insertionOptions.R_min >> insertionOptions.R_max >>
258  insertionOptions.KF_covSigma >>
259  insertionOptions.KF_initialCellStd >>
260  insertionOptions.KF_observationModelNoise >>
261  insertionOptions.KF_defaultCellMeanValue >>
262  insertionOptions.KF_W_size;
263  }
264 
265  {
266  uint64_t N;
267  in >> m_average_normreadings_mean >>
268  m_average_normreadings_var >> N;
269  m_average_normreadings_count = N;
270  }
271 
272  in >> genericMapParams;
273 
274  m_hasToRecoverMeanAndCov = true;
275  }
276  break;
277  default:
279  };
280 }
281 
282 /*---------------------------------------------------------------
283  TInsertionOptions
284  ---------------------------------------------------------------*/
286 /*---------------------------------------------------------------
287  dumpToTextStream
288  ---------------------------------------------------------------*/
290  mrpt::utils::CStream& out) const
291 {
292  out.printf(
293  "\n----------- [CHeightGridMap2D_MRF::TInsertionOptions] ------------ "
294  "\n\n");
295  out.printf("[TInsertionOptions.Common] ------------ \n\n");
296  internal_dumpToTextStream_common(
297  out); // Common params to all random fields maps:
298 
299  // out.printf("[TInsertionOptions.CHeightGridMap2D_MRF] ------------
300  //\n\n");
301  // out.printf("std_windNoise_phi = %f\n",
302  // std_windNoise_phi);
303 
304  out.printf("\n");
305 }
306 
307 /*---------------------------------------------------------------
308  loadFromConfigFile
309  ---------------------------------------------------------------*/
311  const mrpt::utils::CConfigFileBase& iniFile, const std::string& section)
312 {
313  // Common data fields for all random fields maps:
314  internal_loadFromConfigFile_common(iniFile, section);
315 
316  // Specific data fields for this class:
317  // ...
318 }
319 
320 /*---------------------------------------------------------------
321  getAs3DObject
322 ---------------------------------------------------------------*/
324  mrpt::opengl::CSetOfObjects::Ptr& outObj) const
325 {
326  MRPT_START
327  if (!genericMapParams.enableSaveAs3DObject) return;
329  MRPT_END
330 }
331 
332 /*---------------------------------------------------------------
333  getAs3DObject
334 ---------------------------------------------------------------*/
337  mrpt::opengl::CSetOfObjects::Ptr& varObj) const
338 {
339  MRPT_START
340  if (!genericMapParams.enableSaveAs3DObject) return;
341  CRandomFieldGridMap2D::getAs3DObject(meanObj, varObj);
342  MRPT_END
343 }
#define ASSERT_EQUAL_(__A, __B)
void clear()
Erase all the contents of the map.
Definition: CMetricMap.cpp:31
bool run_map_estimation_at_ctor
Runs map estimation at start up (Default:true)
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
Extra params for insertIndividualPoint()
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLdouble GLdouble z
Definition: glext.h:3872
virtual void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &outObj) const override
Returns a 3D object representing the map.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
mrpt::maps::CHeightGridMap2D_MRF::TMapRepresentation mapType
The kind of map representation (see CHeightGridMap2D_MRF::CHeightGridMap2D_MRF)
#define THROW_EXCEPTION(msg)
GLenum GLsizei n
Definition: glext.h:5074
#define LOADABLEOPTS_DUMP_VAR(variableName, variableType)
Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types a...
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
Definition: CStream.cpp:64
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
TMapRepresentation
The type of map representation to be used, see CRandomFieldGridMap2D for a discussion.
STL namespace.
CHeightGridMap2D_MRF represents digital-elevation-model over a 2D area, with uncertainty, based on a Markov-Random-Field (MRF) estimator.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
virtual void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &outObj) const override
Returns a 3D object representing the map (mean)
This class allows loading and storing values and vectors of different types from a configuration text...
unsigned char uint8_t
Definition: rptypes.h:41
bool internal_insertObservation(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D *robotPose=nullptr) override
Internal method called by insertObservation()
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
double kf_mean
[KF-methods only] The mean value of this cell
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.
#define MRPT_END
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
The contents of each cell in a CRandomFieldGridMap2D map.
A helper class that can convert an enum value into its textual representation, and viceversa...
Definition: TEnumType.h:38
double min_x
See CHeightGridMap2D_MRF::CHeightGridMap2D_MRF.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
virtual size_t dem_get_size_y() const override
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &section) override
This method load the options from a ".ini"-like file or memory-stored string list.
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:32
This namespace contains representation of robot actions and observations.
void loadFromConfigFile_map_specific(const mrpt::utils::CConfigFileBase &source, const std::string &sectionNamePrefix) override
Load all map-specific params.
virtual size_t dem_get_size_x() const override
GLsizei const GLchar ** string
Definition: glext.h:4101
virtual void dem_update_map() override
Ensure that all observations are reflected in the map estimate.
virtual bool insertIndividualPoint(const double x, const double y, const double z, const CHeightGridMap2D_Base::TPointInsertParams &params=CHeightGridMap2D_Base::TPointInsertParams()) override
Update the DEM with one new point.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
virtual bool dem_get_z_by_cell(const size_t cx, const size_t cy, double &z_out) const override
Get cell &#39;z&#39; by (cx,cy) cell indices.
static mrpt::maps::CMetricMap * internal_CreateFromMapDefinition(const mrpt::maps::TMetricMapInitializer &def)
#define MRPT_START
unsigned __int64 uint64_t
Definition: rptypes.h:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define MAP_DEFINITION_REGISTER(_CLASSNAME_STRINGS, _CLASSNAME_WITH_NS)
Registers one map class into TMetricMapInitializer factory.
CRandomFieldGridMap2D represents a 2D grid map where each cell is associated one real-valued property...
Declares a virtual base class for all metric maps storage classes.
Definition: CMetricMap.h:55
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
mrpt::maps::CHeightGridMap2D_MRF::TInsertionOptions insertionOpts
Observations insertion options.
virtual void internal_clear() override
Erase all the contents of the map.
void internal_clear() override
Erase all the contents of the map.
GLuint in
Definition: glext.h:7274
double internal_computeObservationLikelihood(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D &takenFrom) override
Internal method called by computeObservationLikelihood()
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
GLenum GLint GLint y
Definition: glext.h:3538
virtual bool dem_get_z(const double x, const double y, double &z_out) const override
Get cell &#39;z&#39; (x,y) by metric coordinates.
virtual double dem_get_resolution() const override
#define MRPT_LOAD_CONFIG_VAR( variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
GLenum GLint x
Definition: glext.h:3538
unsigned __int32 uint32_t
Definition: rptypes.h:47
Lightweight 2D point.
GLenum const GLfloat * params
Definition: glext.h:3534
void dumpToTextStream_map_specific(mrpt::utils::CStream &out) const override
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