Main MRPT website > C++ reference for MRPT 1.5.9
obs/CObservation2DRangeScan.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-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 #ifndef CObservation2DRangeScan_H
10 #define CObservation2DRangeScan_H
11 
13 #include <mrpt/obs/CObservation.h>
15 #include <mrpt/poses/CPose3D.h>
16 #include <mrpt/maps/CMetricMap.h>
17 #include <mrpt/math/CPolygon.h>
19 
20 // Add for declaration of mexplus::from template specialization
22 
23 namespace mrpt
24 {
25 namespace obs
26 {
27  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CObservation2DRangeScan, CObservation, OBS_IMPEXP)
28 
29  /** A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser scanner).
30  * The data structures are generic enough to hold a wide variety of 2D scanners and "3D" planar rotating 2D lasers.
31  *
32  * These are the most important data fields:
33  * - These three fields are private data member (since MRPT 1.5.0) for safety and to ensure data consistency. Read them with the backwards-compatible proxies `scan`, `intensity`, `validRange` or (preferred) with the new `get_*`, `set_*` and `resize()` methods:
34  * - CObservation2DRangeScan::scan -> A vector of float values with all the range measurements (in meters).
35  * - CObservation2DRangeScan::validRange -> A vector (of <b>identical size</b> to <i>scan<i>), has non-zeros for those ranges than are valid (i.e. will be zero for non-reflected rays, etc.)
36  * - CObservation2DRangeScan::intensity -> A vector (of <b>identical size</b> to <i>scan<i>) a unitless int values representing the relative strength of each return. Higher values indicate a more intense return. This is useful for filtering out low intensity(noisy) returns or detecting intense landmarks.
37  * - CObservation2DRangeScan::aperture -> The field-of-view of the scanner, in radians (typically, M_PI = 180deg).
38  * - CObservation2DRangeScan::sensorPose -> The 6D location of the sensor on the robot reference frame (default=at the origin).
39  *
40  * \sa CObservation, CPointsMap, T2DScanProperties
41  * \ingroup mrpt_obs_grp
42  */
44  {
45  // This must be added to any CSerializable derived class:
47  // This must be added for declaration of MEX-related functions
49  private:
50  std::vector<float> m_scan; //!< The range values of the scan, in meters. Must have same length than \a validRange
51  std::vector<int32_t> m_intensity; //!< The intensity values of the scan. If available, must have same length than \a validRange
52  std::vector<char> m_validRange; //!< It's false (=0) on no reflected rays, referenced to elements in \a scan
53  bool m_has_intensity; //!< Whether the intensity values are present or not. If not, space is saved during serialization.
54 
55  public:
56  typedef std::vector<mrpt::math::CPolygon> TListExclusionAreas; //!< Used in filterByExclusionAreas
57  typedef std::vector<std::pair<mrpt::math::CPolygon,std::pair<double,double> > > TListExclusionAreasWithRanges; //!< Used in filterByExclusionAreas
58 
59  CObservation2DRangeScan(); //!< Default constructor
60  CObservation2DRangeScan(const CObservation2DRangeScan &o); //!< copy ctor
61  virtual ~CObservation2DRangeScan(); //!< Destructor
62 
63  /** @name Scan data
64  @{ */
65  void resizeScan(const size_t len); //!< Resizes all data vectors to allocate a given number of scan rays
66  void resizeScanAndAssign(const size_t len, const float rangeVal, const bool rangeValidity, const int32_t rangeIntensity = 0); //!< Resizes all data vectors to allocate a given number of scan rays and assign default values.
67  size_t getScanSize() const; //!< Get number of scan rays
68 
69  mrpt::utils::ContainerReadOnlyProxyAccessor<std::vector<float> > scan; //!< The range values of the scan, in meters. Must have same length than \a validRange
70  float getScanRange(const size_t i) const;
71  void setScanRange(const size_t i, const float val);
72 
73  mrpt::utils::ContainerReadOnlyProxyAccessor<std::vector<int32_t> > intensity; //!< The intensity values of the scan. If available, must have same length than \a validRange
74  int32_t getScanIntensity(const size_t i) const;
75  void setScanIntensity(const size_t i, const int val);
76 
77  mrpt::utils::ContainerReadOnlyProxyAccessor<std::vector<char> > validRange; //!< It's false (=0) on no reflected rays, referenced to elements in \a scan
78  bool getScanRangeValidity(const size_t i) const;
79  void setScanRangeValidity(const size_t i, const bool val);
80 
81  float aperture; //!< The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees).
82  bool rightToLeft; //!< The scanning direction: true=counterclockwise; false=clockwise
83  float maxRange; //!< The maximum range allowed by the device, in meters (e.g. 80m, 50m,...)
84  mrpt::poses::CPose3D sensorPose; //!< The 6D pose of the sensor on the robot at the moment of starting the scan.
85  float stdError; //!< The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid.
86  float beamAperture; //!< The aperture of each beam, in radians, used to insert "thick" rays in the occupancy grid.
87  double deltaPitch; //!< If the laser gathers data by sweeping in the pitch/elevation angle, this holds the increment in "pitch" (=-"elevation") between the beginning and the end of the scan (the sensorPose member stands for the pose at the beginning of the scan).
88 
89  void getScanProperties(T2DScanProperties& p) const; //!< Fill out a T2DScanProperties structure with the parameters of this scan
90  /** @} */
91 
92  void loadFromVectors(size_t nRays, const float *scanRanges, const char *scanValidity );
93 
94  /** @name Cached points map
95  @{ */
96  protected:
97  /** A points map, build only under demand by the methods getAuxPointsMap() and buildAuxPointsMap().
98  * It's a generic smart pointer to avoid depending here in the library mrpt-obs on classes on other libraries.
99  */
100  mutable mrpt::maps::CMetricMapPtr m_cachedMap;
101  void internal_buildAuxPointsMap( const void *options = NULL ) const; //!< Internal method, used from buildAuxPointsMap()
102  public:
103 
104  /** Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(), or NULL otherwise.
105  * Usage:
106  * \code
107  * mrpt::maps::CPointsMap *map = obs->getAuxPointsMap<mrpt::maps::CPointsMap>();
108  * \endcode
109  * \sa buildAuxPointsMap
110  */
111  template <class POINTSMAP>
112  inline const POINTSMAP* getAuxPointsMap() const {
113  return static_cast<const POINTSMAP*>(m_cachedMap.pointer());
114  }
115 
116  /** Returns a cached points map representing this laser scan, building it upon the first call.
117  * \param options Can be NULL to use default point maps' insertion options, or a pointer to a "CPointsMap::TInsertionOptions" structure to override some params.
118  * Usage:
119  * \code
120  * mrpt::maps::CPointsMap *map = obs->buildAuxPointsMap<mrpt::maps::CPointsMap>(&options or NULL);
121  * \endcode
122  * \sa getAuxPointsMap
123  */
124  template <class POINTSMAP>
125  inline const POINTSMAP *buildAuxPointsMap( const void *options = NULL ) const {
126  if (!m_cachedMap.present()) internal_buildAuxPointsMap(options);
127  return static_cast<const POINTSMAP*>(m_cachedMap.pointer());
128  }
129 
130  /** @} */
131 
132 
133 
134  /** Return true if the laser scanner is "horizontal", so it has an absolute value of "pitch" and "roll" less or equal to the given tolerance (in rads, default=0) (with the normal vector either upwards or downwards).
135  */
136  bool isPlanarScan(const double tolerance = 0) const;
137 
138  bool hasIntensity() const; //!< Return true if scan has intensity
139  void setScanHasIntensity(bool setHasIntensityFlag); //!< Marks this scan as having or not intensity data.
140 
141  // See base class docs
142  void getSensorPose( mrpt::poses::CPose3D &out_sensorPose ) const MRPT_OVERRIDE { out_sensorPose = sensorPose; }
143  void setSensorPose( const mrpt::poses::CPose3D &newSensorPose ) MRPT_OVERRIDE { sensorPose = newSensorPose; }
144  void getDescriptionAsText(std::ostream &o) const MRPT_OVERRIDE;
145 
146  /** A general method to truncate the scan by defining a minimum valid distance and a maximum valid angle as well as minimun and maximum heights
147  (NOTE: the laser z-coordinate must be provided).
148  */
149  void truncateByDistanceAndAngle(float min_distance, float max_angle, float min_height = 0, float max_height = 0, float h = 0 );
150 
151  /** Mark as invalid sensed points that fall within any of a set of "exclusion areas", given in coordinates relative to the vehicle (taking into account "sensorPose").
152  * \sa C2DRangeFinderAbstract::loadExclusionAreas
153  */
154  void filterByExclusionAreas( const TListExclusionAreas &areas );
155 
156  /** Mark as invalid sensed points that fall within any of a set of "exclusion areas", given in coordinates relative to the vehicle (taking into account "sensorPose"), AND such as the Z coordinate of the point falls in the range [min,max] associated to each exclusion polygon.
157  * \sa C2DRangeFinderAbstract::loadExclusionAreas
158  */
159  void filterByExclusionAreas( const TListExclusionAreasWithRanges &areas );
160 
161  /** Mark as invalid the ranges in any of a given set of "forbiden angle ranges", given as pairs<min_angle,max_angle>.
162  * \sa C2DRangeFinderAbstract::loadExclusionAreas
163  */
164  void filterByExclusionAngles( const std::vector<std::pair<double,double> > &angles );
165 
166  }; // End of class def.
167  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CObservation2DRangeScan, CObservation, OBS_IMPEXP)
168 
169  } // End of namespace
170  namespace utils
171  {
172  // Specialization must occur in the same namespace
173  MRPT_DECLARE_TTYPENAME_PTR_NAMESPACE(CObservation2DRangeScan, ::mrpt::obs)
174  }
175 
176 } // End of namespace
177 
178 #endif
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
float beamAperture
The aperture of each beam, in radians, used to insert "thick" rays in the occupancy grid...
#define DECLARE_MEXPLUS_FROM(complete_type)
This must be inserted if a custom conversion method for MEX API is implemented in the class...
std::vector< std::pair< mrpt::math::CPolygon, std::pair< double, double > > > TListExclusionAreasWithRanges
Used in filterByExclusionAreas.
float stdError
The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid...
GLenum GLsizei len
Definition: glext.h:4349
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) MRPT_OVERRIDE
A general method to change the sensor pose on the robot.
std::vector< char > m_validRange
It&#39;s false (=0) on no reflected rays, referenced to elements in scan.
float maxRange
The maximum range allowed by the device, in meters (e.g. 80m, 50m,...)
#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...
Auxiliary struct that holds all the relevant geometry information about a 2D scan.
#define DECLARE_MEX_CONVERSION
This must be inserted if a custom conversion method for MEX API is implemented in the class...
std::vector< int32_t > m_intensity
The intensity values of the scan. If available, must have same length than validRange.
This namespace contains representation of robot actions and observations.
int val
Definition: mrpt_jpeglib.h:953
mrpt::utils::ContainerReadOnlyProxyAccessor< std::vector< char > > validRange
It&#39;s false (=0) on no reflected rays, referenced to elements in scan.
bool m_has_intensity
Whether the intensity values are present or not. If not, space is saved during serialization.
mrpt::utils::ContainerReadOnlyProxyAccessor< std::vector< int32_t > > intensity
The intensity values of the scan. If available, must have same length than validRange.
#define MRPT_DECLARE_TTYPENAME_PTR_NAMESPACE(_TYPE, __NS)
Definition: TTypeName.h:72
std::vector< mrpt::math::CPolygon > TListExclusionAreas
Used in filterByExclusionAreas.
__int32 int32_t
Definition: rptypes.h:48
A generic proxy accessor template that only allows read-only access to the original binded STL contai...
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...
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
Declares a class that represents any robot&#39;s observation.
double deltaPitch
If the laser gathers data by sweeping in the pitch/elevation angle, this holds the increment in "pitc...
const POINTSMAP * getAuxPointsMap() const
Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(), or NULL otherwise.
float aperture
The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees)...
std::vector< float > m_scan
The range values of the scan, in meters. Must have same length than validRange.
mrpt::maps::CMetricMapPtr m_cachedMap
A points map, build only under demand by the methods getAuxPointsMap() and buildAuxPointsMap().
mrpt::utils::ContainerReadOnlyProxyAccessor< std::vector< float > > scan
The range values of the scan, in meters. Must have same length than validRange.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
GLfloat GLfloat p
Definition: glext.h:5587
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot at the moment of starting the scan.
bool rightToLeft
The scanning direction: true=counterclockwise; false=clockwise.
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const MRPT_OVERRIDE
A general method to retrieve the sensor pose on the robot.
const POINTSMAP * buildAuxPointsMap(const void *options=NULL) const
Returns a cached points map representing this laser scan, building it upon the first call...



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020