Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
14#include <map>
15
16namespace 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];
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 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)
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
A (persistent) sequence of (x,y) coordinates, allowing queries of intermediate points through spline ...
CSplineInterpolator1D(const VECTOR &initial_x, const VECTOR &initial_y, bool wrap2pi=false)
Constructor with optional initial values.
bool queryVector(const VECTOR1 &x, VECTOR2 &out_y) const
As query, but for a whole vector at once.
bool getWrap2pi()
Return the wrap property.
void setWrap2pi(bool wrap)
If set to true, the interpolated data will be wrapped to ]-pi,pi].
double & query(double x, double &y, bool &out_valid) const
Query an interpolation of the curve at some "x".
CSplineInterpolator1D(bool wrap2pi=false)
Constructor.
void clear()
Clears all stored points.
void setXY(const VECTOR &x, const VECTOR &y, bool clearPreviousContent=true)
Set all the data at once .
std::map< double, double > m_x2y
The placeholders for the data.
void appendXY(double x, double y)
Append a new point:
The virtual base class which provides a unified interface for all persistent objects in MRPT.
Definition: CSerializable.h:40
#define ASSERT_EQUAL_(__A, __B)
Definition: mrpt_macros.h:264
#define MRPT_START
Definition: mrpt_macros.h:349
#define MRPT_END
Definition: mrpt_macros.h:353
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.9.2 for MRPT 1.4.0 SVN: at Mon Sep 20 00:21:40 UTC 2021