Main MRPT website > C++ reference for MRPT 1.9.9
CPoses2DSequence.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 "base-precomp.h" // Precompiled headers
11 
13 #include <mrpt/utils/CStream.h>
14 
15 using namespace mrpt;
16 using namespace mrpt::poses;
17 using namespace mrpt::math;
18 using namespace mrpt::utils;
19 
21 
22 /*---------------------------------------------------------------
23  Default constructor
24  ---------------------------------------------------------------*/
26 /*---------------------------------------------------------------
27  Returns the poses count in the sequence:
28  ---------------------------------------------------------------*/
29 size_t CPoses2DSequence::posesCount() { return poses.size(); }
30 /*---------------------------------------------------------------
31  Implements the writing to a CStream capability of
32  CSerializable objects
33  ---------------------------------------------------------------*/
35  mrpt::utils::CStream& out, int* version) const
36 {
37  if (version)
38  *version = 0;
39  else
40  {
41  uint32_t i, n;
42 
43  // The poses:
44  n = poses.size();
45  out << n;
46  for (i = 0; i < n; i++) out << poses[i];
47  }
48 }
49 
50 /*---------------------------------------------------------------
51  Implements the reading from a CStream capability of
52  CSerializable objects
53  ---------------------------------------------------------------*/
55 {
56  switch (version)
57  {
58  case 0:
59  {
60  uint32_t i, n;
61 
62  // The poses:
63  in >> n;
64  poses.resize(n);
65  for (i = 0; i < n; i++) in >> poses[i];
66  }
67  break;
68  default:
70  };
71 }
72 
73 /*---------------------------------------------------------------
74 Reads the stored pose at index "ind", where the first one is 0, the last
75 "posesCount() - 1"
76  ---------------------------------------------------------------*/
77 void CPoses2DSequence::getPose(unsigned int ind, CPose2D& outPose)
78 {
79  if (ind >= poses.size()) THROW_EXCEPTION("Index out of range!!");
80 
81  outPose = poses[ind];
82 }
83 
84 /*---------------------------------------------------------------
85 Changes the stored pose at index "ind", where the first one is 0, the last
86 "posesCount() - 1"
87  ---------------------------------------------------------------*/
88 void CPoses2DSequence::changePose(unsigned int ind, CPose2D& inPose)
89 {
90  if (ind >= poses.size()) THROW_EXCEPTION("Index out of range!!");
91 
92  *((&(poses[ind])) + ind) = inPose;
93 }
94 
95 /*---------------------------------------------------------------
96  Appends a new pose at the end of sequence. Remember that poses are relative,
97  incremental to the last one.
98  ---------------------------------------------------------------*/
100 {
101  poses.push_back(newPose);
102 }
103 
104 /*---------------------------------------------------------------
105  Clears the sequence.
106  ---------------------------------------------------------------*/
107 void CPoses2DSequence::clear() { poses.clear(); }
108 /*---------------------------------------------------------------
109  ---------------------------------------------------------------*/
110 /** Returns the absolute pose of a robot after moving "n" poses, so for "n=0"
111  * the origin pose (0,0,0deg) is returned, for "n=1" the first pose is returned,
112  * and for "n=posesCount()", the pose
113  * of robot after moving ALL poses is returned, all of them relative to the
114  * starting pose.
115  */
117 {
118  CPose2D ret(0, 0, 0);
119  unsigned int i;
120 
121  if (n > poses.size()) THROW_EXCEPTION("Index out of range!!");
122 
123  for (i = 0; i < n; i++) ret = ret + poses[i];
124 
125  return ret;
126 }
127 
128 /*---------------------------------------------------------------
129  A shortcut for "absolutePoseOf( posesCount() )".
130  ---------------------------------------------------------------*/
132 {
133  return absolutePoseOf(posesCount());
134 }
135 
136 /*---------------------------------------------------------------
137  Returns the traveled distance after moving "n" poses, so for "n=0" it
138  returns 0, for "n=1" the first traveled distance, and for "n=posesCount()", the
139  total
140  distance after ALL movements.
141  ---------------------------------------------------------------*/
143 {
144  unsigned int i;
145  float dist = 0;
146 
147  if (n > poses.size()) THROW_EXCEPTION("Index out of range!!");
148 
149  for (i = 0; i < n; i++) dist += poses[i].norm();
150 
151  return dist;
152 }
153 
154 /*---------------------------------------------------------------
155  Returns the traveled distance after ALL movements.
156  A shortcut for "computeTraveledDistanceAfter( posesCount() )".
157  ---------------------------------------------------------------*/
159 {
160  return computeTraveledDistanceAfter(posesCount());
161 }
This class stores a sequence of relative, incremental 2D poses.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
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.
CPose2D absolutePoseOf(unsigned int n)
Returns the absolute pose of a robot after moving "n" poses, so for "n=0" the origin pose (0...
#define THROW_EXCEPTION(msg)
GLenum GLsizei n
Definition: glext.h:5074
void getPose(unsigned int ind, CPose2D &outPose)
Reads the stored pose at index "ind", where the first one is 0, the last "posesCount() - 1"...
size_t posesCount()
Returns the poses count in the sequence:
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
float computeTraveledDistanceAfterAll()
Returns the traveled distance after ALL movements.
void clear()
Clears the sequence.
void changePose(unsigned int ind, CPose2D &inPose)
Changes the stored pose at index "ind", where the first one is 0, the last "posesCount() - 1"...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
GLuint in
Definition: glext.h:7274
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...
unsigned __int32 uint32_t
Definition: rptypes.h:47
void appendPose(CPose2D &newPose)
Appends a new pose at the end of sequence.
CONTAINER::Scalar norm(const CONTAINER &v)
float computeTraveledDistanceAfter(unsigned int n)
Returns the traveled distance after moving "n" poses, so for "n=0" it returns 0, for "n=1" the first ...
CPose2D absolutePoseAfterAll()
A shortcut for "absolutePoseOf( posesCount() )".



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