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

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