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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019