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