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-2018, 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 "poses-precomp.h" // Precompiled headers
11 
14 
15 using namespace mrpt;
16 using namespace mrpt::poses;
17 using namespace mrpt::math;
18 
20 
21 size_t CPoses2DSequence::posesCount() { return poses.size(); }
24 {
25  out.WriteAs<uint32_t>(poses.size());
26  for (const auto& p : poses) out << p;
27 }
30 {
31  switch (version)
32  {
33  case 0:
34  {
35  poses.resize(in.ReadAs<uint32_t>());
36  for (auto& p : poses) in >> p;
37  }
38  break;
39  default:
41  };
42 }
43 
44 /*---------------------------------------------------------------
45 Reads the stored pose at index "ind", where the first one is 0, the last
46 "posesCount() - 1"
47  ---------------------------------------------------------------*/
48 void CPoses2DSequence::getPose(unsigned int ind, CPose2D& outPose)
49 {
50  if (ind >= poses.size()) THROW_EXCEPTION("Index out of range!!");
51 
52  outPose = poses[ind];
53 }
54 
55 /*---------------------------------------------------------------
56 Changes the stored pose at index "ind", where the first one is 0, the last
57 "posesCount() - 1"
58  ---------------------------------------------------------------*/
59 void CPoses2DSequence::changePose(unsigned int ind, CPose2D& inPose)
60 {
61  if (ind >= poses.size()) THROW_EXCEPTION("Index out of range!!");
62 
63  *((&(poses[ind])) + ind) = inPose;
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  poses.push_back(newPose);
73 }
74 
75 /*---------------------------------------------------------------
76  Clears the sequence.
77  ---------------------------------------------------------------*/
78 void CPoses2DSequence::clear() { 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  CPose2D ret(0, 0, 0);
90  unsigned int i;
91 
92  if (n > poses.size()) THROW_EXCEPTION("Index out of range!!");
93 
94  for (i = 0; i < n; i++) ret = ret + poses[i];
95 
96  return ret;
97 }
98 
99 /*---------------------------------------------------------------
100  A shortcut for "absolutePoseOf( posesCount() )".
101  ---------------------------------------------------------------*/
103 {
104  return absolutePoseOf(posesCount());
105 }
106 
107 /*---------------------------------------------------------------
108  Returns the traveled distance after moving "n" poses, so for "n=0" it
109  returns 0, for "n=1" the first traveled distance, and for "n=posesCount()", the
110  total
111  distance after ALL movements.
112  ---------------------------------------------------------------*/
114 {
115  unsigned int i;
116  float dist = 0;
117 
118  if (n > poses.size()) THROW_EXCEPTION("Index out of range!!");
119 
120  for (i = 0; i < n; i++) dist += poses[i].norm();
121 
122  return dist;
123 }
124 
125 /*---------------------------------------------------------------
126  Returns the traveled distance after ALL movements.
127  A shortcut for "computeTraveledDistanceAfter( posesCount() )".
128  ---------------------------------------------------------------*/
130 {
131  return computeTraveledDistanceAfter(posesCount());
132 }
n
GLenum GLsizei n
Definition: glext.h:5074
poses-precomp.h
mrpt::poses::CPoses2DSequence::computeTraveledDistanceAfter
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 ...
Definition: CPoses2DSequence.cpp:113
mrpt::poses::CPoses2DSequence::appendPose
void appendPose(CPose2D &newPose)
Appends a new pose at the end of sequence.
Definition: CPoses2DSequence.cpp:70
mrpt::poses::CPoses2DSequence::getPose
void getPose(unsigned int ind, CPose2D &outPose)
Reads the stored pose at index "ind", where the first one is 0, the last "posesCount() - 1".
Definition: CPoses2DSequence.cpp:48
mrpt::poses::CPoses2DSequence::changePose
void changePose(unsigned int ind, CPose2D &inPose)
Changes the stored pose at index "ind", where the first one is 0, the last "posesCount() - 1".
Definition: CPoses2DSequence.cpp:59
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
p
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
mrpt::poses::CPoses2DSequence::clear
void clear()
Clears the sequence.
Definition: CPoses2DSequence.cpp:78
mrpt::math::norm
CONTAINER::Scalar norm(const CONTAINER &v)
Definition: ops_containers.h:134
mrpt::serialization::CArchive::WriteAs
void WriteAs(const TYPE_FROM_ACTUAL &value)
Definition: CArchive.h:152
mrpt::poses::CPoses2DSequence::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CPoses2DSequence.cpp:28
mrpt::poses::CPose2D
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:40
mrpt::poses::CPoses2DSequence
This class stores a sequence of relative, incremental 2D poses.
Definition: CPoses2DSequence.h:26
mrpt::poses::CPoses2DSequence::absolutePoseOf
CPose2D absolutePoseOf(unsigned int n)
Returns the absolute pose of a robot after moving "n" poses, so for "n=0" the origin pose (0,...
Definition: CPoses2DSequence.cpp:87
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Definition: CSerializable.h:114
mrpt::poses::CPoses2DSequence::computeTraveledDistanceAfterAll
float computeTraveledDistanceAfterAll()
Returns the traveled distance after ALL movements.
Definition: CPoses2DSequence.cpp:129
mrpt::poses::CPoses2DSequence::absolutePoseAfterAll
CPose2D absolutePoseAfterAll()
A shortcut for "absolutePoseOf( posesCount() )".
Definition: CPoses2DSequence.cpp:102
mrpt::poses::CPoses2DSequence::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CPoses2DSequence.cpp:23
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
CPoses2DSequence.h
in
GLuint in
Definition: glext.h:7274
mrpt::poses::CPoses2DSequence::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CPoses2DSequence.cpp:22
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
uint32_t
unsigned __int32 uint32_t
Definition: rptypes.h:47



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST