Main MRPT website > C++ reference for MRPT 1.9.9
CSplineInterpolator1D.h
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 #ifndef CSplineInterpolator1D_H
10 #define CSplineInterpolator1D_H
11 
12 #include <mrpt/utils/utils_defs.h>
14 #include <map>
15 
16 namespace mrpt
17 {
18 namespace math
19 {
20 /** A (persistent) sequence of (x,y) coordinates, allowing queries of
21  * intermediate points through spline interpolation, where possible.
22  * This class internally relies on mrpt::math::spline. Optionally the y
23  * coordinate can be set as wrapped in ]-pi,pi].
24  * For querying interpolated points, see
25  * \ sa mrpt::math::spline, mrpt::poses::CPose3DInterpolator
26  * \ingroup interpolation_grp
27  */
29 {
31 
32  private:
33  /** The placeholders for the data */
34  std::map<double, double> m_x2y;
35 
36  /** Whether to wrap "y" */
37  bool m_wrap2pi;
38 
39  public:
40  /** Constructor with optional initial values. */
41  template <class VECTOR>
43  const VECTOR& initial_x, const VECTOR& initial_y, bool wrap2pi = false)
44  : m_wrap2pi(wrap2pi)
45  {
46  setXY(initial_x, initial_y);
47  }
48 
49  /** Constructor */
50  CSplineInterpolator1D(bool wrap2pi = false);
51 
52  /** If set to true, the interpolated data will be wrapped to ]-pi,pi] */
53  void setWrap2pi(bool wrap) { m_wrap2pi = wrap; }
54  /** Return the wrap property */
55  bool getWrap2pi() { return m_wrap2pi; }
56  /** Set all the data at once .
57  * The vectors must have the same length.
58  */
59  template <class VECTOR>
60  void setXY(
61  const VECTOR& x, const VECTOR& y, bool clearPreviousContent = true)
62  {
64  if (clearPreviousContent) m_x2y.clear();
65  ASSERT_EQUAL_(x.size(), y.size())
66  const size_t n = size_t(x.size());
67  for (size_t i = 0; i < n; i++) m_x2y[x[i]] = y[i];
68  MRPT_END
69  }
70 
71  /** Append a new point: */
72  void appendXY(double x, double y);
73 
74  /** Clears all stored points */
75  void clear() { m_x2y.clear(); }
76  /** Query an interpolation of the curve at some "x".
77  * The result is stored in "y". If the "x" point is out of range,
78  * "valid_out" is set to false.
79  * \return A reference to "y"
80  * \sa queryVector
81  */
82  double& query(double x, double& y, bool& out_valid) const;
83 
84  /** As query, but for a whole vector at once.
85  * \return false if there is at least one value that couldn't be
86  * interpolated (in this case the output is indeterminate).
87  * \sa query
88  */
89  template <class VECTOR1, class VECTOR2>
90  bool queryVector(const VECTOR1& x, VECTOR2& out_y) const
91  {
92  const size_t n = size_t(x.size());
93  out_y.resize(n);
94  bool valid, anyValid = false;
95  for (size_t i = 0; i < n; i++)
96  {
97  query(x[i], out_y[i], valid);
98  if (valid) anyValid = true;
99  }
100  return anyValid;
101  }
102 };
103 
104 } // End of namespace
105 } // End of namespace
106 #endif
#define ASSERT_EQUAL_(__A, __B)
std::map< double, double > m_x2y
The placeholders for the data.
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
void clear()
Clears all stored points.
bool m_wrap2pi
Whether to wrap "y".
GLenum GLsizei n
Definition: glext.h:5074
void appendXY(double x, double y)
Append a new point:
A (persistent) sequence of (x,y) coordinates, allowing queries of intermediate points through spline ...
#define MRPT_END
void setWrap2pi(bool wrap)
If set to true, the interpolated data will be wrapped to ]-pi,pi].
bool queryVector(const VECTOR1 &x, VECTOR2 &out_y) const
As query, but for a whole vector at once.
#define MRPT_START
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
GLenum GLint GLint y
Definition: glext.h:3538
GLenum GLint x
Definition: glext.h:3538
void setXY(const VECTOR &x, const VECTOR &y, bool clearPreviousContent=true)
Set all the data at once .
bool getWrap2pi()
Return the wrap property.
double & query(double x, double &y, bool &out_valid) const
Query an interpolation of the curve at some "x".
CSplineInterpolator1D(const VECTOR &initial_x, const VECTOR &initial_y, bool wrap2pi=false)
Constructor with optional initial values.



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