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



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020