OpendTect-6_4  6.4
valseriesinterpol.h
Go to the documentation of this file.
1 #ifndef valseriesinterpol_h
2 #define valseriesinterpol_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert Bril & Kris Tingdahl
9  Date: Mar 2005
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "valseries.h"
16 #include "periodicvalue.h"
17 
18 /*\brief interpolates between values of a ValueSeries object
19 
20  Note that we assume that the values are equidistant in 'X'.
21 
22  */
23 
24 template <class T>
26 {
27 public:
28  ValueSeriesInterpolator( int mxidx=mUdf(int) )
29  : maxidx_(mxidx)
30  , snapdist_(0)
31  , smooth_(true)
32  , extrapol_(false)
33  , udfval_(mUdf(T))
34  , isperiodic_(false)
35  , period_(1)
36  , linear_(false)
37  , hasudfs_(true) {}
38 
39  inline T value(const ValueSeries<T>&,T pos) const;
40 
41  int maxidx_;
44  bool smooth_;
45  bool extrapol_;
47  bool hasudfs_;
49  bool linear_;
50 
51 };
52 
53 
54 #define mChkVSIRg \
55  { if ( curidx < 0 ) curidx = 0; \
56  else if ( curidx > maxidx_ ) curidx = maxidx_; }
57 
58 
59 template <class T>
61  T pos ) const
62 {
63  if ( !extrapol_ && (pos < -snapdist_ || pos > maxidx_ + snapdist_) )
64  return udfval_;
65  else if ( maxidx_ < 1 )
66  return vda.value( 0 );
67 
68  int curidx = mNINT32(pos); mChkVSIRg
69  if ( !smooth_ || mIsEqual(pos,curidx,snapdist_) )
70  return vda.value( curidx );
71 
72  T v[4]; const int lopos = (int)pos;
73  curidx = lopos - 1; mChkVSIRg; v[0] = vda.value( curidx );
74  curidx = lopos; mChkVSIRg; v[1] = vda.value( curidx );
75  curidx = lopos + 1; mChkVSIRg; v[2] = vda.value( curidx );
76  curidx = lopos + 2; mChkVSIRg; v[3] = vda.value( curidx );
77 
78  pos -= lopos; // now 0 < pos < 1
79  T rv;
80  if ( !isperiodic_ )
81  {
82  if ( linear_ )
83  {
84  if ( hasudfs_ && (mIsUdf(v[1]) || mIsUdf(v[2])) )
85  rv = pos < 0.5 ? v[1] : v[2];
86  else
87  rv = pos*v[2] + (1-pos)*v[1];
88  }
89  else
90  rv = hasudfs_
91  ? Interpolate::polyReg1DWithUdf( v[0], v[1], v[2], v[3], pos )
92  : Interpolate::polyReg1D( v[0], v[1], v[2], v[3], pos );
93  }
94  else
95  {
96  if ( hasudfs_ )
97  {
98  if ( mIsUdf(v[0]) ) v[0] = v[1];
99  if ( mIsUdf(v[3]) ) v[3] = v[2];
100  if ( mIsUdf(v[1]) || mIsUdf(v[2]) )
101  return udfval_;
102  }
103  pos += 1; // now 1 < pos < 2
104  rv = IdxAble::interpolateYPeriodicReg( v, 4, pos, period_, false );
105  }
106  if ( mIsUdf(rv) )
107  rv = udfval_;
108 
109  return rv;
110 }
111 
112 #undef mChkVSIRg
113 
114 
115 #endif
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
virtual T value(int64_t) const =0
T period_
Definition: valseriesinterpol.h:48
bool linear_
Definition: valseriesinterpol.h:49
#define mChkVSIRg
Definition: valseriesinterpol.h:54
T polyReg1D(T vm1, T v0, T v1, T v2, float x)
Definition: interpol1d.h:130
T value(const ValueSeries< T > &, T pos) const
Definition: valseriesinterpol.h:60
#define mIsEqual(x, y, eps)
Definition: commondefs.h:54
bool isperiodic_
Definition: valseriesinterpol.h:46
int maxidx_
Definition: valseriesinterpol.h:41
#define mNINT32(x)
Definition: commondefs.h:45
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
Interface to a series of values.
Definition: odmemory.h:17
Definition: valseriesinterpol.h:25
void interpolateYPeriodicReg(const T &idxabl, int sz, float pos, RT &ret, RT period, bool extrapolate=false)
Definition: periodicvalue.h:127
bool extrapol_
Definition: valseriesinterpol.h:45
T snapdist_
Definition: valseriesinterpol.h:42
ValueSeriesInterpolator(int mxidx=mUdf(int))
Definition: valseriesinterpol.h:28
#define mClass(module)
Definition: commondefs.h:164
bool smooth_
Definition: valseriesinterpol.h:44
bool hasudfs_
Definition: valseriesinterpol.h:47
T udfval_
Definition: valseriesinterpol.h:43

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019