MRPT  1.9.9
CPoses3DSequence.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, 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 
10 #include "poses-precomp.h" // Precompiled headers
11 
12 #include <mrpt/math/TPose3D.h>
15 
16 using namespace mrpt;
17 using namespace mrpt::poses;
18 using namespace mrpt::math;
19 
21 
22 size_t CPoses3DSequence::posesCount() { return m_poses.size(); }
23 uint8_t CPoses3DSequence::serializeGetVersion() const { return 0; }
25 {
26  out.WriteAs<uint32_t>(m_poses.size());
27  for (const auto& p : m_poses) out << p;
28 }
30  mrpt::serialization::CArchive& in, uint8_t version)
31 {
32  switch (version)
33  {
34  case 0:
35  {
36  m_poses.resize(in.ReadAs<uint32_t>());
37  for (auto& p : m_poses) in >> p;
38  }
39  break;
40  default:
42  };
43 }
44 
45 /*---------------------------------------------------------------
46 Reads the stored pose at index "ind", where the first one is 0, the last
47 "posesCount() - 1"
48  ---------------------------------------------------------------*/
49 void CPoses3DSequence::getPose(unsigned int ind, CPose3D& outPose)
50 {
51  if (ind >= m_poses.size()) THROW_EXCEPTION("getPose: Index out of range!!");
52 
53  outPose = CPose3D(m_poses[ind]);
54 }
55 
56 /*---------------------------------------------------------------
57 Changes the stored pose at index "ind", where the first one is 0, the last
58 "posesCount() - 1"
59  ---------------------------------------------------------------*/
60 void CPoses3DSequence::changePose(unsigned int ind, CPose3D& inPose)
61 {
62  if (ind >= m_poses.size()) THROW_EXCEPTION("getPose: Index out of range!!");
63  m_poses[ind] = inPose.asTPose();
64 }
65 
66 /*---------------------------------------------------------------
67  Appends a new pose at the end of sequence. Remember that poses are relative,
68  incremental to the last one.
69  ---------------------------------------------------------------*/
71 {
72  m_poses.push_back(newPose.asTPose());
73 }
74 
75 /*---------------------------------------------------------------
76  Clears the sequence.
77  ---------------------------------------------------------------*/
78 void CPoses3DSequence::clear() { m_poses.clear(); }
79 /*---------------------------------------------------------------
80  ---------------------------------------------------------------*/
81 /** Returns the absolute pose of a robot after moving "n" poses, so for "n=0"
82  * the origin pose (0,0,0deg) is returned, for "n=1" the first pose is returned,
83  * and for "n=posesCount()", the pose
84  * of robot after moving ALL poses is returned, all of them relative to the
85  * starting pose.
86  */
88 {
89  CPose3D ret(0, 0, 0);
90  unsigned int i;
91 
92  if (n > m_poses.size())
93  THROW_EXCEPTION("absolutePoseOf: Index out of range!!");
94 
95  for (i = 0; i < n; i++) ret = ret + CPose3D(m_poses[i]);
96 
97  return ret;
98 }
99 
100 /*---------------------------------------------------------------
101  A shortcut for "absolutePoseOf( posesCount() )".
102  ---------------------------------------------------------------*/
104 {
105  return absolutePoseOf(posesCount());
106 }
107 
108 /*---------------------------------------------------------------
109  Returns the traveled distance after moving "n" poses, so for "n=0" it
110  returns 0, for "n=1" the first traveled distance, and for "n=posesCount()", the
111  total
112  distance after ALL movements.
113  ---------------------------------------------------------------*/
115 {
116  unsigned int i;
117  float dist = 0;
118 
119  if (n > m_poses.size())
120  THROW_EXCEPTION("computeTraveledDistanceAfter: Index out of range!!");
121 
122  for (i = 0; i < n; i++) dist += m_poses[i].norm();
123  return dist;
124 }
125 
126 /*---------------------------------------------------------------
127  Returns the traveled distance after ALL movements.
128  A shortcut for "computeTraveledDistanceAfter( posesCount() )".
129  ---------------------------------------------------------------*/
131 {
132  return computeTraveledDistanceAfter(posesCount());
133 }
mrpt::math::TPose3D asTPose() const
Definition: CPose3D.cpp:775
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 ...
void clear()
Clears the sequence.
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
float computeTraveledDistanceAfterAll()
Returns the traveled distance after ALL movements.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
GLenum GLsizei n
Definition: glext.h:5136
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
This base provides a set of functions for maths stuff.
CPose3D absolutePoseOf(unsigned int n)
Returns the absolute pose of a robot after moving "n" poses, so for "n=0" the origin pose (0...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
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.
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::vision::TStereoCalibResults out
GLuint in
Definition: glext.h:7391
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"...
GLfloat GLfloat p
Definition: glext.h:6398
CONTAINER::Scalar norm(const CONTAINER &v)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 1d7b2c899 Thu Nov 14 18:59:07 2019 +0100 at jue nov 14 19:15:09 CET 2019