Main MRPT website > C++ reference for MRPT 1.9.9
CSimplePointsMap.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
11 
13 #include <mrpt/utils/CStream.h>
14 
15 #include "CPointsMap_crtp_common.h"
16 
17 using namespace std;
18 using namespace mrpt;
19 using namespace mrpt::maps;
20 using namespace mrpt::obs;
21 using namespace mrpt::utils;
22 using namespace mrpt::poses;
23 using namespace mrpt::math;
24 
25 // =========== Begin of Map definition ============
27  "CSimplePointsMap,pointsMap", mrpt::maps::CSimplePointsMap)
28 
30 void CSimplePointsMap::TMapDefinition::loadFromConfigFile_map_specific(
32  const std::string& sectionNamePrefix)
33 {
34  insertionOpts.loadFromConfigFile(
35  source, sectionNamePrefix + string("_insertOpts"));
36  likelihoodOpts.loadFromConfigFile(
37  source, sectionNamePrefix + string("_likelihoodOpts"));
38 }
39 
40 void CSimplePointsMap::TMapDefinition::dumpToTextStream_map_specific(
41  mrpt::utils::CStream& out) const
42 {
43  this->insertionOpts.dumpToTextStream(out);
44  this->likelihoodOpts.dumpToTextStream(out);
45 }
46 
47 mrpt::maps::CMetricMap* CSimplePointsMap::internal_CreateFromMapDefinition(
49 {
51  *dynamic_cast<const CSimplePointsMap::TMapDefinition*>(&_def);
53  obj->insertionOptions = def.insertionOpts;
54  obj->likelihoodOptions = def.likelihoodOpts;
55  return obj;
56 }
57 // =========== End of Map definition Block =========
58 
60 
61 /*---------------------------------------------------------------
62  Constructor
63  ---------------------------------------------------------------*/
64 CSimplePointsMap::CSimplePointsMap() { reserve(400); }
65 /*---------------------------------------------------------------
66  Destructor
67  ---------------------------------------------------------------*/
68 CSimplePointsMap::~CSimplePointsMap() {}
69 /*---------------------------------------------------------------
70  reserve & resize methods
71  ---------------------------------------------------------------*/
72 void CSimplePointsMap::reserve(size_t newLength)
73 {
74  newLength = mrpt::utils::length2length4N(newLength);
75 
76  x.reserve(newLength);
77  y.reserve(newLength);
78  z.reserve(newLength);
79 }
80 
81 // Resizes all point buffers so they can hold the given number of points: newly
82 // created points are set to default values,
83 // and old contents are not changed.
84 void CSimplePointsMap::resize(size_t newLength)
85 {
86  this->reserve(newLength); // to ensure 4N capacity
87  x.resize(newLength, 0);
88  y.resize(newLength, 0);
89  z.resize(newLength, 0);
90  mark_as_modified();
91 }
92 
93 // Resizes all point buffers so they can hold the given number of points,
94 // *erasing* all previous contents
95 // and leaving all points to default values.
96 void CSimplePointsMap::setSize(size_t newLength)
97 {
98  this->reserve(newLength); // to ensure 4N capacity
99  x.assign(newLength, 0);
100  y.assign(newLength, 0);
101  z.assign(newLength, 0);
102  mark_as_modified();
103 }
104 
105 /*---------------------------------------------------------------
106  Copy constructor
107  ---------------------------------------------------------------*/
108 void CSimplePointsMap::copyFrom(const CPointsMap& obj)
109 {
110  CPointsMap::base_copyFrom(
111  obj); // This also does a ::resize(N) of all data fields.
112 }
113 
114 /*---------------------------------------------------------------
115  writeToStream
116  Implements the writing to a CStream capability of
117  CSerializable objects
118  ---------------------------------------------------------------*/
119 void CSimplePointsMap::writeToStream(
120  mrpt::utils::CStream& out, int* version) const
121 {
122  if (version)
123  *version = 9;
124  else
125  {
126  uint32_t n = x.size();
127 
128  // First, write the number of points:
129  out << n;
130 
131  if (n > 0)
132  {
133  out.WriteBufferFixEndianness(&x[0], n);
134  out.WriteBufferFixEndianness(&y[0], n);
135  out.WriteBufferFixEndianness(&z[0], n);
136  }
137  out << genericMapParams; // v9
138 
139  insertionOptions.writeToStream(
140  out); // version 9: insert options are saved with its own method:
141  likelihoodOptions.writeToStream(out); // Added in version 5:
142  }
143 }
144 
145 /*---------------------------------------------------------------
146  readFromStream
147  Implements the reading from a CStream capability of
148  CSerializable objects
149  ---------------------------------------------------------------*/
150 void CSimplePointsMap::readFromStream(mrpt::utils::CStream& in, int version)
151 {
152  switch (version)
153  {
154  case 8:
155  case 9:
156  {
157  mark_as_modified();
158 
159  // Read the number of points:
160  uint32_t n;
161  in >> n;
162 
163  this->resize(n);
164 
165  if (n > 0)
166  {
167  in.ReadBufferFixEndianness(&x[0], n);
168  in.ReadBufferFixEndianness(&y[0], n);
169  in.ReadBufferFixEndianness(&z[0], n);
170  }
171  if (version >= 9)
172  in >> genericMapParams;
173  else
174  {
175  bool disableSaveAs3DObject;
176  in >> disableSaveAs3DObject;
177  genericMapParams.enableSaveAs3DObject = !disableSaveAs3DObject;
178  }
179 
180  insertionOptions.readFromStream(in);
181  likelihoodOptions.readFromStream(in);
182  }
183  break;
184 
185  case 0:
186  case 1:
187  case 2:
188  case 3:
189  case 4:
190  case 5:
191  case 6:
192  case 7:
193  {
194  mark_as_modified();
195 
196  // Read the number of points:
197  uint32_t n;
198  in >> n;
199 
200  this->resize(n);
201 
202  if (n > 0)
203  {
204  in.ReadBufferFixEndianness(&x[0], n);
205  in.ReadBufferFixEndianness(&y[0], n);
206  in.ReadBufferFixEndianness(&z[0], n);
207 
208  // Version 1: weights are also stored:
209  // Version 4: Type becomes long int -> uint32_t for
210  // portability!!
211  if (version >= 1)
212  {
213  if (version >= 4)
214  {
215  if (version >= 7)
216  {
217  // Weights were removed from this class in v7 (MRPT
218  // 0.9.5),
219  // so nothing else to do.
220  }
221  else
222  {
223  // Go on with old serialization format, but discard
224  // weights:
225  std::vector<uint32_t> dummy_pointWeight(n);
226  in.ReadBufferFixEndianness(
227  &dummy_pointWeight[0], n);
228  }
229  }
230  else
231  {
232  std::vector<uint32_t> dummy_pointWeight(n);
233  in.ReadBufferFixEndianness(&dummy_pointWeight[0], n);
234  }
235  }
236  }
237 
238  if (version >= 2)
239  {
240  // version 2: options saved too
241  in >> insertionOptions.minDistBetweenLaserPoints >>
242  insertionOptions.addToExistingPointsMap >>
243  insertionOptions.also_interpolate >>
244  insertionOptions.disableDeletion >>
245  insertionOptions.fuseWithExisting >>
246  insertionOptions.isPlanarMap;
247 
248  if (version < 6)
249  {
250  bool old_matchStaticPointsOnly;
251  in >> old_matchStaticPointsOnly;
252  }
253 
254  in >> insertionOptions.maxDistForInterpolatePoints;
255 
256  {
257  bool disableSaveAs3DObject;
258  in >> disableSaveAs3DObject;
259  genericMapParams.enableSaveAs3DObject =
260  !disableSaveAs3DObject;
261  }
262  }
263 
264  if (version >= 3)
265  {
266  in >> insertionOptions.horizontalTolerance;
267  }
268 
269  if (version >= 5) // version 5: added likelihoodOptions
270  likelihoodOptions.readFromStream(in);
271 
272  if (version >= 8) // version 8: added insertInvalidPoints
273  in >> insertionOptions.insertInvalidPoints;
274  }
275  break;
276  default:
278  };
279 }
280 
281 /*---------------------------------------------------------------
282  Clear
283  ---------------------------------------------------------------*/
284 void CSimplePointsMap::internal_clear()
285 {
286  // This swap() thing is the only way to really deallocate the memory.
290 
291  mark_as_modified();
292 }
293 
294 void CSimplePointsMap::setPointFast(size_t index, float x, float y, float z)
295 {
296  this->x[index] = x;
297  this->y[index] = y;
298  this->z[index] = z;
299 }
300 
301 void CSimplePointsMap::insertPointFast(float x, float y, float z)
302 {
303  this->x.push_back(x);
304  this->y.push_back(y);
305  this->z.push_back(z);
306 }
307 
308 namespace mrpt
309 {
310 namespace maps
311 {
312 namespace detail
313 {
315 
316 template <>
318 {
319  /** Helper method fot the generic implementation of
320  * CPointsMap::loadFromRangeScan(), to be called only once before inserting
321  * points - this is the place to reserve memory in lric for extra working
322  * variables. */
324  CSimplePointsMap& me,
326  {
327  MRPT_UNUSED_PARAM(me);
328  MRPT_UNUSED_PARAM(lric);
329  }
330  /** Helper method fot the generic implementation of
331  * CPointsMap::loadFromRangeScan(), to be called once per range data */
333  CSimplePointsMap& me, const float gx, const float gy, const float gz,
335  {
336  MRPT_UNUSED_PARAM(me);
337  MRPT_UNUSED_PARAM(gx);
338  MRPT_UNUSED_PARAM(gy);
339  MRPT_UNUSED_PARAM(gz);
340  MRPT_UNUSED_PARAM(lric);
341  }
342  /** Helper method fot the generic implementation of
343  * CPointsMap::loadFromRangeScan(), to be called after each
344  * "{x,y,z}.push_back(...);" */
346  CSimplePointsMap& me,
348  {
349  MRPT_UNUSED_PARAM(me);
350  MRPT_UNUSED_PARAM(lric);
351  }
352 
353  /** Helper method fot the generic implementation of
354  * CPointsMap::loadFromRangeScan(), to be called only once before inserting
355  * points - this is the place to reserve memory in lric for extra working
356  * variables. */
358  CSimplePointsMap& me,
360  {
361  MRPT_UNUSED_PARAM(me);
362  MRPT_UNUSED_PARAM(lric);
363  }
364  /** Helper method fot the generic implementation of
365  * CPointsMap::loadFromRangeScan(), to be called once per range data */
367  CSimplePointsMap& me, const float gx, const float gy, const float gz,
369  {
370  MRPT_UNUSED_PARAM(me);
371  MRPT_UNUSED_PARAM(gx);
372  MRPT_UNUSED_PARAM(gy);
373  MRPT_UNUSED_PARAM(gz);
374  MRPT_UNUSED_PARAM(lric);
375  }
376  /** Helper method fot the generic implementation of
377  * CPointsMap::loadFromRangeScan(), to be called after each
378  * "{x,y,z}.push_back(...);" */
380  CSimplePointsMap& me,
382  {
383  MRPT_UNUSED_PARAM(me);
384  MRPT_UNUSED_PARAM(lric);
385  }
386  /** Helper method fot the generic implementation of
387  * CPointsMap::loadFromRangeScan(), to be called once per range data, at the
388  * end */
390  CSimplePointsMap& me,
392  {
393  MRPT_UNUSED_PARAM(me);
394  MRPT_UNUSED_PARAM(lric);
395  }
396 };
397 }
398 }
399 }
400 
401 /** See CPointsMap::loadFromRangeScan() */
402 void CSimplePointsMap::loadFromRangeScan(
403  const CObservation2DRangeScan& rangeScan, const CPose3D* robotPose)
404 {
406  CSimplePointsMap>::templ_loadFromRangeScan(*this, rangeScan, robotPose);
407 }
408 
409 /** See CPointsMap::loadFromRangeScan() */
410 void CSimplePointsMap::loadFromRangeScan(
411  const CObservation3DRangeScan& rangeScan, const CPose3D* robotPose)
412 {
414  CSimplePointsMap>::templ_loadFromRangeScan(*this, rangeScan, robotPose);
415 }
416 
417 // ================================ PLY files import & export virtual methods
418 // ================================
419 
420 /** In a base class, reserve memory to prepare subsequent calls to
421  * PLY_import_set_vertex */
422 void CSimplePointsMap::PLY_import_set_vertex_count(const size_t N)
423 {
424  this->setSize(N);
425 }
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
GLdouble GLdouble z
Definition: glext.h:3872
static void internal_loadFromRangeScan3D_init(CSimplePointsMap &me, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called only on...
static void internal_loadFromRangeScan2D_init(CSimplePointsMap &me, mrpt::maps::CPointsMap::TLaserRange2DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called only on...
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
GLenum GLsizei n
Definition: glext.h:5074
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
STL namespace.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
This class allows loading and storing values and vectors of different types from a configuration text...
void WriteBufferFixEndianness(const T *ptr, size_t ElementCount)
Writes a sequence of elemental datatypes, taking care of reordering their bytes from the running arch...
Definition: CStream.h:159
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
Definition: CPointsMap.h:63
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
T length2length4N(T len)
Returns the smaller number >=len such that it&#39;s a multiple of 4.
Definition: bits.h:273
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
GLuint index
Definition: glext.h:4054
static void internal_loadFromRangeScan3D_postPushBack(CSimplePointsMap &me, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called after e...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
mrpt::maps::CPointsMap::TInsertionOptions insertionOpts
Observations insertion options.
mrpt::maps::CPointsMap::TLikelihoodOptions likelihoodOpts
Probabilistic observation likelihood options.
This namespace contains representation of robot actions and observations.
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
GLsizei const GLchar ** string
Definition: glext.h:4101
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
static void internal_loadFromRangeScan3D_postOneRange(CSimplePointsMap &me, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called once pe...
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &sectionNamePrefix) override
Load all params from a config file/source.
void vector_strong_clear(VECTOR_T &v)
Like calling a std::vector<>&#39;s clear() method, but really forcing deallocating the memory...
Definition: bits.h:265
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.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
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
GLuint in
Definition: glext.h:7274
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
Helper struct used for internal_loadFromRangeScan3D_prepareOneRange()
Definition: CPointsMap.h:93
GLenum GLint GLint y
Definition: glext.h:3538
GLenum GLint x
Definition: glext.h:3538
static void internal_loadFromRangeScan2D_postPushBack(CSimplePointsMap &me, mrpt::maps::CPointsMap::TLaserRange2DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called after e...
static void internal_loadFromRangeScan2D_prepareOneRange(CSimplePointsMap &me, const float gx, const float gy, const float gz, mrpt::maps::CPointsMap::TLaserRange2DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called once pe...
unsigned __int32 uint32_t
Definition: rptypes.h:47
Helper struct used for internal_loadFromRangeScan2D_prepareOneRange()
Definition: CPointsMap.h:75
static void internal_loadFromRangeScan3D_prepareOneRange(CSimplePointsMap &me, const float gx, const float gy, const float gz, mrpt::maps::CPointsMap::TLaserRange3DInsertContext &lric)
Helper method fot the generic implementation of CPointsMap::loadFromRangeScan(), to be called once pe...



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