00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://www.mrpt.org/ | 00005 | | 00006 | Copyright (C) 2005-2011 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CActionCollection_H 00029 #define CActionCollection_H 00030 00031 #include <mrpt/slam/CAction.h> 00032 #include <mrpt/slam/CActionRobotMovement2D.h> 00033 #include <mrpt/utils/CSerializable.h> 00034 #include <mrpt/poses/CPose3DPDFGaussian.h> 00035 00036 namespace mrpt 00037 { 00038 namespace slam 00039 { 00040 // This must be added to any CSerializable derived class: 00041 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CActionCollection, mrpt::utils::CSerializable, OBS_IMPEXP ) 00042 00043 /** Declares a class for storing a collection of robot actions. It is used in mrpt::slam::CRawlog, 00044 * for logs storage and particle filter based simulations. 00045 * 00046 * \sa CAction, CRawlog 00047 * \ingroup mrpt_obs_grp 00048 */ 00049 class OBS_IMPEXP CActionCollection : public mrpt::utils::CSerializable 00050 { 00051 // This must be added to any CSerializable derived class: 00052 DEFINE_SERIALIZABLE( CActionCollection ) 00053 00054 protected: 00055 /** The actions: 00056 */ 00057 std::deque<CActionPtr> m_actions; 00058 00059 public: 00060 /** Constructor 00061 */ 00062 CActionCollection(); 00063 00064 /** Constructor from a single action. 00065 */ 00066 CActionCollection( CAction &a ); 00067 00068 /** Copy Constructor 00069 */ 00070 CActionCollection(const CActionCollection &o ); 00071 00072 /** Copy operator 00073 */ 00074 CActionCollection& operator = (const CActionCollection &o ); 00075 00076 /** Destructor 00077 */ 00078 virtual ~CActionCollection(); 00079 00080 /** You can use CActionCollection::begin to get a iterator to the first element. 00081 */ 00082 typedef std::deque<CActionPtr>::iterator iterator; 00083 00084 /** You can use CActionCollection::begin to get a iterator to the first element. 00085 */ 00086 typedef std::deque<CActionPtr>::const_iterator const_iterator; 00087 00088 /** Returns a iterator to the first action: this is an example of usage: 00089 * \code 00090 * CActionCollection acts; 00091 * ... 00092 * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it) 00093 * { 00094 * (*it)->... // (*it) is a "CActionPtr" 00095 * } 00096 * 00097 * \endcode 00098 */ 00099 const_iterator begin() const { return m_actions.begin(); } 00100 00101 /** Returns a iterator to the first action: this is an example of usage: 00102 * \code 00103 * CActionCollection acts; 00104 * ... 00105 * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it) 00106 * { 00107 * (*it)->... // (*it) is a "CActionPtr" 00108 * } 00109 * 00110 * \endcode 00111 */ 00112 iterator begin() { return m_actions.begin(); } 00113 00114 /** Returns a iterator pointing to the end of the list: this is an example of usage: 00115 * \code 00116 * CActionCollection acts; 00117 * ... 00118 * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it) 00119 * { 00120 * (*it)->... // (*it) is a "CActionPtr" 00121 * } 00122 * 00123 * \endcode 00124 */ 00125 const_iterator end() const { return m_actions.end(); } 00126 00127 /** Returns a iterator pointing to the end of the list: this is an example of usage: 00128 * \code 00129 * CActionCollection acts; 00130 * ... 00131 * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it) 00132 * { 00133 * (*it)->... // (*it) is a "CActionPtr" 00134 * } 00135 * 00136 * \endcode 00137 */ 00138 iterator end() { return m_actions.end(); } 00139 00140 00141 /** Removes the given action in the list, and return an iterator to the next element (or this->end() if it was the last one). 00142 */ 00143 iterator erase( const iterator &it); 00144 00145 /** Erase all actions from the list. 00146 */ 00147 void clear(); 00148 00149 /** Access the i'th action.DO NOT MODIFY the returned object, make a copy of ir with "CSerializable::duplicate" if desired. 00150 * First element is 0. 00151 * \exception std::exception On index out of bounds. 00152 */ 00153 CActionPtr get(size_t index); 00154 00155 /** 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. 00156 * Example: 00157 * \code 00158 CActionRobotMovement2DPtr obs = acts->getActionByClass<CActionRobotMovement2D>(); 00159 * \endcode 00160 * By default (ith=0), the first one is returned. 00161 */ 00162 template <typename T> 00163 typename T::SmartPtr getActionByClass( const size_t &ith = 0 ) const 00164 { 00165 MRPT_START 00166 size_t foundCount = 0; 00167 const mrpt::utils::TRuntimeClassId* class_ID = T::classinfo; 00168 for (const_iterator it = begin();it!=end();++it) 00169 if ( (*it)->GetRuntimeClass()->derivedFrom( class_ID ) ) 00170 if (foundCount++ == ith) 00171 return typename T::SmartPtr(*it); 00172 return typename T::SmartPtr(); // Not found: return empty smart pointer 00173 MRPT_END 00174 } 00175 00176 00177 /** Add a new object to the list. 00178 */ 00179 void insert(CAction &action); 00180 00181 /** Returns the actions count in the collection. 00182 */ 00183 size_t size(); 00184 00185 /** Returns the best pose increment estimator in the collection, based on the determinant of its pose change covariance matrix. 00186 * \return The estimation, or NULL if none is available. 00187 */ 00188 CActionRobotMovement2DPtr getBestMovementEstimation() const; 00189 00190 /** Returns the pose increment estimator in the collection having the specified type. 00191 * \return The estimation, or NULL if none is available. 00192 */ 00193 CActionRobotMovement2DPtr getMovementEstimationByType( CActionRobotMovement2D::TEstimationMethod method); 00194 00195 /** 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. 00196 * \return true on success,false on no odometry found. 00197 */ 00198 bool getFirstMovementEstimationMean( CPose3D &out_pose_increment ) const; 00199 00200 /** 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. 00201 * \return true on success,false on no odometry found. 00202 */ 00203 bool getFirstMovementEstimation( CPose3DPDFGaussian &out_pose_increment ) const; 00204 00205 /** Remove an action from the list by its index. 00206 * \exception std::exception On index out of bounds. 00207 */ 00208 void eraseByIndex(const size_t & index); 00209 00210 00211 }; // End of class def. 00212 00213 00214 } // End of namespace 00215 } // End of namespace 00216 00217 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |