Main MRPT website > C++ reference for MRPT 1.3.2
maps/CSimplePointsMap.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2015, 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 #ifndef CSimplePointsMap_H
10 #define CSimplePointsMap_H
11 
12 #include <mrpt/maps/CPointsMap.h>
14 #include <mrpt/math/CMatrix.h>
15 #include <mrpt/obs/obs_frwds.h>
16 
17 #include <mrpt/maps/link_pragmas.h>
18 
19 namespace mrpt
20 {
21  namespace maps
22  {
23  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSimplePointsMap , CPointsMap, MAPS_IMPEXP )
24 
25  /** A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
26  * This class only stores the coordinates (x,y,z) of each point.
27  *
28  * See mrpt::maps::CPointsMap and derived classes for other point cloud classes.
29  *
30  * \sa CMetricMap, CWeightedPointsMap, CPoint, mrpt::utils::CSerializable
31  * \ingroup mrpt_maps_grp
32  */
34  {
35  // This must be added to any CSerializable derived class:
37 
38  public:
39  CSimplePointsMap(); //!< Default constructor
40  virtual ~CSimplePointsMap(); //!< Destructor
41 
42  // --------------------------------------------
43  /** @name Pure virtual interfaces to be implemented by any class derived from CPointsMap
44  @{ */
45 
46  /** Reserves memory for a given number of points: the size of the map does not change, it only reserves the memory.
47  * This is useful for situations where it is approximately known the final size of the map. This method is more
48  * efficient than constantly increasing the size of the buffers. Refer to the STL C++ library's "reserve" methods.
49  */
50  virtual void reserve(size_t newLength);
51 
52  /** Resizes all point buffers so they can hold the given number of points: newly created points are set to default values,
53  * and old contents are not changed.
54  * \sa reserve, setPoint, setPointFast, setSize
55  */
56  virtual void resize(size_t newLength);
57 
58  /** Resizes all point buffers so they can hold the given number of points, *erasing* all previous contents
59  * and leaving all points to default values.
60  * \sa reserve, setPoint, setPointFast, setSize
61  */
62  virtual void setSize(size_t newLength);
63 
64  /** Changes the coordinates of the given point (0-based index), *without* checking for out-of-bounds and *without* calling mark_as_modified() \sa setPoint */
65  virtual void setPointFast(size_t index,float x, float y, float z);
66 
67  /** The virtual method for \a insertPoint() *without* calling mark_as_modified() */
68  virtual void insertPointFast( float x, float y, float z = 0 );
69 
70  /** Virtual assignment operator, to be implemented in derived classes.
71  */
72  virtual void copyFrom(const CPointsMap &obj);
73 
74  /** Get all the data fields for one point as a vector: [X Y Z]
75  * Unlike getPointAllFields(), this method does not check for index out of bounds
76  * \sa getPointAllFields, setPointAllFields, setPointAllFieldsFast
77  */
78  virtual void getPointAllFieldsFast( const size_t index, std::vector<float> & point_data ) const {
79  point_data.resize(3);
80  point_data[0] = x[index];
81  point_data[1] = y[index];
82  point_data[2] = z[index];
83  }
84 
85  /** Set all the data fields for one point as a vector: [X Y Z]
86  * Unlike setPointAllFields(), this method does not check for index out of bounds
87  * \sa setPointAllFields, getPointAllFields, getPointAllFieldsFast
88  */
89  virtual void setPointAllFieldsFast( const size_t index, const std::vector<float> & point_data ) {
90  ASSERTDEB_(point_data.size()==3)
91  x[index] = point_data[0];
92  y[index] = point_data[1];
93  z[index] = point_data[2];
94  }
95 
96  /** See CPointsMap::loadFromRangeScan() */
97  virtual void loadFromRangeScan(
98  const mrpt::obs::CObservation2DRangeScan &rangeScan,
99  const mrpt::poses::CPose3D *robotPose = NULL );
100 
101  /** See CPointsMap::loadFromRangeScan() */
102  virtual void loadFromRangeScan(
103  const mrpt::obs::CObservation3DRangeScan &rangeScan,
104  const mrpt::poses::CPose3D *robotPose = NULL );
105 
106 
107  protected:
108 
109  /** Auxiliary method called from within \a addFrom() automatically, to finish the copying of class-specific data */
110  virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints) {
111  MRPT_UNUSED_PARAM(anotherMap); MRPT_UNUSED_PARAM(nPreviousPoints);
112  // No extra data.
113  }
114 
115  // Friend methods:
116  template <class Derived> friend struct detail::loadFromRangeImpl;
117  template <class Derived> friend struct detail::pointmap_traits;
118 
119  public:
120 
121 
122  /** @} */
123  // --------------------------------------------
124 
125 
126  /** If the map is a simple points map or it's a multi-metric map that contains EXACTLY one simple points map, return it.
127  * Otherwise, return NULL
128  */
129  virtual const mrpt::maps::CSimplePointsMap * getAsSimplePointsMap() const { return this; }
131 
132  protected:
133  /** Clear the map, erasing all the points.
134  */
135  virtual void internal_clear();
136 
137  /** @name PLY Import virtual methods to implement in base classes
138  @{ */
139  /** In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex */
140  virtual void PLY_import_set_vertex_count(const size_t N);
141  /** @} */
142 
144  mrpt::maps::CPointsMap::TInsertionOptions insertionOpts; //!< Observations insertion options
145  mrpt::maps::CPointsMap::TLikelihoodOptions likelihoodOpts; //!< Probabilistic observation likelihood options
147 
148  }; // End of class def.
149  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CSimplePointsMap , CPointsMap, MAPS_IMPEXP )
150  } // End of namespace
151 
152  namespace utils
153  {
154  /** Specialization mrpt::utils::PointCloudAdapter<mrpt::maps::CSimplePointsMap> \ingroup mrpt_adapters_grp*/
155  template <>
156  class PointCloudAdapter<mrpt::maps::CSimplePointsMap> : public detail::PointCloudAdapterHelperNoRGB<mrpt::maps::CSimplePointsMap,float>
157  {
158  private:
160  public:
161  typedef float coords_t; //!< The type of each point XYZ coordinates
162  static const int HAS_RGB = 0; //!< Has any color RGB info?
163  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
164  static const int HAS_RGBu8 = 0; //!< Has native RGB info (as uint8_t)?
165 
166  /** Constructor (accept a const ref for convenience) */
167  inline PointCloudAdapter(const mrpt::maps::CSimplePointsMap &obj) : m_obj(*const_cast<mrpt::maps::CSimplePointsMap*>(&obj)) { }
168  /** Get number of points */
169  inline size_t size() const { return m_obj.size(); }
170  /** Set number of points (to uninitialized values) */
171  inline void resize(const size_t N) { m_obj.resize(N); }
172 
173  /** Get XYZ coordinates of i'th point */
174  template <typename T>
175  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
176  m_obj.getPointFast(idx,x,y,z);
177  }
178  /** Set XYZ coordinates of i'th point */
179  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
180  m_obj.setPointFast(idx,x,y,z);
181  }
182  }; // end of PointCloudAdapter<mrpt::maps::CPointsMap>
183 
184  }
185 
186 } // End of namespace
187 
188 #endif
float coords_t
The type of each point XYZ coordinates.
virtual void resize(size_t newLength)
Resizes all point buffers so they can hold the given number of points: newly created points are set t...
void getPointFast(size_t index, float &x, float &y, float &z) const
Just like getPoint() but without checking out-of-bound index and without returning the point weight...
#define MAP_DEFINITION_END(_CLASS_NAME_, _LINKAGE_)
virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints)
Auxiliary method called from within addFrom() automatically, to finish the copying of class-specific ...
A helper base class for those PointCloudAdapter<> which do not handle RGB data; it declares needed in...
Definition: adapters.h:48
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.
void setPointXYZ(const size_t idx, const coords_t x, const coords_t y, const coords_t z)
Set XYZ coordinates of i&#39;th point.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
STL namespace.
With this struct options are provided to the observation insertion process.
virtual mrpt::maps::CSimplePointsMap * getAsSimplePointsMap()
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
virtual void setPointAllFieldsFast(const size_t index, const std::vector< float > &point_data)
Set all the data fields for one point as a vector: [X Y Z] Unlike setPointAllFields(), this method does not check for index out of bounds.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
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...
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.
virtual const mrpt::maps::CSimplePointsMap * getAsSimplePointsMap() const
If the map is a simple points map or it&#39;s a multi-metric map that contains EXACTLY one simple points ...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
PointCloudAdapter(const mrpt::maps::CSimplePointsMap &obj)
Constructor (accept a const ref for convenience)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
Options used when evaluating "computeObservationLikelihood" in the derived classes.
An adapter to different kinds of point cloud object.
Definition: adapters.h:38
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
size_t size() const
Returns the number of stored points in the map.
#define MAP_DEFINITION_START(_CLASS_NAME_, _LINKAGE_)
Add a MAP_DEFINITION_START() ...
void resize(const size_t N)
Set number of points (to uninitialized values)
virtual void setPointFast(size_t index, float x, float y, float z)
Changes the coordinates of the given point (0-based index), without checking for out-of-bounds and wi...



Page generated by Doxygen 1.8.12 for MRPT 1.3.2 SVN: at Mon Oct 3 19:22:36 UTC 2016