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



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014