Main MRPT website > C++ reference
MRPT logo
CSensoryFrame.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-2014, 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 CSENSORYFRAME_H
10 #define CSENSORYFRAME_H
11 
12 #include <mrpt/slam/CObservation.h>
15 
16 
17 namespace mrpt
18 {
19  namespace slam
20  {
21  class CMetricMap;
22 
23  // This must be added to any CSerializable derived class:
25 
26  /** Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximately at the same time as one "snapshot" of the environment.
27  * It can contain "observations" of many different kinds.
28  *
29  * New observations can be added using:
30  *
31  * \code
32  * CObservationXXXPtr o = CObservationXXX::Create(); // Create a smart pointer containing an object of class "CObservationXXX"
33  * o->(...)
34  *
35  * CSensoryFrame sf;
36  * sf.insert(o);
37  * \endcode
38  *
39  * The following methods are equivalent for adding new observations to a "sensory frame":
40  * - CSensoryFrame::operator +=
41  * - CSensoryFrame::push_back
42  * - CSensoryFrame::insert
43  *
44  * To examine the objects within a sensory frame, the following methods exist:
45  * - CSensoryFrame::getObservationByClass : Looks for some specific observation class.
46  * - CSensoryFrame::begin : To iterate over all observations.
47  * - CSensoryFrame::getObservationByIndex : To query by index.
48  *
49  * Notice that contained observations objects are automatically deleted on
50  * this object's destruction or clear.
51  * \sa CObservation
52  * \ingroup mrpt_obs_grp
53  */
54  class OBS_IMPEXP CSensoryFrame : public mrpt::utils::CSerializable
55  {
56  // This must be added to any CSerializable derived class:
58 
59  public:
60  /** Default constructor
61  */
62  CSensoryFrame();
63 
64  /** Copy constructor
65  */
66  CSensoryFrame( const CSensoryFrame &);
67 
68  /** @name Cached points map
69  @{ */
70  protected:
71  /** A points map, build only under demand by the methods getAuxPointsMap() and buildAuxPointsMap().
72  * It's a generic smart pointer to avoid depending here in the library mrpt-obs on classes on other libraries.
73  */
75 
76  void internal_buildAuxPointsMap( const void *options = NULL ) const; //!< Internal method, used from buildAuxPointsMap()
77 
78  public:
79 
80  /** Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(), or NULL otherwise.
81  * Usage:
82  * \code
83  * mrpt::slam::CPointsMap *map = obs->getAuxPointsMap<mrpt::slam::CPointsMap>();
84  * \endcode
85  * \sa buildAuxPointsMap
86  */
87  template <class POINTSMAP>
88  inline const POINTSMAP* getAuxPointsMap() const {
89  return static_cast<POINTSMAP*>(m_cachedMap.pointer());
90  }
91 
92  /** Returns a cached points map representing this laser scan, building it upon the first call.
93  * \param options Can be NULL to use default point maps' insertion options, or a pointer to a "CPointsMap::TInsertionOptions" structure to override some params.
94  * Usage:
95  * \code
96  * mrpt::slam::CPointsMap *map = sf->buildAuxPointsMap<mrpt::slam::CPointsMap>(&options or NULL);
97  * \endcode
98  * \sa getAuxPointsMap
99  */
100  template <class POINTSMAP>
101  inline const POINTSMAP *buildAuxPointsMap( const void *options = NULL ) const {
102  internal_buildAuxPointsMap(options);
103  return static_cast<POINTSMAP*>(m_cachedMap.pointer());
104  }
105 
106  /** @} */
107 
108 
109  /** Copy
110  */
111  CSensoryFrame& operator =( const CSensoryFrame &o);
112 
113  /** Destructor.
114  */
115  virtual ~CSensoryFrame();
116 
117  /** Clear all current observations.
118  */
119  void clear();
120 
121  /** Insert all the observations in this SF into a metric map or any kind (see mrpt::slam::CMetricMap).
122  * It calls CObservation::insertObservationInto for all stored observation.
123  * \param theMap The map where this observation is to be inserted: the map will be updated.
124  * \param robotPose The pose of the robot base for this observation, relative to the target metric map. Set to NULL (default) to use (0,0,0deg)
125  *
126  * \return Returns true if the map has been updated, or false if this observations
127  * has nothing to do with a metric map (for example, a sound observation).
128  *
129  * \sa mrpt::slam::CMetricMap, CObservation::insertObservationInto, CMetricMap::insertObservation
130  */
131  bool insertObservationsInto( mrpt::slam::CMetricMap *theMap, const CPose3D *robotPose = NULL ) const;
132 
133  /** Insert all the observations in this SF into a metric map or any kind (see mrpt::slam::CMetricMap).
134  * It calls CObservation::insertObservationInto for all stored observation.
135  * \param theMap The map where this observation is to be inserted: the map will be updated.
136  * \param robotPose The pose of the robot base for this observation, relative to the target metric map. Set to NULL (default) to use (0,0,0deg)
137  *
138  * \return Returns true if the map has been updated, or false if this observations
139  * has nothing to do with a metric map (for example, a sound observation).
140  *
141  * \sa mrpt::slam::CMetricMap, CObservation::insertObservationInto, CMetricMap::insertObservation
142  */
143  inline bool insertObservationsInto( mrpt::slam::CMetricMapPtr &theMap, const CPose3D *robotPose = NULL ) const
144  {
145  return insertObservationsInto(theMap.pointer(), robotPose);
146  }
147 
148 
149  /** You can use "sf1+=sf2;" to add observations in sf2 to sf1. Objects are copied, not referenced, thus the source can be safely deleted next.
150  * \sa moveFrom
151  */
152  void operator += (const CSensoryFrame &sf);
153 
154  /** You can use "sf+=obs;" to add the observation "obs" to the "sf1". Objects are copied, using the smart pointer, thus the original pointer can be safely deleted next.
155  * \sa moveFrom
156  */
157  void operator += (const CObservationPtr &obs);
158 
159  /** Copies all the observation from another object, then erase them from the origin object (this method is fast since only pointers are copied); Previous objects in this objects are not deleted.
160  * \sa operator +=
161  */
162  void moveFrom(CSensoryFrame &sf);
163 
164  /** Inserts a new observation to the list: The pointer to the objects is copied, thus DO NOT delete the passed object, this class will do at destructor or when appropriate.
165  */
166  void push_back(const CObservationPtr &obs);
167 
168  /** Inserts a new observation to the list: The pointer to the objects is copied, thus DO NOT delete the passed object, this class will do at destructor or when appropriate.
169  */
170  void insert(const CObservationPtr &obs);
171 
172  /** Returns the i'th observation of a given class (or of a descendant class), or NULL if there is no such observation in the array.
173  * Example:
174  * \code
175  CObservationImagePtr obs = m_SF->getObservationByClass<CObservationImage>();
176  * \endcode
177  * By default (ith=0), the first observation is returned.
178  */
179  template <typename T>
180  typename T::SmartPtr getObservationByClass( const size_t &ith = 0 ) const
181  {
182  MRPT_START
183  size_t foundCount = 0;
184  const mrpt::utils::TRuntimeClassId* class_ID = T::classinfo;
185  for (const_iterator it = begin();it!=end();++it)
186  if ( (*it)->GetRuntimeClass()->derivedFrom( class_ID ) )
187  if (foundCount++ == ith)
188  return typename T::SmartPtr(*it);
189  return typename T::SmartPtr(); // Not found: return empty smart pointer
190  MRPT_END
191  }
192 
193  /** You can use CSensoryFrame::begin to get a iterator to the first element.
194  */
196 
197  /** You can use CSensoryFrame::begin to get a iterator to the first element.
198  */
200 
201  /** Returns a iterator to the first observation: this is an example of usage:
202  * \code
203  * CSensoryFrame sf;
204  * ...
205  * for (CSensoryFrame::iterator it=sf.begin();it!=sf.end();++it)
206  * {
207  * (*it)->... // (*it) is a "CObservation*"
208  * }
209  *
210  * \endcode
211  */
212  const_iterator begin() const { return m_observations.begin(); }
213 
214  /** Returns a iterator to the end of the list of observations: this is an example of usage:
215  * \code
216  * CSensoryFrame sf;
217  * ...
218  * for (CSensoryFrame::iterator it=sf.begin();it!=sf.end();++it)
219  * {
220  * (*it)->... // (*it) is a "CObservation*"
221  * }
222  *
223  * \endcode
224  */
225  const_iterator end() const { return m_observations.end(); }
226 
227  /** Returns a iterator to the first observation: this is an example of usage:
228  * \code
229  * CSensoryFrame sf;
230  * ...
231  * for (CSensoryFrame::iterator it=sf.begin();it!=sf.end();++it)
232  * {
233  * (*it)->... // (*it) is a "CObservation*"
234  * }
235  *
236  * \endcode
237  */
238  iterator begin() { return m_observations.begin(); }
239 
240  /** Returns a iterator to the end of the list of observations: this is an example of usage:
241  * \code
242  * CSensoryFrame sf;
243  * ...
244  * for (CSensoryFrame::iterator it=sf.begin();it!=sf.end();++it)
245  * {
246  * (*it)->... // (*it) is a "CObservation*"
247  * }
248  *
249  * \endcode
250  */
251  inline iterator end() { return m_observations.end(); }
252 
253 
254  /** Returns the number of observations in the list. */
255  inline size_t size() const { return m_observations.size(); }
256 
257  /** Returns true if there are no observations in the list. */
258  inline bool empty() const { return m_observations.empty(); }
259 
260  /** Removes the i'th observation in the list (0=first). */
261  void eraseByIndex(const size_t &idx);
262 
263  /** Removes the given observation in the list, and return an iterator to the next element (or this->end() if it was the last one).
264  */
265  iterator erase( const iterator &it);
266 
267  /** Removes all the observations that match a given sensorLabel.
268  */
269  void eraseByLabel(const std::string &label);
270 
271  /** Returns the i'th observation in the list (0=first).
272  * \sa begin, size
273  */
274  CObservationPtr getObservationByIndex( const size_t &idx ) const;
275 
276  /** Returns the i'th observation in the list (0=first), and as a different smart pointer type:
277  * \code
278  * sf.getObservationByIndexAs<CObservationStereoImagesPtr>(i);
279  * \endcode
280  * \sa begin, size
281  */
282  template <typename T>
283  T getObservationByIndexAs( const size_t &idx ) const
284  {
285  return static_cast<T>(getObservationByIndex(idx));
286  }
287 
288  /** Returns the i'th observation in the list with the given "sensorLabel" (0=first).
289  * \return The observation, or NULL if not found.
290  * \sa begin, size
291  */
292  CObservationPtr getObservationBySensorLabel( const std::string &label, const size_t &idx = 0) const;
293 
294  /** Returns the i'th observation in the list with the given "sensorLabel" (0=first), and as a different smart pointer type:
295  * \code
296  * sf.getObservationBySensorLabelAs<CObservationStereoImagesPtr>(i);
297  * \endcode
298  * \sa begin, size
299  */
300  template <typename T>
301  T getObservationBySensorLabelAs( const std::string &label, const size_t &idx = 0) const
302  {
303  return T(getObservationBySensorLabel(label,idx));
304  }
305 
306  /** Efficiently swaps the contents of two objects.
307  */
308  void swap( CSensoryFrame &sf );
309 
310  protected:
311  /** The set of observations taken at the same time instant. See the top of this page for instructions on accessing this.
312  */
313  //std::deque<CObservation*> m_observations;
314  std::deque<CObservationPtr> m_observations;
315 
316  }; // End of class def.
317 
318 
319  } // End of namespace
320 } // End of namespace
321 
322 #endif
const POINTSMAP * buildAuxPointsMap(const void *options=NULL) const
Returns a cached points map representing this laser scan, building it upon the first call...
T getObservationByIndexAs(const size_t &idx) const
Returns the i&#39;th observation in the list (0=first), and as a different smart pointer type: ...
EIGEN_STRONG_INLINE iterator end()
Definition: eigen_plugins.h:27
size_t size() const
Returns the number of observations in the list.
const_iterator end() const
Returns a iterator to the end of the list of observations: this is an example of usage: ...
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:32
Scalar * iterator
Definition: eigen_plugins.h:23
const POINTSMAP * getAuxPointsMap() const
Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(), or NULL otherwise.
Definition: CSensoryFrame.h:88
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
EIGEN_STRONG_INLINE void push_back(Scalar val)
Insert an element at the end of the container (for 1D vectors/arrays)
const_iterator begin() const
Returns a iterator to the first observation: this is an example of usage:
const Scalar * const_iterator
Definition: eigen_plugins.h:24
T getObservationBySensorLabelAs(const std::string &label, const size_t &idx=0) const
Returns the i&#39;th observation in the list with the given "sensorLabel" (0=first), and as a different s...
T::SmartPtr getObservationByClass(const size_t &ith=0) const
Returns the i&#39;th observation of a given class (or of a descendant class), or NULL if there is no such...
std::deque< CObservationPtr >::const_iterator const_iterator
You can use CSensoryFrame::begin to get a iterator to the first element.
Declares a virtual base class for all metric maps storage classes.
Definition: CMetricMap.h:90
iterator end()
Returns a iterator to the end of the list of observations: this is an example of usage: ...
#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...
#define MRPT_END
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
Definition: ops_vectors.h:64
CMetricMap * pointer()
Definition: CMetricMap.h:71
mrpt::slam::CMetricMapPtr m_cachedMap
A points map, build only under demand by the methods getAuxPointsMap() and buildAuxPointsMap().
Definition: CSensoryFrame.h:74
iterator begin()
Returns a iterator to the first observation: this is an example of usage:
#define MRPT_START
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...
bool empty() const
Returns true if there are no observations in the list.
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:54
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:71
std::deque< CObservationPtr >::iterator iterator
You can use CSensoryFrame::begin to get a iterator to the first element.
A structure that holds runtime class type information.
Definition: CObject.h:42
bool insertObservationsInto(mrpt::slam::CMetricMapPtr &theMap, const CPose3D *robotPose=NULL) const
Insert all the observations in this SF into a metric map or any kind (see mrpt::slam::CMetricMap).
std::deque< CObservationPtr > m_observations
The set of observations taken at the same time instant.



Page generated by Doxygen 1.8.14 for MRPT 1.1.0 SVN: at lun oct 28 00:54:49 CET 2019 Hosted on:
SourceForge.net Logo