1 #ifndef periodicvalue_h 2 #define periodicvalue_h 28 int n = (int) (val / period);
31 return n ? val - n * period : val;
39 template <
class T,
int P>
43 T
val(
bool positive=
true)
const 46 if ( !positive && res > ((T)P)/2 )
73 { val_ = nv;
return this; }
75 { val_ += nv;
return this; }
77 { val_ -= nv;
return this; }
79 { val_ *= nv;
return this; }
81 { val_ /= nv;
return this; }
83 { val_ = nv.
val();
return this; }
85 { val_ += nv.
val();
return this; }
87 { val_ -= nv.
val();
return this; }
89 { val_ *= nv.
val();
return this; }
91 { val_ /= nv.
val();
return this; }
93 bool operator<(const PeriodicValue<T,P>& b)
const 96 if ( tmp.
val(
true)>
P/2 )
return true;
102 if ( tmp.
val(
true)<=
P/2 )
return true;
106 {
return *this < PeriodicValue<T,P>(b); }
126 template <
class T,
class RT>
128 RT& ret,
RT period,
bool extrapolate=
false )
130 const float halfperiod = period / 2;
132 float dist = pos - intpos;
133 if(
mIsZero(dist,1e-10) && intpos >= 0 && intpos < sz )
134 { ret = idxabl[intpos];
return; }
136 int prevpos = dist > 0 ? intpos : intpos - 1;
137 if ( !extrapolate && (prevpos > sz-2 || prevpos < 0) )
139 else if ( prevpos < 1 )
141 const float val0 = idxabl[0];
143 while ( val1 - val0 > halfperiod ) val1 -= period;
144 while ( val1 - val0 < -halfperiod ) val1 += period;
149 else if ( prevpos > sz-3 )
151 const RT val0 = idxabl[sz-2];
153 while ( val1 - val0 > halfperiod ) val1 -= period;
154 while ( val1 - val0 < -halfperiod ) val1 += period;
160 const RT val0 = idxabl[prevpos-1];
162 RT val1 = idxabl[prevpos];
163 while ( val1 - val0 > halfperiod ) val1 -= period;
164 while ( val1 - val0 < -halfperiod ) val1 += period;
166 RT val2 = idxabl[prevpos+1];
167 while ( val2 - val1 > halfperiod ) val2 -= period;
168 while ( val2 - val1 < -halfperiod ) val2 += period;
170 RT val3 = idxabl[prevpos+2];
171 while ( val3 - val2 > halfperiod ) val3 -= period;
172 while ( val3 - val2 < -halfperiod ) val3 += period;
175 pos - prevpos ), period );
182 float period,
bool extrapolate=
false )
184 float ret =
mUdf(
float);
196 template <
class T,
class RT>
201 float dist = pos - intpos;
202 if(
mIsZero(dist,1e-10) && intpos >= 0 && intpos < sz )
203 { ret = idxabl[intpos];
return; }
205 int prevpos = dist > 0 ? intpos : intpos - 1;
206 const float relpos = pos - prevpos;
209 int prevpos2 = prevpos - 1;
212 int nextpos = prevpos + 1;
215 int nextpos2 = prevpos + 2;
218 const RT prevval2 = idxabl[prevpos2];
219 const RT prevval = idxabl[prevpos];
220 const RT nextval = idxabl[nextpos];
221 const RT nextval2 = idxabl[nextpos2];
PeriodicValue(T nv)
Definition: periodicvalue.h:111
#define mIsZero(x, eps)
Definition: commondefs.h:53
const PeriodicValue< T, P > & operator-=(const PeriodicValue< T, P > &nv)
Definition: periodicvalue.h:86
void interpolateXPeriodicReg(const T &idxabl, int sz, float pos, RT &ret)
Definition: periodicvalue.h:197
const PeriodicValue< T, P > & operator/=(T nv)
Definition: periodicvalue.h:80
T polyReg1D(T vm1, T v0, T v1, T v2, float x)
Definition: interpol1d.h:130
const PeriodicValue< T, P > & operator-=(T nv)
Definition: periodicvalue.h:76
PeriodicValue handles periodic data through mathematical operations.
Definition: periodicvalue.h:40
PeriodicValue< T, P > operator+(const PeriodicValue< T, P > &nv) const
Definition: periodicvalue.h:63
const PeriodicValue< T, P > & operator=(const PeriodicValue< T, P > &nv) const
Definition: periodicvalue.h:82
PeriodicValue< T, P > operator*(const PeriodicValue< T, P > &nv) const
Definition: periodicvalue.h:67
PeriodicValue< T, P > operator-(const PeriodicValue< T, P > &nv) const
Definition: periodicvalue.h:65
#define mNINT32(x)
Definition: commondefs.h:45
const T val2
Definition: arrayndalgo.h:1699
T val_
Definition: periodicvalue.h:114
PeriodicValue< T, P > operator/(const PeriodicValue< T, P > &nv) const
Definition: periodicvalue.h:69
PeriodicValue< T, P > operator+(T nv) const
Definition: periodicvalue.h:55
PeriodicValue< T, P > operator/(T nv) const
Definition: periodicvalue.h:61
Definition: seistype.h:61
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
T val(bool positive=true) const
Definition: periodicvalue.h:43
bool operator<(T b) const
Definition: periodicvalue.h:105
void interpolateYPeriodicReg(const T &idxabl, int sz, float pos, RT &ret, RT period, bool extrapolate=false)
Definition: periodicvalue.h:127
T linearReg1D(T v0, T v1, float x)
Definition: interpol1d.h:46
const PeriodicValue< T, P > & operator=(T nv) const
Definition: periodicvalue.h:72
const PeriodicValue< T, P > & operator/=(const PeriodicValue< T, P > &nv)
Definition: periodicvalue.h:90
bool operator>(T b) const
Definition: periodicvalue.h:107
Position-sorted indexable objects.
Definition: idxable.h:30
PeriodicValue< T, P > operator*(T nv) const
Definition: periodicvalue.h:59
T dePeriodize(T val, T period)
Definition: periodicvalue.h:26
const PeriodicValue< T, P > & operator*=(T nv)
Definition: periodicvalue.h:78
const PeriodicValue< T, P > & operator+=(T nv)
Definition: periodicvalue.h:74
bool operator>(const PeriodicValue< T, P > &b) const
Definition: periodicvalue.h:99
PeriodicValue< T, P > operator-(T nv) const
Definition: periodicvalue.h:57
const PeriodicValue< T, P > & operator*=(const PeriodicValue< T, P > &nv)
Definition: periodicvalue.h:88
#define mClass(module)
Definition: commondefs.h:164
const T val1
Definition: arrayndalgo.h:1699
const PeriodicValue< T, P > & operator+=(const PeriodicValue< T, P > &nv)
Definition: periodicvalue.h:84