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



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.0 SVN: at Sun Sep 13 03:55:12 UTC 2015