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-2018, 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() = default;
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  /** Clear all current observations.
123  */
124  void clear();
125 
126  /** Insert all the observations in this SF into a metric map or any kind
127  *(see mrpt::maps::CMetricMap).
128  * It calls CObservation::insertObservationInto for all stored observation.
129  * \param theMap The map where this observation is to be inserted: the map
130  *will be updated.
131  * \param robotPose The pose of the robot base for this observation,
132  *relative to the target metric map. Set to nullptr (default) to use
133  *(0,0,0deg)
134  *
135  * \return Returns true if the map has been updated, or false if this
136  *observations
137  * has nothing to do with a metric map (for example, a sound
138  *observation).
139  *
140  * \sa mrpt::maps::CMetricMap, CObservation::insertObservationInto,
141  *CMetricMap::insertObservation
142  */
144  mrpt::maps::CMetricMap* theMap,
145  const mrpt::poses::CPose3D* robotPose = nullptr) const;
146 
147  /** Insert all the observations in this SF into a metric map or any kind
148  *(see mrpt::maps::CMetricMap).
149  * It calls CObservation::insertObservationInto for all stored observation.
150  * \param theMap The map where this observation is to be inserted: the map
151  *will be updated.
152  * \param robotPose The pose of the robot base for this observation,
153  *relative to the target metric map. Set to nullptr (default) to use
154  *(0,0,0deg)
155  *
156  * \return Returns true if the map has been updated, or false if this
157  *observations
158  * has nothing to do with a metric map (for example, a sound
159  *observation).
160  *
161  * \sa mrpt::maps::CMetricMap, CObservation::insertObservationInto,
162  *CMetricMap::insertObservation
163  */
166  const mrpt::poses::CPose3D* robotPose = nullptr) const
167  {
168  return insertObservationsInto(theMap.get(), robotPose);
169  }
170 
171  /** You can use "sf1+=sf2;" to add observations in sf2 to sf1. Objects are
172  * copied, not referenced, thus the source can be safely deleted next.
173  * \sa moveFrom
174  */
175  void operator+=(const CSensoryFrame& sf);
176 
177  /** You can use "sf+=obs;" to add the observation "obs" to the "sf1".
178  * Objects are copied, using the smart pointer, thus the original pointer
179  * can be safely deleted next.
180  * \sa moveFrom
181  */
182  void operator+=(const CObservation::Ptr& obs);
183 
184  /** Copies all the observation from another object, then erase them from the
185  * origin object (this method is fast since only pointers are copied);
186  * Previous objects in this objects are not deleted.
187  * \sa operator +=
188  */
189  void moveFrom(CSensoryFrame& sf);
190 
191  /** Inserts a new observation to the list: The pointer to the objects is
192  * copied, thus DO NOT delete the passed object, this class will do at
193  * destructor or when appropriate.
194  */
195  void push_back(const CObservation::Ptr& obs);
196 
197  /** Inserts a new observation to the list: The pointer to the objects is
198  * copied, thus DO NOT delete the passed object, this class will do at
199  * destructor or when appropriate.
200  */
201  void insert(const CObservation::Ptr& obs);
202 
203  /** Returns the i'th observation of a given class (or of a descendant
204  class), or nullptr if there is no such observation in the array.
205  * Example:
206  * \code
207  CObservationImage::Ptr obs =
208  m_SF->getObservationByClass<CObservationImage>();
209  * \endcode
210  * By default (ith=0), the first observation is returned.
211  */
212  template <typename T>
213  typename T::Ptr getObservationByClass(const size_t& ith = 0) const
214  {
215  MRPT_START
216  size_t foundCount = 0;
217  const mrpt::rtti::TRuntimeClassId* class_ID =
218  &T::GetRuntimeClassIdStatic();
219  for (const_iterator it = begin(); it != end(); ++it)
220  if ((*it)->GetRuntimeClass()->derivedFrom(class_ID))
221  if (foundCount++ == ith)
222  return std::dynamic_pointer_cast<T>(*it);
223  return typename T::Ptr(); // Not found: return empty smart pointer
224  MRPT_END
225  }
226 
227  /** You can use CSensoryFrame::begin to get a iterator to the first element.
228  */
230 
231  /** You can use CSensoryFrame::begin to get a iterator to the first element.
232  */
234 
235  /** Returns a constant iterator to the first observation: this is an example
236  *of usage:
237  * \code
238  * CSensoryFrame sf;
239  * ...
240  * for (CSensoryFrame::const_iterator it=sf.begin();it!=sf.end();++it)
241  * {
242  * (*it)->... // (*it) is a "CObservation*"
243  * }
244  *
245  * \endcode
246  */
247  const_iterator begin() const { return m_observations.begin(); }
248  /** Returns a constant iterator to the end of the list of observations: this
249  *is an example of usage:
250  * \code
251  * CSensoryFrame sf;
252  * ...
253  * for (CSensoryFrame::const_iterator it=sf.begin();it!=sf.end();++it)
254  * {
255  * (*it)->... // (*it) is a "CObservation*"
256  * }
257  *
258  * \endcode
259  */
260  const_iterator end() const { return m_observations.end(); }
261  /** Returns a iterator to the first observation: this is an example of
262  *usage:
263  * \code
264  * CSensoryFrame sf;
265  * ...
266  * for (CSensoryFrame::iterator it=sf.begin();it!=sf.end();++it)
267  * {
268  * (*it)->... // (*it) is a "CObservation*"
269  * }
270  *
271  * \endcode
272  */
273  iterator begin() { return m_observations.begin(); }
274  /** Returns a iterator to the end of the list of observations: this is an
275  *example of usage:
276  * \code
277  * CSensoryFrame sf;
278  * ...
279  * for (CSensoryFrame::iterator it=sf.begin();it!=sf.end();++it)
280  * {
281  * (*it)->... // (*it) is a "CObservation*"
282  * }
283  *
284  * \endcode
285  */
286  inline iterator end() { return m_observations.end(); }
287  /** Returns the number of observations in the list. */
288  inline size_t size() const { return m_observations.size(); }
289  /** Returns true if there are no observations in the list. */
290  inline bool empty() const { return m_observations.empty(); }
291  /** Removes the i'th observation in the list (0=first). */
292  void eraseByIndex(const size_t& idx);
293 
294  /** Removes the given observation in the list, and return an iterator to the
295  * next element (or this->end() if it was the last one).
296  */
297  iterator erase(const iterator& it);
298 
299  /** Removes all the observations that match a given sensorLabel.
300  */
301  void eraseByLabel(const std::string& label);
302 
303  /** Returns the i'th observation in the list (0=first).
304  * \sa begin, size
305  */
306  CObservation::Ptr getObservationByIndex(const size_t& idx) const;
307 
308  /** Returns the i'th observation in the list (0=first), and as a different
309  * smart pointer type:
310  * \code
311  * sf.getObservationByIndexAs<CObservationStereoImages::Ptr>(i);
312  * \endcode
313  * \sa begin, size
314  */
315  template <typename T>
316  T getObservationByIndexAs(const size_t& idx) const
317  {
318  return std::dynamic_pointer_cast<typename T::element_type>(
319  getObservationByIndex(idx));
320  }
321 
322  /** Returns the i'th observation in the list with the given "sensorLabel"
323  * (0=first).
324  * \return The observation, or nullptr if not found.
325  * \sa begin, size
326  */
328  const std::string& label, const size_t& idx = 0) const;
329 
330  /** Returns the i'th observation in the list with the given "sensorLabel"
331  * (0=first), and as a different smart pointer type:
332  * \code
333  * sf.getObservationBySensorLabelAs<CObservationStereoImages::Ptr>(i);
334  * \endcode
335  * \sa begin, size
336  */
337  template <typename T>
339  const std::string& label, const size_t& idx = 0) const
340  {
341  return std::dynamic_pointer_cast<typename T::element_type>(
342  getObservationBySensorLabel(label, idx));
343  }
344 
345  /** Efficiently swaps the contents of two objects.
346  */
347  void swap(CSensoryFrame& sf);
348 
349  protected:
350  /** The set of observations taken at the same time instant. See the top of
351  * this page for instructions on accessing this.
352  */
353  // std::deque<CObservation*> m_observations;
354  std::deque<CObservation::Ptr> m_observations;
355 
356 }; // End of class def.
357 
358 } // End of namespace
359 } // End of namespace
360 
361 #endif
mrpt::obs::CSensoryFrame::empty
bool empty() const
Returns true if there are no observations in the list.
Definition: CSensoryFrame.h:290
mrpt::obs::CObservation::Ptr
std::shared_ptr< CObservation > Ptr
Definition: CObservation.h:45
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
mrpt::rtti::TRuntimeClassId
A structure that holds runtime class type information.
Definition: CObject.h:30
mrpt::obs::CSensoryFrame::clear
void clear()
Clear all current observations.
Definition: CSensoryFrame.cpp:42
mrpt::obs::CSensoryFrame::m_cachedMap
mrpt::maps::CMetricMap::Ptr m_cachedMap
A points map, build only under demand by the methods getAuxPointsMap() and buildAuxPointsMap().
Definition: CSensoryFrame.h:75
mrpt::obs::CSensoryFrame::CSensoryFrame
CSensoryFrame()=default
Default constructor.
mrpt::obs::CSensoryFrame::end
const_iterator end() const
Returns a constant iterator to the end of the list of observations: this is an example of usage:
Definition: CSensoryFrame.h:260
mrpt::obs::CSensoryFrame::m_observations
std::deque< CObservation::Ptr > m_observations
The set of observations taken at the same time instant.
Definition: CSensoryFrame.h:354
mrpt::obs::CSensoryFrame::getAuxPointsMap
const POINTSMAP * getAuxPointsMap() const
Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(),...
Definition: CSensoryFrame.h:91
mrpt::obs::CSensoryFrame::getObservationBySensorLabel
CObservation::Ptr getObservationBySensorLabel(const std::string &label, const size_t &idx=0) const
Returns the i'th observation in the list with the given "sensorLabel" (0=first).
Definition: CSensoryFrame.cpp:195
mrpt::obs::CSensoryFrame::insertObservationsInto
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).
Definition: CSensoryFrame.cpp:280
mrpt::obs::CSensoryFrame::swap
void swap(CSensoryFrame &sf)
Efficiently swaps the contents of two objects.
Definition: CSensoryFrame.cpp:225
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::obs::CSensoryFrame::getObservationByIndexAs
T getObservationByIndexAs(const size_t &idx) const
Returns the i'th observation in the list (0=first), and as a different smart pointer type:
Definition: CSensoryFrame.h:316
CMetricMap.h
mrpt::obs::CSensoryFrame::erase
iterator erase(const iterator &it)
Removes the given observation in the list, and return an iterator to the next element (or this->end()...
Definition: CSensoryFrame.cpp:182
mrpt::obs::CSensoryFrame::size
size_t size() const
Returns the number of observations in the list.
Definition: CSensoryFrame.h:288
mrpt::obs::CSensoryFrame
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:54
mrpt::maps::CMetricMap
Declares a virtual base class for all metric maps storage classes.
Definition: CMetricMap.h:56
mrpt::obs::CSensoryFrame::end
iterator end()
Returns a iterator to the end of the list of observations: this is an example of usage:
Definition: CSensoryFrame.h:286
mrpt::obs::CSensoryFrame::internal_buildAuxPointsMap
void internal_buildAuxPointsMap(const void *options=nullptr) const
Internal method, used from buildAuxPointsMap()
Definition: CSensoryFrame.cpp:266
mrpt::obs::CSensoryFrame::moveFrom
void moveFrom(CSensoryFrame &sf)
Copies all the observation from another object, then erase them from the origin object (this method i...
Definition: CSensoryFrame.cpp:213
mrpt::obs::CSensoryFrame::begin
const_iterator begin() const
Returns a constant iterator to the first observation: this is an example of usage:
Definition: CSensoryFrame.h:247
mrpt::obs::CSensoryFrame::operator+=
void operator+=(const CSensoryFrame &sf)
You can use "sf1+=sf2;" to add observations in sf2 to sf1.
Definition: CSensoryFrame.cpp:105
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::obs::CSensoryFrame::getObservationByClass
T::Ptr getObservationByClass(const size_t &ith=0) const
Returns the i'th observation of a given class (or of a descendant class), or nullptr if there is no s...
Definition: CSensoryFrame.h:213
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::serialization::CSerializable
The virtual base class which provides a unified interface for all persistent objects in MRPT.
Definition: CSerializable.h:32
mrpt::obs::CSensoryFrame::insert
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...
Definition: CSensoryFrame.cpp:139
mrpt::maps::CMetricMap::Ptr
std::shared_ptr< CMetricMap > Ptr
Definition: CMetricMap.h:59
mrpt::obs::CSensoryFrame::eraseByIndex
void eraseByIndex(const size_t &idx)
Removes the i'th observation in the list (0=first).
Definition: CSensoryFrame.cpp:148
mrpt::obs::CSensoryFrame::const_iterator
std::deque< CObservation::Ptr >::const_iterator const_iterator
You can use CSensoryFrame::begin to get a iterator to the first element.
Definition: CSensoryFrame.h:233
mrpt::obs::CSensoryFrame::push_back
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...
Definition: CSensoryFrame.cpp:130
mrpt::obs::CSensoryFrame::iterator
std::deque< CObservation::Ptr >::iterator iterator
You can use CSensoryFrame::begin to get a iterator to the first element.
Definition: CSensoryFrame.h:229
mrpt::obs::CSensoryFrame::buildAuxPointsMap
const POINTSMAP * buildAuxPointsMap(const void *options=nullptr) const
Returns a cached points map representing this laser scan, building it upon the first call.
Definition: CSensoryFrame.h:109
mrpt::obs::CSensoryFrame::insertObservationsInto
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).
Definition: CSensoryFrame.h:164
mrpt::obs::CSensoryFrame::getObservationBySensorLabelAs
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...
Definition: CSensoryFrame.h:338
mrpt::obs::CSensoryFrame::getObservationByIndex
CObservation::Ptr getObservationByIndex(const size_t &idx) const
Returns the i'th observation in the list (0=first).
Definition: CSensoryFrame.cpp:166
mrpt::obs::CSensoryFrame::operator=
CSensoryFrame & operator=(const CSensoryFrame &o)
Copy.
Definition: CSensoryFrame.cpp:31
CObservation.h
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
mrpt::obs::CSensoryFrame::eraseByLabel
void eraseByLabel(const std::string &label)
Removes all the observations that match a given sensorLabel.
Definition: CSensoryFrame.cpp:234
string
GLsizei const GLchar ** string
Definition: glext.h:4101
iterator
Scalar * iterator
Definition: eigen_plugins.h:26
CSerializable.h
mrpt::obs::CSensoryFrame::begin
iterator begin()
Returns a iterator to the first observation: this is an example of usage:
Definition: CSensoryFrame.h:273



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST