37 template <
class RT,
class PT>
43 virtual RT getNDValue(
const PT*)
const = 0;
44 virtual int getNrDim()
const = 0;
58 template <
class RT,
class PT>
64 {
return getValue(*pos); }
67 virtual RT getValue( PT )
const = 0;
79 template <
class RT,
class PT>
87 {
return func_.getValue( sd.atIndex(idx) ); }
102 template <
class RT,
class PT>
107 virtual RT getValue(PT,PT)
const = 0;
110 {
return getValue(pos[0],pos[1]);}
119 template <
class RT,
class PT>
124 virtual RT getValue(PT,PT,PT)
const = 0;
127 {
return getValue(pos[0],pos[1],pos[2]);}
148 template <
class xT,
class yT>
162 int size()
const {
return x_.size(); }
165 void remove(
int idx);
167 {
return itype_ == Snap ? snapVal(x) : interpVal(x); }
177 virtual yT
getNDValue(
const xT* p )
const {
return getValue(*p); }
186 int baseIdx(xT)
const;
187 yT snapVal(xT)
const;
188 yT interpVal(xT)
const;
189 yT outsideVal(xT)
const;
193 void setXValue(
int idx,xT x);
212 template <
class RT,
class PT>
217 const PT* P_,
const PT* N_)
225 const int nrdim = func.getNrDim();
227 for (
int idx=0; idx<nrdim; idx++ )
228 pos[idx] =
P[idx] + N[idx]*lambda;
230 return func.getNDValue( pos );
249 : a( a_ ), b( b_ ), c( c_ )
259 a = ( (y0+y2) / 2 ) - y1;
266 return pos*pos * a + pos * b + c;
277 pos0 = pos1 =
mUdf(
float);
288 const double halfp = b/a/2;
289 const double q = c/a;
291 const double squareterm = halfp*halfp-q;
298 pos0 = (float)(-halfp+sq);
299 pos1 = (float)(-halfp-sq);
317 float c_=0,
float d_=0 )
318 : a( a_ ), b( b_ ), c( c_ ), d( d_ )
327 b = ( (y2+y0) / 2 ) - y1;
328 c = y2 - ( ( 2*y0 + 3*y1 + y3 ) / 6 );
329 a = ( (y2-y0) / 2 ) - c;
336 const float possq = pos * pos;
337 return possq * pos * a + possq * b + pos * c + d;
345 pos0 = pos1 =
mUdf(
float);
355 return derivate.
getRoots(pos0, pos1);
368 float getValue(
float)
const;
377 template <
class mXT,
class mYT>
inline 380 const int sz = x_.size();
381 if ( sz < 1 )
return -1;
382 const mXT x0 = x_[0];
383 if ( x < x0 )
return -1;
384 if ( sz == 1 )
return x >= x0 ? 0 : -1;
385 const mXT xlast = x_[sz-1];
386 if ( x >= xlast )
return sz-1;
387 if ( sz == 2 )
return 0;
389 int ilo = 0;
int ihi = sz - 1;
390 while ( ihi - ilo > 1 )
392 int imid = (ihi+ilo) / 2;
403 template <
class mXT,
class mYT>
inline 407 if ( x_.isPresent(x) )
return;
409 const int baseidx = baseIdx( x );
412 const int sz = x_.size();
413 if ( baseidx > sz - 3 )
416 mXT prevx = x; mYT prevy = y;
417 for (
int idx=baseidx+1; idx<sz; idx++ )
419 mXT tmpx = x_[idx]; mYT tmpy = y_[idx];
420 x_[idx] = prevx; y_[idx] = prevy;
421 prevx = tmpx; prevy = tmpy;
426 template <
class mXT,
class mYT>
inline 429 if ( idx<0 || idx >= size() )
436 template <
class mXT,
class mYT>
inline 439 if ( idx<0 || idx>=size() )
442 x_.removeSingle( idx );
443 y_.removeSingle( idx );
447 template <
class mXT,
class mYT>
inline 450 if ( extrapol_ ==
None )
453 const int sz = x_.size();
455 if ( extrapol_==EndVal || sz<2 )
456 return x-x_[0] < x_[sz-1]-x ? y_[0] : y_[sz-1];
460 const mYT gradient = (mYT)(y_[1]-y_[0]) / (mYT) (x_[1]-x_[0]);
461 return (mYT)(y_[0] + (x-x_[0]) * gradient);
464 const mYT gradient = (mYT)(y_[sz-1]-y_[sz-2]) / (mYT) (x_[sz-1]-x_[sz-2]);
465 return (mYT)(y_[sz-1] + (x-x_[sz-1]) * gradient);
471 template <
class mXT,
class mYT>
inline 474 const int sz = x_.size();
475 if ( sz < 1 )
return mUdf(mYT);
477 if ( x < x_[0] || x > x_[sz-1] )
478 return outsideVal(x);
480 const int baseidx = baseIdx( x );
484 if ( baseidx > sz-2 )
486 return x - x_[baseidx] < x_[baseidx+1] - x ? y_[baseidx] : y_[baseidx+1];
490 template <
class mXT,
class mYT>
inline 493 const int sz = x_.size();
494 if ( sz < 1 )
return mUdf(mYT);
496 if ( x < x_[0] || x > x_[sz-1] )
497 return outsideVal(x);
501 const int i0 = baseIdx( x );
502 const mYT v0 = y_[i0];
506 const mXT x0 = x_[i0];
507 const int i1 = i0 + 1;
const mXT x1 = x_[i1];
const mYT v1 = y_[i1];
508 const mXT dx = x1 - x0;
509 if ( dx == 0 )
return v0;
511 const mXT relx = (x - x0) / dx;
513 return relx < 0.5 ? v0 : v1;
520 return (mYT)(v1 * relx + v0 * (1-relx));
522 const int im1 = i0 > 0 ? i0 - 1 : i0;
523 const mXT xm1 = im1 == i0 ? x0 - dx : x_[im1];
524 const mYT vm1 =
mIsUdf(y_[im1]) ? v0 : y_[im1];
526 const int i2 = i1 < sz-1 ? i1 + 1 : i1;
527 const mXT x2 = i2 == i1 ? x1 + dx : x_[i2];
528 const mYT v2 =
mIsUdf(y_[i2]) ? v1 : y_[i2];
532 (
float) x2, v2, (
float) x );
#define mExpClass(module)
Definition: commondefs.h:157
ExtrapolType
Definition: mathfunc.h:154
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:285
SecondOrderPoly * createDerivative() const
Definition: mathfunc.h:340
RT operator[](int idx) const
Definition: mathfunc.h:86
const TypeSet< xT > & xVals() const
Definition: mathfunc.h:169
yT outsideVal(xT) const
Definition: mathfunc.h:448
void setExtrapolateType(ExtrapolType t)
Definition: mathfunc.h:176
A class for 3rd order polynomials on the form: a x^3 + b x^2 + c x + d.
Definition: mathfunc.h:313
float getValue(float pos) const
Definition: mathfunc.h:333
T poly1D(float x0, T v0, float x1, T v1, float x2, T v2, float x3, T v3, float x)
Definition: interpol1d.h:216
InterpolType
Definition: mathfunc.h:153
MathFunctionND< float, float > FloatMathFunctionND
Definition: mathfunc.h:47
const PT * N
Definition: mathfunc.h:236
Steepness and intercept.
Definition: linear.h:25
#define mIsZero(x, eps)
Definition: commondefs.h:55
TypeSet< xT > x_
Definition: mathfunc.h:183
MathFunction< float, float > FloatMathFunction
Definition: mathfunc.h:71
virtual yT getNDValue(const xT *p) const
Definition: mathfunc.h:177
float d
Definition: mathfunc.h:358
int getNrDim() const
Definition: mathfunc.h:128
void setXValue(int idx, xT x)
Definition: mathfunc.h:427
float getExtremePos() const
Definition: mathfunc.h:269
Mathematical function.
Definition: mathfunc.h:59
SecondOrderPoly(float a_=0, float b_=0, float c_=0)
Definition: mathfunc.h:248
void remove(int idx)
Definition: mathfunc.h:437
bool isEmpty() const
Definition: mathfunc.h:163
void setFromSamples(float y0, float y1, float y2, float y3)
Definition: mathfunc.h:325
Makes a MathFunction indexable through an operator[].
Definition: mathfunc.h:80
InterpolType interpolType() const
Definition: mathfunc.h:172
float c
Definition: mathfunc.h:305
void setInterpolType(InterpolType t)
Definition: mathfunc.h:175
SamplingData< PT > sd
Definition: mathfunc.h:89
FixedString None()
Definition: keystrs.h:90
RT getNDValue(const PT *pos) const
Definition: mathfunc.h:126
const TypeSet< yT > & yVals() const
Definition: mathfunc.h:170
ThirdOrderPoly(float a_=0, float b_=0, float c_=0, float d_=0)
Definition: mathfunc.h:316
bool extrapolate() const
Definition: mathfunc.h:174
virtual RT getNDValue(const PT *pos) const
Definition: mathfunc.h:63
const MathFunctionND< RT, PT > & func
Definition: mathfunc.h:237
int sz_
Definition: mathfunc.h:372
Definition: seistype.h:59
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:270
const PT * P
Definition: mathfunc.h:235
A Math Function as in F(x,y,z).
Definition: mathfunc.h:120
void setEmpty()
Definition: mathfunc.h:161
Interface to a series of values.
Definition: odmemory.h:15
yT interpVal(xT) const
Definition: mathfunc.h:491
int getExtremePos(float &pos0, float &pos1) const
Definition: mathfunc.h:343
BendPointBasedMathFunction< float, float > PointBasedMathFunction
Definition: mathfunc.h:199
Multidimensional Mathematical function.
Definition: mathfunc.h:38
virtual int getNrDim() const
Definition: mathfunc.h:65
#define mAllocVarLenArr(type, varnm, __size)
Definition: varlenarray.h:52
#define mDefEps
Definition: commondefs.h:60
void add(xT x, yT y)
Definition: mathfunc.h:404
AlongVectorFunction(const MathFunctionND< RT, PT > &func_, const PT *P_, const PT *N_)
Definition: mathfunc.h:216
Definition: mathfunc.h:363
RT getNDValue(const PT *pos) const
Definition: mathfunc.h:109
ExtrapolType extrapolateType() const
Definition: mathfunc.h:173
ExtrapolType extrapol_
Definition: mathfunc.h:182
BendPointBasedMathFunction(InterpolType t=Linear, ExtrapolType extr=EndVal)
Definition: mathfunc.h:156
A Math Function as in F(x,y).
Definition: mathfunc.h:103
virtual ~MathFunctionND()
Definition: mathfunc.h:41
yT snapVal(xT) const
Definition: mathfunc.h:472
int size() const
Definition: mathfunc.h:162
const ValueSeries< float > & vs_
Definition: mathfunc.h:371
int getNrDim() const
Definition: mathfunc.h:111
Definition: simpnumer.h:188
RT getValue(PT lambda) const
Definition: mathfunc.h:223
float getValue(float pos) const
Definition: mathfunc.h:263
void setFromSamples(float y0, float y1, float y2)
Definition: mathfunc.h:256
A MathFunction that cuts through another mathfunction with higher number of dimensions.
Definition: mathfunc.h:213
MathFunction based on bend points.
Definition: mathfunc.h:149
TypeSet< yT > y_
Definition: mathfunc.h:184
#define mClass(module)
Definition: commondefs.h:161
MathFunctionSampler(const MathFunction< RT, PT > &f)
Definition: mathfunc.h:83
bool isUdf(const T &t)
Definition: undefval.h:241
const MathFunction< RT, PT > & func_
Definition: mathfunc.h:93
MathFunction< double, double > DoubleMathFunction
Definition: mathfunc.h:72
int baseIdx(xT) const
Definition: mathfunc.h:378
InterpolType itype_
Definition: mathfunc.h:181
A class for 2nd order polynomials of the form: a x^2 + b x + c.
Definition: mathfunc.h:245
yT getValue(xT x) const
Definition: mathfunc.h:166
Definition: mathfunc.h:154
int getRoots(float &pos0, float &pos1) const
Definition: mathfunc.h:275