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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019