Main MRPT website > C++ reference
MRPT logo
CActionCollection.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CActionCollection_H
29 #define CActionCollection_H
30 
31 #include <mrpt/slam/CAction.h>
35 
36 namespace mrpt
37 {
38  namespace slam
39  {
40  // This must be added to any CSerializable derived class:
42 
43  /** Declares a class for storing a collection of robot actions. It is used in mrpt::slam::CRawlog,
44  * for logs storage and particle filter based simulations.
45  *
46  * \sa CAction, CRawlog
47  * \ingroup mrpt_obs_grp
48  */
49  class OBS_IMPEXP CActionCollection : public mrpt::utils::CSerializable
50  {
51  // This must be added to any CSerializable derived class:
53 
54  protected:
55  /** The actions:
56  */
57  std::deque<CActionPtr> m_actions;
58 
59  public:
60  /** Constructor
61  */
63 
64  /** Constructor from a single action.
65  */
66  CActionCollection( CAction &a );
67 
68  /** Copy Constructor
69  */
70  CActionCollection(const CActionCollection &o );
71 
72  /** Copy operator
73  */
74  CActionCollection& operator = (const CActionCollection &o );
75 
76  /** Destructor
77  */
78  virtual ~CActionCollection();
79 
80  /** You can use CActionCollection::begin to get a iterator to the first element.
81  */
82  typedef std::deque<CActionPtr>::iterator iterator;
83 
84  /** You can use CActionCollection::begin to get a iterator to the first element.
85  */
87 
88  /** Returns a iterator to the first action: this is an example of usage:
89  * \code
90  * CActionCollection acts;
91  * ...
92  * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
93  * {
94  * (*it)->... // (*it) is a "CActionPtr"
95  * }
96  *
97  * \endcode
98  */
99  const_iterator begin() const { return m_actions.begin(); }
100 
101  /** Returns a iterator to the first action: this is an example of usage:
102  * \code
103  * CActionCollection acts;
104  * ...
105  * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
106  * {
107  * (*it)->... // (*it) is a "CActionPtr"
108  * }
109  *
110  * \endcode
111  */
112  iterator begin() { return m_actions.begin(); }
113 
114  /** Returns a iterator pointing to the end of the list: this is an example of usage:
115  * \code
116  * CActionCollection acts;
117  * ...
118  * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
119  * {
120  * (*it)->... // (*it) is a "CActionPtr"
121  * }
122  *
123  * \endcode
124  */
125  const_iterator end() const { return m_actions.end(); }
126 
127  /** Returns a iterator pointing to the end of the list: this is an example of usage:
128  * \code
129  * CActionCollection acts;
130  * ...
131  * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
132  * {
133  * (*it)->... // (*it) is a "CActionPtr"
134  * }
135  *
136  * \endcode
137  */
138  iterator end() { return m_actions.end(); }
139 
140 
141  /** Removes the given action in the list, and return an iterator to the next element (or this->end() if it was the last one).
142  */
143  iterator erase( const iterator &it);
144 
145  /** Erase all actions from the list.
146  */
147  void clear();
148 
149  /** Access the i'th action.DO NOT MODIFY the returned object, make a copy of ir with "CSerializable::duplicate" if desired.
150  * First element is 0.
151  * \exception std::exception On index out of bounds.
152  */
153  CActionPtr get(size_t index);
154 
155  /** 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.
156  * Example:
157  * \code
158  CActionRobotMovement2DPtr obs = acts->getActionByClass<CActionRobotMovement2D>();
159  * \endcode
160  * By default (ith=0), the first one is returned.
161  */
162  template <typename T>
163  typename T::SmartPtr getActionByClass( const size_t &ith = 0 ) const
164  {
165  MRPT_START
166  size_t foundCount = 0;
167  const mrpt::utils::TRuntimeClassId* class_ID = T::classinfo;
168  for (const_iterator it = begin();it!=end();++it)
169  if ( (*it)->GetRuntimeClass()->derivedFrom( class_ID ) )
170  if (foundCount++ == ith)
171  return typename T::SmartPtr(*it);
172  return typename T::SmartPtr(); // Not found: return empty smart pointer
173  MRPT_END
174  }
175 
176 
177  /** Add a new object to the list.
178  */
179  void insert(CAction &action);
180 
181  /** Returns the actions count in the collection.
182  */
183  size_t size();
184 
185  /** Returns the best pose increment estimator in the collection, based on the determinant of its pose change covariance matrix.
186  * \return The estimation, or NULL if none is available.
187  */
188  CActionRobotMovement2DPtr getBestMovementEstimation() const;
189 
190  /** Returns the pose increment estimator in the collection having the specified type.
191  * \return The estimation, or NULL if none is available.
192  */
193  CActionRobotMovement2DPtr getMovementEstimationByType( CActionRobotMovement2D::TEstimationMethod method);
194 
195  /** 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.
196  * \return true on success,false on no odometry found.
197  */
198  bool getFirstMovementEstimationMean( CPose3D &out_pose_increment ) const;
199 
200  /** 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.
201  * \return true on success,false on no odometry found.
202  */
203  bool getFirstMovementEstimation( CPose3DPDFGaussian &out_pose_increment ) const;
204 
205  /** Remove an action from the list by its index.
206  * \exception std::exception On index out of bounds.
207  */
208  void eraseByIndex(const size_t & index);
209 
210 
211  }; // End of class def.
212 
213 
214  } // End of namespace
215 } // End of namespace
216 
217 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013