Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
interp1.hpp
1
9#ifndef QLIBS_INTERP1
10#define QLIBS_INTERP1
11
12#include <include/qlibs_types.hpp>
13
17namespace qlibs {
40
44 class interp1 {
45 private:
46 using interp1Fcn_t = real_t (*)( const real_t x,
47 const real_t * const tx,
48 const real_t * const ty,
49 const size_t tableSize );
50 const real_t *xData{ nullptr };
51 const real_t *yData{ nullptr };
52 size_t dataSize{ 0U };
53 interp1Fcn_t method{ &linear };
54 static real_t slope( const real_t * const tx,
55 const real_t * const ty,
56 const size_t i );
57 static real_t firstDerivate( const real_t * const tx,
58 const real_t * const ty,
59 const size_t n,
60 const size_t i );
61 static real_t leftSecondDerivate( const real_t * const tx,
62 const real_t * const ty,
63 const size_t n,
64 const size_t i );
65 static real_t rightSecondDerivate( const real_t * const tx,
66 const real_t * const ty,
67 const size_t n,
68 const size_t i );
69 static real_t next( const real_t x,
70 const real_t * const tx,
71 const real_t * const ty,
72 const size_t tableSize );
73 static real_t previous( const real_t x,
74 const real_t * const tx,
75 const real_t * const ty,
76 const size_t tableSize );
77 static real_t nearest( const real_t x,
78 const real_t * const tx,
79 const real_t * const ty,
80 const size_t tableSize );
81 static real_t linear( const real_t x,
82 const real_t * const tx,
83 const real_t * const ty,
84 const size_t tableSize );
85 static real_t sine( const real_t x,
86 const real_t * const tx,
87 const real_t * const ty,
88 const size_t tableSize );
89 static real_t cubic( const real_t x,
90 const real_t * const tx,
91 const real_t * const ty,
92 const size_t tableSize );
93 static real_t hermite( const real_t x,
94 const real_t * const tx,
95 const real_t * const ty,
96 const size_t tableSize );
97 static real_t spline( const real_t x,
98 const real_t * const tx,
99 const real_t * const ty,
100 const size_t tableSize );
101 static real_t cSpline( const real_t x,
102 const real_t * const tx,
103 const real_t * const ty,
104 const size_t tableSize );
105 public:
106 virtual ~interp1() {}
113 interp1( const real_t * const xTable,
114 const real_t * const yTable,
115 const size_t sizeTable ) : xData( xTable ), yData( yTable ), dataSize( sizeTable ) {}
116
122 template <size_t sizeTable>
123 interp1( real_t (&xTable)[ sizeTable ],
124 real_t (&yTable)[ sizeTable ] ) : interp1( xTable, yTable, sizeTable ) {}
125
132 bool setData( const real_t * const xTable,
133 const real_t * const yTable,
134 const size_t sizeTable )
135 {
136 bool retValue = false;
137
138 if ( ( nullptr != xTable ) && ( nullptr != yTable ) && ( sizeTable >= 4U ) ) {
139 xData = xTable;
140 yData = yTable;
141 dataSize = sizeTable;
142 retValue = true;
143 }
144 return retValue;
145 }
146
152 template <size_t sizeTable>
153 bool setData( real_t (&xTable)[ sizeTable ],
154 real_t (&yTable)[ sizeTable ] )
155 {
156 return setData( xTable, yTable, sizeTable );
157 }
158
164 bool setMethod( const interp1Method m ) noexcept;
165 template <typename T>
166
174 inline real_t get( const T x ) noexcept
175 {
176 return method( static_cast<real_t>( x ), xData, yData, dataSize );
177 }
178 };
179
181}
182
183
184#endif /*QLIBS_INTERP1*/
A 1D interpolation object.
Definition interp1.hpp:44
interp1(real_t(&xTable)[sizeTable], real_t(&yTable)[sizeTable])
Constructor for the 1D interpolation instance.
Definition interp1.hpp:123
real_t get(const T x) noexcept
Interpolate input point x to determine the value of y at the points xi using the current method....
Definition interp1.hpp:174
bool setData(real_t(&xTable)[sizeTable], real_t(&yTable)[sizeTable])
Set the data for the 1D interpolation instance.
Definition interp1.hpp:153
bool setMethod(const interp1Method m) noexcept
Specify the interpolation method to use.
Definition interp1.cpp:8
bool setData(const real_t *const xTable, const real_t *const yTable, const size_t sizeTable)
Set the data table for the 1D interpolation instance.
Definition interp1.hpp:132
virtual ~interp1()
Definition interp1.hpp:106
interp1(const real_t *const xTable, const real_t *const yTable, const size_t sizeTable)
Constructor for the 1D interpolation instance.
Definition interp1.hpp:113
interp1Method
An enum with all the available interpolation methods.
Definition interp1.hpp:26
@ INTERP1_CUBIC
Definition interp1.hpp:32
@ INTERP1_LINEAR
Definition interp1.hpp:30
@ INTERP1_PREVIOUS
Definition interp1.hpp:28
@ INTERP1_NEAREST
Definition interp1.hpp:29
@ INTERP1_NEXT
Definition interp1.hpp:27
@ INTERP1_SPLINE
Definition interp1.hpp:34
@ INTERP1_SINE
Definition interp1.hpp:31
@ INTERP1_CONSTRAINED_SPLINE
Definition interp1.hpp:35
@ INTERP1_HERMITE
Definition interp1.hpp:33
The qLibs++ library namespace.
Definition fp16.cpp:4
float real_t
A type to instantiate a real variable double-precision of 64-bits IEEE 754.
Definition qlibs_types.hpp:43