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