Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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  virtual void reserve(size_t newLength) MRPT_OVERRIDE; // See base class docs
46  virtual void resize(size_t newLength) MRPT_OVERRIDE; // See base class docs
47  virtual void setSize(size_t newLength) MRPT_OVERRIDE; // See base class docs
48  /** Changes the coordinates of the given point (0-based index), *without* checking for out-of-bounds and *without* calling mark_as_modified() \sa setPoint */
49  virtual void setPointFast(size_t index,float x, float y, float z) MRPT_OVERRIDE;
50  /** The virtual method for \a insertPoint() *without* calling mark_as_modified() */
51  virtual void insertPointFast( float x, float y, float z = 0 ) MRPT_OVERRIDE;
52  /** Virtual assignment operator, to be implemented in derived classes */
53  virtual void copyFrom(const CPointsMap &obj) MRPT_OVERRIDE;
54  /** Get all the data fields for one point as a vector: [X Y Z]
55  * Unlike getPointAllFields(), this method does not check for index out of bounds
56  * \sa getPointAllFields, setPointAllFields, setPointAllFieldsFast
57  */
58  virtual void getPointAllFieldsFast( const size_t index, std::vector<float> & point_data ) const MRPT_OVERRIDE {
59  point_data.resize(3);
60  point_data[0] = x[index];
61  point_data[1] = y[index];
62  point_data[2] = z[index];
63  }
64  /** Set all the data fields for one point as a vector: [X Y Z]
65  * Unlike setPointAllFields(), this method does not check for index out of bounds
66  * \sa setPointAllFields, getPointAllFields, getPointAllFieldsFast
67  */
68  virtual void setPointAllFieldsFast( const size_t index, const std::vector<float> & point_data ) MRPT_OVERRIDE {
69  ASSERTDEB_(point_data.size()==3)
70  x[index] = point_data[0];
71  y[index] = point_data[1];
72  z[index] = point_data[2];
73  }
74 
75  // See CPointsMap::loadFromRangeScan()
76  virtual void loadFromRangeScan(const mrpt::obs::CObservation2DRangeScan &rangeScan,const mrpt::poses::CPose3D *robotPose = NULL) MRPT_OVERRIDE;
77  // See CPointsMap::loadFromRangeScan()
78  virtual void loadFromRangeScan(const mrpt::obs::CObservation3DRangeScan &rangeScan,const mrpt::poses::CPose3D *robotPose = NULL ) MRPT_OVERRIDE;
79 
80  protected:
81  /** Auxiliary method called from within \a addFrom() automatically, to finish the copying of class-specific data */
82  virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints) MRPT_OVERRIDE {
83  MRPT_UNUSED_PARAM(anotherMap); MRPT_UNUSED_PARAM(nPreviousPoints);
84  // No extra data.
85  }
86 
87  // Friend methods:
88  template <class Derived> friend struct detail::loadFromRangeImpl;
89  template <class Derived> friend struct detail::pointmap_traits;
90 
91  public:
92 
93 
94  /** @} */
95  // --------------------------------------------
96 
97 
98  /** If the map is a simple points map or it's a multi-metric map that contains EXACTLY one simple points map, return it.
99  * Otherwise, return NULL
100  */
101  virtual const mrpt::maps::CSimplePointsMap * getAsSimplePointsMap() const MRPT_OVERRIDE { return this; }
103 
104  protected:
105  /** Clear the map, erasing all the points.
106  */
107  virtual void internal_clear() MRPT_OVERRIDE;
108 
109  /** @name PLY Import virtual methods to implement in base classes
110  @{ */
111  /** In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex */
112  virtual void PLY_import_set_vertex_count(const size_t N) MRPT_OVERRIDE;
113  /** @} */
114 
116  mrpt::maps::CPointsMap::TInsertionOptions insertionOpts; //!< Observations insertion options
117  mrpt::maps::CPointsMap::TLikelihoodOptions likelihoodOpts; //!< Probabilistic observation likelihood options
119 
120  }; // End of class def.
122  } // End of namespace
123 
124  namespace utils
125  {
126  /** Specialization mrpt::utils::PointCloudAdapter<mrpt::maps::CSimplePointsMap> \ingroup mrpt_adapters_grp*/
127  template <>
128  class PointCloudAdapter<mrpt::maps::CSimplePointsMap> : public detail::PointCloudAdapterHelperNoRGB<mrpt::maps::CSimplePointsMap,float>
129  {
130  private:
132  public:
133  typedef float coords_t; //!< The type of each point XYZ coordinates
134  static const int HAS_RGB = 0; //!< Has any color RGB info?
135  static const int HAS_RGBf = 0; //!< Has native RGB info (as floats)?
136  static const int HAS_RGBu8 = 0; //!< Has native RGB info (as uint8_t)?
137 
138  /** Constructor (accept a const ref for convenience) */
139  inline PointCloudAdapter(const mrpt::maps::CSimplePointsMap &obj) : m_obj(*const_cast<mrpt::maps::CSimplePointsMap*>(&obj)) { }
140  /** Get number of points */
141  inline size_t size() const { return m_obj.size(); }
142  /** Set number of points (to uninitialized values) */
143  inline void resize(const size_t N) { m_obj.resize(N); }
144 
145  /** Get XYZ coordinates of i'th point */
146  template <typename T>
147  inline void getPointXYZ(const size_t idx, T &x,T &y, T &z) const {
148  m_obj.getPointFast(idx,x,y,z);
149  }
150  /** Set XYZ coordinates of i'th point */
151  inline void setPointXYZ(const size_t idx, const coords_t x,const coords_t y, const coords_t z) {
152  m_obj.setPointFast(idx,x,y,z);
153  }
154  }; // end of PointCloudAdapter<mrpt::maps::CPointsMap>
155 
156  }
157 
158 } // End of namespace
159 
160 #endif
mrpt::utils::PointCloudAdapter
An adapter to different kinds of point cloud object.
Definition: adapters.h:38
mrpt::maps::CSimplePointsMap::getAsSimplePointsMap
virtual const mrpt::maps::CSimplePointsMap * getAsSimplePointsMap() const MRPT_OVERRIDE
If the map is a simple points map or it's a multi-metric map that contains EXACTLY one simple points ...
Definition: maps/CSimplePointsMap.h:101
mrpt::utils::PointCloudAdapter< mrpt::maps::CSimplePointsMap >::setPointXYZ
void setPointXYZ(const size_t idx, const coords_t x, const coords_t y, const coords_t z)
Set XYZ coordinates of i'th point.
Definition: maps/CSimplePointsMap.h:151
mrpt::maps::CPointsMap::size
size_t size() const
Returns the number of stored points in the map.
Definition: maps/CPointsMap.h:319
mrpt::maps::CPointsMap::TLikelihoodOptions
Options used when evaluating "computeObservationLikelihood" in the derived classes.
Definition: maps/CPointsMap.h:190
mrpt::maps::CPointsMap::getPointFast
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,...
Definition: maps/CPointsMap.h:350
mrpt::maps::CSimplePointsMap::resize
virtual void resize(size_t newLength) MRPT_OVERRIDE
Resizes all point buffers so they can hold the given number of points: newly created points are set t...
MAP_DEFINITION_END
#define MAP_DEFINITION_END(_CLASS_NAME_, _LINKAGE_)
Definition: TMetricMapTypesRegistry.h:52
mrpt::utils::PointCloudAdapter< mrpt::maps::CSimplePointsMap >::getPointXYZ
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i'th point.
Definition: maps/CSimplePointsMap.h:147
mrpt::obs::CObservation2DRangeScan
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
Definition: obs/CObservation2DRangeScan.h:40
mrpt::maps::CPointsMap::TInsertionOptions
With this struct options are provided to the observation insertion process.
Definition: maps/CPointsMap.h:164
mrpt::utils::PointCloudAdapter< mrpt::maps::CSimplePointsMap >::size
size_t size() const
Get number of points.
Definition: maps/CSimplePointsMap.h:141
CPointsMap.h
CMatrix.h
MRPT_UNUSED_PARAM
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Definition: mrpt_macros.h:290
mrpt::maps::CPointsMap
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors.
Definition: maps/CPointsMap.h:56
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CParticleFilter.h:16
MAP_DEFINITION_START
#define MAP_DEFINITION_START(_CLASS_NAME_, _LINKAGE_)
Add a MAP_DEFINITION_START() ...
Definition: TMetricMapTypesRegistry.h:44
ASSERTDEB_
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
Definition: mrpt_macros.h:283
mrpt::obs::CObservation3DRangeScan
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement,...
Definition: obs/CObservation3DRangeScan.h:112
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
mrpt::maps::CSimplePointsMap::getAsSimplePointsMap
virtual mrpt::maps::CSimplePointsMap * getAsSimplePointsMap() MRPT_OVERRIDE
Definition: maps/CSimplePointsMap.h:102
DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
Definition: CSerializable.h:174
mrpt::maps::CSimplePointsMap
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
Definition: maps/CSimplePointsMap.h:33
mrpt::utils::PointCloudAdapter< mrpt::maps::CSimplePointsMap >::PointCloudAdapter
PointCloudAdapter(const mrpt::maps::CSimplePointsMap &obj)
Constructor (accept a const ref for convenience)
Definition: maps/CSimplePointsMap.h:139
obs_frwds.h
mrpt::utils::PointCloudAdapter< mrpt::maps::CSimplePointsMap >::resize
void resize(const size_t N)
Set number of points (to uninitialized values)
Definition: maps/CSimplePointsMap.h:143
mrpt::maps::detail::pointmap_traits
Definition: maps/CPointsMap.h:38
setSize
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...
Definition: eigen_plugins.h:280
mrpt::maps::CSimplePointsMap::setPointAllFieldsFast
virtual void setPointAllFieldsFast(const size_t index, const std::vector< float > &point_data) MRPT_OVERRIDE
Set all the data fields for one point as a vector: [X Y Z] Unlike setPointAllFields(),...
Definition: maps/CSimplePointsMap.h:68
DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE
#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...
Definition: CSerializable.h:170
mrpt::maps::CSimplePointsMap::addFrom_classSpecific
virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints) MRPT_OVERRIDE
Auxiliary method called from within addFrom() automatically, to finish the copying of class-specific ...
Definition: maps/CSimplePointsMap.h:82
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:147
mrpt::maps::CSimplePointsMap::setPointFast
virtual void setPointFast(size_t index, float x, float y, float z) MRPT_OVERRIDE
Changes the coordinates of the given point (0-based index), without checking for out-of-bounds and wi...
mrpt::utils::PointCloudAdapter< mrpt::maps::CSimplePointsMap >::m_obj
mrpt::maps::CSimplePointsMap & m_obj
Definition: maps/CSimplePointsMap.h:131
mrpt::maps::detail::loadFromRangeImpl
Definition: maps/CPointsMap.h:37
CSerializable.h
mrpt::utils::PointCloudAdapter< mrpt::maps::CSimplePointsMap >::coords_t
float coords_t
The type of each point XYZ coordinates.
Definition: maps/CSimplePointsMap.h:133
MRPT_OVERRIDE
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
mrpt::utils::detail::PointCloudAdapterHelperNoRGB
A helper base class for those PointCloudAdapter<> which do not handle RGB data; it declares needed in...
Definition: adapters.h:48



Page generated by Doxygen 1.8.16 for MRPT 1.4.0 SVN: at Mon Oct 14 23:11:08 UTC 2019