Main MRPT website > C++ reference for MRPT 1.9.9
CPose2DInterpolator.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 "CPoseInterpolatorBase.hpp" // templ impl
15 
16 using namespace mrpt::utils;
17 using namespace mrpt::poses;
18 
20 
21 void CPose2DInterpolator::writeToStream(
22  mrpt::utils::CStream& out, int* version) const
23 {
24  if (version)
25  *version = 0;
26  else
27  {
28  out << m_path;
29  }
30 }
31 
32 void CPose2DInterpolator::readFromStream(mrpt::utils::CStream& in, int version)
33 {
34  switch (version)
35  {
36  case 0:
37  {
38  in >> m_path;
39  }
40  break;
41  default:
43  };
44 }
45 
46 namespace mrpt
47 {
48 namespace poses
49 {
50 // Specialization for DIM=2
51 template <>
53  const mrpt::math::CArrayDouble<4>& ts, const TTimePosePair p1,
54  const TTimePosePair p2, const TTimePosePair p3, const TTimePosePair p4,
55  const TInterpolatorMethod method, double td, pose_t& out_interp) const
56 {
57  using mrpt::math::TPose2D;
59  X[0] = p1.second.x;
60  Y[0] = p1.second.y;
61  yaw[0] = p1.second.phi;
62  X[1] = p2.second.x;
63  Y[1] = p2.second.y;
64  yaw[1] = p2.second.phi;
65  X[2] = p3.second.x;
66  Y[2] = p3.second.y;
67  yaw[2] = p3.second.phi;
68  X[3] = p4.second.x;
69  Y[3] = p4.second.y;
70  yaw[3] = p4.second.phi;
71 
72  unwrap2PiSequence(yaw);
73 
74  // Target interpolated values:
75  switch (method)
76  {
77  case imSpline:
78  {
79  // ---------------------------------------
80  // SPLINE INTERPOLATION
81  // ---------------------------------------
82  out_interp.x = math::spline(td, ts, X);
83  out_interp.y = math::spline(td, ts, Y);
84  out_interp.phi = math::spline(td, ts, yaw, true); // Wrap 2pi
85  }
86  break;
87 
88  case imLinear2Neig:
89  {
90  out_interp.x =
91  math::interpolate2points(td, ts[1], X[1], ts[2], X[2]);
92  out_interp.y =
93  math::interpolate2points(td, ts[1], Y[1], ts[2], Y[2]);
94  out_interp.phi = math::interpolate2points(
95  td, ts[1], yaw[1], ts[2], yaw[2], true); // Wrap 2pi
96  }
97  break;
98 
99  case imLinear4Neig:
100  {
101  out_interp.x =
102  math::leastSquareLinearFit<double, decltype(ts), 4>(td, ts, X);
103  out_interp.y =
104  math::leastSquareLinearFit<double, decltype(ts), 4>(td, ts, Y);
105  out_interp.phi =
106  math::leastSquareLinearFit<double, decltype(ts), 4>(
107  td, ts, yaw, true); // Wrap 2pi
108  }
109  break;
110 
111  case imSSLLLL:
112  {
113  out_interp.x = math::spline(td, ts, X);
114  out_interp.y = math::spline(td, ts, Y);
115  out_interp.phi =
116  math::leastSquareLinearFit<double, decltype(ts), 4>(
117  td, ts, yaw, true); // Wrap 2pi
118  }
119  break;
120 
121  case imSSLSLL:
122  {
123  out_interp.x = math::spline(td, ts, X);
124  out_interp.y = math::spline(td, ts, Y);
125  out_interp.phi = math::spline(td, ts, yaw, true); // Wrap 2pi
126  }
127  break;
128 
129  case imLinearSlerp:
130  {
131  const double ratio = (td - ts[1]) / (ts[2] - ts[1]);
132  const double Aang = mrpt::math::angDistance(yaw[1], yaw[2]);
133  out_interp.phi = yaw[1] + ratio * Aang;
134 
135  out_interp.x =
136  math::interpolate2points(td, ts[1], X[1], ts[2], X[2]);
137  out_interp.y =
138  math::interpolate2points(td, ts[1], Y[1], ts[2], Y[2]);
139  }
140  break;
141 
142  case imSplineSlerp:
143  {
144  const double ratio = (td - ts[1]) / (ts[2] - ts[1]);
145  const double Aang = mrpt::math::angDistance(yaw[1], yaw[2]);
146  out_interp.phi = yaw[1] + ratio * Aang;
147 
148  out_interp.x = math::spline(td, ts, X);
149  out_interp.y = math::spline(td, ts, Y);
150  }
151  break;
152 
153  default:
154  THROW_EXCEPTION("Unknown value for interpolation method!");
155  }; // end switch
156 }
157 
158 // Explicit instantations:
159 template class CPoseInterpolatorBase<2>;
160 }
161 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Base class for SE(2)/SE(3) interpolators.
This class stores a time-stamped trajectory in SE(2) (mrpt::math::TPose2D poses). ...
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.
#define THROW_EXCEPTION(msg)
T angDistance(T from, T to)
Computes the shortest angular increment (or distance) between two planar orientations, such that it is constrained to [-pi,pi] and is correct for any combination of angles (e.g.
Definition: wrap2pi.h:98
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
#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
mrpt::poses::SE_traits< DIM >::lightweight_pose_t pose_t
TPose2D or TPose3D.
std::pair< mrpt::system::TTimeStamp, pose_t > TTimePosePair
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void unwrap2PiSequence(VECTOR &x)
Modify a sequence of angle values such as no consecutive values have a jump larger than PI in absolut...
Definition: wrap2pi.h:74
NUMTYPE spline(const NUMTYPE t, const VECTORLIKE &x, const VECTORLIKE &y, bool wrap2pi=false)
Interpolates the value of a function in a point "t" given 4 SORTED points where "t" is between the tw...
Definition: interp_fit.hpp:37
GLuint in
Definition: glext.h:7274
Lightweight 2D pose.
A partial specialization of CArrayNumeric for double numbers.
Definition: CArrayNumeric.h:87
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
double interpolate2points(const double x, const double x0, const double y0, const double x1, const double y1, bool wrap2pi=false)
Linear interpolation/extrapolation: evaluates at "x" the line (x0,y0)-(x1,y1).
Definition: math.cpp:1975
TInterpolatorMethod
Type to select the interpolation method in CPoseInterpolatorBase derived classes. ...



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