Main MRPT website > C++ reference for MRPT 1.9.9
CPoses3DSequence.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 CPoses3DSequence::posesCount() { return m_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 = m_poses.size();
45  out << n;
46  for (i = 0; i < n; i++) out << m_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  m_poses.resize(n);
65  for (i = 0; i < n; i++) in >> m_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 CPoses3DSequence::getPose(unsigned int ind, CPose3D& outPose)
78 {
79  if (ind >= m_poses.size()) THROW_EXCEPTION("getPose: Index out of range!!");
80 
81  outPose = CPose3D(m_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 CPoses3DSequence::changePose(unsigned int ind, CPose3D& inPose)
89 {
90  if (ind >= m_poses.size()) THROW_EXCEPTION("getPose: Index out of range!!");
91  m_poses[ind] = inPose;
92 }
93 
94 /*---------------------------------------------------------------
95  Appends a new pose at the end of sequence. Remember that poses are relative,
96  incremental to the last one.
97  ---------------------------------------------------------------*/
99 {
100  m_poses.push_back(newPose);
101 }
102 
103 /*---------------------------------------------------------------
104  Clears the sequence.
105  ---------------------------------------------------------------*/
106 void CPoses3DSequence::clear() { m_poses.clear(); }
107 /*---------------------------------------------------------------
108  ---------------------------------------------------------------*/
109 /** Returns the absolute pose of a robot after moving "n" poses, so for "n=0"
110  * the origin pose (0,0,0deg) is returned, for "n=1" the first pose is returned,
111  * and for "n=posesCount()", the pose
112  * of robot after moving ALL poses is returned, all of them relative to the
113  * starting pose.
114  */
116 {
117  CPose3D ret(0, 0, 0);
118  unsigned int i;
119 
120  if (n > m_poses.size())
121  THROW_EXCEPTION("absolutePoseOf: Index out of range!!");
122 
123  for (i = 0; i < n; i++) ret = ret + CPose3D(m_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 > m_poses.size())
148  THROW_EXCEPTION("computeTraveledDistanceAfter: Index out of range!!");
149 
150  for (i = 0; i < n; i++) dist += m_poses[i].norm();
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 }
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 ...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void clear()
Clears the sequence.
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
float computeTraveledDistanceAfterAll()
Returns the traveled distance after ALL movements.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
#define THROW_EXCEPTION(msg)
GLenum GLsizei n
Definition: glext.h:5074
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
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
CPose3D absolutePoseOf(unsigned int n)
Returns the absolute pose of a robot after moving "n" poses, so for "n=0" the origin pose (0...
size_t posesCount()
Returns the poses count in the sequence:
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
void appendPose(CPose3D &newPose)
Appends a new pose at the end of sequence.
This class stores a sequence of relative, incremental 3D poses.
void getPose(unsigned int ind, CPose3D &outPose)
Reads the stored pose at index "ind", where the first one is 0, the last "posesCount() - 1"...
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
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...
CPose3D absolutePoseAfterAll()
A shortcut for "absolutePoseOf( posesCount() )".
void changePose(unsigned int ind, CPose3D &inPose)
Changes the stored pose at index "ind", where the first one is 0, the last "posesCount() - 1"...
unsigned __int32 uint32_t
Definition: rptypes.h:47
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
CONTAINER::Scalar norm(const CONTAINER &v)



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