Main MRPT website > C++ reference for MRPT 1.5.6
obs/CActionCollection.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 CActionCollection_H
10 #define CActionCollection_H
11 
12 #include <mrpt/obs/CAction.h>
17 
18 namespace mrpt
19 {
20  namespace obs
21  {
22  // This must be added to any CSerializable derived class:
24 
25  /** Declares a class for storing a collection of robot actions. It is used in mrpt::obs::CRawlog,
26  * for logs storage and particle filter based simulations.
27  *
28  * \sa CAction, CRawlog
29  * \ingroup mrpt_obs_grp
30  */
31  class OBS_IMPEXP CActionCollection : public mrpt::utils::CSerializable
32  {
33  // This must be added to any CSerializable derived class:
35 
36  protected:
37  std::deque<mrpt::utils::poly_ptr_ptr<CActionPtr> > m_actions; //!< The robot "actionss"
38 
39  public:
40  CActionCollection(); //!< ctor
41  CActionCollection( CAction &a ); //!< Constructor from a single action.
42 
43  /** You can use CActionCollection::begin to get a iterator to the first element.
44  */
45  typedef std::deque<mrpt::utils::poly_ptr_ptr<CActionPtr> >::iterator iterator;
46 
47  /** You can use CActionCollection::begin to get a iterator to the first element.
48  */
49  typedef std::deque<mrpt::utils::poly_ptr_ptr<CActionPtr> >::const_iterator const_iterator;
50 
51  /** Returns a iterator to the first action: this is an example of usage:
52  * \code
53  * CActionCollection acts;
54  * ...
55  * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
56  * {
57  * (*it)->... // (*it) is a "CActionPtr"
58  * }
59  *
60  * \endcode
61  */
62  const_iterator begin() const { return m_actions.begin(); }
63 
64  /** Returns a iterator to the first action: this is an example of usage:
65  * \code
66  * CActionCollection acts;
67  * ...
68  * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
69  * {
70  * (*it)->... // (*it) is a "CActionPtr"
71  * }
72  *
73  * \endcode
74  */
75  iterator begin() { return m_actions.begin(); }
76 
77  /** Returns a iterator pointing to the end of the list: this is an example of usage:
78  * \code
79  * CActionCollection acts;
80  * ...
81  * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
82  * {
83  * (*it)->... // (*it) is a "CActionPtr"
84  * }
85  *
86  * \endcode
87  */
88  const_iterator end() const { return m_actions.end(); }
89 
90  /** Returns a iterator pointing to the end of the list: this is an example of usage:
91  * \code
92  * CActionCollection acts;
93  * ...
94  * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
95  * {
96  * (*it)->... // (*it) is a "CActionPtr"
97  * }
98  *
99  * \endcode
100  */
101  iterator end() { return m_actions.end(); }
102 
103 
104  /** Removes the given action in the list, and return an iterator to the next element (or this->end() if it was the last one).
105  */
106  iterator erase( const iterator &it);
107 
108  /** Erase all actions from the list.
109  */
110  void clear();
111 
112  /** Access the i'th action.DO NOT MODIFY the returned object, make a copy of ir with "CSerializable::duplicate" if desired.
113  * First element is 0.
114  * \exception std::exception On index out of bounds.
115  */
116  CActionPtr get(size_t index);
117  const CAction& get(size_t index) const;
118 
119  /** Access to the i'th action of a given class, or a NULL smart pointer if there is no action of that class in the list.
120  * Example:
121  * \code
122  CActionRobotMovement2DPtr obs = acts->getActionByClass<CActionRobotMovement2D>();
123  * \endcode
124  * By default (ith=0), the first one is returned.
125  */
126  template <typename T>
127  typename T::Ptr getActionByClass( const size_t &ith = 0 ) const
128  {
129  MRPT_START
130  size_t foundCount = 0;
131  const mrpt::utils::TRuntimeClassId* class_ID = T::classinfo;
132  for (const_iterator it = begin();it!=end();++it)
133  if ( (*it)->GetRuntimeClass()->derivedFrom( class_ID ) )
134  if (foundCount++ == ith)
135  return typename T::Ptr(it->get_ptr());
136  return typename T::Ptr(); // Not found: return empty smart pointer
137  MRPT_END
138  }
139 
140 
141  /** Add a new object to the list.
142  */
143  void insert(CAction &action);
144 
145  /** Returns the actions count in the collection.
146  */
147  size_t size();
148 
149  /** Returns the best pose increment estimator in the collection, based on the determinant of its pose change covariance matrix.
150  * \return The estimation, or NULL if none is available.
151  */
152  CActionRobotMovement2DPtr getBestMovementEstimation() const;
153 
154  /** Returns the pose increment estimator in the collection having the specified type.
155  * \return The estimation, or NULL if none is available.
156  */
157  CActionRobotMovement2DPtr getMovementEstimationByType( CActionRobotMovement2D::TEstimationMethod method);
158 
159  /** Look for the first 2D or 3D "odometry" found in this collection of actions, and return the "mean" increment of the robot according to it.
160  * \return true on success,false on no odometry found.
161  */
162  bool getFirstMovementEstimationMean( mrpt::poses::CPose3D &out_pose_increment ) const;
163 
164  /** Look for the first 2D or 3D "odometry" found in this collection of actions, and return the "mean" increment of the robot and its covariance according to it.
165  * \return true on success,false on no odometry found.
166  */
167  bool getFirstMovementEstimation( mrpt::poses::CPose3DPDFGaussian &out_pose_increment ) const;
168 
169  /** Remove an action from the list by its index.
170  * \exception std::exception On index out of bounds.
171  */
172  void eraseByIndex(const size_t & index);
173 
174 
175  }; // End of class def.
177 
178 
179  } // End of namespace
180 } // End of namespace
181 
182 #endif
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:5406
iterator begin()
Returns a iterator to the first action: this is an example of usage:
const_iterator end() const
Returns a iterator pointing to the end of the list: this is an example of usage:
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
T::Ptr getActionByClass(const size_t &ith=0) const
Access to the i'th action of a given class, or a NULL smart pointer if there is no action of that cla...
std::deque< mrpt::utils::poly_ptr_ptr< CActionPtr > >::const_iterator const_iterator
You can use CActionCollection::begin to get a iterator to the first element.
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:113
Declares a class for storing a collection of robot actions.
std::deque< mrpt::utils::poly_ptr_ptr< CActionPtr > >::iterator iterator
You can use CActionCollection::begin to get a iterator to the first element.
#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...
GLuint GLuint end
Definition: glew.h:1167
#define MRPT_END
TEstimationMethod
A list of posible ways for estimating the content of a CActionRobotMovement2D object.
Declares a class for storing a robot action.
Definition: obs/CAction.h:33
GLsizeiptr size
Definition: glew.h:1586
#define MRPT_START
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
GLuint index
Definition: glew.h:1721
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
iterator end()
Returns a iterator pointing to the end of the list: this is an example of usage:
Declares a class that represents a Probability Density function (PDF) of a 3D pose ...
A structure that holds runtime class type information.
Definition: CObject.h:46
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018