MRPT  2.0.1
CActionCollection.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 #include <mrpt/obs/CAction.h>
16 
17 namespace mrpt::obs
18 {
19 /** Declares a class for storing a collection of robot actions. It is used in
20  * mrpt::obs::CRawlog,
21  * for logs storage and particle filter based simulations.
22  *
23  * \sa CAction, CRawlog
24  * \ingroup mrpt_obs_grp
25  */
27 {
29 
30  protected:
31  /** The robot "actionss" */
32  std::deque<mrpt::containers::deepcopy_poly_ptr<CAction::Ptr>> m_actions;
33 
34  public:
35  /** ctor */
36  CActionCollection() = default;
37  /** Constructor from a single action. */
39 
40  /** You can use CActionCollection::begin to get a iterator to the first
41  * element.
42  */
43  using iterator =
44  std::deque<mrpt::containers::deepcopy_poly_ptr<CAction::Ptr>>::iterator;
45 
46  /** You can use CActionCollection::begin to get a iterator to the first
47  * element.
48  */
49  using const_iterator = std::deque<
51 
52  /** Returns a iterator to the first action: this is an example of usage:
53  * \code
54  * CActionCollection acts;
55  * ...
56  * for (CActionCollection::iterator it=acts.begin();it!=acts.end();++it)
57  * {
58  * (*it)->... // (*it) is a "CAction::Ptr"
59  * }
60  *
61  * \endcode
62  */
63  const_iterator begin() const { return m_actions.begin(); }
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 "CAction::Ptr"
71  * }
72  *
73  * \endcode
74  */
75  iterator begin() { return m_actions.begin(); }
76  /** Returns a iterator pointing to the end of the list: this is an example
77  *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 "CAction::Ptr"
84  * }
85  *
86  * \endcode
87  */
88  const_iterator end() const { return m_actions.end(); }
89  /** Returns a iterator pointing to the end of the list: this is an example
90  *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 "CAction::Ptr"
97  * }
98  *
99  * \endcode
100  */
101  iterator end() { return m_actions.end(); }
102  /** Removes the given action in the list, and return an iterator to the next
103  * element (or this->end() if it was the last one).
104  */
105  iterator erase(const iterator& it);
106 
107  /** Erase all actions from the list.
108  */
109  void clear();
110 
111  /** Access the i'th action.DO NOT MODIFY the returned object, make a copy of
112  * ir with "CSerializable::duplicate" if desired.
113  * First element is 0.
114  * \exception std::exception On index out of bounds.
115  */
116  CAction::Ptr 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 nullptr smart pointer
120  if there is no action of that class in the list.
121  * Example:
122  * \code
123  CActionRobotMovement2D::Ptr obs =
124  acts->getActionByClass<CActionRobotMovement2D>();
125  * \endcode
126  * By default (ith=0), the first one is returned.
127  */
128  template <typename T>
129  typename T::Ptr getActionByClass(size_t ith = 0) const
130  {
131  MRPT_START
132  size_t foundCount = 0;
133  const mrpt::rtti::TRuntimeClassId* class_ID =
134  &T::GetRuntimeClassIdStatic();
135  for (const auto& it : *this)
136  if (it->GetRuntimeClass()->derivedFrom(class_ID))
137  if (foundCount++ == ith)
138  return std::dynamic_pointer_cast<T>(it.get_ptr());
139  return typename T::Ptr(); // Not found: return empty smart pointer
140  MRPT_END
141  }
142 
143  /** Add a new object to the list.
144  */
145  void insert(CAction& action);
146 
147  /** Returns the actions count in the collection.
148  */
149  size_t size();
150 
151  /** Returns the best pose increment estimator in the collection, based on
152  * the determinant of its pose change covariance matrix.
153  * \return The estimation, or nullptr if none is available.
154  */
156 
157  /** Returns the pose increment estimator in the collection having the
158  * specified type.
159  * \return The estimation, or nullptr if none is available.
160  */
163 
164  /** Look for the first 2D or 3D "odometry" found in this collection of
165  * actions, and return the "mean" increment of the robot according to it.
166  * \return true on success,false on no odometry found.
167  */
169  mrpt::poses::CPose3D& out_pose_increment) const;
170 
171  /** Look for the first 2D or 3D "odometry" found in this collection of
172  * actions, and return the "mean" increment of the robot and its covariance
173  * according to it.
174  * \return true on success,false on no odometry found.
175  */
177  mrpt::poses::CPose3DPDFGaussian& out_pose_increment) const;
178 
179  /** Remove an action from the list by its index.
180  * \exception std::exception On index out of bounds.
181  */
182  void eraseByIndex(size_t index);
183 
184 }; // End of class def.
185 
186 } // namespace mrpt::obs
#define MRPT_START
Definition: exceptions.h:241
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:31
CActionRobotMovement2D::Ptr getMovementEstimationByType(CActionRobotMovement2D::TEstimationMethod method)
Returns the pose increment estimator in the collection having the specified type. ...
void eraseByIndex(size_t index)
Remove an action from the list by its index.
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...
std::deque< mrpt::containers::deepcopy_poly_ptr< CAction::Ptr > > m_actions
The robot "actionss".
void clear()
Erase all actions from the list.
This namespace contains representation of robot actions and observations.
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...
T::Ptr getActionByClass(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 ...
Declares a class for storing a robot action.
Definition: CAction.h:24
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
#define MRPT_END
Definition: exceptions.h:245
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:30
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
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
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.
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 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020