48 return x * v1 + (1-x) * v0;
60 return x < 0.5 ?
mUdf(T) : v1;
62 return x >= 0.5 ?
mUdf(T) : v0;
74 inline T
linear1D(
float x0, T v0,
float x1, T v1,
float x )
76 return v0 + (x-x0) * (v1-v0) / (x1-x0);
81 inline iT
linear1Di(
float x0, iT v0,
float x1, iT v1,
float x )
83 const float tmp = v0 + (x-x0) * (v1-v0) / (x1-x0);
103 set( v[0], v[1], v[2], v[3] );
108 set( vm1, v0, v1, v2 );
111 inline void set( T vm1, T v0, T v1, T v2 )
114 a_[1] = v1 - (( 2*vm1 + 3*v0 + v2 ) / 6);
115 a_[2] = (( v1 + vm1 ) / 2) - v0;
116 a_[3] = (( v1 - vm1 ) / 2) - a_[1];
121 const float xsq = x * x;
122 return xsq * x * a_[3] + xsq * a_[2] + x * a_[1] + a_[0];
150 {
set ( 0, 0, 0, 0 ); }
154 set( v[0], v[1], v[2], v[3] );
159 set( vm1, v0, v1, v2 );
162 inline void set( T vm1, T v0, T v1, T v2 )
165 if ( v0udf_ && v1udf_ )
return;
167 if (
mIsUdf(vm1) ) vm1 = v0udf_ ? v1 : v0;
168 if (
mIsUdf(v2) ) v2 = v1udf_ ? v0 : v1;
169 if ( v0udf_ ) v0 = vm1;
170 if ( v1udf_ ) v1 = v2;
172 intp_.set( vm1, v0, v1, v2 );
177 if ( (v0udf_ && x < 0.5) || (v1udf_ && x >= 0.5) )
179 return intp_.apply( x );
202 inline T
parabolic1D(
float x0, T v0,
float x1, T v1,
float x2, T v2,
float x )
204 float xx0 = x - x0, xx1 = x-x1, xx2 = x-x2;
205 return v0 * xx1 * xx2 / ((x0 - x1) * (x0 - x2)) +
206 v1 * xx0 * xx2 / ((x1 - x0) * (x1 - x2)) +
207 v2 * xx0 * xx1 / ((x2 - x0) * (x2 - x1));
218 inline T
poly1D(
float x0, T v0,
float x1, T v1,
float x2, T v2,
219 float x3, T v3,
float x )
221 float xx0 = x - x0, xx1 = x-x1, xx2 = x-x2, xx3 = x-x3;
222 return v0 * xx1 * xx2 * xx3 / ((x0 - x1) * (x0 - x2) * (x0 - x3)) +
223 v1 * xx0 * xx2 * xx3 / ((x1 - x0) * (x1 - x2) * (x1 - x3)) +
224 v2 * xx0 * xx1 * xx3 / ((x2 - x0) * (x2 - x1) * (x2 - x3)) +
225 v3 * xx0 * xx1 * xx2 / ((x3 - x0) * (x3 - x1) * (x3 - x2));
237 return (-2 * vm2 + 8 * vm1 + 8 * v1 - 2 * v2) / 12;
249 return (vm3 - 6 * vm2 + 15 * vm1 + 15 * v1 - 6 * v2 + v3) / 20;
Definition: interpol1d.h:38
bool v1udf_
Definition: interpol1d.h:184
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
PolyReg1D< T > intp_
Definition: interpol1d.h:182
T apply(float x) const
Definition: interpol1d.h:175
T poly1D(float x0, T v0, float x1, T v1, float x2, T v2, float x3, T v3, float x)
Definition: interpol1d.h:218
#define mRounded(typ, x)
Definition: commondefs.h:44
iT linear1Di(float x0, iT v0, float x1, iT v1, float x)
Interpolate 1D regularly sampled, using a 3rd order polynome.
Definition: interpol1d.h:81
T linearReg1DWithUdf(T v0, T v1, float x)
Definition: interpol1d.h:57
Definition: interpol1d.h:92
T predictAtZero1D(T vm2, T vm1, T v1, T v2)
Definition: interpol1d.h:235
PolyReg1D(const T *v)
Definition: interpol1d.h:101
T polyReg1D(T vm1, T v0, T v1, T v2, float x)
Definition: interpol1d.h:130
PolyReg1D()
Definition: interpol1d.h:96
T apply(float x) const
Definition: interpol1d.h:119
PolyReg1DWithUdf(T vm1, T v0, T v1, T v2)
Definition: interpol1d.h:157
bool v0udf_
Definition: interpol1d.h:183
PolyReg1D(T vm1, T v0, T v1, T v2)
Definition: interpol1d.h:106
T polyReg1DWithUdf(T vm1, T v0, T v1, T v2, float x)
Definition: interpol1d.h:189
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
PolyReg1DWithUdf()
Definition: interpol1d.h:149
T linearReg1D(T v0, T v1, float x)
Definition: interpol1d.h:46
T linear1D(float x0, T v0, float x1, T v1, float x)
Definition: interpol1d.h:74
PolyReg1DWithUdf(const T *v)
Definition: interpol1d.h:152
T parabolic1D(float x0, T v0, float x1, T v1, float x2, T v2, float x)
Definition: interpol1d.h:202
#define mClass(module)
Definition: commondefs.h:164
PolyReg1D which smoothly handles undefined values.
Definition: interpol1d.h:145