Main MRPT website > C++ reference for MRPT 1.4.0
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-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 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>
18 
19 // Add for declaration of mexplus::from template specialization
21 
22 namespace mrpt
23 {
24 namespace obs
25 {
26  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CObservation2DRangeScan, CObservation, OBS_IMPEXP)
27 
28  /** A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser scanner).
29  * The data structures are generic enough to hold a wide variety of 2D scanners and "3D" planar rotating 2D lasers.
30  *
31  * These are the most important data fields:
32  * - CObservation2DRangeScan::scan -> A vector of float values with all the range measurements (in meters).
33  * - CObservation2DRangeScan::validRange -> A vector (of <b>identical size</b> than <i>scan<i>), has non-zeros for those ranges than are valid (i.e. will be zero for non-reflected rays, etc.)
34  * - CObservation2DRangeScan::aperture -> The field-of-view of the scanner, in radians (typically, M_PI = 180deg).
35  * - CObservation2DRangeScan::sensorPose -> The 6D location of the sensor on the robot reference frame (default=at the origin).
36  *
37  * \sa CObservation, CPointsMap, T2DScanProperties
38  * \ingroup mrpt_obs_grp
39  */
41  {
42  // This must be added to any CSerializable derived class:
44  // This must be added for declaration of MEX-related functions
46 
47  public:
48  typedef std::vector<mrpt::math::CPolygon> TListExclusionAreas; //!< Used in filterByExclusionAreas
49  typedef std::vector<std::pair<mrpt::math::CPolygon,std::pair<double,double> > > TListExclusionAreasWithRanges; //!< Used in filterByExclusionAreas
50 
51  /** Default constructor */
53 
54  /** Destructor */
55  virtual ~CObservation2DRangeScan( );
56 
57 
58  /** @name Scan data
59  @{ */
60  std::vector<float> scan; //!< The range values of the scan, in meters. Must have same length than \a validRange
61  std::vector<char> validRange; //!< It's false (=0) on no reflected rays, referenced to elements in \a scan
62  float aperture; //!< The "aperture" or field-of-view of the range finder, in radians (typically M_PI = 180 degrees).
63  bool rightToLeft; //!< The scanning direction: true=counterclockwise; false=clockwise
64  float maxRange; //!< The maximum range allowed by the device, in meters (e.g. 80m, 50m,...)
65  mrpt::poses::CPose3D sensorPose; //!< The 6D pose of the sensor on the robot at the moment of starting the scan.
66  float stdError; //!< The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid.
67  float beamAperture; //!< The aperture of each beam, in radians, used to insert "thick" rays in the occupancy grid.
68  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).
69 
70  void getScanProperties(T2DScanProperties& p) const; //!< Fill out a T2DScanProperties structure with the parameters of this scan
71  /** @} */
72 
73  /** @name Cached points map
74  @{ */
75  protected:
76  /** A points map, build only under demand by the methods getAuxPointsMap() and buildAuxPointsMap().
77  * It's a generic smart pointer to avoid depending here in the library mrpt-obs on classes on other libraries.
78  */
79  mutable mrpt::maps::CMetricMapPtr m_cachedMap;
80 
81  void internal_buildAuxPointsMap( const void *options = NULL ) const; //!< Internal method, used from buildAuxPointsMap()
82 
83  public:
84 
85  /** Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(), or NULL otherwise.
86  * Usage:
87  * \code
88  * mrpt::maps::CPointsMap *map = obs->getAuxPointsMap<mrpt::maps::CPointsMap>();
89  * \endcode
90  * \sa buildAuxPointsMap
91  */
92  template <class POINTSMAP>
93  inline const POINTSMAP* getAuxPointsMap() const {
94  return static_cast<const POINTSMAP*>(m_cachedMap.pointer());
95  }
96 
97  /** Returns a cached points map representing this laser scan, building it upon the first call.
98  * \param options Can be NULL to use default point maps' insertion options, or a pointer to a "CPointsMap::TInsertionOptions" structure to override some params.
99  * Usage:
100  * \code
101  * mrpt::maps::CPointsMap *map = obs->buildAuxPointsMap<mrpt::maps::CPointsMap>(&options or NULL);
102  * \endcode
103  * \sa getAuxPointsMap
104  */
105  template <class POINTSMAP>
106  inline const POINTSMAP *buildAuxPointsMap( const void *options = NULL ) const {
107  if (!m_cachedMap.present()) internal_buildAuxPointsMap(options);
108  return static_cast<const POINTSMAP*>(m_cachedMap.pointer());
109  }
110 
111  /** @} */
112 
113 
114 
115  /** 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).
116  */
117  bool isPlanarScan(const double tolerance = 0) const;
118 
119  // See base class docs
120  void getSensorPose( mrpt::poses::CPose3D &out_sensorPose ) const MRPT_OVERRIDE { out_sensorPose = sensorPose; }
121  void setSensorPose( const mrpt::poses::CPose3D &newSensorPose ) MRPT_OVERRIDE { sensorPose = newSensorPose; }
122  void getDescriptionAsText(std::ostream &o) const MRPT_OVERRIDE;
123 
124  /** 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
125  (NOTE: the laser z-coordinate must be provided).
126  */
127  void truncateByDistanceAndAngle(float min_distance, float max_angle, float min_height = 0, float max_height = 0, float h = 0 );
128 
129  /** 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").
130  * \sa C2DRangeFinderAbstract::loadExclusionAreas
131  */
132  void filterByExclusionAreas( const TListExclusionAreas &areas );
133 
134  /** 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.
135  * \sa C2DRangeFinderAbstract::loadExclusionAreas
136  */
137  void filterByExclusionAreas( const TListExclusionAreasWithRanges &areas );
138 
139  /** Mark as invalid the ranges in any of a given set of "forbiden angle ranges", given as pairs<min_angle,max_angle>.
140  * \sa C2DRangeFinderAbstract::loadExclusionAreas
141  */
142  void filterByExclusionAngles( const std::vector<std::pair<double,double> > &angles );
143 
144  }; // End of class def.
146 
147  } // End of namespace
148  namespace utils
149  {
150  // Specialization must occur in the same namespace
152  }
153 
154 } // End of namespace
155 
156 #endif
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
#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.
STL namespace.
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) MRPT_OVERRIDE
A general method to change the sensor pose on the robot.
#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...
This namespace contains representation of robot actions and observations.
const POINTSMAP * buildAuxPointsMap(const void *options=NULL) const
Returns a cached points map representing this laser scan, building it upon the first call...
#define MRPT_DECLARE_TTYPENAME_PTR_NAMESPACE(_TYPE, __NS)
Definition: TTypeName.h:72
std::vector< mrpt::math::CPolygon > TListExclusionAreas
Used in filterByExclusionAreas.
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.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const MRPT_OVERRIDE
A general method to retrieve the sensor pose on the robot.



Page generated by Doxygen 1.8.11 for MRPT 1.4.0 SVN: at Mon Aug 15 11:50:21 UTC 2016