Main MRPT website > C++ reference
MRPT logo

CActionCollection.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
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                  */
00048                 class OBS_IMPEXP CActionCollection : public mrpt::utils::CSerializable
00049                 {
00050                         // This must be added to any CSerializable derived class:
00051                         DEFINE_SERIALIZABLE( CActionCollection )
00052 
00053                 protected:
00054                         /** The actions:
00055                           */
00056                         std::deque<CActionPtr>  m_actions;
00057 
00058                  public:
00059                          /** Constructor
00060                            */
00061                         CActionCollection();
00062 
00063                         /** Constructor from a single action.
00064                            */
00065                         CActionCollection( CAction &a );
00066 
00067                         /** Copy Constructor
00068                            */
00069                         CActionCollection(const CActionCollection &o );
00070 
00071                         /** Copy operator
00072                           */
00073                         CActionCollection&  operator = (const CActionCollection &o );
00074 
00075                         /** Destructor
00076                            */
00077                         virtual ~CActionCollection();
00078 
00079                         /** You can use CActionCollection::begin to get a iterator to the first element.
00080                           */
00081                         typedef std::deque<CActionPtr>::iterator                iterator;
00082 
00083                         /** You can use CActionCollection::begin to get a iterator to the first element.
00084                           */
00085                         typedef std::deque<CActionPtr>::const_iterator  const_iterator;
00086 
00087                         /** Returns a iterator to the first action: this is an example of usage:
00088                           * \code
00089                           *   CActionCollection  acts;
00090                           *   ...
00091                           *   for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
00092                           *       {
00093                           *      (*it)->... // (*it) is a "CActionPtr"
00094                           *   }
00095                           *
00096                           * \endcode
00097                           */
00098                         const_iterator begin() const { return m_actions.begin(); }
00099 
00100                         /** Returns a iterator to the first action: this is an example of usage:
00101                           * \code
00102                           *   CActionCollection  acts;
00103                           *   ...
00104                           *   for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
00105                           *       {
00106                           *      (*it)->... // (*it) is a "CActionPtr"
00107                           *   }
00108                           *
00109                           * \endcode
00110                           */
00111                         iterator begin() { return m_actions.begin(); }
00112 
00113                         /** Returns a iterator pointing to the end of the list: this is an example of usage:
00114                           * \code
00115                           *   CActionCollection  acts;
00116                           *   ...
00117                           *   for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
00118                           *       {
00119                           *      (*it)->... // (*it) is a "CActionPtr"
00120                           *   }
00121                           *
00122                           * \endcode
00123                           */
00124                         const_iterator end() const { return m_actions.end(); }
00125 
00126                         /** Returns a iterator pointing to the end of the list: this is an example of usage:
00127                           * \code
00128                           *   CActionCollection  acts;
00129                           *   ...
00130                           *   for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
00131                           *       {
00132                           *      (*it)->... // (*it) is a "CActionPtr"
00133                           *   }
00134                           *
00135                           * \endcode
00136                           */
00137                         iterator end() { return m_actions.end(); }
00138 
00139 
00140                         /** Removes the given action in the list, and return an iterator to the next element (or this->end() if it was the last one).
00141                           */
00142                         iterator erase( const iterator &it);
00143 
00144                         /** Erase all actions from the list.
00145                           */
00146                         void  clear();
00147 
00148                         /** Access the i'th action.DO NOT MODIFY the returned object, make a copy of ir with "CSerializable::duplicate" if desired.
00149                           *  First element is 0.
00150                           * \exception std::exception On index out of bounds.
00151                           */
00152                         CActionPtr get(size_t index);
00153 
00154                          /** 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.
00155                            *  Example:
00156                            * \code
00157                                         CActionRobotMovement2DPtr obs = acts->getActionByClass<CActionRobotMovement2D>();
00158                            * \endcode
00159                            * By default (ith=0), the first one is returned.
00160                            */
00161                          template <typename T>
00162                          typename T::SmartPtr getActionByClass( const size_t &ith = 0 ) const
00163                          {
00164                                 MRPT_START;
00165                                 size_t  foundCount = 0;
00166                                 const mrpt::utils::TRuntimeClassId*     class_ID = T::classinfo;
00167                                 for (const_iterator it = begin();it!=end();++it)
00168                                         if ( (*it)->GetRuntimeClass()->derivedFrom( class_ID ) )
00169                                                 if (foundCount++ == ith)
00170                                                         return typename T::SmartPtr(*it);
00171                                 return typename T::SmartPtr();  // Not found: return empty smart pointer
00172                                 MRPT_END;
00173                          }
00174 
00175 
00176                         /** Add a new object to the list.
00177                           */
00178                         void  insert(CAction    &action);
00179 
00180                         /** Returns the actions count in the collection.
00181                           */
00182                         size_t  size();
00183 
00184                         /** Returns the best pose increment estimator in the collection, based on the determinant of its pose change covariance matrix.
00185                           * \return The estimation, or NULL if none is available.
00186                           */
00187                         CActionRobotMovement2DPtr  getBestMovementEstimation() const;
00188 
00189                         /** Returns the pose increment estimator in the collection having the specified type.
00190                           * \return The estimation, or NULL if none is available.
00191                           */
00192                         CActionRobotMovement2DPtr  getMovementEstimationByType( CActionRobotMovement2D::TEstimationMethod method);
00193 
00194                         /** 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.
00195                           * \return true on success,false on no odometry found.
00196                           */
00197                         bool getFirstMovementEstimationMean( CPose3D &out_pose_increment ) const;
00198 
00199                         /** 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.
00200                           * \return true on success,false on no odometry found.
00201                           */
00202                         bool getFirstMovementEstimation( CPose3DPDFGaussian &out_pose_increment ) const;
00203 
00204                         /** Remove an action from the list by its index.
00205                           * \exception std::exception On index out of bounds.
00206                           */
00207                         void  eraseByIndex(const size_t & index);
00208 
00209 
00210                 }; // End of class def.
00211 
00212 
00213         } // End of namespace
00214 } // End of namespace
00215 
00216 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011