39 template <
class RT,
class PT>
45 virtual RT getNDValue(
const PT*)
const = 0;
46 virtual int getNrDim()
const = 0;
60 template <
class RT,
class PT>
66 {
return getValue(*pos); }
69 virtual RT getValue( PT )
const = 0;
81 template <
class RT,
class PT>
89 {
return func_.getValue( sd.atIndex(idx) ); }
104 template <
class RT,
class PT>
109 virtual RT getValue(PT,PT)
const = 0;
112 {
return getValue(pos[0],pos[1]);}
121 template <
class RT,
class PT>
126 virtual RT getValue(PT,PT,PT)
const = 0;
129 {
return getValue(pos[0],pos[1],pos[2]);}
150 template <
class xT,
class yT>
164 int size()
const {
return x_.size(); }
167 void remove(
int idx);
169 {
return itype_ == Snap ? snapVal(x) : interpVal(x); }
179 virtual yT
getNDValue(
const xT* p )
const {
return getValue(*p); }
188 int baseIdx(xT)
const;
189 yT snapVal(xT)
const;
190 yT interpVal(xT)
const;
191 yT outsideVal(xT)
const;
195 void setXValue(
int idx,xT x);
214 template <
class RT,
class PT>
219 const PT* P_,
const PT* N_)
227 const int nrdim = func.getNrDim();
229 for (
int idx=0; idx<nrdim; idx++ )
230 pos[idx] =
P[idx] + N[idx]*lambda;
232 return func.getNDValue( pos );
251 : a( a_ ), b( b_ ), c( c_ )
261 a = ( (y0+y2) / 2 ) - y1;
268 return pos*pos * a + pos * b + c;
279 pos0 = pos1 =
mUdf(
float);
290 const double halfp = b/a/2;
291 const double q = c/a;
293 const double squareterm = halfp*halfp-q;
300 pos0 = (float)(-halfp+sq);
301 pos1 = (float)(-halfp-sq);
319 float c_=0,
float d_=0 )
320 : a( a_ ), b( b_ ), c( c_ ), d( d_ )
329 b = ( (y2+y0) / 2 ) - y1;
330 c = y2 - ( ( 2*y0 + 3*y1 + y3 ) / 6 );
331 a = ( (y2-y0) / 2 ) - c;
338 const float possq = pos * pos;
339 return possq * pos * a + possq * b + pos * c + d;
347 pos0 = pos1 =
mUdf(
float);
357 return derivate.
getRoots(pos0, pos1);
370 float getValue(
float)
const;
379 template <
class mXT,
class mYT>
inline 382 const int sz = x_.size();
383 if ( sz < 1 )
return -1;
384 const mXT x0 = x_[0];
385 if ( x < x0 )
return -1;
386 if ( sz == 1 )
return x >= x0 ? 0 : -1;
387 const mXT xlast = x_[sz-1];
388 if ( x >= xlast )
return sz-1;
389 if ( sz == 2 )
return 0;
391 int ilo = 0;
int ihi = sz - 1;
392 while ( ihi - ilo > 1 )
394 int imid = (ihi+ilo) / 2;
405 template <
class mXT,
class mYT>
inline 409 if ( x_.isPresent(x) )
return;
411 const int baseidx = baseIdx( x );
414 const int sz = x_.size();
415 if ( baseidx > sz - 3 )
418 mXT prevx = x; mYT prevy = y;
419 for (
int idx=baseidx+1; idx<sz; idx++ )
421 mXT tmpx = x_[idx]; mYT tmpy = y_[idx];
422 x_[idx] = prevx; y_[idx] = prevy;
423 prevx = tmpx; prevy = tmpy;
428 template <
class mXT,
class mYT>
inline 431 if ( idx<0 || idx >= size() )
438 template <
class mXT,
class mYT>
inline 441 if ( idx<0 || idx>=size() )
444 x_.removeSingle( idx );
445 y_.removeSingle( idx );
449 template <
class mXT,
class mYT>
inline 452 if ( extrapol_ ==
None )
455 const int sz = x_.size();
457 if ( extrapol_==EndVal || sz<2 )
458 return x-x_[0] < x_[sz-1]-x ? y_[0] : y_[sz-1];
462 const mYT gradient = (mYT)(y_[1]-y_[0]) / (mYT) (x_[1]-x_[0]);
463 return (mYT)(y_[0] + (x-x_[0]) * gradient);
466 const mYT gradient = (mYT)(y_[sz-1]-y_[sz-2]) / (mYT) (x_[sz-1]-x_[sz-2]);
467 return (mYT)(y_[sz-1] + (x-x_[sz-1]) * gradient);
473 template <
class mXT,
class mYT>
inline 476 const int sz = x_.size();
477 if ( sz < 1 )
return mUdf(mYT);
479 if ( x < x_[0] || x > x_[sz-1] )
480 return outsideVal(x);
482 const int baseidx = baseIdx( x );
486 if ( baseidx > sz-2 )
488 return x - x_[baseidx] < x_[baseidx+1] - x ? y_[baseidx] : y_[baseidx+1];
492 template <
class mXT,
class mYT>
inline 495 const int sz = x_.size();
496 if ( sz < 1 )
return mUdf(mYT);
498 if ( x < x_[0] || x > x_[sz-1] )
499 return outsideVal(x);
503 const int i0 = baseIdx( x );
504 const mYT v0 = y_[i0];
508 const mXT x0 = x_[i0];
509 const int i1 = i0 + 1;
const mXT x1 = x_[i1];
const mYT v1 = y_[i1];
510 const mXT dx = x1 - x0;
511 if ( dx == 0 )
return v0;
513 const mXT relx = (x - x0) / dx;
515 return relx < 0.5 ? v0 : v1;
522 return (mYT)(v1 * relx + v0 * (1-relx));
524 const int im1 = i0 > 0 ? i0 - 1 : i0;
525 const mXT xm1 = im1 == i0 ? x0 - dx : x_[im1];
526 const mYT vm1 =
mIsUdf(y_[im1]) ? v0 : y_[im1];
528 const int i2 = i1 < sz-1 ? i1 + 1 : i1;
529 const mXT x2 = i2 == i1 ? x1 + dx : x_[i2];
530 const mYT v2 =
mIsUdf(y_[i2]) ? v1 : y_[i2];
534 (
float) x2, v2, (
float) x );
#define mExpClass(module)
Definition: commondefs.h:160
ExtrapolType
Definition: mathfunc.h:156
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
SecondOrderPoly * createDerivative() const
Definition: mathfunc.h:342
RT operator[](int idx) const
Definition: mathfunc.h:88
const TypeSet< xT > & xVals() const
Definition: mathfunc.h:171
yT outsideVal(xT) const
Definition: mathfunc.h:450
void setExtrapolateType(ExtrapolType t)
Definition: mathfunc.h:178
A class for 3rd order polynomials on the form: a x^3 + b x^2 + c x + d.
Definition: mathfunc.h:315
float getValue(float pos) const
Definition: mathfunc.h:335
T poly1D(float x0, T v0, float x1, T v1, float x2, T v2, float x3, T v3, float x)
Definition: interpol1d.h:218
InterpolType
Definition: mathfunc.h:155
MathFunctionND< float, float > FloatMathFunctionND
Definition: mathfunc.h:49
const PT * N
Definition: mathfunc.h:238
Steepness and intercept.
Definition: linear.h:26
#define mIsZero(x, eps)
Definition: commondefs.h:53
TypeSet< xT > x_
Definition: mathfunc.h:185
MathFunction< float, float > FloatMathFunction
Definition: mathfunc.h:73
virtual yT getNDValue(const xT *p) const
Definition: mathfunc.h:179
float d
Definition: mathfunc.h:360
int getNrDim() const
Definition: mathfunc.h:130
void setXValue(int idx, xT x)
Definition: mathfunc.h:429
float getExtremePos() const
Definition: mathfunc.h:271
Mathematical function.
Definition: mathfunc.h:61
SecondOrderPoly(float a_=0, float b_=0, float c_=0)
Definition: mathfunc.h:250
void remove(int idx)
Definition: mathfunc.h:439
bool isEmpty() const
Definition: mathfunc.h:165
void setFromSamples(float y0, float y1, float y2, float y3)
Definition: mathfunc.h:327
Makes a MathFunction indexable through an operator[].
Definition: mathfunc.h:82
InterpolType interpolType() const
Definition: mathfunc.h:174
float c
Definition: mathfunc.h:307
void setInterpolType(InterpolType t)
Definition: mathfunc.h:177
SamplingData< PT > sd
Definition: mathfunc.h:91
FixedString None()
Definition: keystrs.h:90
RT getNDValue(const PT *pos) const
Definition: mathfunc.h:128
const TypeSet< yT > & yVals() const
Definition: mathfunc.h:172
ThirdOrderPoly(float a_=0, float b_=0, float c_=0, float d_=0)
Definition: mathfunc.h:318
bool extrapolate() const
Definition: mathfunc.h:176
virtual RT getNDValue(const PT *pos) const
Definition: mathfunc.h:65
const MathFunctionND< RT, PT > & func
Definition: mathfunc.h:239
int sz_
Definition: mathfunc.h:374
Definition: seistype.h:61
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
const PT * P
Definition: mathfunc.h:237
A Math Function as in F(x,y,z).
Definition: mathfunc.h:122
void setEmpty()
Definition: mathfunc.h:163
Interface to a series of values.
Definition: odmemory.h:17
yT interpVal(xT) const
Definition: mathfunc.h:493
int getExtremePos(float &pos0, float &pos1) const
Definition: mathfunc.h:345
BendPointBasedMathFunction< float, float > PointBasedMathFunction
Definition: mathfunc.h:201
Multidimensional Mathematical function.
Definition: mathfunc.h:40
virtual int getNrDim() const
Definition: mathfunc.h:67
#define mAllocVarLenArr(type, varnm, __size)
Definition: varlenarray.h:54
#define mDefEps
Definition: commondefs.h:58
void add(xT x, yT y)
Definition: mathfunc.h:406
AlongVectorFunction(const MathFunctionND< RT, PT > &func_, const PT *P_, const PT *N_)
Definition: mathfunc.h:218
Definition: mathfunc.h:365
RT getNDValue(const PT *pos) const
Definition: mathfunc.h:111
ExtrapolType extrapolateType() const
Definition: mathfunc.h:175
ExtrapolType extrapol_
Definition: mathfunc.h:184
BendPointBasedMathFunction(InterpolType t=Linear, ExtrapolType extr=EndVal)
Definition: mathfunc.h:158
A Math Function as in F(x,y).
Definition: mathfunc.h:105
virtual ~MathFunctionND()
Definition: mathfunc.h:43
yT snapVal(xT) const
Definition: mathfunc.h:474
int size() const
Definition: mathfunc.h:164
const ValueSeries< float > & vs_
Definition: mathfunc.h:373
int getNrDim() const
Definition: mathfunc.h:113
Definition: simpnumer.h:190
RT getValue(PT lambda) const
Definition: mathfunc.h:225
float getValue(float pos) const
Definition: mathfunc.h:265
void setFromSamples(float y0, float y1, float y2)
Definition: mathfunc.h:258
A MathFunction that cuts through another mathfunction with higher number of dimensions.
Definition: mathfunc.h:215
MathFunction based on bend points.
Definition: mathfunc.h:151
TypeSet< yT > y_
Definition: mathfunc.h:186
#define mClass(module)
Definition: commondefs.h:164
MathFunctionSampler(const MathFunction< RT, PT > &f)
Definition: mathfunc.h:85
bool isUdf(const T &t)
Definition: undefval.h:243
const MathFunction< RT, PT > & func_
Definition: mathfunc.h:95
MathFunction< double, double > DoubleMathFunction
Definition: mathfunc.h:74
int baseIdx(xT) const
Definition: mathfunc.h:380
InterpolType itype_
Definition: mathfunc.h:183
A class for 2nd order polynomials of the form: a x^2 + b x + c.
Definition: mathfunc.h:247
yT getValue(xT x) const
Definition: mathfunc.h:168
Definition: mathfunc.h:156
int getRoots(float &pos0, float &pos1) const
Definition: mathfunc.h:277