OpendTect-6_4  6.4
samplfunc.h
Go to the documentation of this file.
1 #ifndef samplfunc_h
2 #define samplfunc_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Kristofer Tingdahl
9  Date: 07-10-1999
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "mathfunc.h"
16 #include "periodicvalue.h"
17 
25 template <class RT,class T>
27 {
28 public:
29  SampledFunction( bool periodic_= false )
30  : periodic( periodic_ ) {}
31 
32  virtual RT operator[](od_int64) const = 0;
33 
34  virtual float getDx() const = 0;
35  virtual float getX0() const = 0;
36 
37  virtual int size() const = 0;
38 
39  virtual float period() const { return mUdf(float); }
40  void setPeriodic( bool np ) { periodic = np; }
41 
42  float getIndex(float x) const
43  { return (x-getX0()) / getDx(); }
44 
45  int getNearestIndex(float x) const
46  { return mNINT32(getIndex( x )); }
47 
48  RT getValue( RT x ) const
49  {
50  if ( !doInterpolate() )
51  {
52  const int smpl = mNINT32( getIndex(x) );
53  if ( smpl<0 || smpl>=size() )
54  return mUdf(RT);
55  return (*this)[smpl];
56  }
57 
58  if ( periodic )
59  {
60  return
62  *this, size(),
63  getIndex(x), period(),
64  extrapolate());
65  }
66 
67  return hasUdfs()
69  size(), getIndex(x),
70  extrapolate())
71  : IdxAble::interpolateReg( *this,
72  size(), getIndex(x),
73  extrapolate());
74  }
75 
76  RT getValue( const RT* x ) const
77  { return getValue(*x); }
78 
79 protected:
80  bool periodic;
81 
82 
83  virtual bool extrapolate() const { return false; }
84  virtual bool hasUdfs() const { return false; }
85  virtual bool doInterpolate() const { return true; }
86 };
87 
88 
93 template <class RT, class T>
95 {
96 public:
97  SampledFunctionImpl(const T& idxabl,int sz,
98  float x0=0,float dx=1 )
99  : idxabl_( idxabl )
100  , sz_( sz )
101  , x0_( x0 )
102  , dx_( dx )
103  , period_ ( mUdf(float) )
104  , hasudfs_( false )
105  , interpolate_( true )
106  {}
107 
108  RT operator[](od_int64 idx) const { return idxabl_[idx];}
109 
110  float getDx() const { return dx_; }
111  float getX0() const { return x0_; }
112 
113  int size() const { return sz_; }
114 
115  float period() const { return period_; }
116  void setPeriod(float np) { period_ = np; }
117 
118  bool hasUdfs() const { return hasudfs_; }
119  void setHasUdfs(bool yn) { hasudfs_=yn; }
120 
121  bool doInterpolate() const { return interpolate_; }
122  void setInterpolate( bool yn ) { interpolate_=yn; }
123 
124 protected:
125 
126  const T& idxabl_;
127  int sz_;
129 
130  float dx_;
131  float x0_;
132 
133  float period_;
134  bool hasudfs_;
136 };
137 
138 #endif
bool interpolate_
Definition: samplfunc.h:135
void setPeriod(float np)
Definition: samplfunc.h:116
bool periodic
Definition: samplfunc.h:80
virtual bool extrapolate() const
Definition: samplfunc.h:83
float getIndex(float x) const
Definition: samplfunc.h:42
bool interpolateReg(const T &idxabl, int sz, float pos, RT &ret, bool extrapolate=false, float snapdist=mDefEps)
Definition: idxable.h:273
void setInterpolate(bool yn)
Definition: samplfunc.h:122
#define od_int64
Definition: plftypes.h:36
Mathematical function.
Definition: mathfunc.h:61
float period_
Definition: samplfunc.h:133
void setHasUdfs(bool yn)
Definition: samplfunc.h:119
virtual bool doInterpolate() const
Definition: samplfunc.h:85
int size() const
Definition: samplfunc.h:113
RT getValue(RT x) const
Definition: samplfunc.h:48
#define mNINT32(x)
Definition: commondefs.h:45
int sz_
Definition: samplfunc.h:127
int firstidx_
Definition: samplfunc.h:128
SampledFunction(bool periodic_=false)
Definition: samplfunc.h:29
float getX0() const
Definition: samplfunc.h:111
float period() const
Definition: samplfunc.h:115
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
SampledFunctionImpl(const T &idxabl, int sz, float x0=0, float dx=1)
Definition: samplfunc.h:97
RT operator[](od_int64 idx) const
Definition: samplfunc.h:108
void interpolateYPeriodicReg(const T &idxabl, int sz, float pos, RT &ret, RT period, bool extrapolate=false)
Definition: periodicvalue.h:127
bool interpolateRegWithUdf(const T &idxabl, int sz, float pos, RT &ret, bool extrapolate=false, float snapdist=mDefEps)
Definition: idxable.h:314
float dx_
Definition: samplfunc.h:130
virtual float period() const
Definition: samplfunc.h:39
float getDx() const
Definition: samplfunc.h:110
RT getValue(const RT *x) const
Definition: samplfunc.h:76
const RefTree & RT()
virtual bool hasUdfs() const
Definition: samplfunc.h:84
bool hasudfs_
Definition: samplfunc.h:134
float x0_
Definition: samplfunc.h:131
Implementation for array-type of SampledFunction.
Definition: samplfunc.h:94
#define mClass(module)
Definition: commondefs.h:164
bool hasUdfs() const
Definition: samplfunc.h:118
void setPeriodic(bool np)
Definition: samplfunc.h:40
int getNearestIndex(float x) const
Definition: samplfunc.h:45
Make any sampled series comply with MathFunction.
Definition: samplfunc.h:26
const T & idxabl_
Definition: samplfunc.h:126
bool doInterpolate() const
Definition: samplfunc.h:121

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