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



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