Main MRPT website > C++ reference for MRPT 1.9.9
CActionCollection.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, 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 
10 #include "obs-precomp.h" // Precompiled headers
11 
15 #include <mrpt/poses/CPosePDF.h>
16 #include <mrpt/utils/CStream.h>
17 
18 using namespace mrpt;
19 using namespace mrpt::obs;
20 using namespace mrpt::poses;
21 using namespace mrpt::utils;
22 
24 using namespace mrpt::utils::metaprogramming;
25 
27 
28 /*---------------------------------------------------------------
29  Constructor
30  ---------------------------------------------------------------*/
32 /*---------------------------------------------------------------
33  Constructor
34  ---------------------------------------------------------------*/
36 {
37  m_actions.push_back(CAction::Ptr(static_cast<CAction*>(a.clone())));
38 }
39 
40 /*---------------------------------------------------------------
41  Implements the writing to a CStream capability of CSerializable objects
42  ---------------------------------------------------------------*/
44  mrpt::utils::CStream& out, int* version) const
45 {
46  if (version)
47  *version = 0;
48  else
49  {
50  uint32_t n;
51 
52  n = static_cast<uint32_t>(m_actions.size());
53  out << n;
54  for (const_iterator it = begin(); it != end(); ++it) out << *(*it);
55  }
56 }
57 
58 /*---------------------------------------------------------------
59  Implements the reading from a CStream capability of CSerializable objects
60  ---------------------------------------------------------------*/
62 {
63  switch (version)
64  {
65  case 0:
66  {
67  uint32_t n;
68 
69  clear();
70 
71  in >> n;
72  m_actions.resize(n);
73  for_each(
75  }
76  break;
77  default:
79  };
80 }
81 
82 /*---------------------------------------------------------------
83  clear
84  ---------------------------------------------------------------*/
86 /*---------------------------------------------------------------
87  get
88  ---------------------------------------------------------------*/
90 {
91  if (index >= m_actions.size()) THROW_EXCEPTION("Index out of bounds");
92 
93  return m_actions.at(index).get_ptr();
94 }
95 
96 const CAction& CActionCollection::get(size_t index) const
97 {
98  if (index >= m_actions.size()) THROW_EXCEPTION("Index out of bounds");
99 
100  return *(m_actions.at(index).get_ptr());
101 }
102 
103 /*---------------------------------------------------------------
104  size
105  ---------------------------------------------------------------*/
106 size_t CActionCollection::size() { return m_actions.size(); }
107 /*---------------------------------------------------------------
108  insert
109  ---------------------------------------------------------------*/
111 {
112  m_actions.push_back(CAction::Ptr(static_cast<CAction*>(action.clone())));
113 }
114 
115 /*---------------------------------------------------------------
116  getBestMovementEstimation
117  ---------------------------------------------------------------*/
119 {
121  double bestDet = 1e3;
122 
123  // Find the best
124  for (const_iterator it = begin(); it != end(); ++it)
125  {
126  if ((*it)->GetRuntimeClass()->derivedFrom(
128  {
130  std::dynamic_pointer_cast<CActionRobotMovement2D>(
131  it->get_ptr());
132 
133  if (temp->estimationMethod ==
135  {
136  return temp;
137  }
138 
139  double det = temp->poseChange->getCovariance().det();
140 
141  // If it is the best until now, save it:
142  if (det < bestDet)
143  {
144  bestEst = temp;
145  bestDet = det;
146  }
147  }
148  }
149 
150  return bestEst;
151 }
152 
153 /*---------------------------------------------------------------
154  eraseByIndex
155  ---------------------------------------------------------------*/
157 {
158  if (index >= m_actions.size()) THROW_EXCEPTION("Index out of bounds");
159 
160  iterator it = m_actions.begin() + index;
161  m_actions.erase(it);
162 }
163 
164 /*---------------------------------------------------------------
165  eraseByIndex
166  ---------------------------------------------------------------*/
169 {
170  // Find it:
171  for (iterator it = begin(); it != end(); ++it)
172  {
173  if ((*it)->GetRuntimeClass()->derivedFrom(
175  {
177  std::dynamic_pointer_cast<CActionRobotMovement2D>(
178  it->get_ptr());
179 
180  // Is it of the required type?
181  if (temp->estimationMethod == method)
182  {
183  // Yes!:
184  return temp;
185  }
186  }
187  }
188 
189  // Not found:
191 }
192 
193 /*---------------------------------------------------------------
194  erase
195  ---------------------------------------------------------------*/
197 {
198  MRPT_START
199  ASSERT_(it != end());
200 
201  return m_actions.erase(it);
202  MRPT_END
203 }
204 
205 /*---------------------------------------------------------------
206  getFirstMovementEstimationMean
207  ---------------------------------------------------------------*/
209  CPose3D& out_pose_increment) const
210 {
212  getActionByClass<CActionRobotMovement3D>();
213  if (act3D)
214  {
215  out_pose_increment = act3D->poseChange.mean;
216  return true;
217  }
219  getActionByClass<CActionRobotMovement2D>();
220  if (act2D)
221  {
222  out_pose_increment = CPose3D(act2D->poseChange->getMeanVal());
223  return true;
224  }
225  return false;
226 }
227 
228 /*---------------------------------------------------------------
229  getFirstMovementEstimation
230  ---------------------------------------------------------------*/
232  CPose3DPDFGaussian& out_pose_increment) const
233 {
235  getActionByClass<CActionRobotMovement3D>();
236  if (act3D)
237  {
238  out_pose_increment = act3D->poseChange;
239  return true;
240  }
242  getActionByClass<CActionRobotMovement2D>();
243  if (act2D)
244  {
245  out_pose_increment.copyFrom(*act2D->poseChange);
246  return true;
247  }
248  return false;
249 }
EIGEN_STRONG_INLINE Scalar det() const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
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...
void copyFrom(const CPose3DPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
const_iterator end() const
Returns a iterator pointing to the end of the list: this is an example of usage:
#define THROW_EXCEPTION(msg)
virtual CObject * clone() const =0
Returns a deep copy (clone) of the object, indepently of its class.
GLenum GLsizei n
Definition: glext.h:5074
std::deque< mrpt::utils::poly_ptr_ptr< CAction::Ptr > > m_actions
The robot "actionss".
CActionRobotMovement2D::Ptr getMovementEstimationByType(CActionRobotMovement2D::TEstimationMethod method)
Returns the pose increment estimator in the collection having the specified type. ...
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
Declares a class for storing a collection of robot actions.
Represents a probabilistic 2D movement of the robot mobile base.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:85
#define MRPT_END
std::shared_ptr< CActionRobotMovement2D > Ptr
CActionRobotMovement2D::Ptr getBestMovementEstimation() const
Returns the best pose increment estimator in the collection, based on the determinant of its pose cha...
CAction::Ptr get(size_t index)
Access the i&#39;th action.DO NOT MODIFY the returned object, make a copy of ir with "CSerializable::dupl...
GLuint index
Definition: glext.h:4054
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
std::shared_ptr< CAction > Ptr
Definition: CAction.h:30
void clear()
Erase all actions from the list.
std::deque< mrpt::utils::poly_ptr_ptr< CAction::Ptr > >::iterator iterator
You can use CActionCollection::begin to get a iterator to the first element.
This namespace contains representation of robot actions and observations.
TEstimationMethod
A list of posible ways for estimating the content of a CActionRobotMovement2D object.
A set of utility objects for metaprogramming with STL algorithms.
std::shared_ptr< CActionRobotMovement3D > Ptr
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
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:28
#define MRPT_START
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
GLuint in
Definition: glext.h:7274
#define ASSERT_(f)
Declares a class that represents a Probability Density function (PDF) of a 3D pose ...
size_t size()
Returns the actions count in the collection.
std::deque< mrpt::utils::poly_ptr_ptr< CAction::Ptr > >::const_iterator const_iterator
You can use CActionCollection::begin to get a iterator to the first element.
void eraseByIndex(const size_t &index)
Remove an action from the list by its index.
unsigned __int32 uint32_t
Definition: rptypes.h:47
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
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: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019